import Api from '~/service/Api';
import commonFunctions from '~/mixin/commonFunctions.js';
import Utils from "~/utils/index";
export default {
  mixins: [commonFunctions],
  methods: {
    async handleSearch () {
      let opndatfrom = this.model.opndatfrom;
      if (!opndatfrom || opndatfrom == '') {
        this.$notify.error({ title: this.$t('factoring.错误'), message: this.$t('factoring.查询开始日期必输!') });
        return;
      }
      let opndatto = this.model.opndatto;
      if (!opndatto || opndatto == '') {
        this.$notify.error({ title: this.$t('factoring.错误'), message: this.$t('factoring.查询结束日期必输!') });
        return;
      }
      let params = {
        ...this.model,
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        opndatfrom: moment(opndatfrom).format('YYYY-MM-DD'),
        opndatto: moment(opndatto).format('YYYY-MM-DD'),
      };
      this.model.branch = JSON.parse(sessionStorage.getItem('currentOrg')).departmentNumber
      this.load = true;
      let rtnmsg = await Api.post("/factoring/trtsel/list", params);
      if (rtnmsg.respCode == SUCCESS) {
        this.load = false;
        this.stmData.data = [];
        this.stmData.data = rtnmsg.data.list;
        this.pagination = {
          pageNum: rtnmsg.data.pageNum || 1,
          pageSize: rtnmsg.data.pageSize || 10,
          total: rtnmsg.data.total
        };
      } else {
        this.$notify.error({ title: this.$t('factoring.错误'), message: this.$t('factoring.服务请求失败!') });
      }
      this.load = false;
    },
    async handleReset () {
      this.model.sealcrtyp = '';
      this.model.opndatfrom = new Date();
      this.model.opndatto = new Date();
      this.model.seaownref = '';
      this.model.seashgref = '';
      this.model.seaamtfr = '';
      this.model.seasta = '';
      this.model.seacur = '';
      this.model.pty.extkey = '';
      this.model.pty.nam = '';
      this.model.usr.extkey = '';
      this.model.seaamtto = '';
      this.model.searol = '';
      this.model.nam = '';
      this.model.seapty = '';
      this.model.searef = '';
    },
    // pageSize改变
    handleSizeChange (val) {
      this.pagination.pageNum = 1;
      this.pagination.pageSize = val;
      this.handleSearch();
    },
    // 页码改变
    handleCurrentChange (val) {
      this.pagination.pageNum = val;
      this.handleSearch();
    },
    // 获取处理按钮
    getButtons (row) {
      this.$set(this.codes, "rowList", row);
      this.handleVisible = true;
    },
    // 跳转对应交易
    onChoose (code, row) {
      this.routerPush({
        path: "/business/" + code,
        query: { inr: row.inr }
      });
      this.handleVisible = false;
    },
    // 保理开立
    toTrtopn () {
      this.routerPush('/business/lmtreg');
    },
  }
}