<template>
  <div style="height: 100%">
    <template-page
      style="height: 90%"
      ref="pageRef"
      :getList="getList"
      :exportList="exportList"
      :tableEvents="tableEvents"
      :tableAttributes="tableAttributes"
      :operation="operation()"
      :columnParsing="columnParsing"
    >
    </template-page>
    <div class="btn">
      <div>
        <el-button size="small" type="primary" @click="clickSubmit()">提 交</el-button>
      </div>
      <div class="tip">注：提交成功后，系统将自动生成采购计划订单</div>
    </div>
  </div>
</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 { getPlanCustomerListV2, exportPlanCustomerListV2, submitPlan } from '@/api/supply/purchase'
import { getDictList } from '@/api/common'
export default {
  components: { TemplatePage, Popu },
  mixins: [import_mixin, add_callback_mixin],
  data() {
    return {
      visible: false,
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true
      }, // 关闭新增弹窗

      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      }
    }
  },
  methods: {
    // 列表请求函数
    getList(...p) {
      this.recordSelected = []
      return getPlanCustomerListV2(...p)
    },
    // 列表导出函数
    exportList: exportPlanCustomerListV2,
    // 表格列解析渲染数据更改
    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.detailsId = row.id
              }}
            >
              查看
            </el-button>
          </div>
        )
      }
    },
    handleClose() {
      this.addOff(() => {
        this.visible = false
      })()
    },
    getDictList() {
      getDictList({ sysDictEnum: 'PRODUCT_TYPE' }).then(res => {
        this.typeList = res.data
      })
    },

    // 提交
    clickSubmit() {
      if (this.recordSelected.length < 1) {
        return this.$errorMsg('请选择单据')
      }
      let ids = []
      this.recordSelected.forEach(item => {
        ids.push(item.id)
      })
      submitPlan(ids).then(res => {
        this.$successMsg()
        this.$refs.pageRef.refreshList()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.btn {
  margin: 0 20px;
}
.tip {
  margin-top: 10px;
  text-align: left;
  font-size: 14px;
  color: #f00;

}
</style>
