<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="categoryName"  class="is-required">
          <el-input v-model="temp.categoryName" placeholder="分类名" />
        </el-form-item>

        <el-form-item label="状态" prop="categoryStatus"  class="is-required">
          <el-radio-group v-model="temp.categoryStatus" size="small">
            <el-radio-button label="0">正常</el-radio-button>
            <el-radio-button label="1">禁用</el-radio-button>
          </el-radio-group>
        </el-form-item>

<!--        <el-form-item label="所属门店" prop="shopId"  class="is-required">-->
<!--          <dept-select v-model="temp.shopId" @changeSelect="getDept"  style="width: 100%;"/>-->
<!--        </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 { editCategory } from "@/api/business/category/category";
import {setRequiredFields} from "@/utils";
import DeptSelect from "@/views/common/system/deptSelect";

const requiredFields = []

export default {
  name: "editForm",
  components: {DeptSelect},
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        categoryId:'',
        categoryName:'',
        categoryStatus:'',
        shopId:'',
        shopName:'',
      },
    }
  },
  methods: {
    open(row) {
      this.temp = this.$options.data().temp
      this.temp = row
      this.dialogVisible = true
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          editCategory(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()
    },
    getDept(e){
      console.log(e)
      this.temp.shopName = e.deptName
    }
  },
}
</script>

<style scoped>

</style>
