<template>
  <template-page
    ref="pageRef"
    :get-list="getList"
    :export-list="exportList"
    :options-evens-group="optionsEvensGroup"
    :operation="operation()"
    :column-parsing="columnParsing"
    :replace-or-not-map="false"
  >
    <Popu v-if="visible">
      <el-page-header slot="head" content="对账" @back="handleClose" />
      <ReconciliationDetail :order-code="orderCode" :detail="detail" param="sales_check_code" @close="handleClose" />
    </Popu>
  </template-page>
</template>

<script>
import ReconciliationDetail from './components/reconciliationDetail.vue'

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 { getCostBillListSalesList, exportCostBillListSalesList, costBillSalesCheck } from '@/api/salesReconciliation'
export default {
  components: { TemplatePage, Popu, ReconciliationDetail },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [
        // [
        //   [
        //     {
        //       name: '导入',
        //       render: this.importButton(importCustomerV2)
        //     }
        //   ]
        // ]
      ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],
      formData: {},
      dialogVisible: false,
      orderCode: null,
      detail: {}
    }
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getCostBillListSalesList(...p)
    },
    // 列表导出函数
    exportList: exportCostBillListSalesList,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return (h, { row, index, column }) => {
        return (
          <div class='operation-btns'>
            {row.processStatus == 'COST_IN_SALES_CHECK'?<div>
              <el-button
              size='mini'
              type='text'
              onClick={() => {
                this.visible = true
                this.orderCode = row.salesCheckCode
                this.detail = row
              }}
            >
              对账
            </el-button>
            <el-button
              size='mini'
              type='text'
              onClick={() => {
                this.$confirm('请确认本月对账账单数据正确，经确认后则不能回退对账结果', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                })
                  .then(() => {
                    costBillSalesCheck({ salesCheckCode: row.salesCheckCode }).then(res => {
                      this.$message({
                        type: 'success',
                        message: '完成对账成功!'
                      })
                      this.$refs.pageRef.refreshList()
                    })
                  })
                  .catch(() => {
                    this.$message({
                      type: 'info',
                      message: '已取消完成对账'
                    })
                  })
              }}
            >
              完成对账
            </el-button>
              </div>:null}
       
          </div>
        )
      }
    },
    handleClose() {
      this.visible = false
    },
    onSbumit() {
      costBillSalesCheck({ salesCheckCode: 11 }).then(res => {})
    }
  }
}
</script>

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