<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :export-list="exportList"
    :operation="operation()"
    :options-evens-group="optionsEvensGroup"
    :column-parsing="columnParsing"
    :default-search-data="searchData"
  />
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import add_callback_mixin from '@/components/template/add_callback_mixin.js'

import {
  getStockCostListCustomer,
  getStockCostListCustomerV2Export,
  updateOrderFull
} from '@/api/basic_data/dailyWarehouseRent'

export default {
  components: { TemplatePage },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],

      detailsId: '',
      searchData: this.$route.query.orderId
        ? [
          {
            param: 'a.order_no',
            compare: 'like',
            value: this.$route.query.orderId || ''
          }
        ]
        : this.$route.query.yearTime
          ? [
            {
              param: 'a.year_time',
              compare: 'like',
              value: this.$route.query.yearTime
            },
            {
              param: 'a.month_time',
              compare: 'like',
              value: this.$route.query.monthTime
            },
            {
              param: 'a.customer_number',
              compare: 'like',
              value: this.$route.query.customerNumber
            },
            {
              param: 'a.status',
              compare: '=',
              value: 'ENABLE'
            }
          ]
          : []
    }
  },
  watch: {
    $route(val, oval) {
      if (val && this.$route.path === '/basic_data/dailyWarehouseRent') {
        if (this.$route.query.yearTime) {
          this.searchData = [
            {
              param: 'a.year_time',
              compare: 'like',
              value: val.query.yearTime
            },
            {
              param: 'a.month_time',
              compare: 'like',
              value: val.query.monthTime
            },
            {
              param: 'a.customer_number',
              compare: 'like',
              value: val.query.customerNumber
            },
            {
              param: 'a.status',
              compare: '=',
              value: 'ENABLE'
            }
          ]
        }
        if (this.$route.query.orderId) {
          this.searchData = [
            {
              param: 'a.order_no',
              compare: 'like',
              value: this.$route.query.orderId
            }
          ]
        }
      }
    }
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getStockCostListCustomer(...p)
    },
    // 列表导出函数
    exportList: getStockCostListCustomerV2Export,
    // 表格列解析渲染数据更改
    columnParsing(_item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return (_h, { row, index, column }) => {
        return (
          <div class='operation-btns'>
            {this.$checkBtnRole('tichu', this.$route.meta.roles) ? (
              <el-popconfirm
                title='确定剔除吗？'
                onConfirm={() => {
                  updateOrderFull({ id: row.orderFullCostId }).then(res => {
                    this.$refs.pageRef.refreshList()

                    this.$successMsg('剔除成功')
                  })
                }}
              >
                <el-button slot='reference' type='text'>
                  剔除
                </el-button>
              </el-popconfirm>
            ) : null}
          </div>
        )
      }
    },
    handleClose() {
      this.addOff(() => {
        this.visible = false
      })()
    }
  }
}
</script>

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