<template>

  <el-dialog
    :visible.sync="dialogVisible"
    :before-close="()=>{
      $parent.show = false;
    }"
    width="80%">
    <div style="padding: 0 20px">
      <h1>{{$t('申请退仓')}}-{{orderDetails.orderNo}}</h1>
      <el-divider></el-divider>
      <el-form label-width="150px">
        <el-form-item :label="$t('退仓原因')">
          <el-input v-model="params.reason" style="width:500px" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <el-divider></el-divider>
      <h2>{{$t('审批流程')}}</h2>
      <div style="padding: 20px">
        <work-flow xmlkey="retired_warehouse" v-model="params.copyUserId"  />
      </div>
      <div>
        <el-button v-if="isExamine" @click="submit" type="primary" style="margin-right: 20px;">{{$t('确定退仓')}}</el-button>
        <el-button v-if="!isExamine" @click="$router.push({query:{id:details.formId},path:'/bpm/process-instance/detail'})" type="primary" style="margin-right: 20px;">{{$t('审核中')}}</el-button>
        <el-button  v-if="!isExamine" type="primary" style="margin-right: 20px;" @click="cancellationOfOrder">{{$t('取消审核')}}</el-button>
        <el-button @click="$parent.show = false;">{{$t('不，再考虑考虑')}}</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<!--退仓-->
<script>
import {cancelAdjust, getOrder} from "@/api/ecw/order";
import {
  getRollbackApprovalInfo,
  orderWarehouseInDelete,
  warehouseApprovalCancel
} from "@/api/ecw/batchSingleApplication";
import workFlow from "@/components/WorkFlow";

export default {
  name: "withdrawal",
  props:{
    orderId:Number,
    dialogVisible:Boolean
  },
  components:{
    workFlow
  },
  data(){
    return {
      orderDetails:{},
      params:{
        orderId:undefined,
        orderNo:undefined,
        reason:'',
        copyUserId:[],
      },
      isExamine:true,
      details:{},


    }
  },
  created() {
    getOrder(this.orderId).then(r => this.orderDetails = r.data);
    getRollbackApprovalInfo({orderId:this.orderId}).then(r => {
      console.log(r)
      if(r.data.status === 1){
          this.details = r.data;
          this.isExamine = false;
          this.params.reason = JSON.parse(this.details.details).reason
      }

    })
  },
  methods:{
    submit(){
      this.params.orderId =  this.orderDetails.orderId;
      this.params.orderNo =this.orderDetails.orderNo;
      orderWarehouseInDelete(this.params).then(r => {
       if(r.code === 0){
         this.$message.success(this.$t('退仓成功'));
         this.params = {}
         this.$parent.show = false
       }
      })
    },
    cancellationOfOrder(){
      this.$prompt(this.$t('请输入取消审核原因'), this.$t('提示'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
      }).then(({ value }) => {
        warehouseApprovalCancel(this.details.id,value) .then(r => {
          if(r.data){
            this.$message.success(this.$t('取消成功'))
            this.params = {}
            this.$parent.show = false

          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: this.$t('取消成功')
        });
      });
    }
  }
}
</script>

<style scoped>

</style>
