<template>
  <div class="form-wrap">
    <div class="searchBox">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        label-width="100px">
        <el-form-item
          label="项目ID"
          prop="projectId">
          <el-input v-model="form.projectId"></el-input>
        </el-form-item>
        <el-form-item
          label="项目名称"
          prop="projectName">
          <el-input v-model="form.projectName"></el-input>
        </el-form-item>
        <el-form-item
          label="分销商"
          prop="otaSourceId">
          <el-select
            v-model="form.otaSourceId"
            placeholder="请选择分销商">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in otaSourceList"
              :key="item.id"
              :label="item.otaSourceName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="btn-wrap">
        <el-button
          type="primary"
          @click="getOtaProductList">搜索</el-button>
      </div>
    </div>
    <div class="tableBox">
      <div class="block-title">
        分销产品列表
      </div>

      <el-table
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="projectId"
          label="项目ID" />
        <el-table-column
          prop="projectName"
          label="项目名称" />
        <el-table-column
          prop="otaSourceId"
          label="分销商ID" />
        <el-table-column
          prop="ticketTypeId"
          label="线下票种ID" />
        <el-table-column
          prop="otaProductId"
          label="分销产品ID" />
      </el-table>
    </div>
    <!-- 账号弹框 -->
    <ElDialog
      title="添加账号"
      width="660px"
      v-model="addVisible">
      <AddDialog @updateList="getOtaProductList"></AddDialog>
    </ElDialog>

    <ElDialog
      title="编辑账号"
      width="660px"
      v-model="editVisible">
      <EditDialog
        :account-item="currentItem"
        @updateList="getOtaProductList"></EditDialog>
    </ElDialog>

    <el-pagination
      background
      :page-size="10"
      @current-change="handlePage"
      layout="prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { getOtaProductList, getOtaSourceList } from '@/api/platform'

export default {
  computed: {
    canAddUsers () {
      return true
      // return this.$store.state.user.permissionList.includes('system_settings:add_users')
    }
  },

  created () {
    this.getOtaSourceList()
    this.getOtaProductList()
  },
  data () {
    return {
      loading: false,
      addVisible: false,
      editVisible: false,
      tableData: [],
      otaSourceList: [],
      total: 0,
      form: {
        projectName: '', // 账号名
        projectId: '',
        otaSourceId: '', // 分销商
        pageNum: 1,
        pageSize: 10
      },
      // 当前账号对象
      currentItem: {}
    }
  },
  methods: {
    showDialog (type, item) {
      this[`${type}Visible`] = true
      this.currentItem = item
    },
    getOtaProductList (goFirst) {
      this.loading = true
      if (goFirst) {
        this.form.pageNum = 1
      }
      getOtaProductList(this.form).then(res => {
        this.loading = false
        this.tableData = res.data.records || []
        this.total = res.data.total || 0
      })
    },
    getOtaSourceList () {
      getOtaSourceList({ pageSize: -1, pageNum: 1 }).then(res => {
        this.otaSourceList = res.data.records || []
      })
    },
    handlePage (pageNum) {
      this.form.pageNum = pageNum
      this.getOtaProductList()
    }
  }
}
</script>

<style scoped>

</style>
