<template>
  <template-page
    ref="pageRef"
    :getList="getList"
    :exportList="exportList"
    :columnParsing="columnParsing"
    :optionsEvensGroup="optionsEvensGroup"
    :tableAttributes="tableAttributes"
    :tableEvents="tableEvents"
    :operation="operation()"
    :operationColumnWidth="180"
    :moreParameters="moreParameters"
    :defaultSearchData="defaultSearchData"
  >
    <website-new-parts-to-sales-information
      v-if="showFromBool"
      v-bind="fromPm"
      @success="$refs.pageRef.refreshList"
      @goBack="
        bool => {
          showFromBool = false
          if (bool === true) {
            this.$refs.pageRef.refreshList()
          }
        }
      " 
    />
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import operation_mixin from '@/components/template/operation_mixin.js'
import { partsChangeSalesList, partsChangeSalesExport } from '@/api/material-system/website/website-new-parts-to-sales'
import WebsiteNewPartsToSalesInformation from './components/website-new-parts-to-sales-information.vue'
export default {
  components: { TemplatePage, WebsiteNewPartsToSalesInformation },
  mixins: [operation_mixin],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {},
      // 表格事件
      tableEvents: {},
      showFromBool: false,
      fromPm: {},
      defaultSearchData: []
    }
  },
  computed: {
    moreParameters() {
      return [
        {
          name: '单据状态',
          key: 'flag',
          value: this?.$route?.params?.pageCode || '',
          conditions: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '驳回',
              value: 'REJECT'
            },
            {
              label: '已复核',
              value: 'REVIEWED'
            },
            {
              label: '已返还',
              value: 'REFUNDED'
            },
            {
              label: '待复核',
              value: 'WAIT_REVIEW'
            },
            {
              label: '提交',
              value: 'SUBMIT'
            },
            {
              label: '未返还',
              value: 'NOTREFUND'
            },
            {
              label: '通过',
              value: 'AGREE'
            },
            {
              label: '保存',
              value: 'SAVE'
            }
          ]
        }
      ]
    }
  },
  created() {
    if (this?.$route?.params?.pageType == 'flag' && this?.$route?.params?.pageCode) {
      this.defaultSearchData = [
        {
          param: `a.${this?.$route?.params?.pageType}`,
          compare: '=',
          value: this?.$route?.params?.pageCode,
          label: this?.$route?.params?.pageName
        }
      ]
    }
  },
  methods: {
    // 列表请求函数
    getList(p, cb) {
      var pam = JSON.parse(JSON.stringify(p))
      try {
        if (pam.flag) {
          var item = pam.params.find(item => item.param == 'a.flag')
          if (item) {
            item.compare = '='
            item.value = pam.flag
          } else {
            pam.params.push({ param: 'a.flag', compare: '=', value: pam.flag })
          }
        }
        cb && cb(pam)
        return partsChangeSalesList(pam)
      } catch (err) {}
    },
    // 列表导出函数
    exportList: partsChangeSalesExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    operation() {
      return this.operationBtn({
        view: {
          click: ({ row, index, column }) => {
            this.fromPm = {
              type: 2,
              item: { ...row }
            }
            this.showFromBool = true
          }
        },
        examine: {
          conditions: ({ row, index, column }) => {
            return row.flag == 'SUBMIT'
          },
          click: ({ row, index, column }) => {
            this.fromPm = {
              type: 1,
              item: { ...row }
            }
            this.showFromBool = true
          }
        }
      })
    }
  }
}
</script>

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