<template xmlns="http://www.w3.org/1999/html">

  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="()=>{
      $parent.showReturnWarehouse = false;
    }"
    width="80%">
    <div style="padding: 0 20px">
      <h1>{{consDetails.expressNo}}-{{$t('集运包裹退仓处理')}}</h1>
      <h3>{{$t('包裹ID')}}-{{consDetails.consNum}}</h3>
      <h3><span>{{$t('退仓原因')}}-{{params.reason}}</span><span style="margin-left: 20px">{{$t('退仓审核通过时间')}}-{{params.approvalTime|parseTime}}</span></h3>
      <el-divider></el-divider>
      <el-form label-width="150px">
        <el-form-item :label="$t('退仓快递公司')">
          <el-select v-model="params.expressId" :placeholder="$t('请选择快递公司')">
            <el-option v-for="nodeItem in expressList" :key="nodeItem.id" :label="nodeItem.companyName"
                       :value="nodeItem.id"/>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('退仓快递单号')">
          <el-input v-model="params.expressNo" :placeholder="$t('请输入退仓的快递单号')" :disabled="false"/>
        </el-form-item>
        <el-form-item  :label="$t('退仓费用')" >
            <el-input v-model="params.expenses" :disabled="isExamine" placeholder="" class="w-100 mr-10"></el-input>
            <el-select  :disabled="isExamine" defaultable v-model="params.currency" :placeholder="$t('请选择货币单位')" style="width: 110px">
              <el-option v-for="item in currencyList" :key="item.id" :label="isChinese ? item.titleZh :item.titleEn" :value="item.id" />
            </el-select>
        </el-form-item>
        <el-form-item :label="$t('退仓收件人')">
          <el-input v-model="params.name" style="width:500px"></el-input>
        </el-form-item>
        <el-form-item :label="$t('退仓收件电话')">
          <el-input v-model="params.phone" style="width:500px"></el-input>
        </el-form-item>
        <el-form-item :label="$t('退仓收件地址')">
          <el-input v-model="params.address" style="width:500px" type="textarea"></el-input>
        </el-form-item>
        <el-form-item :label="$t('图片')">
          <image-and-video-upload   :file-type="['png' , 'jpg', 'jpeg']" :fileSize="50" :isShowTip="true" v-model="params.imgUrl" ></image-and-video-upload>
        </el-form-item>
      </el-form>
      <el-divider></el-divider>
      <div>
        <el-button v-if="!isExamine" @click="submit(1)" type="primary" style="margin-right: 20px;">{{$t('退仓完成')}}</el-button>
        <el-button  @click="submit(2)" type="primary" style="margin-right: 20px;">{{$t('确认修改')}}</el-button>
        <el-button @click="$parent.showReturnWarehouse = false;">{{$t('稍后再看')}}</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<!--退仓-->
<script>
import ImageAndVideoUpload from "@/components/ImageAndVideoUpload/index.vue";
import {editAndUpdateConsRetiredWarehouseDeal, getCons} from "@/api/ecw/cons";
import {getConsApprovalList} from "@/api/ecw/consApproval";
import {parseTime} from "@/utils/ruoyi";
import {getExpressPage} from "@/api/ecw/express";
import {getCurrencyPage} from "@/api/ecw/currency";

export default {
  filters: { parseTime },
  name: "withdrawal",
  props:{
    consId:Number,
    dialogVisible:Boolean
  },
  components:{
    ImageAndVideoUpload,
  },
  data(){
    return {
      consDetails:{},
      approvalDetail:{},
      params:{
        consId:undefined,
        expressNo:undefined,
        name:'',
        phone:'',
        address:'',
        reason:'',
        copyUserId:[],
        imgUrl:[]
      },
      isExamine:false,
      details:{},
      expressList: [],
      currencyList:[],
    }
  },
  computed:{
    isChinese(){
      return this.$i18n.locale === 'zh_CN'
    },
  },
  created() {
    this.getExpressList()
    getCurrencyPage(this.params).then(res => this.currencyList = res.data.list)
    getCons(this.consId).then(r =>{
      this.consDetails = r.data
    });
    getConsApprovalList({consId:this.consId,approvalType:0,status: 2}).then(r => {
      if(r.data.length!=0){
          this.details = r.data[0];
          this.approvalDetail = JSON.parse(r.data[0].approvalDetail)
          this.params.reason = this.approvalDetail.reason
          this.params.imgUrl = this.approvalDetail.imgUrl
          this.params.name = this.approvalDetail.name
          this.params.phone = this.approvalDetail.phone
          this.params.address = this.approvalDetail.address
          this.params.expressId = this.approvalDetail.expressId
          this.params.expressNo = this.approvalDetail.expressNo
          this.params.expenses = this.approvalDetail.expenses
          this.params.currency = this.approvalDetail.currency
          if (this.approvalDetail.isDeal){
            this.isExamine = this.approvalDetail.isDeal;
          }
          this.params.approvalTime = r.data[0].approvalTime
          this.params.formId = r.data[0].formId
      }

    })
  },
  methods:{
    getExpressList() {
      let params = {
        pageNo: 1,
        pageSize: 1000
      }
      getExpressPage(params).then((res) => {
        this.expressList = res.data.list
      })
    },
    submit(val){
      this.params.consId =  this.consDetails.id;
      this.params.imgUrl =  Array.isArray(this.params.imgUrl)? this.params.imgUrl.join(','): this.params.imgUrl;
      this.params.consNum =  this.consDetails.consNum
      if (val === 1){
        this.params.isDeal = true
      }else {
        this.params.isDeal = false
      }
        //退仓完成
      editAndUpdateConsRetiredWarehouseDeal(this.params).then(r => {
       if(r.code === 0){
         if (val === 1){
           this.$message.success(this.$t('退仓成功'));
         }else {
           this.$message.success(this.$t('退仓修改成功'));
         }
         this.params = {}
         this.$parent.showReturnWarehouse = false
       }
      })
    }
  }
}
</script>

<style scoped>

</style>
