﻿/*
 * @Author: lisl 
 * @Email:lishenglin9@crc.com.hk 
 * @Date: 2018-09-20 13:51:33 
 * @Last Modified by: huang.junhui
 * @Last Modified time: 2019-02-01 14:47:54
 * 导入失败收款工作台查询
 */
<template>
<div>
  <EMSTable
    ref="listTable"
    :server="server"
    action="find"
    :columnsFn="getColumnsFun"
    :params="searchParams"
    :highlight-row="true"
    @on-selection-change="handle_sel_table"
  >
    <div slot="search-bar">
      <SearchFormItem ref="searchItem" :elItem="searchParams"></SearchFormItem>
    </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 :disabled="this.ids.length <= 0" type="warning" icon="checkmark-circled" @click="re_import">重新导入</Button>
      <Button :disabled="this.ids.length <= 0" type="info" icon="checkmark-circled" @click="go_back">退回</Button>
      <Button @click.native="exportResult"  type="success" icon="arrow-down-a">查询结果导出</Button>
    </div>
  </EMSTable>
</div>
</template>

<script>
import { EMSTable, DataSelect } from "ems-components";

import SearchFormItem from "../receivableComponent/searchFormItem";
import TableConfig from "../receivableComponent/tableConfig.js";
import DetailInfo from "./detail";
import ExcelExport from "../receivableComponent/excelExportPreview";
import Server from "./server.js";
import { exportFile } from "../receivableComponent/exportFile.js";
import getModalTextarea from "ems-receivable@/components/modalTextarea/index.js";
import ReceivableDetail from "../receivableComponent/receivableDetail/index.vue";
const server = new Server();
export default {
  components: {
    EMSTable,
    
    DataSelect,
    SearchFormItem
  },
  data() {
    return {
      server: server,
      searchParams: {
        // parentCode: "",
        batchNum: "", // 批次号
        compCode: "",
        receivablesBankNum: "",
        paymentCompName: "",
        paymentBankNum: "",
        currencyCode: "",
        paymentTypeCode: "",
        receivablesStatus: "-3",//2018/12/27 修改  EMS-3158 / 2019-2-1 EMS-3538 -3表示只查导入失败和生成失败两种数据
        _status_fail: true,
        receivablesSource: "",
        receivablesLineNum: "",
        //  "resourceCode":window.location.hash.substring(window.location.hash.lastIndexOf("\/")+1),//菜单code
        // _amount: "",
        _claimedAmount: "",//认领金额查询
        receivablesStartAmount: "", // 收款开始金额 输入
        receivablesEndAmount: "", // 收款结束金额输入
        _date: "", //收款日期
        receivablesStartDate: "", // 收款日期 收款开始日期，格式为“2018-12-12”
        receivablesEndDate: "", //   收款结束日期，格式为“2018-12-12”
        businessType: "", //业务类型
        receivablesClass: "", //收款分类
        _receivablesClass: "", //是否显示收款分类
        updatedByName: "" //操作人
      },
      ids: [],
      modalOptions: {}
    };
  },
  computed: {},
  created: function() {},
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    //退回
    go_back() {
      let self = this;
      this.modalOptions = {
        text: `确认退回当前选择的${this.ids.length}项记录嘛？`,
        placeholder: "请输入退回原因",
        val: ""
      };
      this.$Modal.confirm({
        title: "退回提示",
        render: getModalTextarea(this.modalOptions),
        loading: true,
        okText: "确定",
        cancelText: "取消",
        onOk: async function() {
          if (self.modalOptions.val.trim().length <= 0) {
            let modal = this;
            modal.$data.buttonLoading = false;
            return self.$Message.warning("请在文本框中输入退回原因");
          }
          //2018/12/27 修改  EMS-3158
          // let param = self.ids.map(item => {
          //   return {
          //     receivablesNum: item,
          //     receivablesStatus: 2,
          //     logRemark: self.modalOptions.val
          //   };
          // });
          let param = {
              ids: self.ids,
              receivablesStatus:2,
              logRemark: self.modalOptions.val
            }; 
          //返回结果
          let data = await self.server.updateStatus(param);
          if (data.statusCode === "-1") {
            self.$Message.error(data.msg);
            let modal = this;
            modal.$data.buttonLoading = false;
          } else {
            self.search();
            self.$Message.success("退回成功");
            self.$Modal.remove();
          }
        }
      });
    },
    detail(row) {
      //查看详细
      new this.$pageModal(
        DetailInfo,
        {
          props: {
            title: "查看导入失败详情",
            lineNum: row.receivablesLineNum
          }
        },
        data => {
          if (data) {
            this.search(1);
          }
        }
      );
    },
    re_import() {
      //重新导入
      this.$Modal.confirm({
        title: "重新导入提示",
        content: `<p>确认重新导入当前选择的${this.ids.length}项记录嘛？</p>`,
        loading: true,
        okText: "确定",
        cancelText: "取消",
        onOk: async () => {
          let param = this.ids.map(item => {
            return {
              receivablesNum: item
            };
          });

          //返回结果
          let data = await this.server.reimport(param);
          if (data.statusCode === "-1") {
            this.$Message.error(data.msg);
          } else {
            this.search(1);
            this.$Message.success("重新导入完成");
          }
          this.$Modal.remove();
        }
      });
    },
    handle_sel_table(selection) {
      if (selection.length > 0) {
        this.ids = selection.map(item => item.receivablesLineId);
      } else {
        this.ids = [];
      }
    },
    /**
     * 查询结果导出
     */
    exportResult() {
      //选择导出列
      new this.$pageModal(
        ExcelExport,
        {
          props: {
            title: "选择导出列",
            businessType: "lineReceivable"
          }
        },
        async data => {
          if (!data) return;
          let selectColunms = data.selectColunms || [];
          let selectData = data.selectData || [];
          //导出请求参数
          let resData = {
            lineReturnDto: this.searchParams,
            selectColunms: selectColunms,
            selectData: selectData,
            businessType: "lineReceivable",
            businessName: "导入失败数据导出",
            businessUrl: "receivableClaimServiceImpl.exportReceivableLine"
          };
          //返回结果
          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.searchParams.receivablesStatus = "-3" 
      this.search(1);
    },
    /**
     * 生成表格列
     */
    getColumnsFun() {
      let arr = [
        "批次号",
        "原收款单号",
        "收款单号",
        "收款分类",
        "收款单位",
        "收款账号",
        "付款单位",
        "付款账号",
        "认领金额",
        "收款币种",
        "手续费",
        "收款日期",
        "操作人",
        "收款来源",
        "收款方式",
        "收款状态"
      ];
      let columns = new TableConfig(this, arr).getColumns();
      columns.splice(0, 0, {
        title: "操作",
        key: "action",
        width: 120,
        align: "center",
        fixed: "left",
        render: (h, params) => {
          return h("RowTools", {
            props: {
              data: [
                {
                  text: "详细",
                  handle: () => {
                    this.detail(params.row);
                  }
                },
                {
                  text: "查看",
                  handle: () => {
                    let self = this;
                    new this.$pageModal(
                      ReceivableDetail,
                      {
                        props: {
                          title: "导入失败收款工作台查询详情", 
                          receivablesLineNum: params.row.receivablesLineNum,
                          receivablesClass: params.row.receivablesClass,
                          // vm:self,
                          // columns:arr,
                          detail:params.row
                        }
                      },
                      data => { }
                    );
                  }
                }
              ]
            }
          });
        }
      }); 
      columns.splice(0, 0, {
        type: "selection",
        width: 45,
        fixed: "left",
        align: "center"
      });
      return columns;
    }
  },
  watch: {},
  directives: {}
};
</script>

<style>
</style>
