<template>
  <div id="root">
    <el-form :model="formInline" label-width="80px" class="form-class">
      <el-form-item label="名称">
        <el-input v-model="formInline.name"/>
      </el-form-item>
      <el-form-item label="号码">
        <el-input v-model="formInline.tel"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="formInline.remark"/>
      </el-form-item>
      <div class="button-class">
        <el-button type="info" @click="exit">取消</el-button>
        <el-button type="primary" @click="add">保存</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
      formInline: {
        name: '',
        tel: '',
        remark: ''
      }
    }
  },
  methods: {
    add() {
      this.$store.dispatch('TelAdd', this.formInline).then(res => {
        const resCode = res.code
        if (resCode === '1') {
          this.$message.error(res.message)
          return
        }
        this.$message.success(res.message)
        this.$router.go(-1)
      }).catch(() => {
        console.log('error TelAdd')
      })
    },
    exit() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
.form-class {
  width: 400px;
  margin-right: auto;
  margin-left: auto;
  margin-top: 20px;
}
.button-class {
  display: flex;
  justify-content: center;
}
</style>
