ApplyForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view :class="['qn-page-' + theme]">
  3. <block v-if="apply_set.applyProp">
  4. <view v-if="apply_set.banner_img"><image :src="apply_set.banner_img" mode="aspectFill" class="top-img"></image></view>
  5. <view class="apply-form" v-if="apply_set.applyProp">
  6. <u-form :model="apply_form" ref="applyForm" label-position="top" :label-width="120">
  7. <block v-for="(item, index) in apply_term" :key="index">
  8. <block v-if="item.is_enable">
  9. <u-form-item :label="item.name" v-if="item.type === 1" :required="item.is_required">
  10. <u-input v-if="item.data_type === 1" v-model="apply_form[item.prop]" />
  11. <u-input v-if="item.data_type === 2" v-model="apply_form[item.prop]" type="textarea" />
  12. <RegionSel @pickerRegionChange="pickerRegionChange($event, index)" v-if="item.data_type === 3">
  13. <span v-if="apply_form[item.prop]">{{ apply_form[item.prop] }}</span>
  14. <span style="color: #999;" v-else>请选择</span>
  15. </RegionSel>
  16. <QiniuUpload @uploadSuccess="uploadLicense($event, index, item.prop)" v-if="item.data_type === 4">
  17. <div slot="cont">
  18. <view class="user-img-license">
  19. <img v-if="apply_form[item.prop]" class="license-pic" :src="apply_form[item.prop]" alt="" />
  20. <text v-else>+</text>
  21. </view>
  22. </div>
  23. </QiniuUpload>
  24. <view @click="openLocation(index)" v-if="item.data_type === 5">
  25. <span v-if="apply_form[item.prop]">{{ apply_form[item.prop] }}</span>
  26. <span style="color: #999;" v-else>请选择</span>
  27. </view>
  28. </u-form-item>
  29. <u-form-item :label="item.name" :required="item.is_required" v-else>
  30. <u-input v-if="item.data_type === 1" @blur="inputBlur($event, index)" :value="apply_form.info[index - form_length].value" />
  31. <u-input v-if="item.data_type === 2" @blur="inputBlur($event, index)" :value="apply_form.info[index - form_length].value" type="textarea" />
  32. <RegionSel @pickerRegionChange="pickerRegionChange($event, index)" v-if="item.data_type === 3">
  33. <span v-if="apply_form.info[index - form_length].value">{{ apply_form.info[index - form_length].value }}</span>
  34. <span style="color: #999;" v-else>请选择</span>
  35. </RegionSel>
  36. <QiniuUpload @uploadSuccess="uploadLicense($event, index)" v-if="item.data_type === 4">
  37. <div slot="cont">
  38. <view class="user-img-license">
  39. <img v-if="apply_form.info[index - form_length].value" class="license-pic" :src="apply_form.info[index - form_length].value" alt="" />
  40. <text v-else>+</text>
  41. </view>
  42. </div>
  43. </QiniuUpload>
  44. </u-form-item>
  45. </block>
  46. </block>
  47. </u-form>
  48. <view class="agreement" v-if="apply_set.settlement === 5">
  49. <text class="ibonfont" :class="[is_agree ? 'ibonxuanze1 primary-color' : 'ibonweixuanze']" @click="is_agree = !is_agree"></text>
  50. <text @click="is_agree = !is_agree">我已阅读并同意</text>
  51. <text class="agreement-name primary-color" @click="agreement_show = true">《入驻申请协议》</text>
  52. </view>
  53. </view>
  54. <view class="btn-bottom">
  55. <view class="btn-li primary-btn-pain" @click="goPage('/pages/index/index', 'switchTab')">回到首页</view>
  56. <view class="btn-li primary-btn" @click="MerchantApply">申请入驻</view>
  57. </view>
  58. <u-popup v-model="agreement_show" :width="600" mode="center" border-radius="14">
  59. <view class="agreement_view">
  60. <view class="agreement_tit">{{ apply_set.settlement_set || '入驻申请协议' }}</view>
  61. <view class="agreement_main"><u-input disabled :value="apply_set.settlement_content" type="textarea" :border="false" :height="100" :auto-height="true" /></view>
  62. <view class="primary-btn agreement_btn" @click="agreement_show = false">我知道了</view>
  63. </view>
  64. </u-popup>
  65. </block>
  66. <block v-else>
  67. <!-- 空白页 -->
  68. <Aempty text="该商家未开通商户入驻,敬请期待" src="https://onlineimg.qianniao.vip/data.png"></Aempty>
  69. </block>
  70. </view>
  71. </template>
  72. <script>
  73. import RegionSel from '../../components/region/RegionSel.vue';
  74. import QiniuUpload from '../../components/qiniu/QiniuUpload.vue';
  75. import webUrl from '@/config.js';
  76. export default {
  77. components: {
  78. RegionSel,
  79. QiniuUpload
  80. },
  81. props: {
  82. merchantInfo: {
  83. type: Object,
  84. default: () => {
  85. return {};
  86. }
  87. }
  88. },
  89. data() {
  90. return {
  91. agreement_show: false,
  92. is_agree: false,
  93. apply_form: {
  94. info: [],
  95. userCenterId: '',
  96. provinceCode: '',
  97. cityCode: '',
  98. districtCode: '',
  99. latitude: '', //经度
  100. longitude: '' // 纬度
  101. },
  102. apply_set: {},
  103. apply_term: [
  104. {
  105. origin_name: '联系人姓名',
  106. name: '联系人姓名',
  107. prop: 'contactName',
  108. is_enable: true,
  109. is_required: true,
  110. data_type: 1,
  111. type: 1,
  112. disable: true
  113. },
  114. {
  115. origin_name: '联系方式',
  116. name: '联系方式',
  117. prop: 'contactMobile',
  118. is_enable: true,
  119. is_required: true,
  120. data_type: 1,
  121. disable: true,
  122. type: 1
  123. },
  124. {
  125. origin_name: '商户名称',
  126. name: '商户名称',
  127. prop: 'name',
  128. is_enable: true,
  129. is_required: true,
  130. data_type: 1,
  131. disable: true,
  132. type: 1
  133. },
  134. {
  135. origin_name: '主营类目',
  136. name: '主营类目',
  137. prop: 'category',
  138. is_enable: true,
  139. is_required: true,
  140. data_type: 1,
  141. type: 1
  142. },
  143. {
  144. origin_name: '商户地区',
  145. name: '商户地区',
  146. prop: 'regionName',
  147. is_enable: true,
  148. is_required: true,
  149. data_type: 3,
  150. type: 1
  151. },
  152. {
  153. origin_name: '详细地址',
  154. name: '详细地址',
  155. prop: 'address',
  156. is_enable: true,
  157. is_required: true,
  158. data_type: 1,
  159. type: 1
  160. },
  161. {
  162. origin_name: '商户简介',
  163. name: '商户简介',
  164. prop: 'desc',
  165. is_enable: true,
  166. is_required: true,
  167. data_type: 2,
  168. type: 1
  169. },
  170. {
  171. origin_name: '营业执照',
  172. name: '营业执照',
  173. prop: 'license',
  174. is_enable: true,
  175. is_required: true,
  176. data_type: 4,
  177. type: 1
  178. }
  179. ],
  180. form_length: 8
  181. };
  182. },
  183. created() {
  184. this.MerchantGetSeting();
  185. // 获取客户的ID
  186. this.apply_form.userCenterId = this.$store.state.userStatus.id;
  187. },
  188. methods: {
  189. openLocation(index) {
  190. // uni.setStorageSync('12', '213');
  191. // #ifdef MP-WEIXIN
  192. uni.chooseLocation({
  193. success: res => {
  194. console.log(res);
  195. // const location = this.$_utils.getArea(res.address);
  196. this.apply_form.address = res.name;
  197. this.apply_form.latitude = res.latitude;
  198. this.apply_form.longitude = res.longitude;
  199. console.log(this.apply_form);
  200. }
  201. });
  202. // #endif
  203. // #ifdef APP-PLUS || MP-TOUTIAO
  204. // this.goPage('/pages/index/SearchAddress');
  205. // #endif
  206. },
  207. // 获取设置(小程序)
  208. MerchantGetSeting() {
  209. this.$u.api.MerchantGetSeting().then(res => {
  210. this.apply_set = res.data;
  211. uni.setNavigationBarTitle({
  212. title: res.data.apply_title || '入驻申请'
  213. });
  214. if (this.apply_set.applyProp) {
  215. // 获取没有禁用的字段
  216. this.apply_term = this.apply_set.applyProp.filter(item => item.is_enable);
  217. // 获取系统自带字段的length
  218. this.form_length = this.apply_term.filter(item => item.type === 1).length;
  219. // 把字段放进form的obj里
  220. this.apply_term.forEach((item, index) => {
  221. if (item.type === 1) {
  222. // 系统自带字段直接放入
  223. this.apply_form[item.prop] = '';
  224. } else {
  225. // 自定义字段塞进info对象里面
  226. this.apply_form.info.push({
  227. name: item.name,
  228. value: ''
  229. });
  230. }
  231. });
  232. // 重新申请,获取之前填写的信息
  233. if (this.merchantInfo.id) {
  234. for (let i in this.apply_form) {
  235. if (this.merchantInfo[i]) {
  236. this.apply_form[i] = this.merchantInfo[i];
  237. }
  238. }
  239. if (this.merchantInfo.area) {
  240. this.apply_form.regionName = `${this.merchantInfo.area.provinceName}-${this.merchantInfo.area.cityName}-${this.merchantInfo.area.districtName}`;
  241. }
  242. this.apply_form.userCenterId = this.$store.state.userStatus.id;
  243. }
  244. }
  245. });
  246. },
  247. // 立即申请
  248. MerchantApply() {
  249. // 验证必填项
  250. let isSubmit = true;
  251. for (let i in this.apply_term) {
  252. let item = this.apply_term[i];
  253. if (item.type === 1) {
  254. // 判断系统自带字段的必填项
  255. if (item.is_required && !this.apply_form[item.prop]) {
  256. this.$api.msg(`${item.name}不能为空`);
  257. isSubmit = false;
  258. break;
  259. }
  260. } else {
  261. // 判断自定义字段的必填项
  262. if (i - this.form_length >= 0) {
  263. if (item.is_required && !this.apply_form.info[i - this.form_length].value) {
  264. this.$api.msg(`${item.name}不能为空`);
  265. isSubmit = false;
  266. break;
  267. }
  268. }
  269. }
  270. }
  271. // 如果有必填项没有值的,不允许提交
  272. if (!isSubmit) {
  273. return;
  274. }
  275. if (this.apply_set.settlement === 5 && !this.is_agree) {
  276. this.$api.msg('请先阅读并勾选入驻申请协议');
  277. return;
  278. }
  279. if (this.merchantInfo.id) {
  280. // 入住申请修改(小程序)
  281. this.$u.api.updateApply(this.merchantInfo.id, this.apply_form).then(res => {
  282. this.$api.msg('已申请');
  283. this.$emit('applySuccess');
  284. });
  285. } else {
  286. this.$u.api.MerchantApply(this.apply_form).then(res => {
  287. this.$api.msg('已申请');
  288. this.$emit('applySuccess');
  289. });
  290. }
  291. },
  292. // 上传图片
  293. uploadLicense(res, index, prop) {
  294. let target = this.$u.deepClone(this.apply_form);
  295. const uploadPicUrl = `${webUrl.QINIU_URL}/${res.key}`;
  296. if (index <= this.form_length) {
  297. target.license = uploadPicUrl;
  298. } else {
  299. target.info[index - this.form_length].value = uploadPicUrl;
  300. }
  301. this.apply_form = target;
  302. },
  303. // 输入框失去焦点
  304. // 也不知道为什么使用 v-model 双向绑定不行,所以只能使用失去焦点事件了
  305. inputBlur(val, index) {
  306. this.apply_form.info[index - this.form_length].value = val;
  307. },
  308. // 地区
  309. pickerRegionChange(row, index) {
  310. if (index <= this.form_length) {
  311. this.apply_form.provinceCode = row[0].value;
  312. this.apply_form.cityCode = row[1].value;
  313. this.apply_form.districtCode = row[2].value;
  314. this.apply_form.regionName = `${row[0].label}-${row[1].label}-${row[2].label}`;
  315. } else {
  316. this.apply_form.info[index - this.form_length].value = `${row[0].label}-${row[1].label}-${row[2].label}`;
  317. }
  318. }
  319. }
  320. };
  321. </script>
  322. <style>
  323. page {
  324. background-color: #ffffff;
  325. }
  326. </style>
  327. <style scoped lang="scss">
  328. .top-img {
  329. width: 750rpx;
  330. height: 320rpx;
  331. }
  332. .apply-form {
  333. padding: 0 30rpx;
  334. padding-bottom: 120rpx;
  335. }
  336. .agreement_view {
  337. padding: 30rpx;
  338. .agreement_tit {
  339. font-size: 32rpx;
  340. font-weight: bold;
  341. padding: 30rpx 0;
  342. text-align: center;
  343. }
  344. .agreement_main {
  345. font-size: 26rpx;
  346. line-height: 36rpx;
  347. color: #666666;
  348. }
  349. .agreement_btn {
  350. border-radius: 8rpx;
  351. width: 300rpx;
  352. text-align: center;
  353. line-height: 70rpx;
  354. color: #ffffff;
  355. margin: 60rpx auto 30rpx;
  356. height: 70rpx;
  357. }
  358. }
  359. .btn-bottom {
  360. position: fixed;
  361. bottom: 0;
  362. left: 0;
  363. width: 100%;
  364. padding: 20rpx;
  365. display: flex;
  366. background-color: #ffffff;
  367. border-top: 1px solid #f4f4f4;
  368. z-index: 9;
  369. .btn-li {
  370. flex: 2;
  371. line-height: 70rpx;
  372. text-align: center;
  373. border-radius: 8rpx;
  374. &:first-child {
  375. border: 1px solid #f53c28;
  376. margin-right: 10rpx;
  377. }
  378. &:last-child {
  379. color: #ffffff;
  380. margin-left: 10px;
  381. }
  382. }
  383. }
  384. .agreement {
  385. font-size: 24rpx;
  386. line-height: 60rpx;
  387. .ibonfont {
  388. font-size: 24rpx;
  389. margin-right: 10rpx;
  390. color: #666666;
  391. }
  392. }
  393. .user-img-license {
  394. width: 120upx;
  395. height: 120upx;
  396. border-radius: 8upx;
  397. margin: 32upx auto;
  398. background: #f4f5f6;
  399. text-align: center;
  400. line-height: 100upx;
  401. color: #999999;
  402. font-size: 100rpx;
  403. font-weight: 300;
  404. }
  405. .license-pic {
  406. width: 120upx;
  407. height: 120upx;
  408. }
  409. </style>