index.vue 10.5 KB
<!-- 财务详情 -->
<template>
  <d2-container class="merchent-step">
    <div class="d2-container-content">
      <div class="header">
        <p class="flex">
          <span>门店名称:{{ form.merchantName }}</span>
          <span>业务类型:
            <el-select :size="size"
                       v-model="form.bizType">
              <el-option v-for="(item, index) in bizTypeList"
                         :key="index"
                         :value="item.confId"
                         :label="item.confLabel"
                         :disabled="item.confId === '2'" />
            </el-select>
          </span>
        </p>
      </div>

      <div class="flex step-bar">
        <p @click="handleStep(1)"
           :class="{'active': stepStat === 1}">
          财务设置
        </p>
        <p @click="handleStep(2)"
           :class="{'active': stepStat === 2}">
          分账金额设置
        </p>
        <p @click="handleStep(3)"
           :class="{'active': stepStat === 3}">
          分账测试
        </p>
        <p @click="handleStep(4)"
           :class="{'active': stepStat === 4}">
          开启分账
        </p>
      </div>

      <div>
        <step-one ref="step1"
                  v-show="stepStat === 1"
                  :form="form"
                  @handleNextStep="handleNextStep" />
        <step-two ref="step2"
                  v-if="stepStat === 2"
                  :sms-form="form"
                  :merchant-info="ruleForm"
                  @handleNextStep="handleNextStep" />
        <step-three ref="step3"
                    v-show="stepStat === 3"
                    :step-stat="stepStat"
                    :sms-form="form"
                    :merchant-info="ruleForm"
                    @getRuleProgress="getInfo"
                    @changeParentVal="changeParentVal"
                    @handleSave="handleConfirm"
                    @handleNextStep="handleNextStep" />
        <step-four ref="step4"
                   v-show="stepStat === 4"
                   :step-stat="stepStat"
                   :sms-form="form"
                   :merchant-info="ruleForm"
                   @handleNextStep="handleNextStep" />
      </div>
    </div>

    <!-- 短信模块 -->
    <div class="d2-container-content"
         v-show="[1,2,4].includes(stepStat)">
      <p class="edit-sub-title">
        安全验证<span class="title-tips">提交信息后第二天生效!</span>
      </p>
      <el-form ref="form"
               :model="form"
               :rules="rules"
               label-suffix=":"
               label-width="180px">
        <el-form-item label="管理员手机号验证">
          {{ adminInfo.name }} {{ adminInfo.phone }}
          <el-button :size="size"
                     @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="size"
                    style="width: 220px;" />
        </el-form-item>
      </el-form>
    </div>

    <!-- 按钮模块 -->
    <div class="d2-container-content box-btn">
      <el-button v-show="[2,3,4].includes(stepStat)"
                 :size="size"
                 @click="handleLastStep">
        上一步
      </el-button>
      <el-button type="primary"
                 v-show="isShowOkbtn"
                 :size="size"
                 @click="handleConfirm">
        确认
      </el-button>
      <!--  :disabled="isFirstSetEdit || isSecondSetEdit" -->
      <el-button :size="size"
                 @click="handleCancel">
        取消
      </el-button>
    </div>
  </d2-container>
</template>

