<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      top="8vh"
      width="40%"
      :visible.sync="dialogVisible"
      center
      @close="handleCancel"
    >
      <div class="el-dialog-div">
      <el-form
        :rules="rules"
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="120px"
        style="height: 90%;"
      >
          <el-form-item label="工号" prop="serverNo"  class="is-required">
            <el-input v-model="temp.serverNo" placeholder="工号" />
          </el-form-item>

          <el-form-item label="服务人员名称" prop="serverName"  class="is-required">
            <el-input v-model="temp.serverName" placeholder="服务人员名称" />
          </el-form-item>

          <el-form-item label="服务人员手机号" prop="serverPhone"  class="is-required">
            <el-input v-model="temp.serverPhone" placeholder="服务人员手机号" />
          </el-form-item>

          <el-form-item label="入职时间" prop="joinTime"  class="is-required">
            <el-date-picker
              v-model="temp.joinTime"
              type="date"
              placeholder="选择日期"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>

          <el-form-item label="小程序密码" prop="miniappPassword"  class="is-required">
            <el-input v-model="temp.miniappPassword" placeholder="小程序密码-" />
          </el-form-item>

      </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addServer} from "@/api/business/server/server";
import {setRequiredFields} from "@/utils";
const requiredFields = []
export default {
  name: "addForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        serverId:'',
        serverNo:'',
        serverName:'',
        serverPhone:'',
        joinTime:'',
        miniappPassword:'',
        deleted:'',
        shopId:'',
        shopName:'',
        createName:'',
        createTime:'',
        createId:'',
        updateTime:'',
        updateName:'',
        updateId:'',
      },
    }
  },
  methods: {
    open() {
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addServer(this.temp).then(response =>{
            this.handleCancel()
            this.$emit('ok', response.data)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    handleCancel() {
      //初始化
      this.temp = this.$options.data().temp
      this.dialogVisible = false
      this.$refs['dataForm'].resetFields();
    }
  },
}
</script>

<style scoped>

</style>
