﻿/*
 * @Author: Anmin 
 * @Email:changanmin1@crc.com.hk 
 * @Date: 2018-09-03 20:41:47 
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-01-07 15:37:12
 * 收款复核分类工作台
 */
<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
          type="warning"
          :disabled="this.ids.length <= 0"
          icon="plus-round"
          @click="auditing"
        >复核</Button>
        <Button
          type="info"
          :disabled="this.ids.length <= 0"
          icon="checkmark-circled"
          @click="go_back"
        >退回</Button>
        <Button type="success" @click.native="exportResult" 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 { exportFile } from "../receivableComponent/exportFile.js";
import ExcelExport from "../receivableComponent/excelExportPreview";
import Server from "./server.js";
import getModalTextarea from "ems-receivable@/components/modalTextarea/index.js";
const server = new Server();
export default {
  name: "ManuallyAddIndexPage",
  components: {
    EMSTable,
    
    DataSelect,
    SearchFormItem
  },
  data() {
    return {
      ids: [],
      server: server,
      modalOptions: {},
      searchParams: {
        receivablesNum: "", //收款单号 输入
        receivablesClass: "", //收款分类
        _receivablesClass: "", //是否显示收款分类
        compCode: "", // 收款单位 t_md_bank 弹出选择
        receivablesBankNum: "", // 收款账号 弹出选择
        paymentCompName: "", // 付款单位 输入
        paymentBankNum: "", // 付款账号 输入
        _amount: "", // 收款金额 是否显示
        receivablesStartAmount: "", // 收款开始金额 输入
        receivablesEndAmount: "", // 收款结束金额输入
        receivablesStatus: "4", // 收款状态 值集
        updatedByName: "", //操作人
        _date: "", //收款日期
        receivablesStartDate: "", // 收款日期 收款开始日期，格式为“2018-12-12”
        receivablesEndDate: "", //   收款结束日期，格式为“2018-12-12”
        paymentTypeCode: "", // 收款方式 值集
        receivablesSource: "", // 收款来源 值集
        //  "resourceCode":window.location.hash.substring(window.location.hash.lastIndexOf("\/")+1),//菜单code
        currencyCode: "", // 收款币种 值集
        bankSerialNumber: "" //流水号
      }
    };
  },
  computed: {},
  created: function() {},
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    handle_sel_table(selection) {
      this.ids = selection;
    },
    //审核
    auditing(row) {
      this.$Modal.confirm({
        title: "复核提示",
        content: `<p>共选择了${this.ids.length}项信息，确定提交复核嘛？</p>`,
        "ok-text": "确定",
        "cancel-text": "取消",
        loading: true,
        onOk: async () => {
          let param = this.ids.map(item => {
            return {
              receivablesId: item.receivablesId,
              receivablesStatus: 5,
              receivablesClass: item.receivablesClass
            };
          });
          let data = await this.server.modify(param);
          if (data.statusCode === "-1") {
            this.$Message.error(data.msg);
          } else {
            this.$Message.success("提交复核成功");
            this.search(); //  刷新数据列表
          }
          this.$Modal.remove(); //手动关闭对话框
        },
        onCancel: () => {}
      });
    },
    //退回
    go_back() {
      let self = this;
      this.modalOptions = {
        text: `确认退回当前选择的${this.ids.length}项记录嘛？`,
        placeholder: "请输入退回原因",
        val: ""
      };
      this.$Modal.confirm({
        title: "退回提示",
        render: getModalTextarea(this.modalOptions),
        "ok-text": "确定",
        "cancel-text": "取消",
        loading: true,
        onOk: async function() {
          if (self.modalOptions.val.trim().length <= 0) {
            this.$data.buttonLoading = false;
            return self.$Message.warning("请在文本框中输入退回原因");
          }
          let param = self.ids.map(item => {
            return {
              receivablesId: item.receivablesId,
              receivablesStatus: 3, //3 收款状态——未分类
              receivablesClass: 4, //4 表示收款分类 ——未分类
              logRemark: self.modalOptions.val
            };
          });
          let data = await self.server.modify(param);
          if (data.statusCode === "-1") {
            self.$Message.error(data.msg);
            this.$data.buttonLoading = false;
          } else {
            self.$Message.success("退回成功");
            self.search(); //  刷新数据列表
            self.$Modal.remove(); //手动关闭对话框
          }
        },
        onCancel: () => {}
      });
    },
    /**
     * 查询结果导出
     */
    exportResult() {
      //选择导出列
      new this.$pageModal(
        ExcelExport,
        {
          props: {
            title: "选择导出列",
            businessType: "receivableBase"
          }
        },
        async data => {
          if (!data) return;
          let selectColunms = data.selectColunms || [];
          let selectData = data.selectData || [];
          //导出请求参数
          let resData = {
            searchParams: this.searchParams,
            selectColunms: selectColunms,
            selectData: selectData,
            businessType: "receivableBase",
            businessName: "收款复核分类工作台列表导出",
            businessUrl: "receivableService.exportReceivableBaseSearch"
          };
          //返回结果
          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, {
        type: "selection",
        width: 45,
        fixed: "left",
        align: "center"
      });
      return columns;
    }
  },
  watch: {},
  directives: {}
};
</script>

<style>
</style>
