<template>
  <div class="form-wrap ">
    <div class="search-box">
      <div class="block-title">
        查询条件
      </div>
      <!-- <el-form
        ref="form"
        :model="form"
        :inline="true"
        label-width="70px"
      >
        <el-form-item
          label="名称"
          prop="keyWords1">
          <el-input v-model="form.keyWords1"></el-input>
        </el-form-item>
      </el-form> -->
      <div class="btn-wrap">
        <!-- <el-button
          type="default"
          size="mini"
          @click="reset">
          重置
        </el-button> -->

        <el-button
          type="primary"
          size="mini"
          @click="getList">
          查询
        </el-button>

        <el-button
          type="primary"
          size="mini"
          @click="openDialog(false)">
          新建
        </el-button>
      </div>
    </div>

    <div class="table-box">
      <el-table
        border
        stripe
        :data="tableData">
        <el-table-column
          prop="name"
          label="名称">
        </el-table-column>
        <el-table-column
          prop="call_trigger_num"
          label="自动叫号触发人数">
        </el-table-column>
        <el-table-column
          prop="single_call_num"
          label="自动叫号单次人数">
        </el-table-column>
        <el-table-column
          width="200px"
          label="操作">
          <template slot-scope="scope">
            <el-link
              type="primary"
              size="small"
              @click="openDialog(scope.row)"
            >
              编辑
            </el-link>
            <el-link
              type="primary"
              size="small"
              @click="deleteItem(scope.row)"
            >
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="getList()"
        :total="total"
      >
      </el-pagination>
      <!-- 弹框 -->
      <ElDialog
        :title="dialog.title"
        width="760px"
        v-model="dialog.visible">
        <DialogEdit
          :type="dialog.type"
          :current-item="currentItem"
          @updateList="getList"
        ></DialogEdit>
      </ElDialog>
    </div>
  </div>
</template>

<script>
import { queueList, deleteQueue } from '@/api/ticketType'
import ElDialog from '@/components/Dialog'
import DialogEdit from './DialogEdit'
export default {
  data () {
    return {
      form: {
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      dialog: {
        visible: false,
        type: 'new',
        title: '新增通道'
      },
      currentItem: {}
    }
  },
  created () {
    this.getList()
  },
  components: {
    ElDialog,
    DialogEdit
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getList()
    },
    getList () {
      queueList(this.form).then(res => {
        this.total = res?.data.total
        this.tableData = res?.data.list
      })
    },
    openDialog (item) {
      if (item) {
        this.dialog.title = '编辑队列'
        this.dialog.type = 'edit'
        this.currentItem = item
      } else {
        this.dialog.title = '新建队列'
        this.dialog.type = 'new'
      }
      this.dialog.visible = true
    },
    deleteItem (item) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteQueue(item.id).then(() => {
          this.getList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
