<template>
  <template-page
    ref="pageRef"
    :getList="getList"
    :exportList="exportList"
    :columnParsing="columnParsing"
    :optionsEvensGroup="optionsEvensGroup"
    :tableAttributes="tableAttributes"
    :tableEvents="tableEvents"
    :operation="operation()"
    :operationColumnWidth="220"
  >
    <website-old-parts-worker-refund-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 WebsiteOldPartsWorkerRefundInformation from './components/website-old-parts-worker-refund-information.vue'
import {
  workerOldRefundList,
  workerOldRefundRefund,
  workerTemplateExcel,
  WorkerOldRefundListExport,
  workerOldRefundTransferFlag
} from '@/api/material-system/website/website-parts-worker-refund-manage'
import import_mixin from '@/components/template/import_mixin.js'
import operation_mixin from '@/components/template/operation_mixin.js'
export default {
  components: { TemplatePage, WebsiteOldPartsWorkerRefundInformation },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {},
      // 表格事件
      tableEvents: {},
      showFromBool: false,
      fromPm: {}
    }
  },
  methods: {
    // 列表请求函数
    getList(data) {
      var p = JSON.parse(JSON.stringify(data))
      p.params.push({
        compare: '=',
        param: 'a.repair_flag',
        value: 'INNER'
      })
      return workerOldRefundList(p)
    },
    // 列表导出函数
    exportList(data, name) {
      var p = JSON.parse(JSON.stringify(data))
      p.params.push({
        compare: '=',
        param: 'a.repair_flag',
        value: 'INNER'
      })
      return WorkerOldRefundListExport(p, name)
    },
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    operation() {
      return this.operationBtn({
        view: {
          click: ({ row, index, column }) => {
            this.fromPm = {
              type: 2,
              item: { ...row }
            }
            this.showFromBool = true
          }
        },
        edit: {
          conditions: ({ row, index, column }) => {
            return row.flag == 'AGREE'
          },
          click: ({ row, index, column }) => {
            this.fromPm = {
              type: 1,
              item: { ...row }
            }
            this.showFromBool = true
          }
        },
        examine: {
          name: ({ row, index, column }) => {
            return row.flag == 'SAVE' ? '转换' : row.flag == 'AGREE' ? '确认返还' : ''
          },
          prompt: ({ row, index, column }) => {
            return row.flag == 'SAVE' ? '是否确定转保外操作？' : row.flag == 'AGREE' ? '是否确定操作？' : ''
          },
          conditions: ({ row, index, column }) => {
            return row.flag == 'SAVE' || row.flag == 'AGREE'
          },
          click: ({ row, index, column }) => {
            if (row.flag == 'SAVE') {
              this.transferFlag(row)
            } else if (row.flag == 'AGREE') {
              this.confirmBack(row)
            }
          }
        }
      })
    },

    // 确认返还
    confirmBack(row) {
      workerOldRefundRefund({
        applyNo: row.applyNo,
        flag: 'REFUNDED'
      })
        .then(res => {
          this.$message({
            type: 'success',
            message: `设置成功!`
          })
          this.$refs.pageRef.refreshList()
        })
        .catch(err => {
          console.log(err)
        })
    },
    transferFlag(row) {
      workerOldRefundTransferFlag({
        applyNo: row.applyNo
      })
        .then(res => {
          this.$message({
            type: 'success',
            message: `转换成功，请“保外新件转销售”检查差价!`
          })
          this.$refs.pageRef.refreshList()
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

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