tableAccount.vue 9.7 KB
<!-- 2 - 分账金额设置 -->
<template>
  <div class="division-rule">
    <p class="edit-sub-title">
      分账金额设置
    </p>
    <el-form class="formSty" ref="divisionRuleRef" :model="form" :rules="rules" label-suffix=":" label-width="180px">
      <el-form-item label="" label-width="54px">
        <table cellpadding="0" cellspacing="0" class="table-block">
          <!-- <tr>
            <th rowspan="2">
              分账方-账户
            </th>
            <th :colspan="merchantAccountInfo.partnerSettleAccountModel == 2?6:5">
              分账金额
            </th>
          </tr> -->
          <tr class="tableHeader">
            <td>分账对象/分账类目</td>
            <td>平台方分账金额</td>
            <td v-for="(item, index) in radioList" :key="index">{{ item.applicationObjectName }}</td>
            <!-- <td v-if="merchantAccountInfo.partnerSettleAccountModel == 1">
              服务商分账金额
            </td> -->
            <!-- <td v-if="merchantAccountInfo.partnerSettleAccountModel == 2">
              安装费用
            </td>
            <td v-if="merchantAccountInfo.partnerSettleAccountModel == 2">
              营销费用(包含奖惩)
            </td>
            <td>导流方分账金额</td>
            <td>产品成本</td>
            <td>额外成本</td> -->
            <!-- <td>市场费</td> -->
          </tr>
          <tr>
            <td class="merchantNameTd p-b-20 ">
              <!-- <p>默认:嘀加智慧云</p> -->
              <!-- class="one-line-ellipsis"
                 style="width: 300px;" -->
              <!-- 对应的分账对象 -->
              <p :title="item | filterMerchantType" v-for="(item, index) in tableSelectOptions" :key="index">
                {{ item | filterMerchantType }}
              </p>

            </td>
            <td class="p-b-20">
              <el-form-item label-width="0px">
                <el-radio-group v-model="platformSideLabel">
                  <el-radio v-for="(item, index) in tableSelectOptions" :key="index + 'index'" :disabled="item != 0"
                    :label="index" />
                </el-radio-group>
              </el-form-item>
            </td>
            <td class="p-b-20" v-for="(item, index) in radioList" :key="index + 'radioList'">
              <el-form-item label-width="0" :prop="`id${item.expenseCategoryId}`"
                :rules="[{ required: true, message: `请选择${item.applicationObjectName}`, trigger: 'change' }]">
                <el-radio-group v-model="form['id' + (item.expenseCategoryId)]"
                  @change="e => handleClearValid(e, 'id' + (item.expenseCategoryId))">
                  <el-radio v-for="(el, index) in tableSelectOptions" :key="index" :label="+(el.merchantId)" />
                </el-radio-group>
              </el-form-item>
            </td>
          </tr>
        </table>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import { userType } from '@/common/constants'
