schangxiang@126.com
2025-09-10 3d43ffa3152110b7823f9fa6320c08a6ae02358a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<template>
  <div ref="container" class="page-list-container">
    <!--数据Table-->
    <yrt-data-list :ref="dataListRef" :editor-ref="editorRef" :data-options="dataOptions" :fields.sync="dataListOptions.fields" :buttons="dataListOptions.buttons" :button-click="buttonClick" :data-list-selections.sync="dataListSelections" :auth-nodes="authNodes">
      <template slot="common-column-slot" slot-scope="{ row, col }">
 
      </template>
    </yrt-data-list>
 
    <!--数据编辑器Editor-->
    <yrt-editor :ref="editorRef" :data-list-ref="dataListRef" v-bind="editorOptions" :data-options="dataOptions" :action.sync="editorOptions.action" :top.sync="editorOptions.top" :visible.sync="editorOptions.config.visible" :detail-button-click="detailButtonClick" :auth-nodes="authNodes" :btn-read-only="btnReadOnly" @on-change="onChange" @on-detail-change="onDetailChange" @on-row-change="onRowChange">
    </yrt-editor>
 
    <!--预到货选择器-->
    <yrt-selector ref="selector-dialog" :config="selectorConfig" :visible.sync="selectorConfig.visible" @on-selected="onSelected"></yrt-selector>
 
  </div>
</template>
 
<script>
import baseLayout from "@/components/common/base-layout.vue";
import yrtSelector from "@/components/common/yrtSelector.vue";
 
export default {
  name: "finance-pay-finance-payout",
  components: {
    yrtSelector
  },
  mixins: [baseLayout],
  data() {
    return {
      // 选择器配置参数
      selectorConfig: {
        title: "预到货选择器",
        width: "1000px",
        visible: false,
        // 配置路由
        router: "/selector/purchase-order-selector"
      }
    };
  },
  methods: {
    // 明细按钮点击事件
    detailButtonClick(authNode) {
      switch (authNode) {
        case "detailAdd":
          // 物料明细添加
          this.detailAdd();
          return true;
      }
    },
    // 明细添加
    detailAdd() {
      if (!this.masterData.consignorName) {
        this.$message({
          message: "请选择货主!",
          type: "warning"
        });
        return;
      } else if (!this.masterData.providerShortName) {
        this.$message({
          message: "请选择供应商!",
          type: "warning"
        });
        return;
      }
      const selector = this.$refs["selector-dialog"];
      selector.setSearchValue("consignor_Id", [this.masterData.consignor_Id]);
      selector.setReadOnly("consignor_Id", true); // 设为只读
      selector.setSearchValue("provider_Id", [this.masterData.provider_Id]);
      selector.setReadOnly("provider_Id", true); // 设为只读
      selector.loadData();
 
      this.selectorConfig.visible = true;
    },
    onSelected(rows) {
      rows.forEach(element => {
        // 自定义字段赋值
        element.billType = "预到货单";
        element.bill_Id = element.order_Id;
        element.billCode = element.orderCode;
        element.billDate = element.createDate;
        element.grandTotal = element.totalMoney; // 单据金额
        element.totalPaid = element.totalPaid || 0; // 已付
        element.unpaid = element.grandTotal - element.totalPaid; // 未付
        element.totalUnSettle = element.unpaid; // 剩余未结
      });
      this.editor.addDetailDataRow(rows);
      this.selectorConfig.visible = false;
    },
    onDetailChange(ref, val, row, field) {
      if (field.prop === "favourTotal") {
        this.setTotal();
      }
    },
    onChange(ref, val, field, formData) {
      if (field && field.options.prop === "totalSettle") {
        this.setTotal();
      }
    },
    onRowChange(ref, val, field, formData) {
      if (["consignorName"].indexOf(field.options.prop) >= 0) {
        window.setTimeout(() => {
          this.getbankAccountNametems();
        }, 200);
      }
    },
    // 根据客户获取账户名称
    getbankAccountNametems() {
      const formData = this.editor.formData;
      const url = "/api/finance/payout/getShortName";
      const params = {
        consignorCode: formData.consignorCode
      };
      var callback = res => {
        if (res.result) {
          if (res.result) {
            this.$set(formData, "bankAccount_Id", res.data.BankAccount_Id);
            this.$set(formData, "bankAccountCode", res.data.bankAccountCode);
            this.$set(formData, "bankAccountName", res.data.bankAccountName);
          }
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    // 求和
    setTotal() {
      var detailRows = this.detailRows; // 获得明细行数据集合
      let totalSettle = this.masterData.totalSettle; // 本次结算
      // 对明细进行本次结算分配
      for (const row of detailRows) {
        if (totalSettle <= 0) break;
 
        const favourTotal = Number(row.favourTotal) || 0;
        if (row.unpaid - favourTotal > totalSettle) {
          row.totalSettle = totalSettle;
          totalSettle = 0;
        } else {
          row.totalSettle = row.unpaid - favourTotal;
          totalSettle = totalSettle - row.totalSettle;
        }
        // 剩余未结 = 未结算 - 本次结算
        row.totalUnSettle = Math.Round(row.unpaid - row.totalSettle - (favourTotal || 0), 2);
      }
 
      // 主表求和字段计算
      const total = detailRows.reduce(
        (totalItem, currItem) => {
          totalItem.grandTotal += currItem.grandTotal;
          totalItem.totalPaid += currItem.totalPaid;
          totalItem.unpaid += currItem.unpaid;
          totalItem.favourTotal += Number(currItem.favourTotal) || 0;
          totalItem.totalUnSettle += currItem.totalUnSettle;
          return totalItem;
        },
        // 初始值
        { grandTotal: 0, totalPaid: 0, unpaid: 0, favourTotal: 0, totalUnSettle: 0 }
      );
      this.masterData.grandTotal = total.grandTotal;
      this.masterData.totalPaid = total.totalPaid;
      this.masterData.unpaid = total.unpaid;
      this.masterData.favourTotal = total.favourTotal;
      this.masterData.totalUnSettle = total.totalUnSettle;
    }
  }
  // }
};
</script>