share-model.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div>
  3. <el-form :model="form" :rules="rules" ref="ruleForm">
  4. <el-form-item label="所属分部" prop="organId" :label-width="formLabelWidth">
  5. <el-select v-model.trim="form.organId" :disabled="formActionTitle === 'update'" placeholder="请选择所属分部">
  6. <el-option
  7. v-for="item in selects.branchs"
  8. :key="item.id"
  9. :label="item.name"
  10. :value="item.id"
  11. ></el-option>
  12. </el-select>
  13. </el-form-item>
  14. <el-row :gutter="10" v-for="(service, index) in form.serviceList" :key="index + 1000">
  15. <el-col :span="9">
  16. <el-form-item :label-width="formLabelWidth" :label="`服务收入${index + 1}`" :prop="'serviceList.' + index + '.feeType'" :rules="[{ required: true, message: '请选择收费方式', trigger: 'change' }]">
  17. <el-select
  18. v-model.trim="service.feeType"
  19. placeholder="请选择收费方式"
  20. style="width: 100% !important;"
  21. disabled
  22. >
  23. <el-option value="SERVICE" label="服务收入"></el-option>
  24. <el-option value="SELL" label="销售收入"></el-option>
  25. </el-select>
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="5">
  29. <el-form-item :prop="'serviceList.' + index + '.organId'" :rules="[
  30. { required: true, message: '请选择分润分部', trigger: 'change' },
  31. ]">
  32. <el-select
  33. v-model.trim="service.organId"
  34. placeholder="分润分部"
  35. clearable
  36. >
  37. <el-option
  38. v-for="(item, index) in calcBranchList"
  39. :key="index"
  40. :label="item.label"
  41. :value="item.value"
  42. :disabled="item.disabled"
  43. ></el-option>
  44. </el-select>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="5">
  48. <el-form-item :prop="'serviceList.' + index + '.scale'" :rules="[
  49. { required: true, validator: validSale, trigger: 'blur, change' },
  50. { required: true, message: '比例必须为数字值', trigger: 'blur, change' }
  51. ]">
  52. <el-input
  53. type="number"
  54. min="0"
  55. max="100"
  56. placeholder="分润比例"
  57. @mousewheel.native.prevent
  58. v-model.number="service.scale"
  59. >
  60. <i slot="suffix">%</i>
  61. </el-input>
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="5">
  65. <el-button icon="el-icon-plus" @click="onAddDomain('SERVICE')" circle></el-button>
  66. <el-button icon="el-icon-minus" :disabled="form.serviceList.length <= 1" @click="onRemoveDomain('SERVICE', service)" circle type="danger"></el-button>
  67. </el-col>
  68. </el-row>
  69. <el-divider></el-divider>
  70. <el-row :gutter="10" v-for="(domain, index) in form.sellList" :key="index">
  71. <el-col :span="9">
  72. <el-form-item :label-width="formLabelWidth" :label="`销售收入${index + 1}`" :prop="'sellList.' + index + '.feeType'" :rules="[
  73. { required: true, message: '请选择收费方式', trigger: 'change' },
  74. ]">
  75. <el-select
  76. v-model.trim="domain.feeType"
  77. placeholder="请选择收费方式"
  78. style="width: 100% !important;"
  79. disabled
  80. >
  81. <el-option value="SERVICE" label="服务收入"></el-option>
  82. <el-option value="SELL" label="销售收入"></el-option>
  83. </el-select>
  84. </el-form-item>
  85. </el-col>
  86. <el-col :span="5">
  87. <el-form-item :prop="'sellList.' + index + '.organId'" :rules="[
  88. { required: true, message: '请选择分润分部', trigger: 'change' },
  89. ]">
  90. <el-select
  91. v-model.trim="domain.organId"
  92. placeholder="分润分部"
  93. clearable
  94. >
  95. <el-option
  96. v-for="(item, index) in calcBranchList"
  97. :key="index"
  98. :label="item.label"
  99. :value="item.value"
  100. :disabled="item.disabled"
  101. ></el-option>
  102. </el-select>
  103. </el-form-item>
  104. </el-col>
  105. <el-col :span="5">
  106. <el-form-item :prop="'sellList.' + index + '.scale'" :rules="[
  107. { required: true, validator: validSale, trigger: 'blur, change' },
  108. { required: true, message: '比例必须为数字值', trigger: 'blur, change' }
  109. ]">
  110. <el-input
  111. type="number"
  112. v-number
  113. min="0"
  114. max="100"
  115. placeholder="分润比例"
  116. @mousewheel.native.prevent
  117. v-model.number="domain.scale"
  118. >
  119. <i slot="suffix">%</i>
  120. </el-input>
  121. </el-form-item>
  122. </el-col>
  123. <el-col :span="5">
  124. <el-button icon="el-icon-plus" @click="onAddDomain('SELL')" circle></el-button>
  125. <el-button icon="el-icon-minus" :disabled="form.sellList.length <= 1" @click="onRemoveDomain('SELL', domain)" circle type="danger"></el-button>
  126. </el-col>
  127. </el-row>
  128. </el-form>
  129. <span slot="footer" class="dialog-footer">
  130. <el-button @click="close">取 消</el-button>
  131. <el-button @click="onChargeSubmit('ruleForm')" type="primary">确 定</el-button>
  132. </span>
  133. </div>
  134. </template>
  135. <script>
  136. import { getPaymentConfigs, addTypeRoute, updateTypeRoute } from "./api";
  137. import cleanDeep from 'clean-deep'
  138. const validSale = (rule, value, callback) => {
  139. if (value != 0 && typeof value === 'string') {
  140. callback(new Error("请输入分润比例"));
  141. } else if (value < 0) {
  142. callback(new Error("分润比例不能小于0"));
  143. } else if (value > 101) {
  144. callback(new Error("分润比例不能大于100"));
  145. } else {
  146. callback();
  147. }
  148. };
  149. export default {
  150. props:['detail', 'close', 'getList', 'formActionTitle'],
  151. data() {
  152. return {
  153. formLabelWidth: "100px",
  154. form: {
  155. id: null,
  156. organId: null,
  157. serviceList: [{
  158. feeType: 'SERVICE',
  159. organId: null,
  160. scale: null,
  161. }],
  162. sellList: [{
  163. feeType: 'SELL',
  164. organId: null,
  165. scale: null
  166. }]
  167. },
  168. validSale: validSale,
  169. rules: {
  170. organId: [
  171. { required: true, message: "请选择所属分部", trigger: "change" }
  172. ]
  173. },
  174. calcBranchList: [], // 可选比例分部
  175. }
  176. },
  177. mounted() {
  178. this.getPaymentBranchList()
  179. let detail = this.detail
  180. if(detail && this.formActionTitle == 'update') {
  181. this.form = {
  182. id: detail.id,
  183. organId: detail.organId,
  184. serviceList: [],
  185. sellList: []
  186. }
  187. const routeScale = detail.typeRouteScale ? detail.typeRouteScale : []
  188. routeScale.forEach(item => {
  189. if(item.feeType === 'SERVICE') {
  190. this.form.serviceList.push({
  191. feeType: 'SERVICE',
  192. organId: item.organId,
  193. scale: item.scale,
  194. })
  195. } else if(item.feeType === 'SELL') {
  196. this.form.sellList.push({
  197. feeType: 'SELL',
  198. organId: item.organId,
  199. scale: item.scale,
  200. })
  201. }
  202. })
  203. }
  204. },
  205. methods: {
  206. onChargeSubmit(formName) {
  207. this.$refs[formName].validate(valid => {
  208. const form = this.form
  209. let serviceCount = 0
  210. form.serviceList.forEach(item => {
  211. serviceCount += item.scale
  212. })
  213. if(Number(serviceCount.toFixed(5)) !== 100) {
  214. this.$message.error('服务收入分润比例总和必须为100')
  215. return
  216. }
  217. let sellCount = 0
  218. form.sellList.forEach(item => {
  219. sellCount += item.scale
  220. })
  221. if(Number(sellCount.toFixed(5)) !== 100) {
  222. this.$message.error('销售收入分润比例总和必须为100')
  223. return
  224. }
  225. if (valid) {
  226. const params = {
  227. id: form.id,
  228. organId: form.organId,
  229. typeRouteScale: JSON.stringify((form.serviceList).concat(form.sellList))
  230. }
  231. if (this.formActionTitle == "create") {
  232. addTypeRoute(cleanDeep(params)).then(res => {
  233. this.messageTips("添加", res);
  234. });
  235. } else if (this.formActionTitle == "update") {
  236. updateTypeRoute(cleanDeep(params)).then(res => {
  237. this.messageTips("修改", res);
  238. });
  239. }
  240. } else {
  241. return;
  242. }
  243. });
  244. },
  245. messageTips(title, res) {
  246. if (res.code == 200) {
  247. this.$message.success(title + "成功");
  248. this.chargeStatus = false;
  249. this.close()
  250. this.getList();
  251. } else {
  252. this.$message.error(res.msg);
  253. }
  254. },
  255. async getPaymentBranchList() {
  256. await getPaymentConfigs(cleanDeep({ payType: 'ADAPAY' })).then(res => {
  257. if (res.code == 200 && res.data) {
  258. res.data.forEach(item => {
  259. this.calcBranchList.push({
  260. label: item.organName,
  261. value: item.organId,
  262. payType: item.payType
  263. });
  264. });
  265. }
  266. });
  267. },
  268. onAddDomain(type) { // 添加
  269. const tempObj = {
  270. organId: null,
  271. scale: null
  272. }
  273. if(type === 'SERVICE') {
  274. tempObj['feeType'] = 'SERVICE'
  275. this.form.serviceList.push(tempObj)
  276. } else if(type === 'SELL') {
  277. tempObj['feeType'] = 'SELL'
  278. this.form.sellList.push(tempObj)
  279. }
  280. },
  281. onRemoveDomain(type, item) { // 删除
  282. let form = this.form
  283. if(type === 'SERVICE') {
  284. const index = form.serviceList.indexOf(item)
  285. if (index !== -1) {
  286. form.serviceList.splice(index, 1)
  287. }
  288. } else if(type === 'SELL') {
  289. const index = form.sellList.indexOf(item)
  290. if (index !== -1) {
  291. form.sellList.splice(index, 1)
  292. }
  293. }
  294. }
  295. }
  296. }
  297. </script>
  298. <style lang="less" scoped>
  299. .dialog-footer{
  300. display: block;
  301. text-align: right;
  302. margin-top: 20px;
  303. }
  304. </style>