<template>
  <div class="cmain">
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <el-form-item label="项目名称" prop="atvName">
        <el-input
          v-model="form.atvName"
          placeholder="请输入项目名称"
          style="width: 50%"
        ></el-input>
      </el-form-item>
      <el-form-item label="建设规模" prop="scale">
        <el-select
          v-model="form.scale"
          placeholder="请选择建设规模"
          style="width: 50%"
        >
          <el-option
            v-for="item in scaleList"
            :key="item.value + 'typeList'"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="建设内容" prop="content">
        <el-input
          type="textarea"
          :rows="5"
          v-model="form.content"
          placeholder="请输入建设内容"
        ></el-input>
      </el-form-item>
      <el-form-item label="年度投资计划(万)" prop="plan">
        <el-input
          type="number"
          v-model="form.plan"
          placeholder="请输入年度投资计划"
          style="width: 50%"
        ></el-input>
      </el-form-item>
      <el-form-item label="形象进度" prop="schedule">
        <el-input
          v-model="form.schedule"
          placeholder="请输入形象进度"
          style="width: 50%"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="mfooter">
      <el-button type="primary" @click="submitForm(0)">保 存</el-button>
      <el-button type="primary" @click="submitForm(1)">提交审核</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>
  
  <script>
import {
  listARTICLE,
  getARTICLE,
  delARTICLE,
  addARTICLE,
  updateARTICLE,
  audit
} from "@/api/portal/ARTICLE/ARTICLE.js";
export default {
  data() {
    return {
      scaleList: [
        { label: "小型", value: 1 },
        { label: "中型", value: 2 },
        { label: "大型", value: 3 },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        preview: [
          { required: true, message: "项目情况概述不能为空", trigger: "blur" },
        ],
        atvName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" },
        ],
        scale: [
          { required: true, message: "建设规模不能为空", trigger: "blur" },
        ],
        unit: [{ required: true, message: "单位不能为空", trigger: "blur" }],
        content: [
          { required: true, message: "建设内容不能为空", trigger: "blur" },
        ],
        plan: [
          { required: true, message: "年度投资计划不能为空", trigger: "blur" },
        ],
        reality: [
          {
            required: true,
            message: "实际完成投资额不能为空",
            trigger: "blur",
          },
        ],
        retio: [
          { required: true, message: "完成百分比不能为空", trigger: "blur" },
        ],
        schedule: [
          { required: true, message: "形象进度不能为空", trigger: "blur" },
        ],
      },
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      },
    },
    layerid: {
      type: String,
    },
  },
  mounted() {
    if (this.param.id) {
      getARTICLE(this.param.id).then((response) => {
        this.form = response.data;
      });
    }
  },
  methods: {
    /** 提交按钮 */
    submitForm(type) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            if (type == 0) {
              updateARTICLE(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.$layer.close(this.layerid);
                this.$parent.getList();
              });
            } else if (type == 1) {
              this.form.status = 1;
              audit(this.form).then((response) => {
                this.$modal.msgSuccess("提交成功");
                this.$layer.close(this.layerid);
                this.$parent.getList();
              });
            }
          } else {
            this.form.status = 1;
            addARTICLE(this.form).then((response) => {
              this.$modal.msgSuccess("提交审核成功");
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          }
        }

        // if (valid) {
        //   if (this.form.id != null) {
        //     console.log("修改内容");
        //     updateARTICLE(this.form).then((response) => {
        //       this.$modal.msgSuccess("修改成功");
        //       this.$layer.close(this.layerid);
        //       this.$parent.getList();
        //     });
        //   } else {
        //     if (type == 0) {
        //       console.log("草稿保存");
        //       this.form.status = 0;
        //       addARTICLE(this.form).then((response) => {
        //         this.$modal.msgSuccess("保存成功");
        //         this.$layer.close(this.layerid);
        //         this.$parent.getList();
        //       });
        //     } else if (type == 1) {
        //       console.log("草稿提交审核");
        //       this.form.status = 1;
        //       addARTICLE(this.form).then((response) => {
        //         this.$modal.msgSuccess("提交审核成功");
        //         this.$layer.close(this.layerid);
        //         this.$parent.getList();
        //       });
        //     }
        //   }
        // }
      });
    },
  },
};
</script>
  