<template>
  <div>
    <el-card style="margin: 5px;margin-top: -20px">
      <el-form :model="projectSet" ref="dataForm" label-width="100px" style="width: 80%; margin: auto ;">
        <el-button-group style="display: flex;margin: 0px 0 10px 80%; height: 35px">
          <el-button
            type="primary"
            @click.native="submit()"
          >确认
          </el-button>
          <el-button
            type="primary"
            @click.native="cancel()"
          >取消
          </el-button>
        </el-button-group>

        <el-row>
          <el-col :span="20">
            <el-form-item class="query-form-item" label="项目编码:">
              <el-input v-model="projectSet.code" placeholder="请输入项目编码" style="width: 100%"
                        clearable></el-input>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item label="项目类型:">
              <el-select v-model="projectSet.type" style="width: 100%; " placeholder="请选择项目类型" clearable="true"
              >
                <el-option label="巡检" :value="1"></el-option>
                <el-option label="养护" :value="2"></el-option>
                <el-option label="报修" :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item class="query-form-item" label="备注:">
              <el-input v-model="projectSet.remark" placeholder="请输入备注" style="width: 100%"
                        clearable></el-input>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="20">
            <el-form-item class="query-form-item" label="项目内容:">
              <el-input v-model="projectSet.content" placeholder="请输入项目内容" style="width: 100%" rows=10
                        type="textarea"
                        clearable></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

  </div>

</template>

<script>
import {isBlank} from "@/utils/strUtil";

import {insertDevprojectSet, updateDevprojectSet,} from "@/api/dev/deviceProjectSet";


export default {
  props: {
    repairOrder: {
      type: Object,
      required: true
    },
    closeDialog: {
      type: Function,
      required: true
    },
    formName: {
      type: Function,
      required: true
    },

  },
  name: "DeviceProjectSetDialog",
  data() {
    return {
      projectSet: {
        id: null,
        code: "",
        content: null,
        type: null,
      }

    };
  },
  methods: {
    submit() {
      if ("add" === this.formName) {
        insertDevprojectSet(this.projectSet).then((res) => {
          if (res.code == 20000) {
            this.$message.success("添加成功!");
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }

        })
      } else {
        updateDevprojectSet(this.projectSet).then((res) => {
          if (res.code == 20000) {
            this.$message.success("修改成功!");
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }

        })

      }

    },
    cancel() {
      this.closeDialog();
    },


  },
  created() {
    if (!isBlank(this.repairOrder.id)) {
      //编辑
      this.projectSet = this.repairOrder;
    }
  },
}
</script>

<style scoped>

</style>
