<template>
  <el-dialog
    :title="`编辑座位名称`"
    append-to-body
    :visible.sync="visible"
    width="30%"
    @close="handleClose">
    <div class="formWrap">
      <el-form
        inline
        :model="form"
        ref="form"
        class="form-wrap"
        label-width="150px"
      >
        <el-form-item
          verify
          label="座位名称"
          prop="name">
          <el-input
            v-model="form.name"
            placeholder="不超过20个字"
            maxlength="20"></el-input>
        </el-form-item>
      </el-form>
    </div>

    <span slot="footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button
        type="primary"
        @click.stop="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// import { updateSeatArea, addSeatArea, deleteSeatArea } from '@/api/seat'

export default {
  props: {
    chartId: {
      type: Number,
      default: 0
    },
    getSelectedSeats: {
      type: Function,
      default: () => {}
    },
    selectedArea: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      visible: false,
      type: 'add',
      form: {
        name: '',
        x: 1,
        y: 1
      }
    }
  },
  methods: {
    show (type, info) {
      console.log('%c [ this.selectedChart ]-65', 'font-size:13px; background:pink; color:#bf2c9f;', this.selectedChart)

      if (!this.getSelectedSeats().length) return this.$message.error(`请选择座位`)
      this.visible = true
      this.type = type

      this.$nextTick(() => {
        this.$refs.form.resetFields()
      })
    },
    handleClose () {
      this.visible = false
      this.$refs.form.resetFields()
    },
    handleSubmit () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('update', this.form.name)
          this.handleClose()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.formWrap{
  padding: 20px 20px 0;
}
</style>
