<template>
  <div class="container">
    <el-row>
      <el-col :xl="8" :lg="8" :md="8" :sm="12" :xs="24">
        <el-form
          :model="reimebursementItemdata"
          :rules="rules"
          ref="form"
          label-width="120px"
          class="demo-ruleForm"
        >
          <el-form-item label="类型名称" prop="name">
            <el-input v-model="reimebursementItemdata.name"></el-input>
          </el-form-item>
          <el-form-item label="内容说明" prop="explain">
            <el-input v-model="reimebursementItemdata.explain"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="success"
              icon="el-icon-upload2"
              @click="updateType()"
              >提交</el-button
            >
            <el-button type="info" icon="el-icon-refresh-left" @click="cancel()"
              >取消</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { update,seleTypeid } from "@/api/reimburtypeList.js";
export default {
  created(){
    this.reimebursementItemdata.companyId = this.$store.getters.companyId;
    this.getTypeData()
  },
  data() {
    return {
      reimebursementItemdata: {
        companyId: 0,
        explain: "",
        id: 0,
        name: "",
      },
      rules: {
        name: [
          { required: true, message: "类型名称不能为空", trigger: "blur" },
        ],
        explain: [
          { required: true, message: "说明内容不能为空", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    id() {
      return this.$route.query.id;
    },
  },
  methods: {
    //获取数据
    getTypeData(){
      seleTypeid({id:this.id}).then((res)=>{
        if(res.success){
            this.reimebursementItemdata = res.data
        }else{
          this.$message.error(res.msg)
        }
      }).catch((error)=>{
        this.$message.error("查询数据失败")
      })
    },
    // 提交数据
    updateType(){
        update(this.reimebursementItemdata).then((res)=>{
        if(res.success){
          this.$message.success("修改成功")
        }else{
          this.$message.error(res.msg('名称重复'))
        }
      }).catch((error)=>{
        this.$message.error("修改失败")
      })
    },
    // 取消按钮
    cancel(){
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.push('/reimburtypeList')
    }
  },
};
</script>

<style>
.container {
  padding: 10px;
}
</style>