<template>
  <div>
    <el-form :model="editLogin" label-width="120px">
      <el-card>
        <el-row>
          <el-col :span="22">
            <div class="text item">
              <el-form-item label="项目编号" prop="unitId">
                <el-input v-model="editLogin.code" placeholder="请输入模板编号" style="width: 100%"
                          size="small"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <div class="text item">
              <el-form-item label="项目名称" prop="unitId">
                <el-input v-model="editLogin.name" placeholder="请输入模板名称" style="width: 100%"
                          size="small"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <div class="text item">
              <el-form-item label="规格" prop="ggxh">
                <el-input v-model="editLogin.ggxh" placeholder="请输入规格" style="width: 100%"
                          size="small"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <div class="text item">
              <el-form-item label="备注" prop="unitId">
                <el-input type="textarea" :rows="3" v-model="editLogin.remark" placeholder="请输入备注"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <div style="text-align: center; margin-top: 10px;">
          <el-button type="primary" size="small" icon="search" @click="onModifySubmit" :loading="submitLoading">提交</el-button>
          <el-button type="primary" size="small" icon="search" @click="closeDialog">取消</el-button>
        </div>
      </el-card>
    </el-form>
  </div>
</template>

<script>


import {addModeldestiny, editModeldestiny} from "@/api/basic/basicDestinyRel";
import {isBlank} from "@/utils/strUtil";

export default {
  name: 'bindPlatformModel',
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
    editQuery: {
      type: Object,
      required: true,
    },
    type: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      editLogin: {
        id: null,
        name: null,
        code: null,
        remark: null,
      },
      submitLoading: false
    };
  },
  methods: {
    onModifySubmit() {
      if (isBlank(this.editLogin.name)) {
        return this.$message.error("模板名称不能为空");
      }
      if (isBlank(this.editLogin.code)) {
        return this.$message.error("模板编号不能为空");
      }
      this.submitLoading = true
      if (this.editLogin.id != null) {
        editModeldestiny(this.editLogin).then(res => {
          this.submitLoading = false
          if (res.code == 20000) {
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }
        }).catch(() => {
          this.submitLoading = false
          this.$message.error("编辑失败！");
        });
      } else {
        this.editLogin.type =  this.type
        addModeldestiny(this.editLogin).then(res => {
          this.submitLoading = false
          if (res.code == 20000) {
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }
        }).catch(() => {
          this.submitLoading = false
          this.$message.error("提交失败！");
        });
      }
    }


  },
  created() {
    if (isBlank(this.editQuery.id)) {
      this.editLogin = {}
    } else {
      this.editLogin = this.editQuery
    }
  }
};
</script>

<style scoped>

</style>
