define({ name:"rebate", template:`
关闭 开启
`, style:` .shortInput{ width: 500px!important; } .quarter-block{ border: 1px solid #DCDFE6; margin-top: 20px; padding: 0 15px; } .quarter-block .tips{ font-size: 12px; color: #737373; line-height: 20px; width: 100%; } .quarter-block .title{ height: 40px; line-height: 40px; font-weight: bold; font-size: 14px; padding-left: 10px; position: relative; } .quarter-block .title:after{ content: ""; position: absolute; left: 0; top: 11px; width: 4px; height: 18px; background: #29ba9c; } .quarter-block .isRepurchase{ margin-top: 15px; margin-right: 50px; } .quarter-block .monthInput{ min-width: 350px; width: calc((100% - 30px) / 4); margin-bottom: 10px; margin-right: 10px; } .quarter-block .monthInput:nth-child(4n){ margin-right: 0!important; } .quarter-block .monthInput .prepend-month{ font-weight: bold; } .quarter-block .monty-list{ margin-top: 15px; } `, props: { form: { default() { return {} } } }, data() { return { json: { is_open: 0, is_alone: 0, total_quarter: '', quarter_list: {}, } } }, computed:{ countTotalMonth(){ let json = Object.assign({}, this.json); let quarterList = Object.assign({}, json.quarter_list); return Object.values(quarterList).reduce((sum, item) => sum + item.total_month, 0); } }, watch:{ // 总季度信息变更 'json.total_quarter':{ handler(val, olVal) { let value = Number(val) >= 0 ? Number(val) : 0; let newQuarterList = {}; if(Number(value) > 0){ let quarterList = Object.assign({}, this.json.quarter_list); for(value;value > 0;value--){ let currentQuarter = quarterList[value] || {}; if(Object.values(currentQuarter).length <= 0){ // 当前季度信息不存在 newQuarterList[value] = { total_month: 0,// 本季度总多少月 is_repurchase: 0,// 是否需要复购 repurchase_money: 0,// 复购支付金额 month_list: {},// 每月返利金额 }; }else{ // 当前季度信息存在 newQuarterList[value] = currentQuarter; } } } this.$set(this.json, 'quarter_list', newQuarterList) this.$forceUpdate(); }, deep:true }, // 月度信息变更 countTotalMonth:{ handler(val, olVal) { if(Number(val) !== Number(olVal)){ let json = Object.assign({}, this.json); let quarterList = Object.assign({}, json.quarter_list); // 循环处理每个季度 for(const index in quarterList){ let currentMonthInfo = quarterList[index] || {}; let totalMonth = Number(currentMonthInfo.total_month) || 0; let monthList = currentMonthInfo.month_list || {}; let newMonthList = {}; if(totalMonth > 0){ for(totalMonth;totalMonth > 0;totalMonth--){ let currentMonth = monthList[totalMonth] || ''; newMonthList[totalMonth] = currentMonth || ''; } } quarterList[index].month_list = newMonthList; } this.$set(this.json, 'quarter_list', quarterList) this.$forceUpdate(); } }, deep:true }, }, mounted() { if (this.form) { let rebate = this.form || {}; this.json.is_alone = rebate.is_alone ? rebate.is_alone : 0; this.json.is_open = rebate.is_open ? rebate.is_open : 0; this.json.total_quarter = rebate.total_quarter ? rebate.total_quarter : ''; this.json.quarter_list = rebate.quarter_list ? rebate.quarter_list : {}; } }, methods:{ validate(){ return this.json; } } })