<template>
  <div style="width: 100%;height:100%">
    <template-page ref="pageRef" :getList="getList" :operation="operation()" :exportList="exportList"
      :columnParsing="columnParsing" :tableAttributes="tableAttributes" :tableEvents="tableEvents"
      :optionsEvensGroup="optionsEvensGroup">
      <div slot="moreSearch">
        <el-radio-group v-model="examineStatus" size="mini" @change="changeType">
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button label="WAIT">待审核</el-radio-button>
          <el-radio-button label="WAIT_PAY">待收款</el-radio-button>
          <el-radio-button label="PART_PAY">部分收款</el-radio-button>
          <el-radio-button label="PAY">收款完成</el-radio-button>
        </el-radio-group>
        <br /><br />
      </div>
    </template-page>
    <div class="cartographer_big">
      <el-dialog :title="id?'详情':'创建'" width="100%" :modal="false" :visible.sync="createFormBool" :before-close="handleClose">
        <formModule v-if="createFormBool" :id="id" :handleClose="handleClose" />
      </el-dialog>
    </div>
  </div>
</template>

<script>
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'
import { enginPayList, enginPayListExport, enginPayImport } from '@/api/projectCollectionManagement'
import { commonTemplateDownload } from '@/api/common.js'
import formModule from "../workOrderInfo/index.vue"
export default {
  components: {
    TemplatePage,
    formModule
  },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      formBool: false,
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      formData: {},
      detailParams: [],
      examineStatus: this?.$route?.params?.pageCode || '',
      createFormBool: false,
      id: null
    }
  },
  computed: {
    // 事件组合
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth('add', {
              click: () => {
                this.id = null
                this.createFormBool = true
              }
            })
          ],
          [
            this.optionsEvensAuth(['imp', 'template'], {
              name: '导入',
              click: () => { }
            }),
            this.optionsEvensAuth('imp', ({ moduleName }) => {
              return {
                name: moduleName,
                render: () => {
                  return this.importButton(enginPayImport, moduleName)
                }
              }
            }),
            this.optionsEvensAuth('template', {
              click: () => {
                commonTemplateDownload({ name: '工程收款管理模板.xlsx' }, `工程收款管理模板`)
                  .then(res => {
                    this.$message({
                      message: '下载成功',
                      type: 'success'
                    })
                  })
                  .catch(err => {
                    this.$message.error('下载失败')
                  })
              }
            })
          ]
        ]
      ]
    }
  },

  created() {
    if (this.pageType == "detail") {
      this.id = this.pageCode
      this.createFormBool = true
    }
  },

  methods: {
    // 列表请求函数
    getList(p) {
      try {
        var pam = JSON.parse(JSON.stringify(p))
        if (this.examineStatus) {
          pam.params.push({ param: 'a.status', compare: '=', value: this.examineStatus })
        }
        return enginPayList(pam)
      } catch (error) { }
    },

    // 列表导出函数
    exportList: enginPayListExport,

    // 切换状态
    changeType(val) {
      this.$refs.pageRef.refreshList()
    },

    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },

    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },

    operation() {
      return this.operationBtn({
        details: {
          btnType: 'text',
          click: ({ row, index, column }) => {
            this.id = row.id
            this.createFormBool = true
          }
        }
      })
    },

    handleClose() {
      this.$refs.pageRef.refreshList()
      this.createFormBool = false
    }
  }
}
</script>

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