<!--
  @description: 报表统计-采购单位统计-合格供应商列表详情
  @Modifier: 肖文龙
  @routerPath:
  @date: 2021-01-30
-->
<template>
  <el-dialog
    v-dialogDrag
    :modal="false"
    :visible.sync="dialog"
    :close-on-click-modal="false"
    title="详情"
    width="840px"
  >
    <section class="clearfix">
      <el-form ref="searchForm" :model="searchForm" inline>
        <el-form-item label="月份">
          <el-date-picker
            v-model="searchForm.yearMonth"
            :value-format="elValueYearMonth"
            class="el-date-picker-month-input"
            popper-class="el-date-picker-month"
            type="month"
            placeholder="请选择月份"
          />
        </el-form-item>
        <el-form-item class="fr">
          <el-button type="primary" round @click="search">
            查询
          </el-button>
          <el-button type="primary" round @click="resetForm('searchForm')">
            重置
          </el-button>
          <el-button type="primary" round @click="exportChange">
            导出
          </el-button>
        </el-form-item>
      </el-form>
    </section>
    <tableChart
      :height="height"
      class="echart-dom"
      :option="option"
    />
    <pagination :pagination-data="paginationData" @change="loadData" />
  </el-dialog>
</template>

<script>
/* api */
import { listQualifiedSuppliersOfPurchaserMonthInfoPages, exportQualifiedSuppliersOfPurchaserMonthInfoList } from '@api/statisticalAnalysis/reportChart.js'
/* 公用方法*/
import { download, filterObj, restoreInitialValue } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { reportChartGroupMixin } from './../../mixins/reportChartGroup.js'
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 組件 */
import tableChart from './../../components/tableChart'// table列表渲染组件
import pagination from '@comp/common/pagination/pagination'// 分页

export default {
  name: 'BuyerAndQualifiedSupplierListDialog',
  components: {
    tableChart, // table列表渲染组件
    pagination // 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      /* 字典信息-start */
      ...reportChartGroupMixin,
      /* 字典信息-end */
      height: '450px', // 高度
      dialog: false, // 弹窗状态
      // 查询条件
      purchaserId: '', // 采购单位id
      buyersName: '', // 采购单位名称
      searchForm: {
        buyersId: '', // 采购单位id
        yearMonth: '' // 月份
      },
      // 全局的查询条件
      searchChartData: {
      },
      option: {
        // 非TOP排序
        showIndexTOP: false,
        // 标题
        thead: [
          { lable: '月份', prop: 'month' },
          { lable: '准入合格供应商数量（个）', prop: 'qualifiedSupplierNumbers', align: 'center' }
        ],
        // 渲染数据
        data: []
      }
    }
  },
  methods: {
    /**
     * 打开弹窗
     *  @param {row} Object 供应商信息
    */
    open(row, searchData) {
      this.dialog = true
      this.purchaserId = row.purchaserId
      this.buyersName = row.buyersName
      this.searchChartData = searchData
      this.loadData()
    },
    // 获取数据
    loadData() {
      this.option.data = []
      const data = this.getParams()
      listQualifiedSuppliersOfPurchaserMonthInfoPages(data).then(res => {
        this.paginationData.total = res.data.total
        this.option.data.push(...res.data.records)
      })
    },
    // 查询条件
    getParams() {
      // 搜索合并
      const searchData = {
        ...this.searchChartData, // 全局的搜索
        ...this.searchForm // 本页面弹出框的搜索
      }
      const param = Object.assign({}, searchData)
      param.buyersId = this.purchaserId
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      restoreInitialValue(this.searchForm)
      this.search()
    },
    // 导出
    exportChange() {
      const data = this.getParams()
      exportQualifiedSuppliersOfPurchaserMonthInfoList(data).then(res => {
        download(res, this.buyersName + '合格供应商入库详情.xls')
      })
    }
  }
}
</script>

<style scoped lang="less">
</style>
