<template>
    <el-dialog :visible="true" title="撤销拆单" :before-close="close">
      <el-form :model="form" label-width="100px">
        <!--<el-form-item label="申请理由">
          <el-input v-model="form.reason"></el-input>
        </el-form-item>-->
        <el-form-item label="抄送">
          <work-flow v-model="form.ccIds" xmlkey="revoke_split_order"></work-flow>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <template v-if="formId" >
          <el-button type="primary" @click="toBpmDetail">审核中</el-button>
          <el-button type="default" @click="cancelApproval">取消审核</el-button>
        </template>
        <el-button v-else type="primary" @click="submit" :loading="submitting" :disabled="submitting">确认</el-button>
      </div>
    </el-dialog>
</template>

<script>
import WorkFlow from "@/components/WorkFlow";
import {cancelSplitRevoke, orderSplitRevoke, splitRevoke} from '@/api/ecw/order'
export default {
  name: "SplitRevoke",
  components: { WorkFlow},
  props:{
    orderId: Number
  },
  data(){
    return {
      formId: null, // 审批ID
      submitting: false,
      form: {
        ccIds: []
      }
    }
  },
  created() {
    splitRevoke(this.orderId).then(res =>{
      console.log(res)
      if(res.data.formId){
        this.formId = res.data.formId
      }
    })
  },
  methods:{
    submit(){
      console.log('提交')
      if(this.submitting) return
      this.submitting = true
      orderSplitRevoke({
        orderId: this.orderId,
        copyUserId: this.form.ccIds
      }).then(res => {
        this.$message.success(res.msg || '操作成功')
        this.close()
      }).finally(() =>{
        this.submitting = false
      })
    },
    close(){
      this.$emit('close')
    },
    toBpmDetail(){
      this.$router.push(`/bpm/process-instance/detail?id=${this.formId}`)
      this.close()
    },
    // 取消审核
    cancelApproval(){
      this.$prompt(this.$t("请输入取消原因")).then(res => {
        return cancelSplitRevoke({orderId: this.orderId, reason: res.value})
      }).then(res => {
        this.$message.success(res.msg || this.$t('操作成功'))
        this.close()
      })
    }
  }
}
</script>

<style scoped>

</style>
