/*
 * 收款工作台查询
 */
<template>
  <div class="page-table run-mod-box">
    <EMSTable ref="listTable" :server="server" action="find" :columnsFn="getColumnsFun" :params="searchParams">
      <div slot="search-bar"> 
        <component is="SearchFormItem" ref="searchItem" :elItem="searchParams"></component>
      </div>
      <div slot="handle-bar">
        <Button @click.native="search()" type="warning" icon="search">查询</Button>
        <Button @click.native="reset" type="info" icon="loop">重置</Button> 
      </div>
      <div slot="table-bar">
        <Button type="warning" @click.native="exportResult">查询结果导出</Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
import { EMSTable, DataSelect } from "ems-components";

import SearchFormItem from "../receivableComponent/searchFormItem";
import TableConfig from "../receivableComponent/tableConfig.js";
import { exportFile } from "../receivableComponent/exportFile.js";
import ExcelExport from "../receivableComponent/excelExportPreview";
import Server from "./server.js";
import ReceivableDetail from "../receivableComponent/receivableDetail/index.vue";
const server = new Server();
export default {
  components: {
    EMSTable,
    
    DataSelect,
    SearchFormItem
  },
  data() {
    return {
      server: server,
      searchParams: { 
        batchNum: "", // 批次号
        compCode: "",
        receivablesBankNum: "",
        paymentCompName: "",
        paymentBankNum: "",
        currencyCode: "",
        paymentTypeCode: "",
        receivablesAllStatus: "", //查询所有 除草稿状态
        // _status: "", //是否显示收款状态select
        receivablesSource: "",
        updatedByName:"", //操作人
        categoryCode:"",
        receivablesNum: "",
        receivablesLineNum: "",
        _amount: "",
        receivablesStartAmount: "", // 收款开始金额 输入
        receivablesEndAmount: "", // 收款结束金额输入
        _date: [],
        receivablesStartDate: "",
        receivablesEndDate: "",
        businessType: "", //业务类型
        // resourceCode: window.location.hash.substring(
        //   window.location.hash.lastIndexOf("/") + 1
        // ), //菜单code
        receivablesClass: "",//收款分类
        _receivablesClass:"",//是否显示收款分类
      }
    };
  },
  computed: {},
  created: function() {
    this.initRecDate()
  },
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    initRecDate(){
      const now = new Date().Format('yyyy-MM-dd')
      const f = now.split("-")
      const m = (f[1] - 2) > 9 ? (f[1] - 2) : "0"+String((f[1] - 2))
      const ago = `${f[0]}-${m}-01`
      this.searchParams._date = [ago, now]
      this.searchParams.receivablesStartDate = ago
      this.searchParams.receivablesEndDate = now
    },
    /**
     * 查询结果导出
     */
    exportResult() {
      //选择导出列
      new this.$pageModal(
        ExcelExport,
        {
          props: {
            title: "选择导出列",
            businessType: "receivableAll"
          }
        },
        async data => {
          if(!data)return;
          let selectColunms = data.selectColunms || [];
          let selectData = data.selectData || [];
          //导出请求参数
          let resData = {
            searchParams: this.searchParams,
            selectColunms: selectColunms,
            selectData: selectData,
            businessType: "receivableAll",
            businessName: "收款工作台查询列表导出",
            businessUrl: "receivableClaimServiceImpl.findAllReceivablesPage"
          };
          //返回结果
          let result = await this.server.exportResult(resData);
          if (result.statusCode === "-1") {
            this.$Message.error(result.msg);
          } else {
            exportFile(result,"收款工作台查询列表导出");
          }
        }
      ); //end pageModal
    },
    /**
     * 搜索
     */
    search(page = 1) {
      //获取 from 值信息
      this.searchParams = this.$refs["searchItem"].searchForm;
      this.$refs["listTable"].load(this.searchParams, page);
    },
    /**
     * 重置
     */
    reset() {
      this.$refs["searchItem"].reset();
      this.search(1);
    },
    /**
     * 生成表格列
     */
    getColumnsFun() {
      let arr = [
        "批次号",
        "原收款单号",
        "收款单号",
        "收款分类",
        "收款单位",
        "收款账号",
        "付款单位",
        "付款账号",
        "收款金额",
        "认领金额",
        "收款币种",
        "手续费",
        "收款日期",
        "业务类型",
        "操作人",
        "收款来源",
        "收款方式",
        "收款认领时间",
        "收款工作台查询--收款状态",
        "关联单据",
        "备注",
        "操作记录"
      ];
      
       let columns = new TableConfig(this, arr).getColumns();
      columns.splice(0, 0, {
        title: "操作",
        key: "action",
        width: 50,
        align: "center",
        fixed: "left",
        render: (h, params) => {
          return h("RowTools", {
            props: {
              data: [
                {
                  text: "查看",
                  handle: () => {
                    let self = this;
                    new this.$pageModal(
                      ReceivableDetail,
                      {
                        props: {
                          title: "收款工作台查询详情", 
                          receivablesLineNum: params.row.receivablesLineNum,
                          receivablesClass: params.row.receivablesClass,
                          receivablesAllStatus: params.row.receivablesAllStatus,
                          // vm:self,
                          // columns:arr,
                          type:params.row.type,
                          detail:params.row,
                          finishedReceivable:false
                        }
                      },
                      data => { }
                    );
                  }
                }
              ]
            }
          });
        }
      });
      return columns;
    }
  },
  watch: {},
  directives: {}
};
</script>
<style>
</style>

