<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :exportList="exportList"
    :table-attributes="tableAttributes"
    :table-events="tableEvents"
    :options-evens-group="optionsEvensGroup"
    :moreParameters="moreParameters"
    :column-parsing="columnParsing"
    :operation="operation()"
  >
    <Popu v-if="visible">
      <el-page-header slot="head" content="" @back="handleClose" />
      <InsuranceContractForm
        :item="item"
        :type="showType"
        @success="
          () => {
            handleClose()
            $refs.pageRef.refreshList()
          }
        "
      /> </Popu
  ></template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
import {
  policyOrderListEm,
  policyOrderListEmExport,
  policyOrderImportEm,
  policyOrderDetail,
  policyOrderUpdate
} from '@/api/employerInsurance'
import operation_mixin from '@/components/template/operation_mixin.js'
import import_mixin from '@/components/template/import_mixin.js'
import Popu from '@/components/template/popu.vue'
import InsuranceContractForm from './InsuranceContractForm.vue'
import { commonTemplateDownload } from '@/api/common.js'
export default {
  components: { TemplatePage, Popu, InsuranceContractForm },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
      visible: false,
      item: null,
      showType: null
    }
  },
  computed: {
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth('download', {
              click: () => {
                commonTemplateDownload({ name: '雇主险导入.xlsx' }, `${this.$route.meta.title}`)
                  .then(res => {
                    this.$message({
                      message: '下载成功',
                      type: 'success'
                    })
                  })
                  .catch(err => {
                    this.$message.error('下载失败')
                  })
              }
            })
          ],
          [
            this.optionsEvensAuth('import', ({ moduleName }) => {
              return {
                name: moduleName,
                render: () => {
                  return this.importButton(policyOrderImportEm, moduleName)
                }
              }
            })
          ]
        ]
      ]
    },
    // 更多参数
    moreParameters() {
      return [
        {
          name: '保单状态',
          key: 'policyOrderStatus',
          value: '',
          conditions: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '新购',
              value: 'XG'
            },
            {
              label: '待生效',
              value: 'DSX'
            },
            {
              label: '待替换',
              value: 'DTH'
            },
            {
              label: '已购买',
              value: 'YGM'
            },
            {
              label: '保障中',
              value: 'BZZ'
            },
            {
              label: '已失效',
              value: 'YSX'
            },
            {
              label: '可替换',
              value: 'KTH'
            }
          ]
        }
      ]
    },
    formItems() {
      return []
    }
  },
  created() {},
  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 policyOrderListEm(pam)
      } catch (err) {
        console.log(err)
      }
    },
    // 列表导出函数
    exportList: policyOrderListEmExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 表格操作列
    operation() {
      return this.operationBtn({
        edit: {
          click: ({ row, index, column }) => {
            this.item = { ...row }
            this.visible = true
            this.showType = 1
            // policyOrderDetail({ id: row.id }).then(res => {})
          }
        },
        details: {
          click: ({ row, index, column }) => {
            this.item = { ...row }
            this.visible = true
            this.showType = 2
            // policyOrderDetail({ id: row.id }).then(res => {})
          }
        }
      })
    },
    // 关闭新增弹窗
    handleClose() {
      this.visible = false
      this.item = null
      this.showType = null
    }
  }
}
</script>

<style lang="scss" scoped>
.tab {
  padding: 20px 20px 0 20px;
}
</style>
