<template>
  <div>
    <el-form ref="reviewForm" :model="reviewObj" label-width="120px">
      <el-form-item label="申请理由">
        <el-input v-model="reviewObj.applyReason" type="textarea" rows="2" placeholder="请输入申请理由"></el-input>
      </el-form-item>
    </el-form>
    <el-row class="operate-button">
      <el-button type="success" @click="onSubmit">发起申请</el-button>
      <el-button @click="cancel">关闭</el-button>
    </el-row>
  </div>
</template>

<script>
import { approvalCreate, serviceMsg } from "@/api/ecw/boxSea";

/**
 * 反审
 */
export default {
  name: "review",
  inheritAttrs: false,
  data() {
    return {
      // 反审对象
      reviewObj: {},
    };
  },
  methods: {
    /** 提交 */
    onSubmit() {
      this.$refs["reviewForm"].validate((valid) => {
        if (valid) {
          const { currNode, shipmentObj } = this.$attrs;
          approvalCreate({
            shipmentId: shipmentObj.id,
            ...this.reviewObj,
            approvalStatus: 0,
            approvalType: currNode.type === "preinstall" ? 4 : 7, // 4预装反审 7卸柜反审核
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
          });
        }
      });
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
  },
};
</script>