index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="contact">
  3. <view class="head">
  4. <view class="title">
  5. <image class="img-title" src="/static/img/contact/head_title.png" mode="aspectFill" />
  6. </view>
  7. <view class="tel">
  8. <image class="tel-img" src="/static/img/contact/icon_phone.png" mode="aspectFill" />
  9. </view>
  10. </view>
  11. <view class="form-warpper">
  12. <view class="input-content-wrapper">
  13. <form @submit="formSubmit" @reset="formReset">
  14. <view class="input-content">
  15. <view class="iconfont">
  16. <image class="image" src="/static/img/contact/icon_01.png" mode="aspectFill" />
  17. </view>
  18. <view class="flex align-center">
  19. <input class="uni-input" v-model="form.customer_name" name="customerName" placeholder="请输入您的姓名" />
  20. </view>
  21. </view>
  22. <view class="input-content">
  23. <view class="iconfont">
  24. <image class="image" src="/static/img/contact/icon_02.png" mode="aspectFill" />
  25. </view>
  26. <view class="flex align-center">
  27. <input class="uni-input" maxlength="11" v-model="form.mobile" name="mobile" placeholder="请输入联系方式" />
  28. </view>
  29. </view>
  30. <view class="input-content">
  31. <view class="iconfont">
  32. <image class="image" src="/static/img/contact/icon_03.png" mode="aspectFill" />
  33. </view>
  34. <view class="area flex align-center">
  35. <pick-regions name="regionCode" :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
  36. <text :class="['regions', regionName ? '' : 'empty']" >{{ regionName || '请选择所在地区' }}</text>
  37. </pick-regions>
  38. <!-- <input class="uni-input" v-model="form.parentName" name="parentName" placeholder="请选择所在地区" /> -->
  39. <image class="arrow" src="/static/img/contact/down.png" mode="aspectFill" />
  40. </view>
  41. </view>
  42. <view class="input-content">
  43. <view class="iconfont">
  44. <image class="image" src="/static/img/contact/icon_04.png" mode="aspectFill" />
  45. </view>
  46. <view class="area flex align-center">
  47. <picker mode="selector" name="type" @change="typeChange" :value="typeIndex" :range="typeList" range-key="label">
  48. <view class="empty" v-if="typeIndex == -1">
  49. {{ '您的意向' }}
  50. </view>
  51. <view v-else>
  52. {{ typeList[typeIndex] }}
  53. </view>
  54. </picker>
  55. <!-- <input class="uni-input" v-model="form.parentName" name="parentName" placeholder="您的意向" /> -->
  56. <image class="arrow" src="/static/img/contact/down.png" mode="aspectFill" />
  57. </view>
  58. </view>
  59. <view class="submit-btn">
  60. <image src="/static/img/contact/submit.png" mode="aspectFill" />
  61. <button class="confirm-btn" :disabled="disabled" form-type="submit"></button>
  62. <button form-type="reset" ref="resrtBtn" style="display:none;">取消</button>
  63. </view>
  64. </form>
  65. </view>
  66. </view>
  67. <view class="adderss flex align-start">
  68. <view class="text">
  69. <view>
  70. 地址:北京市朝阳区高碑店乡西店记忆文创小镇E6号楼
  71. </view>
  72. <view>
  73. 一层102号
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import pickRegions from '@/components/pick-regions/pick-regions.vue';
  81. import { saveApply } from '@/api/apply';
  82. export default {
  83. data() {
  84. return {
  85. disabled:false,
  86. form: {
  87. customer_name: '',
  88. mobile: '',
  89. type: 0
  90. },
  91. region:[],
  92. defaultRegionCode: '110101',
  93. defaultRegion:['北京市','市辖区','东城区'],
  94. typeIndex: -1,
  95. typeList: ["教学渠道代理", "思维芯游戏教室渠道代理", "家庭版渠道代理", "HOME&PLUS渠道代理", "探索小镇渠道代理(TOWN)", "合作园所(北京地区园所)"],
  96. reqBody: {}
  97. }
  98. },
  99. computed: {
  100. regionName: {
  101. get: function() {
  102. return this.region.map(item=>item.name).join('/')
  103. },
  104. set: function(val) {
  105. if(val) {
  106. this.region = val.map(item => {
  107. return {
  108. name: item
  109. }
  110. })
  111. }
  112. return val;
  113. }
  114. },
  115. regionCode() {
  116. if (this.region.length > 0) {
  117. return this.region[this.region.length - 1].code;
  118. } else {
  119. return this.defaultRegionCode;
  120. }
  121. }
  122. },
  123. components: {
  124. pickRegions
  125. },
  126. methods: {
  127. formSubmit(e) {
  128. console.log(e.detail.value);
  129. console.log(this.typeIndex);
  130. // {
  131. // "entity": {
  132. // "customer_name": "李哈哈测试22",
  133. // "mobile": "13120373714",
  134. // "address": "xxxxx"
  135. // },
  136. // "field": [{
  137. // "fieldId": 135,
  138. // "fieldName": "代理商类型",
  139. // "value": "教学渠道代理",
  140. // }]
  141. // }
  142. let formData = e.detail.value;
  143. let rules = [
  144. { name: 'customerName', checkType: 'notnull', checkRule: '', errorMsg: '请填写姓名' },
  145. { name: 'customerName', checkType: 'string', checkRule: '2,8', errorMsg: '请输入2-8位姓名' },
  146. { name: 'type', checkType: 'in', checkRule: '0, 1, 2, 3, 4, 5', errorMsg: '意向不能为空' },
  147. { name: 'mobile', checkType: 'notnull', checkRule: '', errorMsg: '请填写联系方式'},
  148. { name: 'mobile', checkType: 'phoneno', checkRule: '', errorMsg: '联系方式不正确'},
  149. ]
  150. let regionRule = [
  151. { name: 'regionCode', checkType: 'notnull', checkRule: '', errorMsg: '请选择所在地区'},
  152. ];
  153. this.reqBody['regionCode'] = this.region;
  154. let checkRes = this.$mGraceChecker.check(formData, rules);
  155. if (!checkRes) {
  156. // this.disabled = true;
  157. this.$mHelper.toast(this.$mGraceChecker.error);
  158. return false;
  159. }
  160. let regionRes = this.$mGraceChecker.check(this.reqBody, regionRule)
  161. if (!regionRes) {
  162. this.$mHelper.toast(this.$mGraceChecker.error);
  163. return false;
  164. }
  165. if (this.typeIndex == -1) {
  166. this.$mHelper.toast('请选择您的意向');
  167. return false;
  168. }
  169. let entity = {
  170. customer_name: formData.customerName,
  171. mobile: formData.mobile,
  172. address: this.region.map(item=>item.name).join(',')
  173. };
  174. let field = [{
  175. fieldId: 135,
  176. name: "代理商类型",
  177. value: this.typeList[this.typeIndex]
  178. }];
  179. if (checkRes && regionRes && this.typeIndex != -1) {
  180. this.disabled = true;
  181. this.$http.post(saveApply, {
  182. entity,
  183. field
  184. }).then(res=> {
  185. this.$mHelper.toast('提交成功!我们会在在第一时间内联系您');
  186. this.$refs.resrtBtn.$dispatch('Form', 'uni-form-reset', {
  187. type: 'reset'
  188. })
  189. this.typeIndex = -1;
  190. this.region = [];
  191. this.disabled = false;
  192. }).catch(err => {
  193. this.disabled = false;
  194. console.log('err')
  195. })
  196. }
  197. },
  198. typeChange(e) {
  199. const index = e.detail.value;
  200. this.typeIndex = index;
  201. // this.form.sex = this.genderList[index].value;
  202. },
  203. // 获取选择的地区
  204. handleGetRegion(region){
  205. this.region = region
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .contact {
  212. padding: 86upx 0 120upx;
  213. background: url('@/static/img/contact/bg.png') no-repeat #01A2E8;
  214. background-size: cover;
  215. .title {
  216. text-align: center;
  217. .img-title {
  218. width: 598upx;
  219. height: 168upx;
  220. vertical-align: middle;
  221. }
  222. }
  223. .tel {
  224. margin-top: 36upx;
  225. .tel-img {
  226. width: 564upx;
  227. height: 134upx;
  228. vertical-align: middle;
  229. margin-left: 68upx;
  230. }
  231. }
  232. .form-warpper {
  233. margin-top: 52upx;
  234. padding: 0 96upx;
  235. }
  236. .input-content-wrapper {
  237. margin-bottom: 0upx
  238. }
  239. .input-content {
  240. display: flex;
  241. align-items: center;
  242. box-sizing: border-box;
  243. height: 100upx;
  244. border: 2upx solid #003F66;
  245. margin-bottom: 36upx;
  246. padding: 0 42upx 0 42upx;
  247. background: #FFFFFF;
  248. border-radius: 172upx;
  249. .iconfont {
  250. position: relative;
  251. margin-right: 52upx;
  252. &::after {
  253. content: "";
  254. width: 2upx;
  255. height: 34upx;
  256. background:#B9B9B9;
  257. border-radius: 4upx;
  258. position: absolute;
  259. top: 4upx;
  260. right: -26upx;
  261. }
  262. image {
  263. width: 40upx;
  264. height: 46upx;
  265. vertical-align: middle;
  266. }
  267. }
  268. .input-placeholder {
  269. color: #B9B9B9;
  270. line-height: 36px;
  271. font-size: 28upx;
  272. font-family: PingFangSC-Regular, PingFang SC;
  273. font-weight: 400;
  274. }
  275. .area {
  276. width: 100%;
  277. }
  278. uni-picker {
  279. width: 100%;
  280. }
  281. .regions {
  282. &.empty {
  283. color: #B9B9B9;
  284. line-height: 36px;
  285. font-size: 28upx;
  286. font-family: PingFangSC-Regular, PingFang SC;
  287. font-weight: 400;
  288. }
  289. }
  290. .empty {
  291. color: #B9B9B9;
  292. line-height: 36px;
  293. font-size: 28upx;
  294. font-family: PingFangSC-Regular, PingFang SC;
  295. font-weight: 400;
  296. }
  297. .picker {
  298. color: #B9B9B9;
  299. line-height: 36px;
  300. font-size: 28upx;
  301. font-family: PingFangSC-Regular, PingFang SC;
  302. font-weight: 400;
  303. }
  304. .arrow {
  305. width: 24upx;
  306. height: 12upx;
  307. vertical-align: middle;
  308. }
  309. }
  310. .submit-btn {
  311. position: relative;
  312. margin-top: 94upx;
  313. text-align: center;
  314. image {
  315. width: 334upx;
  316. height: 92upx;
  317. vertical-align: middle;
  318. }
  319. .confirm-btn {
  320. position: absolute;
  321. bottom: 0;
  322. left: 50%;
  323. transform: translateX(-50%);
  324. width: 334upx;
  325. height: 92upx;
  326. background: red;
  327. opacity: 0;
  328. }
  329. }
  330. .adderss {
  331. margin: 150upx 0 0 60upx;
  332. .text {
  333. font-size: 24upx;
  334. font-family: PingFangSC-Semibold, PingFang SC;
  335. font-weight: 600;
  336. color: #B2E8FF;
  337. line-height: 34upx;
  338. }
  339. }
  340. }
  341. </style>