<template>
  <div style="height: 100%">
    <div v-show="!venderGoodsArea" style="height: 100%">
      <template-page
        ref="pageRef"
        :getList="getList"
        :exportList="exportList"
        :columnParsing="columnParsing"
        :operation="operation()"
        :optionsEvensGroup="optionsEvensGroup"
        :tableAttributes="tableAttributes"
        :tableEvents="tableEvents"
      >
      </template-page>
    </div>
    <template v-if="venderGoodsArea">
      <div style="box-sizing: border-box; padding: 20px">
        <el-page-header
          class="pdt"
          :content="
            venderGoodsAreaParam.openType === 'add'
              ? '新增关系维护单'
              : venderGoodsAreaParam.openType === 'view'
              ? '查看关系维护单'
              : '编辑关系维护单'
          "
          @back="backUpdPage"
        />
        <el-divider />
        <vender-goods-area
          :is-open.sync="venderGoodsArea"
          :input-param="venderGoodsAreaParam"
          @getList="$refs.pageRef.refreshList()"
        />
      </div>
    </template>
  </div>
</template>

<script>
import {
  getNewVenderList,
  exportNewVenderList,
  confirmVenderGoodsSheet,
  delVenderGoodsSheet
} from '@/api/material-system/vender'
import VenderGoodsArea from '../components/VenderGoodsArea'
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'
export default {
  name: 'VenderGoodsSheet',
  components: { VenderGoodsArea, TemplatePage },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      venderGoodsArea: false,
      venderGoodsAreaParam: {
        openType: 'add',
        sheetId: ''
      },
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: []
    }
  },
  computed: {
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth('add', {
              click: () => {
                this.addOrEdit('add')
              }
            })
          ]
        ]
      ]
    }
  },
  methods: {
    // 列表请求函数
    getList: getNewVenderList,
    // 列表导出函数
    exportList: exportNewVenderList,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    operation() {
      return this.operationBtn({
        view: {
          click: ({ row, index, column }) => {
            this.addOrEdit('view', row.sheetId)
          }
        },
        edit: {
          conditions: ({ row, index, column }) => {
            return row.status === 'SAVE'
          },
          click: ({ row, index, column }) => {
            this.addOrEdit('edit', row.sheetId)
          }
        },
        del: {
          prompt: '确定删除吗？',
          conditions: ({ row, index, column }) => {
            return row.status === 'SAVE'
          },
          click: ({ row, index, column }) => {
            this.delSheet(row.sheetId)
          }
        },
        confirm: {
          prompt: '确定审核吗？',
          conditions: ({ row, index, column }) => {
            return row.status === 'SAVE'
          },
          click: ({ row, index, column }) => {
            this.confirmSheet(row.sheetId)
          }
        }
      })
    },
    // 新增编辑 辅材
    addOrEdit(type, id) {
      this.venderGoodsArea = true
      this.venderGoodsAreaParam.openType = type
      this.venderGoodsAreaParam.sheetId = id
    },
    // 删除单据
    delSheet(sheetId) {
      delVenderGoodsSheet([sheetId]).then(() => {
        this.$refs.pageRef.refreshList()
        this.$successMsg('删除成功')
      })
    },
    // 审核 供应商关系商品维护单
    confirmSheet(sheetId) {
      confirmVenderGoodsSheet({ sheetId: sheetId }).then(() => {
        this.$refs.pageRef.refreshList()

        this.$successMsg('审核成功')
      })
    },
    backUpdPage() {
      this.$refs.pageRef.refreshList()
      this.venderGoodsArea = false
    }
  }
}
</script>

<style scoped></style>
