share-model.vue 12 KB

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