<script>
// import _ from 'lodash'
import { deepClone } from '@/common/util'
import stepOne from './stepOne'
import stepTwo from './stepTwo'
import stepThree from './stepThree'
import stepFour from './stepFour'
import { mapActions } from 'vuex'
// getPartnerByYq
import { getRuleProgressApi, sendSms, getAdminInfo } from '@api/merchant'
import { BaseData, userType, ghUserType } from '@/common/constants.js'
export default {
  data() {
    return {
      // 缓存当前merchantId
      sessionName: 'applyAccMerchant',
      size: 'small',
      stepStat: 1,
      form: {
        merchantId: '',
        bizType: '1'
      },
      ruleForm: {},
      bizTypeList: [{
        confId: '1',
        confLabel: 'B端转化业务'
      }, {
        confId: '2',
        confLabel: 'C端零售业务'
      }],
      // 短信模块
      isSend: false,
      sendMsg: '发送验证短信',
      adminInfo: {
        name: '',
        phone: ''
      },
      rules: {
        smsCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      // 基本数据
      baseData: {
        productTypeList: [],
        userType: userType,
        ghUserType: ghUserType
      },
      isShowOkbtn: true,
      num: 0
    }
  },

  watch: {
    stepStat(val) {
      this.isShowOkbtn = true
    }
  },

  components: {
    stepOne,
    stepTwo,
    stepThree,
    stepFour
  },

  mounted() {
    getAdminInfo({}).then(res => {
      this.adminInfo = res
    })
    console.log(this.$route.params.merchantId)
    if (this.$route.params.merchantId) {
      // console.log(this.$route.params)
      // this.merchantItem = {
      //   merchantId: this.$route.params.merchantId,
      //   merchantName: this.$route.params.merchantName,
      //   channelType: this.$route.params.channelType,
      //   userType: this.$route.params.userType,
      //   parentMerchantName: this.$route.params.partnerMerchant ? this.$route.params.partnerMerchant.merchantName : '',
      //   parentMerchantId: this.$route.params.partnerMerchant ? this.$route.params.partnerMerchant.merchantId : ''
      // }
      console.log(this.$route.params, 'this.$route.params')
      // 兼容修复v3.2 版本数据结构问题
      // debugger
      const { merchantId, merchantName, channelType, userType, serviceList, yqMerchant } = this.$route.params
      const merchantItem = { merchantId, merchantName, channelType, userType }
      if (yqMerchant) {
        merchantItem.yqMerchantId = yqMerchant.merchantId
        merchantItem.yqMerchantName = yqMerchant.merchantName
      }
      if (serviceList) {
        if (serviceList.length == 1) {
          merchantItem.parentMerchantId = serviceList[0].merchantId
          merchantItem.parentMerchantName = serviceList[0].merchantName
        } else {
          merchantItem.partnerMerchants = serviceList
        }
      }
      // const { merchantId, merchantName, channelType, userType, parentMerchantName, parentMerchantId, partnerMerchants, yqMerchantId, yqMerchantName } = this.$route.params
      Object.assign(this.form, merchantItem)
      sessionStorage.setItem(this.sessionName, JSON.stringify(merchantItem))
      this.getRuleProgress(this.$route.params.merchantId)
    } else {
      Object.assign(this.form, JSON.parse(sessionStorage.getItem(this.sessionName)))
      this.getRuleProgress(this.form.merchantId)
    }

    this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),

    async getBaseData() {
      this.baseData.productTypeList = deepClone(await this.get(BaseData.productType))
    },

    getInfo() {
      // this.num++
      // this.getRuleProgress(this.form.merchantId, true, 3, (this.num % 2) ? 11 : 35)
      this.getRuleProgress(this.form.merchantId, true, 3)
    },
    // 财务-步骤
    getRuleProgress(merchantId, isJump = true, nextPage) {
      getRuleProgressApi({ merchantId: merchantId }).then(res => {
        // console.log(res)
        // console.log(isJump)
        this.ruleForm = res
        // 先写死调试
        // this.stepStat = 1
        isJump ? (this.stepStat = res.progress ?? 1) : this.handleStep(nextPage)
        // isJump ? (this.stepStat = res ? res.progress : 1) : this.handleStep(nextPage)
      })
    },

    handleStep(val) {
      if (val > this.ruleForm.progress) {
        return true
      }
      if ([35, 36].includes(this.ruleForm.subProgress)) {
        return true
      }

      this.stepStat = val
    },

    resetForm() {
      this.form = {
        merchantId: '',
        bizType: '1'
      }
      Object.assign(this.form, JSON.parse(sessionStorage.getItem(this.sessionName)))
    },

    changeParentVal(obj) {
      this[obj.attrName] = obj.value
      if (obj.attrName === 'ruleForm') {
        this.handleStep(this.ruleForm.progress)
      }
    },

    // 确定后,下一步
    handleNextStep(nextPage) {
      // this.handleStep(nextPage)
      // 清空倒计时
      this.sendMsg = 1
      this.resetForm()
      this.getRuleProgress(this.form.merchantId, false, nextPage)
    },

    // 上一步
    handleLastStep() {
      // console.log(this.stepStat)
      this.handleStep(this.stepStat - 1)
    },

    // 短信模块-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

    handleConfirm() {
      if (this.stepStat === 3) {
        this.$refs['step' + this.stepStat].handleConfirm()
        return true
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$refs['step' + this.stepStat].handleConfirm()
        }
      })
    },

    // 删除session
    deleteSession() {
      sessionStorage.removeItem(this.sessionName)
    },

    handleCancel() {
      // this.deleteSession()
      this.$router.push({
        name: 'merchantManage'
      })
      this.close({ tagName: '/merchantDetail' })
    }
  }
}

</script>
<style scoped>
.merchent-step .d2-container-content:first-child {
  margin-top: 0 !important;
}
.merchent-step .flex {
  display: flex;
  justify-content: space-between;
}
.merchent-step {
  font-size: 14px;
  color: #333333;
}
.step-bar {
  height: 40px;
  line-height: 40px;
  text-align: center;
  background: #f8faff;
  margin-bottom: 20px;
}
.step-bar p {
  width: 25%;
  margin: 0 0;
  cursor: pointer;
}
.step-bar .active {
  color: #ffffff;
  background: #2b58ad;
}
.box-btn {
  text-align: center;
}
</style>