subordinateMerchantDialog.vue 9.51 KB
<!-- 商户关联 -->
<template>
  <d2-dialog title="商户关联" :is-visible="subordinateMerchantVisible" class="accountDailog" @closeDialog="handleClose"
             width="850px" @confirmDialog="handleAddConfirm">
    <div class="yseUserCode">虚账编码: {{ subShopMerchantInfo.yseUserCode }}</div>
    <div class="content">
      <el-form ref="editSubordinateMerchantFrom" class="editSubordinateMerchantFrom " :model="form" label-width="150px"
               v-loading="$store.state.d2admin.loading.value">
        <el-table :data="form.tableData" border>
          <el-table-column type="index" label="序号" :index="index => index + 1" width="50" align="center" />
          <el-table-column label="商户名称" width="400" align="center">
            <template slot-scope="scope">
              <div class="inputCol">
                <el-form-item :prop="'tableData.' + scope.$index + '.merchantId'"
                              :rules="[{ required: true, message: '请选择商户', trigger: 'change' }]">
                  <el-select v-model="scope.row.merchantId" filterable remote reserve-keyword placeholder="请输入关键字"
                             style="width: 350px" :remote-method="remoteMethod" @change="changeOpt" :loading="loading">
                    <el-option v-for="(item, index) in options" :key="index" :label="item.merchantName"
                               :value="item.merchantId" :disabled="setDisabled(item.merchantId)">
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="商户号" align="center" prop="merchantId" width="138" />
          <el-table-column label="商户分类" align="center" prop="merchantId" width="138">
            <template slot-scope="scope">
              <!-- {{ scope.row.merchantType }} -->
              {{ scope.row.merchantType ? merchantClassifyList.find(item => item.confId ==
                scope.row.merchantType).confLabel : '' }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" style="color: red;" @click="handleDelMerchant(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="add-btn">
          <el-button type="primary" @click="handleAddMerchant">添加一行</el-button>
        </div>
      </el-form>
      <div class="tips">说明:关联商户完成后,生效后对应商户的分润金额将自动清分至关联的虚拟对公账户; 若商户的关联虚账发生变化,商户需重新做分账测试,请谨慎操作。</div>
      <el-form ref="form" :model="form" :rules="rules" label-suffix=":" label-width="140px">
        <el-form-item label="管理员手机号验证">
          {{ adminInfo.name }} {{ adminInfo.phone }}
          <el-button size="small" @click="handleSend" :disabled="isSend">
            {{ isSend ? sendMsg + '秒后,重试' : '发送验证短信' }}
          </el-button>
        </el-form-item>
        <el-form-item label="验证码" prop="smsCode">
          <el-input placeholder="请填写验证码" v-model="form.smsCode" size="small" style="width: 220px;" />
        </el-form-item>
      </el-form>
    </div>
  </d2-dialog>
</template>

<script>
import { sendSms, getAdminInfo } from '@api/merchant'
import { listWithPageAccountStatuses, yseMerchantModifyMerchantRef } from '@api/publicAccount'
import { deepClone } from '@/common/util'
import { merchantClassifyList } from '@/common/constants'
export default {
  name: 'SubordinateMerchantDialog',
  data() {
    return {
      merchantClassifyList,
      userInfo: this.$store.state.d2admin.user.info,
      form: {
        tableData: []
      },
      // tableData: [],
      subShopMerchantList: [],
      timeout: null,
      loading: false,
      options: [],
      // 短信模块
      isSend: false,
      sendMsg: '发送验证短信',
      adminInfo: {
        name: '',
        phone: ''
      },
      rules: {
        smsCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      isShowOkbtn: true,
      num: 0
    }
  },

  props: {
    subordinateMerchantVisible: {
      type: Boolean,
      default: false
    },
    subShopMerchantInfo: {
      type: Object,
      default: null
    }
  },

  watch: {
  },

  created() {
    getAdminInfo({}).then(res => {
      this.adminInfo = res
    })
  },
  components: {},

  mounted() {
    if (this.subShopMerchantInfo) {
      this.getInfo(this.subShopMerchantInfo)
    }
  },

  methods: {
    // 短信模块-start
    handleSend() {
      sendSms({}).then((res) => {
        this.notice.okTips('已发送,30分钟内有效')
        this.isSend = true
        this.sendMsg = 60
        this.msgDown()
      })
    },
    msgDown() {
      var time = setTimeout(() => {
        clearTimeout(time)
        if (this.sendMsg > 1) {
          --this.sendMsg
          this.msgDown()
        } else {
          this.isSend = false
        }
      }, 1000)
    },
    // 短信模块-end
    getInfo(subShopMerchantInfo) {
      // yseMerchantGetDetail({
      //   yseUserCode: yseUserCode
      // }).then(res => {
      // console.log(res, 'res')
      this.subShopMerchantList = subShopMerchantInfo.yseMerchantRefs || []
      if (this.subShopMerchantList.length > 0) {
        this.form.tableData = deepClone(this.subShopMerchantList)
        this.options = deepClone(this.subShopMerchantList)
      }
    },

    handleAddConfirm() {
      this.$refs.editSubordinateMerchantFrom.validate(valid => {
        if (valid) {
          if (!this.form.tableData.length) return this.$message.warning('请选择关联商户')
          this.$refs.form.validate(valid2 => {
            if (valid2) {
              var params = {
                smsCode: this.form.smsCode,
                yseMerchantId: this.subShopMerchantInfo.id,
                yseMerchantRefs: this.form.tableData
              }
              // params.merchantId = this.subShopMerchantInfo.merchantId
              // params.merchantName = this.subShopMerchantInfo.merchantName
              // // params.smsCode  =
              // const list = []
              // let info
              // this.form.tableData.forEach(item => {
              //   info = deepClone(item)
              //   info.merchantId = info.merchantId
              //   info.merchantName = info.merchantName
              //   list.push(info)
              // })
              // params.list = list
              yseMerchantModifyMerchantRef(params).then(res => {
                this.notice.okTips('操作成功')
                this.handleClose(true)
              })
            }
          })
        }
      })
    },

    handleAddMerchant() {
      this.options = []
      this.form.tableData.push({
        // merchantName: '',
        merchantId: ''
      })
    },

    handleDelMerchant(index) {
      this.form.tableData.splice(index, 1)
    },

    // handleSelect(item) {
    //   console.log(item)
    //   console.log(this.form.tableData);

    // },

    remoteMethod(queryString) {
      if (queryString) {
        this.loading = true
        setTimeout(() => {
          this.loading = false
          var params = { currentPage: 1, pageSize: 1000, accountStatuses: [1, 3, 4], merchantName: queryString, ysemRefedFlag: 'N' }
          listWithPageAccountStatuses(params).then(res => {
            if (res.list) {
              res.list = res.list.map(item => {
                return {
                  merchantId: item.merchantId,
                  merchantName: item.merchantName,
                  merchantType: item.merchantType
                }
              })
            }
            const list = this.subShopMerchantInfo.yseMerchantRefs || []
            this.options = [...list, ...res.list || []]
          })
        }, 200)
      } else {
        this.options = []
      }
    },

    setDisabled(val) {
      const info = this.form.tableData.find(item => item.merchantId == val)
      if (info) {
        return true
      } else {
        return false
      }
    },

    changeOpt(val) {
      const info = this.options.find(item => item.merchantId == val)
      console.log(info)
      this.form.tableData = this.form.tableData.map(item => {
        if (item.merchantId == info.merchantId) {
          const id = deepClone(item.id)
          delete info.id
          item = deepClone(info)
          if (id) {
            item.id = id
            // return item = Object.assign(info, { id: item.id })
          }
        }
        return item
      })
      console.log(this.form.tableData)
    },

    handleClose(flag) {
      this.$emit('dialogClose', flag)
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.add-btn {
  width: 100%;
  display: flex;
  margin-top: 15px;
}

.accountDailog .el-dialog {
  margin-top: 20vh !important;
  min-width: 1000px;
}

.accountDailog .el-select-dropdown__item {
  width: 395px !important;
}

.inputCol {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 20px;
  line-height: 80px;

  ::v-deep.el-form-item__content {
    margin-left: 0 !important;
  }
}

.yseUserCode {
  height: 40px;
  background: #F6F9FF;
  line-height: 40px;
  padding-left: 16px;
  font-family: PingFangSC-Medium;
  font-weight: 500;
}

.tips {
  margin: 10px 0 5px;
  font-size: 12px;
  color: #666666;
}
</style>