EditModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <el-dialog :visible.sync="visible" v-bind="modalOptions">
  3. <el-form ref="formData" :model="formData" :rules="formRules" size="mini" label-suffix=":" label-width="150px">
  4. <el-form-item label="关联活动" prop="activityId">
  5. <el-select
  6. v-model="formData.activityId" size="mini" placeholder="请选择关联活动" filterable
  7. @change="(e) => formData.activityName = activityList.find(i => i.currencyId === e).currencyName"
  8. >
  9. <el-option
  10. v-for="(item, index) in activityList" :key="item.currencyId"
  11. :label="`${item.currencyName}(${item.currencyId})`" :value="item.currencyId"
  12. />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="活动类型" prop="activityType">
  16. <el-select v-model="formData.activityType" size="mini" placeholder="请选择活动类型">
  17. <el-option label="499" :value="1" />
  18. <el-option label="商圈" :value="2" />
  19. <el-option label="爆品" :value="3" />
  20. <el-option label="消费金" :value="4" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="团长规则" prop="leadersRule">
  24. <el-select v-model="formData.leadersRule" size="mini" placeholder="请选择团长规则">
  25. <el-option label="比例" :value="1" />
  26. <el-option label="金额" :value="2" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="直接团长规则" prop="leadersMoney">
  30. <el-input v-model="formData.leadersMoney" placeholder="请输入直接团长规则" style="width: 150px;">
  31. <template #append>
  32. <div v-if="formData.leadersRule === 1">%</div>
  33. <div v-else-if="formData.leadersRule === 2">元</div>
  34. </template>
  35. </el-input>
  36. </el-form-item>
  37. <el-form-item label="间接团长规则" prop="leadersInMoney">
  38. <el-input v-model="formData.leadersInMoney" placeholder="请输入间接团长规则" style="width: 150px;">
  39. <template #append>
  40. <div v-if="formData.leadersRule === 1">%</div>
  41. <div v-else-if="formData.leadersRule === 2">元</div>
  42. </template>
  43. </el-input>
  44. </el-form-item>
  45. <el-form-item label="合伙人规则" prop="partnerRule">
  46. <el-select v-model="formData.partnerRule" size="mini" placeholder="请选择合伙人规则">
  47. <el-option label="比例" :value="1" />
  48. <el-option label="金额" :value="2" />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="直接合伙人规则" prop="partnerMoney">
  52. <el-input v-model="formData.partnerMoney" placeholder="请输入直接合伙人规则" style="width: 150px;">
  53. <template #append>
  54. <div v-if="formData.partnerRule === 1">%</div>
  55. <div v-else-if="formData.leadersRule === 2">元</div>
  56. </template>
  57. </el-input>
  58. </el-form-item>
  59. <el-form-item label="间接合伙人规则" prop="partnerInMoney">
  60. <el-input v-model="formData.partnerInMoney" placeholder="请输入间接合伙人规则" style="width: 150px;">
  61. <template #append>
  62. <div v-if="formData.partnerRule === 1">%</div>
  63. <div v-else-if="formData.leadersRule === 2">元</div>
  64. </template>
  65. </el-input>
  66. </el-form-item>
  67. <el-form-item label="分佣来源" prop="sourceType">
  68. <el-select v-model="formData.sourceType" size="mini" placeholder="请选择分佣来源">
  69. <el-option label="订单金额" :value="1" />
  70. <el-option label="赠送代金券" :value="2" />
  71. <el-option label="消费金" :value="3" />
  72. </el-select>
  73. </el-form-item>
  74. </el-form>
  75. <template #footer>
  76. <span class="dialog-footer">
  77. <el-button size="mini" @click="handleClose">取 消</el-button>
  78. <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
  79. </span>
  80. </template>
  81. </el-dialog>
  82. </template>
  83. <script>
  84. import { getAllPlatformBeeCurrency, getByIdPlatformBeeRule, savePlatformBeeRule, priceControlUpdatePlan } from '@/api/commissionAllocation/gradeCommission'
  85. export default {
  86. name: 'EditModal',
  87. components: {
  88. },
  89. data() {
  90. return {
  91. modalOptions: {
  92. closeOnClickModal: false,
  93. width: '820px',
  94. title: ''
  95. },
  96. visible: false,
  97. activityList: [],
  98. formData: {
  99. ruleId: '',
  100. activityId: '',
  101. activityType: '',
  102. leadersRule: '',
  103. leadersMoney: '',
  104. leadersInMoney: '',
  105. partnerRule: '',
  106. partnerMoney: '',
  107. partnerInMoney: '',
  108. sourceType: ''
  109. },
  110. formRules: {
  111. activityId: [
  112. { required: true, message: '缺少活动' }
  113. ],
  114. activityType: [
  115. { required: true, message: '请选择活动' }
  116. ],
  117. leadersRule: [
  118. { required: true, message: '请选择团长规则' }
  119. ],
  120. leadersMoney: [
  121. { required: false, message: '请输入直接团长规则' },
  122. { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' } // >0的数字, 最多2位小数正则
  123. ],
  124. leadersInMoney: [
  125. { required: false, message: '请输入间接团长规则' },
  126. { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
  127. ],
  128. partnerRule: [
  129. { required: true, message: '请选择合伙人规则' }
  130. ],
  131. partnerMoney: [
  132. { required: false, message: '请输入直接合伙人规则' },
  133. { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
  134. ],
  135. partnerInMoney: [
  136. { required: false, message: '请输入间接合伙人规则' },
  137. { pattern: /^0\.\d{0,2}$|^[1-9]\d*\.\d{0,2}$|^[1-9]\d*$/, message: '数值有误' }
  138. ],
  139. sourceType: [
  140. { required: true, message: '请选择分佣来源' }
  141. ]
  142. }
  143. }
  144. },
  145. methods: {
  146. handleClose() {
  147. this.visible = false
  148. },
  149. async initList() {
  150. const res = await getAllPlatformBeeCurrency({})
  151. this.activityList = res.data
  152. },
  153. handleOpen(params = {}) {
  154. this.modalOptions.title = params.ruleId ? '编辑平台消费金活动分佣规则' : '添加平台消费金活动分佣规则'
  155. this.formData = Object.assign(this.$options.data().formData, params, {
  156. ruleId: params.ruleId || '',
  157. activityId: params.activityId || '',
  158. activityName: params.activityName || '',
  159. activityType: params.activityType || '',
  160. leadersRule: params.leadersRule || '',
  161. leadersMoney: (params.leadersRule === 1) && (typeof params.leadersMoney === 'number') ? params.leadersMoney * 100 : params.leadersMoney,
  162. leadersInMoney: (params.leadersRule === 1) && (typeof params.leadersInMoney === 'number') ? params.leadersInMoney * 100 : params.leadersInMoney,
  163. partnerRule: params.partnerRule || '',
  164. partnerMoney: (params.partnerRule === 1) && (typeof params.partnerMoney === 'number') ? params.partnerMoney * 100 : params.partnerMoney,
  165. partnerInMoney: (params.partnerRule === 1) && (typeof params.partnerInMoney === 'number') ? params.partnerInMoney * 100 : params.partnerInMoney,
  166. sourceType: params.sourceType || ''
  167. })
  168. this.visible = true
  169. this.initList()
  170. if (params.ruleId) {
  171. this.getInfo(params.ruleId)
  172. } else {
  173. this.$refs.formData && this.$refs.formData.resetFields()
  174. }
  175. },
  176. async getInfo(id) {
  177. const loading = this.$loading({ text: '加载中' })
  178. try {
  179. const res = await getByIdPlatformBeeRule({ id })
  180. this.formData = Object.assign(this.$options.data().formData, res.data, {
  181. ruleId: res.data.ruleId || '',
  182. activityId: res.data.activityId || '',
  183. activityName: res.data.activityName || '',
  184. activityType: res.data.activityType || '',
  185. leadersRule: res.data.leadersRule || '',
  186. leadersMoney: (res.data.leadersRule === 1) && (typeof res.data.leadersMoney === 'number') ? res.data.leadersMoney * 100 : res.data.leadersMoney,
  187. leadersInMoney: (res.data.leadersRule === 1) && (typeof res.data.leadersInMoney === 'number') ? res.data.leadersInMoney * 100 : res.data.leadersInMoney,
  188. partnerRule: res.data.partnerRule || '',
  189. partnerMoney: (res.data.partnerRule === 1) && (typeof res.data.partnerMoney === 'number') ? res.data.partnerMoney * 100 : res.data.partnerMoney,
  190. partnerInMoney: (res.data.partnerRule === 1) && (typeof res.data.partnerInMoney === 'number') ? res.data.partnerInMoney * 100 : res.data.partnerInMoney,
  191. sourceType: res.data.sourceType || ''
  192. })
  193. this.$nextTick(() => {
  194. this.$refs.formData && this.$refs.formData.validate()
  195. })
  196. } finally {
  197. loading.close()
  198. }
  199. },
  200. handleSubmit() {
  201. this.$refs.formData.validate(async (valid) => {
  202. if (valid) {
  203. const loading = this.$loading({ text: '提交中,请稍候……' })
  204. try {
  205. const { leadersRule, partnerRule, leadersMoney, leadersInMoney, partnerMoney, partnerInMoney, ...otps } = this.formData
  206. const params = {
  207. leadersMoney: leadersRule === 1 ? leadersMoney / 100 : leadersMoney,
  208. leadersInMoney: leadersRule === 1 ? leadersInMoney / 100 : leadersInMoney,
  209. partnerMoney: partnerRule === 1 ? partnerMoney / 100 : partnerMoney,
  210. partnerInMoney: partnerRule === 1 ? partnerInMoney / 100 : partnerInMoney,
  211. ...otps
  212. }
  213. this.formData.ruleId ? await priceControlUpdatePlan(params) : await savePlatformBeeRule(params)
  214. loading.close()
  215. this.$message({ message: `${this.formData.ruleId ? '编辑' : '添加'}成功!`, type: 'success' })
  216. this.$emit('success')
  217. this.visible = false
  218. } catch (e) {
  219. loading.close()
  220. } finally {
  221. loading.close()
  222. }
  223. } else {
  224. this.$message({ message: '请输入相关信息', type: 'warning' })
  225. return false
  226. }
  227. })
  228. }
  229. }
  230. }
  231. </script>