<template>
  <el-dialog
    :title="title"
    :visible.sync="dialog"
    width="600px"
    append-to-body
    @close="cancelForm"
  >
    <div class="demo-drawer__content" style="padding: 0 20px">
      <el-form :model="form" label-position="left" label-width="70px">
        <el-row :gutter="30">
          <el-col :span="24">
            <el-form-item label="作业内容">
              <el-input v-model="form.opContent" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="24" v-if="type == 1">
            <el-form-item label="取消原因">
              <el-input
                type="textarea"
                :rows="3"
                placeholder="请输入取消原因"
                v-model="form.cancelReason"
                :disabled="title == '明细'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="type == 2">
            <el-form-item label="临时计划原因">
              <el-input
                type="textarea"
                :rows="3"
                placeholder="请输入临时计划原因"
                v-model="form.planReason"
                :disabled="title == '明细'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelForm">取 消 </el-button>
      <el-button type="primary" @click="handleClose" :loading="loading">{{
        loading ? "提交中 ..." : "确 定"
      }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateWorkPlan } from "@/api/secure/pdm-work-plan";
export default {
  data() {
    return {
      title: "",
      form: {
        opContent: "",
        opAddr: "",
        subsOrLineId: "",
        voltLvlCd: "",
        opTypDsc: "",
        mgmtOrgNm: "",
        submitOrgNm: "",
        workPrincipNm: "",
        workTeamNm: "",
        opRiskLvlDsc: "",
        mainBusiOrgOpNum: "",
        planStartWkTm: "",
        planEndTm: "",
        majorTypDsc: "",
        cancelReason: "",
        planReason: "",
      },
      loading: false,
      dialog: false,
      type: null, //1作业取消计划  2临时计划
    };
  },
  methods: {
    openModel(data, title, type) {
      this.form = { ...data };
      this.title = title;
      this.dialog = true;
      this.type = type;
    },
    handleClose(done) {
      if (this.loading) {
        return;
      }
      this.loading = true;
      updateWorkPlan(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.loading = false;
        this.dialog = false;
        this.$emit("refresh");
      });
    },
    cancelForm() {
      this.form = {
        opContent: "",
        opAddr: "",
        subsOrLineId: "",
        voltLvlCd: "",
        opTypDsc: "",
        mgmtOrgNm: "",
        submitOrgNm: "",
        workPrincipNm: "",
        workTeamNm: "",
        opRiskLvlDsc: "",
        mainBusiOrgOpNum: "",
        planStartWkTm: "",
        planEndTm: "",
        majorTypDsc: "",
        cancelReason: "",
        planReason: "",
        id: null,
      };
      this.loading = false;
      this.dialog = false;
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep {
  .el-drawer.ttb,
  .el-drawer.btt {
    height: 90% !important;
  }
}
</style>
