<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-card>
        <div slot="header" class="card-title">{{$t('申请泡货优惠')}}-{{queryParams.orderNo||''}}</div>
        <el-form :model="queryParams" ref="queryForms" size="small" :inline="true"  label-width="120px" class="card">
          <el-row >
              <el-form-item :label="$t('原泡货标准:')" label-width="150px">
                  <span>{{queryParams.orgVWeight}}kg/cbm</span>
              </el-form-item>
          </el-row>
          <el-row :span="8" >
             <el-form-item :label="$t('现泡货申请标准:')" size="medium" label-width="150px" required>
               <el-input style="width: 100px;"  type="text" v-model="queryParams.vweight"  />
                <span style="margin-left: 10px;">kg/cbm</span>
             </el-form-item>
          </el-row>
          <el-row :span="8">
             <el-form-item :label="$t('备注:')" size="medium" label-width="150px">
               <el-input style="width: 500px;"  type="textarea" v-model="queryParams.remarks"  />
             </el-form-item>
          </el-row>
        </el-form>
    </el-card>
    <work-flow xmlkey="heavy_goods_discount" v-model="selectedUsers" style="margin-top: 20px;"></work-flow>
    <div slot="footer" class="card footer_btn">
        <el-button v-if="queryParams.applyStatus==0" type="primary" @click="submitForm">{{$t('提交')}}</el-button>
        <el-button v-if="queryParams.applyStatus==0" plain type="primary" @click="$store.dispatch('tagsView/delCurrentView')">{{$t('取消')}}</el-button>
       <el-button v-if="queryParams.applyStatus==1" type="primary" @click="$router.push(`/bpm/process-instance/detail?id=`+queryParams.formId)">{{$t('审核中')}}</el-button>
       <el-button v-if="queryParams.applyStatus==1" plain type="primary" @click="dialogVisible = true">{{$t('取消审核')}}</el-button>
       <el-button v-if="queryParams.applyStatus==1" plain type="primary" @click="$store.dispatch('tagsView/delCurrentView')">{{$t('返回')}}</el-button>
    </div>
    <el-dialog
      :title="$t('提示')"
      :visible.sync="dialogVisible"
      width="30%">
      <span class="cancel_notice">{{$t('申请泡货优惠正在审核中，你确定取消申请泡货优惠吗？')}}</span>
      <div class="cancel_content">
        <span>{{$t('取消原因')}}：</span>
        <el-input v-model="reason" :placeholder="$t('请输入取消原因')"></el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">{{$t('取消')}}</el-button>
        <el-button type="primary" @click="cancelSplit">{{$t('确定')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {getDictData, getDictDatas,DICT_TYPE} from '@/utils/dict'
import WorkFlow from '@/components/WorkFlow'
import {getOrderSpecial,createOrderSpecial,cancelOrderSpecial} from '@/api/ecw/order'

export default {
  name: "specialLight",
  components: {
    WorkFlow
  },
  props: {
    orderId: [String, Number]
  },
  data() {
    return {
      reason:'',
      dialogVisible:false,
      loading:false,
      queryParams:{
        orderId:7,
        lang:0
      },
      selectedUsers:[],
      orderData:{},
    };
  },
  created() {
    if (this.orderId) {
      this.queryParams.orderId = this.orderId
      this.getOrderSpecialData()
    }
    // this.getList()
  },
  computed:{
    getDictData(){
        return (type, value) => getDictData(type, value) || {}
    },
    getDictDatas(){
        return getDictDatas
    }
  },
  methods: {
   getOrderSpecialData(){
     getOrderSpecial(this.queryParams.orderId,5).then(r => {
       this.queryParams = r.data
     })
   },
    submitForm(){
      this.queryParams.applyType = 5
      this.queryParams.ccIds = this.selectedUsers.join(',')
     createOrderSpecial(this.queryParams).then(r => {
        this.$message.success(r.msg || this.$t('提交成功'))
        this.$store.dispatch('tagsView/delCurrentView')
      })
    },
    cancelSplit(){
      let that = this
      if(!that.reason){
        that.$message.error(this.$t("请输入取消原因"));
        return
      }
       cancelOrderSpecial(that.queryParams.orderApprovalId,{reason:that.reason}).then(res=>{
          that.$message.success(this.$t("取消成功"));
          that.$store.dispatch('tagsView/delCurrentView')
        })
    },

  }
}
</script>
<style scoped>
  .card-title{
      font-size: 18px;
      font-weight: bold;
       margin-top: 10px;
  }
  .card-info{
    font-size: 16px;
  }
  .card{
    margin-top: 20px;
  }
  .btn-header{
    width: 90%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 0;
  }
  .red{
    color:#ff3430;
    font-size: 15px;
  }
  .footer_btn{
    padding-bottom: 60px;
  }
  .cancel_notice{
    font-size: 16px;
    font-weight: 600;
  }
  .cancel_content{
    display: flex;
    align-items: center;
    padding-top: 20px;
  }
  .cancel_content span{
    width: 100px;
  }
</style>
