<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="memberName" class="is-required">
          <el-input v-model="temp.memberName" placeholder="会员姓名" />
        </el-form-item>

        <el-form-item label="手机号" prop="memberPhone" class="is-required">
          <el-input v-model="temp.memberPhone" placeholder="手机号" />
        </el-form-item>

        <el-form-item label="备注" prop="remark" class="is-required">
          <el-input v-model="temp.remark" placeholder="备注" />
        </el-form-item>

        <el-form-item label="消费密码" prop="payPassword" class="is-required">
          <el-input v-model="temp.payPassword" placeholder="消费密码" />
        </el-form-item>

<!--        <el-form-item label="所属门店" prop="shopId"  class="is-required">-->
<!--          <el-select v-model="temp.shopId" placeholder="请选择" @change="handleSelect">-->
<!--            <el-option-->
<!--              v-for="item in deptList"-->
<!--              :key="item.deptId"-->
<!--              :label="item.deptName"-->
<!--              :value="item.deptId">-->
<!--              <span style="float: left">{{ item.deptName }}</span>-->
<!--              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.deptNo }}</span>-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </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 { editMember } from "@/api/business/member/member";
import {getDeptList} from "@/api/system/dept/dept";
import {setRequiredFields,getSelectObj} from "@/utils";
const requiredFields = []

export default {
  name: "editForm",
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        memberId:'',
        memberName:'',
        memberPhone:'',
        remark:'',
        payPassword:'',
        shopName:'',
        shopId:'',
        createTime:'',
      },
      deptList:[]
    }
  },
  methods: {
    open(row) {
      this.temp = this.$options.data().temp
      this.temp = row
      this.dialogVisible = true
      getDeptList().then(response => {
        this.deptList = response.data
      })
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          editMember(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()
    },
    handleSelect(e){
      console.log(e)
      let obj = getSelectObj(e,this.deptList,"deptId")
      console.log(obj)
      this.temp.shopName = obj.deptName
    }
  },
}
</script>

<style scoped>

</style>
