<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :export-list="exportList"
    :operation="operation()"
    :options-evens-group="optionsEvensGroup"
    :column-parsing="columnParsing"
    :replace-or-not-map="false"
  >
    <Popu v-if="visible">
      <SubMerchantForm v-if="moduleType === 1 || moduleType === 3 || moduleType === 4" :module-type="moduleType" :details-id="detailsId" @close="handleClose" />
      <SubMerchantDetail v-if="moduleType === 2" :details-id="detailsId" @close="handleClose" />
    </Popu>
  </template-page>
</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 Popu from '@/components/template/popu.vue'
import { getStagecustomerListV2, exportStagecustomerV2 } from '@/api/basic_data/dealer'
import SubMerchantDetail from './components/subMerchantDetail.vue'
import SubMerchantForm from './components/subMerchantForm.vue'

export default {
  components: { TemplatePage, Popu, SubMerchantDetail, SubMerchantForm },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [
        [
          [
            {
              name: '新增',
              click: this.addOn(() => {
                this.visible = true
                this.moduleType = 1
              })
            //   isRole: this.$checkBtnRole('add', this.$route.meta.roles)
            }
          ]
        ]
      ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

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

      detailsId: ''
    }
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getStagecustomerListV2(...p)
    },
    // 列表导出函数
    exportList: exportStagecustomerV2,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return (h, { row, index, column }) => {
        return (
          <div class='operation-btns'>
            <el-button
              size='mini'
              type='text'
              onClick={ () => {
                this.visible = true
                this.moduleType = 2
                this.detailsId = row.id
              }}
            >
                查看
            </el-button>
            {row.examineStatus === 'SAVE' || row.examineStatus === 'WAIT'
              ? <el-button
                size='mini'
                type='text'
                onClick={ () => {
                  this.visible = true
                  this.moduleType = 4
                  this.detailsId = row.id
                }}
              >
            编辑
              </el-button> : null
            }
            {row.examineStatus === 'SAVE' || row.examineStatus === 'WAIT'
              ? <el-button
                size='mini'
                type='text'
                onClick={ () => {
                  this.visible = true
                  this.moduleType = 3
                  this.detailsId = row.id
                }}
              >
                审核
              </el-button> : null
            }
          </div>
        )
      }
    },
    handleClose() {
      this.addOff(() => {
        this.visible = false
      })()
      this.$refs.pageRef.refreshList()
    }
  }
}
</script>

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

