<template>
  <div class="cmain">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="微信id" prop="openId">
          <el-input v-model="form.openId" placeholder="请输入微信id" clearable/>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态" clearable/>
        </el-form-item>
        <el-form-item label="创建者" prop="createBy">
          <el-input v-model="form.createBy" placeholder="请输入创建者" clearable/>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker clearable
            v-model="form.createTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新者" prop="updateBy">
          <el-input v-model="form.updateBy" placeholder="请输入更新者" clearable/>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateTime">
          <el-date-picker clearable
            v-model="form.updateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
    <div class="mfooter">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      rules: {
        openId: [
          { required: true, message: "微信id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  mounted() {
    if (this.param.id) {
      this.ajax({ url: '/work/user/detail/' + this.param.id }).then(response => {
        this.form = response.data;
      });
    }
  },
  methods: {
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id) {
              this.ajax({method: 'post',url: '/work/user/edit', data: this.form }).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.$layer.close(this.layerid);
                  this.$parent.getList();
              });
          } else {
              this.ajax({method: 'post',url: '/work/user/add', data: this.form }).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.$layer.close(this.layerid);
                  this.$parent.getList();
               });
          }
        }
      });
    }
  }
};
</script>
