<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    @close="handleClose"
    width="20%"
    center>
    <br>
    <el-form
      inline
      :model="form"
      ref="form"
      class="form-wrap"
      label-width="100px">
      <el-form-item
        verify
        label="节目"
        prop="perform_id"
      >
        <el-select
          collapse-tags
          v-model="form.perform_id"
        >
          <el-option
            v-for="item in performList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>

    <div slot="footer">
      <el-button
        type="danger"
        @click="handleDelete">
        删 除
      </el-button>
      <el-button
        type="primary"
        @click="handleSubmit">
        确 定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { list, bindPerformWithBatch, deleteBatchPerformMatrix } from '@/api/perform'

export default {
  computed: {
    ticketTypeList () {
      return this.$store.state.app.ticketTypeList
    }
  },
  data () {
    return {
      title: '编辑场次',
      visible: false,
      performList: [],
      form: {
        perform_id: '',
        batchList: []
      }
    }
  },
  methods: {
    show (data) {
      this.visible = true
      this.$nextTick(() => {
        this.reset()
        // this.form.batchList = Object.assign([], this.form.batchList, JSON.parse(JSON.stringify(data)))
        this.form.batchList = data
      })
      this.getPerformList()
    },
    getPerformList () {
      let params = {
        pageSize: 999
      }
      list(params).then(res => {
        this.performList = res.list
        // 更新全局节目信息
      }).finally(() => {
        this.loading = false
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    handleClose () {
      this.visible = false
    },

    handleSubmit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          let params = JSON.parse(JSON.stringify(this.form))
          this.form.perform_id = params.perform_id
          bindPerformWithBatch(this.form).then(res => {
            this.$message.success('操作成功')
            this.handleClose()
            this.$emit('update')
          })
        }
      })
    },
    handleDelete () {
      let params = JSON.parse(JSON.stringify(this.form))
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteBatchPerformMatrix(params).then(res => {
          this.$message.success('删除成功')
          this.handleClose()
          this.$emit('update')
        })
      })
    }
  }
}
</script>

<style scoped>
</style>
