<template>
  <template-page
    ref="pageRef"
    :getList="getList"
    :exportList="exportList"
    :columnParsing="columnParsing"
    :optionsEvensGroup="optionsEvensGroup"
    :moreParameters="moreParameters"
  >
    <!-- :operationColumnWidth="200"
    :operation="operation()" -->
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import operation_mixin from '@/components/template/operation_mixin.js'
import { policyOrderListDs, policyOrderListDsExport, policyOrderImportDs } from '@/api/thirdPartyInsurance.js'
import { commonTemplateDownload } from '@/api/common.js'
export default {
  components: { TemplatePage },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [
        [
          [
            this.optionsEvensAuth('import', ({ moduleName }) => {
              return {
                name: moduleName,
                render: () => {
                  return this.importButton(policyOrderImportDs, moduleName)
                }
              }
            })
          ],
          [
            this.optionsEvensAuth('download', {
              click: () => {
                commonTemplateDownload({ name: '第三者保险导入.xlsx' }, `第三者保险导入`)
                  .then(res => {
                    this.$message({
                      message: '下载成功',
                      type: 'success'
                    })
                  })
                  .catch(err => {
                    this.$message.error('下载失败')
                  })
              }
            })
          ]
        ]
      ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],
      visible: false,
      item: null,
      showType: null
    }
  },
  computed: {
    // 更多参数
    moreParameters() {
      return [
        {
          name: '保单状态',
          key: 'policyOrderStatus',
          value: '',
          conditions: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '待生效',
              value: 'DSX'
            },
            {
              label: '保障中',
              value: 'BZZ'
            },
            {
              label: '已失效',
              value: 'YSX'
            }
          ]
        }
      ]
    }
  },
  methods: {
    // 列表请求函数
    getList(p, cb) {
      var pam = JSON.parse(JSON.stringify(p))
      try {
        if (pam.policyOrderStatus) {
          pam.params.push({ param: 'policy_order_status', compare: '=', value: pam.policyOrderStatus })
        }
        cb && cb(pam)
        return policyOrderListDs(pam)
      } catch (err) {
        console.log(err)
      }
    },
    // 导出
    exportList: policyOrderListDsExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return this.operationBtn({})
    }
  }
}
</script>

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