export default {
  name: 'TableAccount',
  props: {
    // 列选项
    classificationObjSelect: {
      type: Object,
      default: () => { }
    },
    // merchantInfo: {
    //   type: Object,
    //   default: () => { }
    // },
    merchantDistributionRules: {
      type: Array,
      default: () => {
        return []
      }
    },

    // 分账对象选项 1:平台方 2:服务商 3:导流方 4:子商户
    tableSelectOptions: {
      type: Array,
      default: () => []
    }
  },
  filters: {
    // 过滤商户类型
    filterMerchantType(val) {
      const name = {
        1: '平台方',
        2: '服务商',
        3: '导流方',
        4: '平台方'
      }
      const type = val.targetMerchantType
      return `${name[type]}: ${val.merchantName}`
    }
  },
  data() {
    return {
      form: {
        // settleTimeType: 1
      },
      platformSideLabel: 0,
      merchantAccountInfo: {

      },
      partnerSettleAccountModel: '',
      djDivisionDefalut: 1,
      rules: {},
      // 导流方下拉选项对应
      attrToVal: [{
        confId: 3,
        confLabel: 'city'
      }, {
        // confId: 4,
        confId: 2,
        confLabel: 'province'
      }, {
        // confId: 5,
        confId: 1,
        confLabel: 'factory'
      }
      ],
      realityShopMerchant: {
        merchantId: '',
        merchantName: '',
        userType: ''
      },
      baseData: {
        merchantLevelList: [],
        PlatformLevelList: []
      }
    }
  },

  computed: {
    radioList: function () {
      const obj = this.classificationObjSelect
      const list = []
      for (const key in obj) {
        obj[key].map((item) => {
          list.push(item)
        })
      }
      return list
    }
  },
  watch: {
    classificationObjSelect: {
      handler() {
        this.initList()
      },
      deep: true,
      immediate: true
    },
    merchantDistributionRules: {
      handler() {
        this.initList()
      },
      deep: true
      // immediate: true
    },
    tableSelectOptions: {
      handler() {
        // this.initList()
        this.changFormList()
      },
      deep: true
      // immediate: true
    }
  },
  mounted() { },
  methods: {
    initList() {
      // console.log('initList')
      // this.merchantDistributionRules
      // console.log(this.merchantDistributionRules)
      const obj = this.classificationObjSelect
      const form = {}
      // console.log('obj', obj)
      for (const key in obj) {
        obj[key].map(
          item => {
            // 数字转字符串
            const name = 'id' + item.expenseCategoryId
            // console.log(name, item.id || item.expenseCategoryId, 'item.id')
            // 做回显用数据
            const findObj = this.merchantDistributionRules.find((el) => { return el.expenseCategoryId == item.expenseCategoryId })
            // 还要跟存在现在的选项里面

            // console.log('findObj', findObj)
            // console.log(name)
            // const optIndex = this.tableSelectOptions.findIndex((opt) => { return opt.merchantId == findObj?.merchantId })
            // console.log(optIndex, 'optIndex')
            form[name] = parseInt(findObj?.merchantId) || ''
          }
        )
      }
      // 判断id是否有在选项里面 没有就去掉
      this.form = form
    },
    changFormList() {
      // 判断id是否有在选项里面 没有就去掉
      for (const key in this.form) {
        const element = this.form[key]
        this.tableSelectOptions.findIndex((opt) => { return opt.merchantId == element }) == -1 && (this.form[key] = '')
      }
    },
    handleClearValid(e, validField) {
      this.$forceUpdate()
      // this.handleConfirm()
      // console.log('validField', validField)
      this.$refs.divisionRuleRef.clearValidate(validField)
    },
    handleConfirm() {
      // console.log(this.merchantInfo)
      return new Promise((resolve, reject) => {
        this.$refs.divisionRuleRef.validate(valid => {
          if (valid) {
            // this.form
            const merchantDistributionRules = this.radioList.reduce((prev, next) => {
              const id = this.form['id' + next.expenseCategoryId]
              // console.log(id)
              const merchantObj = this.tableSelectOptions.find(item => item.merchantId == id)
              // console.log(merchantObj, 'merchantObj')
              next = {
                ...next,
                expenseCategoryId: next.expenseCategoryId,
                ...merchantObj
              }
              // console.log(next, 'next')
              // const name = 'id' + next.id
              // prev[name] = this.form[name]
              prev.push(next)
              return prev
            }, [])
            resolve(merchantDistributionRules)
          } else {
            resolve(false)
          }
        })
      }
      )
    },
    getTableAccountParams() {
      const merchantDistributionRules = this.radioList.reduce((prev, next) => {
        const id = this.form['id' + next.expenseCategoryId]
        // console.log(id)
        const merchantObj = this.tableSelectOptions.find(item => item.merchantId == id)
        // console.log(merchantObj, 'merchantObj')
        next = {
          ...next,
          expenseCategoryId: next.expenseCategoryId,
          ...merchantObj
        }
        // console.log(next, 'next')
        // const name = 'id' + next.id
        // prev[name] = this.form[name]
        prev.push(next)
        return prev
      }, [])
      return merchantDistributionRules
      // console.log(this.merchantInfo)
      // return new Promise((resolve, reject) => {
      //   this.$refs.divisionRuleRef.validate(valid => {
      //     if (valid) {
      //       // this.form

      //     } else {
      //       resolve(false)
      //     }
      //   })
      // }
      // )
    }

  }
}

</script>
<style>
.formSty {
  overflow-x: scroll;
}

.division-rule table {
  width: 98%;
  color: #666666;
  border: 1px solid #e5e6e7;
  border-width: 1px 0 0 1px;
}

.division-rule table tr {
  height: 50px;
  line-height: 50px;
}

.division-rule table th,
.division-rule table td {
  font-size: 12px;
  font-weight: normal;
  padding: 0px 10px;
  border: 1px solid #e5e6e7;
  border-width: 0px 1px 1px 0px;
  border-spacing: 0;
  text-align: center;
  min-width: 100px;
  white-space: nowrap;
  /* white-space: nowrap; */
  /* overflow: hidden; */
  /* text-overflow: ellipsis; */
}

.division-rule table .merchantNameTd {
  min-width: 150px;
}

.division-rule .flex {
  display: flex;
  justify-content: space-around;
}

.division-rule .table-block .el-radio {
  display: block;
  height: 60px;
  line-height: 42px;
  margin-right: 0;
}

.division-rule .table-block .el-radio__label {
  display: none !important;
}

.p-b-20 {
  padding-bottom: 26px !important;
}
</style>