index.vue 7.79 KB
<template>
  <baseDialog
    :is-show.sync="dialogShow"
    :config="setting"
    :dialog-config="dialogConfig.config"
    class="detail-content"
    customClose
    @handleClick="handleClick"
    @cancelBtn="handleDetailClose"
    :btnLoding="btnLoding"
  >
    <div
      v-loading="loading"
      class="content"
    >
      <img
        :src="stepImg"
        class="step-img"
      >
      <tips-box
        :step="step"
        :tableData="tableData"
      />
      <div :class="['step-content',{step2:step == 2}, {hide:step == 3}]">
        <div :class="['step-box',{show:step == 1}]">
          <Step1
            ref="step1"
            :loading.sync="loading"
          />
        </div>
        <div :class="['step-box',{show:step == 2}]">
          <Step2
            ref="step2"
            :tableData="tableData"
          />
        </div>
      </div>
    </div>
    <template #footerCustom>
      <template v-if="step == 2 && showAgree">
        <div class="agree-box">
          <el-checkbox v-model="agree">我确认以上已上传的凭证真实有效,并知晓系统将同步变更拍卖平台上的交付人信息。</el-checkbox>
        </div>
      </template>
    </template>
  </baseDialog>
</template>

<script>
import dayjs from "dayjs"
// import reportTrackPageMixin from "@/mixins/reportTrackPageMixin"
import TipsBox from "./TipsBox"

import Step1 from "./step-1"
import Step2 from "./step-2"
import { createStaffHandover, queryAssets } from "@api/usedCarManagement"
export default {
  // mixins: [reportTrackPageMixin],
  name: "addHandover",
  components: {
    TipsBox,
    Step1,
    Step2
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
  },
  computed: {
    dialogShow: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', false)
      }
    },
    setting () {
      const { step } = this
      return {
        isShowFooter: true,
        showClose: true,
        appendToBody: false,
        btnList: [],
        hideConfirmBtn: step == 3,
        cancel_name: step == 2 ? '上一步' : '返回',
        confirm_name: {
          1: '下一步:扫描资产',
          2: '提交变更'
        }[step]
      }
    },
    stepImg () {
      const { step } = this
      return require(`./images/step-${step}.webp`)
    },
    componentName () {
      return {
        1: 'Step1',
        2: 'Step2'
      }[this.step]
    },
    step1Ref () {
      return this.$refs.step1
    },
    step2Ref () {
      return this.$refs.step2
    },
    showAgree () {
      const { tableData } = this
      let flag = false
      let len = tableData.findIndex(item => item.signCustodyStatus)
      if (len != -1) flag = true
      return flag
    }
  },
  mounted () { },
  watch: {
    visible: {
      handler (val) {
        if (val) {
          this.step = 1
          this.loading = true
          this.agree = false
          this.$nextTick(() => {
            this.step1Ref.init()
          })
          // setTimeout(() => this.loading = false, 1e3)
        } else {
          this.step = 1
          this.loading = false
        }
      },
      immediate: true,
      deep: true
    }
  },
  data () {
    return {
      step: 1,
      dialogConfig: {
        config: {
          title: "发起业务交接",
          width: "1200px"
        }
      },
      loading: true,
      tableData: [],
      btnLoding: false,
      agree: false
    }
  },
  methods: {
    handleDetailClose () {
      this.btnLoding = false
      const { step } = this
      if (step != 2) return this.$emit('update:visible', false)
      else this.step = 1
    },
    handleClick () {
      const { step } = this
      if (step == 1) this.queryAssets()
      if (step == 2) this.createStaffHandover()
    },
    async queryAssets () {
      try {
        const { formObj } = this.step1Ref,
          { originalUserId, newUserId } = formObj
        if (!originalUserId) throw '请原责任人'
        if (!newUserId) throw '请选择新接收人'
        this.btnLoding = true
        const data = await queryAssets({
          originalUserId
        })
        this.btnLoding = false
        if (data) {
          console.log(data)
          data.evalOrders.map(e => e.proofUrls = [])
          this.step = 2
          this.tableData = data.evalOrders || []
        }
      } catch (error) {
        this.btnLoding = false
        if (error) this.notice.warningTips(error)
      }
    },
    async createStaffHandover () {
      try {
        this.btnLoding = true
        const { formObj } = this.step1Ref,
          { filterArr } = this.step2Ref,
          { showAgree, agree } = this
        let num = 0
        const assets = filterArr()
        let agreeFlag = false
        if (assets.length) {
          assets.map(i => {
            if (i.signCustodyStatus && !i.proofUrls.length) num += 1
            if (i.signCustodyStatus) agreeFlag = true
          })
          if (num > 0) throw `有${num}辆“已签协议”的车辆未上传交接凭证。\n请在列表中点击“上传凭证”按钮补充材料`
        } else throw {
          text: '至少选择一个资产',
          type: 'infoTips'
        }
        if (showAgree && !agree && agreeFlag) throw {
          text: '请勾选底部的确认协议复选框',
          type: 'infoTips'
        }
        const params = {
          ...formObj,
          assets
        },
          data = await createStaffHandover(params)
        if (data) {
          this.notice.okTips('操作成功')
          this.btnLoding = false
          this.step = 3
          this.$emit("refresh")
        }
      } catch (error) {
        console.log(error)
        this.btnLoding = false
        if (error && error.type) {
          const { text, type } = error
          this.notice[type](text || '未知错误')
        }
        if (typeof error == 'string') this.notice.errorTips(error || '未知错误')
      }
    }

  }
}
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
  align-items: center;
}

.detail-content {
  ::v-deep .el-dialog {
    max-height: 70vh;
    display: flex;
    flex-direction: column;

    .el-dialog__body {
      overflow-y: scroll;
      padding-bottom: 24px;
      max-height: calc(100% - 137px);
    }
    .el-dialog__footer {
      margin-top: auto;
      border-top: 1px solid #e5e5e5;
    }
    .dialog-footer {
      border-top: none;
      padding-top: 10px;
    }
  }
  .content {
    .step-img {
      display: block;
      width: 1040px;
      height: 103px;
      margin: 0 auto;
    }
  }

  .circle {
    display: inline-block;
    border-radius: 50%;
    width: 6px;
    height: 6px;
    margin-right: 8px;
    vertical-align: middle;
  }
  .div-title {
    display: flex;
    align-items: center;
    height: 50px;
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    // margin: 10px 0 20px 0;
  }

  .block {
    height: 24px;
  }
  .step-content {
    position: relative;
    width: 100%;
    min-height: 82px;
    .step-box {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      visibility: hidden;
      height: 0;
      overflow: hidden;
    }
    .show {
      visibility: visible;
      height: auto;
    }
  }
  .step2 {
    min-height: 264px;
    // min-height: 298px;
  }
  .hide {
    min-height: 0 !important;
  }

  .agree-box {
    position: absolute;
    top: 10px;
    left: 0;
    display: flex;
    align-items: center;
    height: 36px;
    color: #666666;
    font-size: 14px;
    ::v-deep.el-checkbox__label {
      color: #666666;
    }
  }
}
</style>