<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-select
            v-model="form.projectId"
            filterable
            clearable
            placeholder="请选择项目">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in projectList"
              :key="item.id"
              :label="item.projectName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="产品ID"
          prop="otaProductId">
          <el-input v-model="form.otaProductId"></el-input>
        </el-form-item>
        <el-form-item
          label="分销商"
          prop="otaSourceId">
          <el-select
            v-model="form.otaSourceId"
            filterable
            clearable
            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"
        row-class-name="is-center"
        :data="tableData">
        <el-table-column
          prop="createTime"
          label="创建时间" />
        <el-table-column />
        <el-table-column
          prop="projectId"
          label="项目ID" />
        <el-table-column
          prop="projectName"
          label="项目名称" />
        <el-table-column
          prop="otaSourceId"
          label="分销商ID" />
        <el-table-column
          prop="otaSourceCode"
          label="分销商编码" />
        <el-table-column
          prop="otaSourceName"
          label="分销商名称" />
        <el-table-column
          prop="ticketTypeId"
          label="线下票种ID" />
        <el-table-column
          prop="otaProductId"
          label="分销产品ID" />
        <el-table-column
          fixed="right"
          label="操作"
          width="80">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="showDialog('detail',scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

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

    <ElDialog
      title="项目详情"
      width="660px"
      v-model="detailVisible">
      <DetailDialog :product-item="currentItem"></DetailDialog>
    </ElDialog>
  </div>
</template>

<script>
import { getProjectList, getOtaProductList, getOtaSourceList } from '@/api/platform'
import ElDialog from '@/components/Dialog'
import DetailDialog from './product/DetailDialog'

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

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