<template>
  <div v-loading.fullscreen.lock="fullscreenLoading" element-loading-spinner="page-loading" class="page special-business-card-binding">
    <pageTitle title="卡解绑" />
    <owner-type ref="ownerType" :step-index="1" :cur-type="onwnerType" />
    <comp-client-confirm
      ref="compClientConfirm"
      :form-data="formData"
      :wait-visible.sync="waitVisible"
      :opreator-uuid="opreatorUuid"
      type="UNBIND"
      prompt-info="操作等待中..."
    />
    <div class="next-step">
      <el-button size="small" plain @click="handlePrev">上一步</el-button>
      <el-button size="small" type="primary" @click="handleSendMsg">发送确认短信</el-button>
    </div>
    <comp-confirm
      :show.sync="tipVisible"
      :desc="desc"
      :show-cancel-btn="false"
      @on-sure="closeVisible"
    />
  </div>
</template>

<script>
import Common from '@/components/Common'
import OwnerType from './components/owner-type'
import CompClientConfirm from '@/components/CompClientConfirm'
import CompConfirm from '@/components/CompConfirm'
import { cardUnbindOriginalOwner } from '@/api/special-business'
export default {
  name: 'CardUnbindingStepTwo',
  components: {
    OwnerType,
    CompClientConfirm,
    CompConfirm
  },
  mixins: [Common],
  data() {
    return {
      onwnerType: 0,
      waitVisible: false,
      formData: {},
      fullscreenLoading: false,
      unbindInfo: {},
      opreatorUuid: '',
      tipVisible: false,
      desc: ''
    }
  },
  created() {
    this.formData = this.cacheGetStepData('CardUnbindingStepOne')
  },
  methods: {
    /**
    * 返回上一步
    * @time 2022-04-23 15:59:56
    */
    handlePrev() {
      this.$router.push({
        name: 'CardUnbindingStepOne',
        params: {
          from: 'prev'
        }
      })
    },

    /**
    * 确认弹出
    * @time 2022-04-23 14:20:57
    */
    handleSendMsg() {
      // ce68c8d1524f403f8bf2113dee0873ca
      const curRnrId = this.$refs.compClientConfirm.rnrId
      if (!curRnrId) {
        this.$message.error('获取当前车卡的实名信息失败')
        return false
      }
      // 解绑原车主
      this.fullscreenLoading = true
      const arr = []
      this.formData.iccidList.map(item => {
        if (item.iccid !== '') {
          arr.push(item.iccid)
        }
      })
      cardUnbindOriginalOwner({
        vin: this.formData.vin,
        iccidList: arr,
        rnrId: curRnrId
      }).then(data => {
        this.unbindInfo = data
        this.opreatorUuid = this.unbindInfo.uuid
        this.fullscreenLoading = false
        this.waitVisible = true
      }).catch((err) => {
        this.fullscreenLoading = false
        this.tipVisible = true
        this.desc = err.message
      })
    },

    /**
    * 关闭警告
    * @time 2022-04-23 15:59:13
    */
    closeVisible() {
      this.tipVisible = false
    }
  }
}
</script>
