<template>
  <div id="root">
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="ruleForm.name" placeholder="姓名"/>
      </el-form-item>
      <el-form-item class="filter-item" label="电话号码" prop="tel">
        <el-input v-model.trim="ruleForm.tel" placeholder="号码" oninput="value=value.replace(/[^\d]/g,'')"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="ruleForm.remark" placeholder="备注"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="editPhone()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        id: '',
        name: '',
        tel: '',
        remark: '',
        pageNum: 1,
        pageSize: 10,
        menuArray: [] // 已选中的权限资源
      },
      defaultProps: { // 设置树形节点的渲染的属性
        id: 'id',
        label: 'roleName',
        children: 'children'
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ],
        tel: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { min: 11, max: 11, required: true, message: '请输入11位手机号', trigger: 'blur' }
        ],
        remark: [
          { required: false, message: '请输入备注', trigger: 'blur' }

        ]
      }
    }
  },
  mounted() {
    console.log('this.$route.query.id', this.$route.query.id)
    this.getOperateId(this.$route.query.id)
  },
  methods: {
    getOperateId(id) {
      this.ruleForm.id = id
      this.$store.dispatch('GetOperateId', this.ruleForm).then((res) => {
        this.ruleForm.name = res.data.name
        this.ruleForm.tel = res.data.tel
        this.ruleForm.remark = res.data.remark
      }).catch(() => {
        console.log('error getOperateId')
      })
    },
    editPhone() {
      this.$store.dispatch('Phoneedit', this.ruleForm).then((res) => {
        if (res.code === '0') {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.$router.push({ name: 'phoneconfig-phoneconfigIndex' })
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        console.log('error Phoneedit')
      })
    }
  }
}
</script>

<style scoped>
.demo-ruleForm {
  width: 500px;
  margin-top: 20px;
  margin-left: auto;
  margin-right: auto;
}
</style>
