<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
  >
    <el-form
      label-width="100px">
      <div class="dialog-info">
        <el-select
          v-model="value"
          multiple
          filterable
          clearable>
          <el-option
            v-for="item in list"
            :key="item.id"
            :value="item.id"
            :label="item.name">
          </el-option>
        </el-select>
      </div>
    </el-form>

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

<script>
import { getAccountList } from '@/api/systemSetting/account'
import { getScenic, getTicketTypeList, updateSubProject } from '@/api/ticketType'
import { getTicketSpotList } from '@/api/ticketSpot'
import { getBatchConfigList } from '@/api/batch'
import { getScheduleList } from '@/api/scheduleConfig'
import { apiGetTravelAgencyList, apiGetGuideList } from '@/api/travelAgency'
import { getMemberType } from '@/api/member'
import { list } from '@/api/perform'

const Map = {
  'managerList': { name: '用户', method: getAccountList },
  'scenicList': { name: '景点', method: getScenic },
  'ticketTypeList': { name: '票种', method: getTicketTypeList },
  'ticketSpotList': { name: '售票点', method: getTicketSpotList },
  'batchConfigList': { name: '场次', method: getBatchConfigList },
  'scheduleConfigList': { name: '班次', method: getScheduleList },
  'travelAgencyList': { name: '旅行社', method: apiGetTravelAgencyList },
  'memberTypeList': { name: '会员', method: getMemberType },
  'performList': { name: '节目', method: list },
  'guideList': { name: '导游', method: apiGetGuideList }
}

export default {
  data () {
    return {
      title: '',
      visible: false,
      id: 0,
      name: '',
      key: '',
      value: [],
      list: []
    }
  },
  methods: {
    async show (data, id, name) {
      this.title = '绑定' + Map[data.key]['name']
      this.id = id
      this.name = name
      this.key = data.key
      let res = await Map[data.key]['method']({ pageNum: 1, pageSize: 9999 })
      if (data.key === 'scenicList') {
        this.list = res?.data.children.map(item => item.data)
      } else {
        this.list = res.list
      }
      this.value = data.value.map(v => v.id)
      this.visible = true
    },
    handleClose () {
      this.visible = false
    },
    async handleSubmit () {
      let params = {
        id: this.id,
        name: this.name
      }
      params[this.key] = this.value.map(v => { return { id: v } })
      await updateSubProject(params)
      this.$message.success('绑定成功')
      this.$emit('update')
      this.handleClose()
    }
  }
}
</script>

  <style lang="scss" scoped>
    ::v-deep .el-input{
        width:500px !important;
    }
    ::v-deep .el-select__tags{
        width:468px !important;
    }
  </style>
