apply.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <!-- 申请分销商 -->
  2. <template>
  3. <view class="apply-commission-wrap">
  4. <!-- 标题栏 -->
  5. <view class="head-box" :style="{ backgroundImage: ' url(' + formHeadImg + ')' }">
  6. <shopro-navbar back-icon-color="#fff" :background="{}"></shopro-navbar>
  7. </view>
  8. <!-- 表单 -->
  9. <view class="apply-form">
  10. <u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
  11. <block v-for="(form, index) in formList" :key="index">
  12. <u-form-item v-if="form.type === 'input'" :labelStyle="labelStyle"   label-width="150" label-position="left" :label="form.name" :prop="`value${index}`">
  13. <u-input
  14. :disabled="!hasPostBtn"
  15. :placeholder="`请输入${form.name}`"
  16. :placeholderStyle="placeholderStyle"
  17. v-model="model['value' + index]"
  18. type="text"
  19. ></u-input>
  20. </u-form-item>
  21. <u-form-item v-if="form.type === 'number'" :labelStyle="labelStyle" label-position="left" :label="form.name" :prop="`value${index}`" label-width="150">
  22. <u-input
  23. :disabled="!hasPostBtn"
  24. :placeholder="`请输入${form.name}`"
  25. :placeholderStyle="placeholderStyle"
  26. v-model="model['value' + index]"
  27. type="number"
  28. ></u-input>
  29. </u-form-item>
  30. <u-form-item
  31. v-if="form.type === 'image'"
  32. :labelStyle="labelStyle"
  33. :prop="`value${index}`"
  34. :label="form.name"
  35. label-position="top"
  36. label-width="150"
  37. :borderBottom="true"
  38. >
  39. <u-upload
  40. :deletable="hasPostBtn"
  41. :placeholderStyle="placeholderStyle"
  42. :showProgress="false"
  43. @on-uploaded="uploadSuccess($event, `value${index}`)"
  44. @on-remove="uploadRemove($event, `value${index}`)"
  45. :file-list="model[`valueList${index}`]"
  46. :action="`${$API_URL}/index/upload`"
  47. width="148"
  48. height="148"
  49. maxCount="1"
  50. ></u-upload>
  51. </u-form-item>
  52. </block>
  53. <view class="agreement u-flex" v-if="protocol && hasPostBtn">
  54. <u-checkbox v-model="model.agreement" activeColor="#b095ff" shape="circle" @change="onAgreement"></u-checkbox>
  55. <view class="agreement-text" @tap="$Router.push({ path: '/pages/public/richtext', query: { id: protocol.richtext_id } })">
  56. 我已阅读并遵守
  57. <text class="text-underline">{{ protocol.name }}</text>
  58. </view>
  59. </view>
  60. <button class="u-reset-button save-btn" v-if="hasPostBtn" @tap="onSubmit" :disabled="isFormEnd">确认提交</button>
  61. </u-form>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. components: {},
  68. data() {
  69. return {
  70. formList: [], //返回的表单
  71. formHeadImg: '', //表单头部背景
  72. protocol: null, //协议
  73. isFormEnd: false, //提交成功
  74. hasPostBtn: false, //是否显示提交按钮
  75. errorType: ['message'],
  76. labelStyle: {
  77. 'font-size': '28rpx',
  78. 'font-weight': '500',
  79. color: '#333'
  80. },
  81. placeholderStyle: 'font-size: 28rpx;color:#c4c4c4;',
  82. model: {},
  83. inputNumber: [
  84. {
  85. required: true,
  86. message: '内容不能为空!',
  87. trigger: ['change', 'blur']
  88. }
  89. ],
  90. inputImage: [
  91. {
  92. required: true,
  93. message: '请上传图片',
  94. trigger: ['change', 'blur']
  95. }
  96. ],
  97. rules: {}
  98. };
  99. },
  100. computed: {},
  101. onLoad() {
  102. this.getFrom();
  103. },
  104. methods: {
  105. // 上传图片成功-单图
  106. uploadSuccess(e, value) {
  107. this.model[value] = e[0].response.data.url;
  108. },
  109. // 移除图片
  110. uploadRemove(index, value) {
  111. this.model[value] = '';
  112. },
  113. // 勾选同意
  114. onAgreement(e) {
  115. this.model.agreement = e.value;
  116. },
  117. // 获取申请分销商表单
  118. getFrom() {
  119. let that = this;
  120. that.$http('commission.form').then(res => {
  121. if (res.code === 1) {
  122. that.protocol = res.data.apply_protocol; //表单协议同
  123. that.formList = res.data.apply_info; //表单
  124. that.hasPostBtn = res.data.apply_status; //是否显示提交按钮
  125. that.formHeadImg = res.data.background_image ? res.data.background_image : this.$IMG_URL + '/imgs/commission/apply_bg.png'; //头部背景
  126. that.initRules(); //规则
  127. that.$refs.uForm.setRules(that.rules);
  128. }
  129. });
  130. },
  131. // 构建验证规则
  132. initRules() {
  133. let that = this;
  134. that.formList.forEach((item, index) => {
  135. that.model = {
  136. ...that.model,
  137. ...{
  138. [`value${index}`]: item.value ? item.value : null
  139. }
  140. }; //构造model数据
  141. that.model.agreement = false;
  142. if (item.type === 'input' || item.type === 'number') {
  143. //构造表单验证规则
  144. that.rules = {
  145. ...that.rules,
  146. ...{
  147. [`value${index}`]: that.inputNumber
  148. }
  149. };
  150. }
  151. if (item.type === 'image') {
  152. if (item.value) {
  153. let arr = [];
  154. arr.push({ url: item.value });
  155. that.model = {
  156. ...that.model,
  157. ...{
  158. [`valueList${index}`]: arr
  159. }
  160. };
  161. }
  162. that.rules = {
  163. ...that.rules,
  164. ...{
  165. [`value${index}`]: that.inputImage
  166. }
  167. };
  168. }
  169. });
  170. },
  171. //申请分销商
  172. applyCommission(data) {
  173. let that = this;
  174. that.isFormEnd = true;
  175. that.$http(
  176. 'commission.apply',
  177. {
  178. data: data
  179. },
  180. '申请中...'
  181. ).then(res => {
  182. that.isFormEnd = false;
  183. if (res.code === 1) {
  184. uni.showToast({
  185. title: res.msg,
  186. success: () => {
  187. that.$Router.back();
  188. }
  189. });
  190. }
  191. });
  192. },
  193. // 提交
  194. onSubmit() {
  195. let that = this;
  196. this.$refs.uForm.validate(valid => {
  197. if (valid) {
  198. if (!this.model.agreement && this.protocol) return this.$u.toast('请勾选协议');
  199. let formData = this.formList;
  200. formData.map((item, index) => {
  201. item.value = that.model[`value${index}`];
  202. });
  203. this.applyCommission(formData);
  204. } else {
  205. this.$u.toast('请完善表单');
  206. }
  207. });
  208. }
  209. }
  210. };
  211. </script>
  212. <style lang="scss">
  213. .apply-commission-wrap {
  214. height: 100%;
  215. background-color: #fff;
  216. .head-box {
  217. width: 100%;
  218. height: 400rpx;
  219. background-size: 100% auto;
  220. background-repeat: no-repeat;
  221. }
  222. }
  223. // 表单
  224. .apply-form {
  225. width: 750rpx;
  226. background: #ffffff;
  227. border-radius: 20rpx;
  228. padding: 30rpx;
  229. .agreement {
  230. margin-top: 20rpx;
  231. .agreement-text {
  232. font-size: 24rpx;
  233. font-weight: 500;
  234. color: #b095ff;
  235. .text-underline {
  236. text-decoration: underline;
  237. }
  238. }
  239. }
  240. .save-btn {
  241. width: 690rpx;
  242. line-height: 86rpx;
  243. background: linear-gradient(-90deg, #a36fff, #5336ff);
  244. box-shadow: 0px 7rpx 11rpx 2rpx rgba(124, 103, 214, 0.34);
  245. border-radius: 43rpx;
  246. font-weight: 500;
  247. color: #ffffff;
  248. margin: 30rpx auto;
  249. }
  250. }
  251. </style>