<template>
  <template-page
    ref="pageRef"
    :getList="getList"
    :optionsEvensGroup="optionsEvensGroup"
    :exportList="exportList"
    :columnParsing="columnParsing"
    :tableAttributes="tableAttributes"
    :tableEvents="tableEvents"
    :operationColumnWidth="200"
  >
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import { getExecList, v2EnginInfoOrderExcelList, v2EnginInfoOrderExcelListExport } from '@/api/supply/implement'
import { getCategoryList, getSalesmanList } from '@/api/common'
// import DisplaceDetail from '@/views/supply/implement/components/displace_detail'
import { getDealerList } from '@/api/supply/apply'

let that
export default {
  components: {
    TemplatePage
  },
  filters: {
    statusFilter(val) {
      if (that.statusList.length) {
        const obj = that.statusList.find(o => o.value === val)
        return obj ? obj.label : ''
      }
      return ''
    }
  },
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],

      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: null, // 列表数据
      listLoading: false, // 列表加载loading
      screenForm: {
        // 筛选表单数据
        confirmName: '',
        customerId: '',
        orderTime: [],
        isClose: '',
        refEnginRecordNo: '',
        refProjectName: '',
        serviceId: '',
        specification: ''
      },
      categoryList: [],
      statusList: [
        { label: '政策零售订单', value: '2' },
        { label: '零售订单', value: '1' },
        { label: '家用工程订单', value: 'HOME' },
        { label: '商用工程订单', value: 'TRADE' }
      ],
      salesmanList: [],
      dealerList: [],
      queryItem: {},
      isCollapse: true,
      isShowDisplaceDetail: false
    }
  },

  computed: {
    exParams() {
      return {
        confirmName: this.screenForm.confirmName,
        customerId: this.screenForm.customerId,
        startOrderDate: this.screenForm.orderTime ? this.screenForm.orderTime[0] : '',
        endOrderDate: this.screenForm.orderTime ? this.screenForm.orderTime[1] : '',
        isClose: this.screenForm.isClose,
        refEnginRecordNo: this.screenForm.refEnginRecordNo,
        refProjectName: this.screenForm.refProjectName,
        serviceId: this.screenForm.serviceId,
        specification: this.screenForm.specification
      }
    }
  },

  beforeCreate() {
    that = this
  },

  created() {
    // this.getList()
    // this.getCategoryList()
    // this.getSalesmanList()
    // this.getDealerList()
  },

  methods: {
    // 列表请求函数
    getList: v2EnginInfoOrderExcelList,
    // 列表导出函数
    exportList: v2EnginInfoOrderExcelListExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },

    // 查询列表
    // getList() {
    //   this.listLoading = true

    //   const params = {
    //     pageNum: this.currentPage,
    //     pageSize: this.pageSize,
    //     confirmName: this.screenForm.confirmName,
    //     customerId: this.screenForm.customerId,
    //     startOrderDate: this.screenForm.orderTime ? this.screenForm.orderTime[0] : '',
    //     endOrderDate: this.screenForm.orderTime ? this.screenForm.orderTime[1] : '',
    //     isClose: this.screenForm.isClose,
    //     refEnginRecordNo: this.screenForm.refEnginRecordNo,
    //     refProjectName: this.screenForm.refProjectName,
    //     serviceId: this.screenForm.serviceId,
    //     specification: this.screenForm.specification
    //   }
    //   getExecList(params).then(res => {
    //     res.data.records.forEach(item => {
    //       item.sums1 = [
    //         'refundableQty',
    //         'qty',
    //         'retiredQty',
    //         'hasSendQty',
    //         'directTransferQty',
    //         'refundProductQty',
    //         'wdQty'
    //       ]
    //       item.sums2 = [
    //         'payAmount',
    //         'payRebateAmount',
    //         'hasSendAmount',
    //         'retiredAmount',
    //         'refundProductAmount',
    //         'totalAmount',
    //         'wdAmount'
    //       ]
    //     })
    //     this.dataList = res.data.records
    //     this.listTotal = res.data.total
    //     this.listLoading = false
    //   })
    // },
    // 获取业务员列表
    getSalesmanList() {
      getSalesmanList({
        pageNum: 1,
        pageSize: -1,
        isCustomer: 0,
        status: true
      }).then(res => {
        this.salesmanList = res.data.records
      })
    },
    // 获取经销商列表
    getDealerList() {
      getDealerList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.dealerList = res.data.records
      })
    },
    // 获取存货类别列表
    getCategoryList() {
      getCategoryList({
        pageNum: 1,
        pageSize: -1,
        keyword: ''
      }).then(res => {
        this.categoryList = res.data.records
      })
    },

    // 提交筛选表单
    submitScreenForm() {
      this.currentPage = 1
      this.getList()
    },

    // 重置筛选表单
    resetScreenForm() {
      this.$refs.screenForm.resetFields()
      this.currentPage = 1
      this.getList()
    },

    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getList()
    },

    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },

    // 置换详情
    openDisplaceDetail(item) {
      this.queryItem = item
      this.isShowDisplaceDetail = true
    },

    backList() {
      this.queryItem = {}
      this.isShowDisplaceDetail = false
    }
  }
}
</script>

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