<template>
  <div class="form-wrap">
    <div
      class="table-box"
      style="margin-top:30px">
      <div class="block-title">
        票种价格方案管理
        <el-button
          type="primary"
          @click="$refs.dialog.show(null,'add')"
        >
          新增
        </el-button>
      </div>

      <el-table
        border
        stripe
        ref="multipleTable"
        tooltip-effect="dark"
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="id"
          label="编号"
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="名称"
        >
        </el-table-column>
        <el-table-column
          prop="description"
          label="描述"
        >
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.status===1?'success':'danger'">
              {{ scope.row.status===1?'激活':'禁用' }}
            </el-tag>
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
        >
          <template slot-scope="scope">
            <el-link
              :type="scope.row.status === 0?'primary':'danger'"
              size="small"
              @click="changeStatus(scope.row)"
            >
              {{ scope.row.status===0?'激活':'禁用' }}
            </el-link>
            <el-link
              type="primary"
              size="small"
              @click="$refs.dialog.show(scope.row,'edit')"
            >
              编辑
            </el-link>

            <el-link
              type="primary"
              size="small"
              @click="handleDelete(scope.row.id)"
            >
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="getList()"
        :total="total">
      </el-pagination>
    </div>

    <Dialog
      ref="dialog"
      @update="getList"></Dialog>
  </div>
</template>

<script>
import Dialog from './Dialog'
import { getTicketPricePlanList, updateTicketPricePlan, deleteTicketPricePlan } from '@/api/ticketPricePlan'

export default {
  created () {
    this.getList()
  },
  components: {
    Dialog
  },
  data () {
    return {
      form: {
        keyWords1: ''
      },
      total: 1,
      loading: false,
      tableData: [],
      multipleSelection: []
    }
  },
  methods: {
    changeStatus (e) {
      e.status = e.status ? 0 : 1
      let params = JSON.parse(JSON.stringify(e))
      updateTicketPricePlan(params).then(res => {
        this.handleClose()
      }).finally(() => {
        this.loading = false
      })
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getList()
    },
    getList () {
      this.loading = true
      let params = JSON.parse(JSON.stringify(this.form))
      getTicketPricePlanList(params).then(res => {
        this.tableData = res.list
        this.total = res.total
        console.log('this.tableData', this.tableData)
      }).finally(() => {
        this.loading = false
      })
    },
    reset () {
      this.$refs.form.resetFields()
    },
    handleDelete (id) {
      this.$confirm('确认删除吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteTicketPricePlan(id).then(res => {
          this.$message.success('删除成功')
          this.getList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.form-wrap {
  .el-input,.el-select,.el-date-editor,.el-date-editor.el-input,.el-input-number {
    width: 300px;
  }
}

</style>
