<template>
  <div>
    <el-form :model="editLogin" label-width="30%">
      <el-card>
        <el-row>
          <el-col :span="18">
            <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="18">
            <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="18">
            <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">提交</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,
    },
  },
  data() {
    return {
      editLogin: {
        id: null,
        name: null,
        code: null,
        remark: null,
      },
    };
  },
  methods: {
    onModifySubmit() {
      if (this.editLogin.id != null) {
        editModeldestiny(this.editLogin).then(res => {
          if (res.code == 20000) {
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }
        }).catch(() => {
          this.$message.error("编辑失败！");
        });
      } else {
        addModeldestiny(this.editLogin).then(res => {
          if (res.code == 20000) {
            this.closeDialog();
          } else {
            this.$message.error(res.message);
          }
        }).catch(() => {
          this.$message.error("提交失败！");
        });
      }
    }


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

<style scoped>

</style>
