<template>
  <div style="width: 100%; height: 100%; overflow-y: auto">
    <template-page
      v-show="!pageType"
      ref="pageRef"
      :get-list="getList"
      :export-list="exportList"
      :operation="operation()"
      :column-parsing="columnParsing"
      :options-evens-group="optionsEvensGroup"
      :replace-or-not-map="false"
    />
    <warehouse-form v-if="pageType == 1" :page-type="pageType" @close="handleClose" />
    <warehouse-examine v-if="pageType == 2" :details-id="detailsId" :page-type="pageType" @close="handleClose" />
    <warehouse-details v-if="pageType == 3" :details-id="detailsId" :page-type="pageType" @close="handleClose" />
  </div>
</template>

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

import { getFrontListCustomerAcc, exportCustomerStockOrderBean, deleteCustomerStockOrder } from '@/api/stock'
import WarehouseForm from '@/views/sales_control/components/WarehouseForm'
import WarehouseExamine from '@/views/sales_control/components/WarehouseExamine'
import WarehouseDetails from '@/views/sales_control/components/WarehouseDetails'

export default {
  components: { TemplatePage, WarehouseForm, WarehouseExamine, WarehouseDetails, popu },
  mixins: [import_mixin],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [
        [
          [
            {
              name: '库存调整',
              click: this.addWarehouse
            }
          ]
        ]
      ],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: [],
      detailsId: '',
      pageType: 0
    }
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getFrontListCustomerAcc(...p)
    },
    // 列表导出函数
    exportList: exportCustomerStockOrderBean,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    addWarehouse() {
      this.pageType = 1
      console.log(this.pageType, '333')
    },
    handleClose() {
      this.pageType = 0
      this.$refs.pageRef.refreshList()
    },
    operation() {
      return (h, { row, index, column }) => {
        return (
          <div class='operation-btns'>
            <el-button
              size='mini'
              type='text'
              onClick={() => {
                this.detailsId = row.id
                this.pageType = 3
              }}
            >
              查看
            </el-button>
            {row.examineStatus != 'OK' && row.examineStatus != 'FAIL' ? (
              <el-button
                size='mini'
                type='text'
                onClick={() => {
                  this.detailsId = row.id
                  this.pageType = 2
                }}
              >
                审批
              </el-button>
            ) : null}
            {row.examineStatus != 'OK' && row.examineStatus != 'FAIL' ? (
              <el-popconfirm
                onOnConfirm={() => {
                  deleteCustomerStockOrder({ id: row.id }).then(res => {
                    this.$successMsg('删除成功')
                    this.$refs.pageRef.refreshList()
                  })
                }}
                title='删除吗？'
              >
                <el-button slot='reference' size='mini' type='text'>
                  删除
                </el-button>
              </el-popconfirm>
            ) : null}
          </div>
        )
      }
    }
    // 批量删除
    // dels() {
    //   if (this.recordSelected.length) {
    //     this.$confirm('此操作将删除数据, 是否继续?', '提示', {
    //       confirmButtonText: '确定',
    //       cancelButtonText: '取消',
    //       type: 'warning'
    //     })
    //       .then(() => {
    //         partsOldOutDel({
    //           ids: this.recordSelected.map(item => item.id).join(',')
    //         })
    //           .then(res => {
    //             this.$refs.pageRef.refreshList()
    //             this.$message({
    //               type: 'success',
    //               message: '删除成功!'
    //             })
    //           })
    //           .catch(() => {
    //             this.$message({
    //               type: 'error',
    //               message: '删除失败'
    //             })
    //           })
    //       })
    //       .catch(() => {
    //         this.$message({
    //           type: 'info',
    //           message: '已取消删除'
    //         })
    //       })
    //   } else {
    //     this.$message({
    //       type: 'info',
    //       message: '请先勾选需要删除的数据!'
    //     })
    //   }
    // }
  }
}
</script>

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