creatCollection.vue 54.6 KB
Newer Older
1 2
<template>
  <div class="app-container">
3
    <el-form
吴滔's avatar
吴滔 committed
4 5 6 7
        ref="form"
        :model="form"
        label-width="120px"
        label-position="left"
我在何方's avatar
我在何方 committed
8
        :inline="true"
吴滔's avatar
吴滔 committed
9
      >
10
      <el-card>
吴滔's avatar
吴滔 committed
11 12
        <div v-if="id" slot="header" class="card-title">{{ $t('修改收款单') }}</div>
        <div v-else slot="header" class="card-title">{{ $t('新增收款单') }}</div>
我在何方's avatar
我在何方 committed
13 14
        <!-- <el-descriptions :column="3" border> -->
          <!-- <el-descriptions-item > -->
吴滔's avatar
吴滔 committed
15
            <el-form-item
我在何方's avatar
我在何方 committed
16
              :label="$t('客户')"
我在何方's avatar
我在何方 committed
17
              style="margin-bottom: 0;margin-top: 20px;"
吴滔's avatar
吴滔 committed
18
              prop="customerId"
我在何方's avatar
我在何方 committed
19
              :span="4"
吴滔's avatar
吴滔 committed
20
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('客户不能为空') }"
吴滔's avatar
吴滔 committed
21 22 23
            >
              <customer-selector
                v-model="form.customerId"
24
                @change="customerChange"
吴滔's avatar
吴滔 committed
25 26
              />
            </el-form-item>
我在何方's avatar
我在何方 committed
27 28
  <!--        </el-descriptions-item>
          <el-descriptions-item > -->
吴滔's avatar
吴滔 committed
29
            <el-form-item
我在何方's avatar
我在何方 committed
30
              :label="$t('部门')"
我在何方's avatar
我在何方 committed
31
              style="margin-bottom: 0;margin-top: 20px;"
吴滔's avatar
吴滔 committed
32
              prop="departmentId"
我在何方's avatar
我在何方 committed
33
              :span="4"
吴滔's avatar
吴滔 committed
34
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('部门不能为空') }"
吴滔's avatar
吴滔 committed
35 36 37 38
            >
              <el-select
                v-model="form.departmentId"
                style="width: 300px"
吴滔's avatar
吴滔 committed
39
                :placeholder="$t('请选择部门')"
吴滔's avatar
吴滔 committed
40 41 42 43 44 45 46 47 48 49
              >
                <el-option
                  v-for="item in deptData"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item
我在何方's avatar
我在何方 committed
50
              :label="$t('业务员')"
我在何方's avatar
我在何方 committed
51
              style="margin-bottom: 0;margin-top: 20px;"
吴滔's avatar
吴滔 committed
52
              prop="salesmanId"
我在何方's avatar
我在何方 committed
53
              :span="4"
吴滔's avatar
吴滔 committed
54
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('业务员不能为空') }"
吴滔's avatar
吴滔 committed
55
            >
吴滔's avatar
吴滔 committed
56
              <el-select v-model="form.salesmanId" :placeholder="$t('请选择业务员')" @change="v => form.salesmanName = creatorData.find(t => t.id === v).nickname">
吴滔's avatar
吴滔 committed
57 58 59 60 61 62 63 64
                <el-option
                  v-for="item in creatorData"
                  :key="item.id"
                  :label="item.nickname"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
我在何方's avatar
我在何方 committed
65 66 67 68 69
          <!-- </el-descriptions-item> -->
          <!-- <el-descriptions-item > -->
<!--            <el-form-item
              :label="$t('手续费(RMB)')"
              style="margin-bottom: 0;margin-top: 20px;"
吴滔's avatar
吴滔 committed
70
              prop="feeRate"
吴滔's avatar
吴滔 committed
71
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('手续费不能为空') }"
吴滔's avatar
吴滔 committed
72 73 74
            >
              <el-input
                v-model="form.feeRate"
吴滔's avatar
吴滔 committed
75
                :placeholder="$t('请输入手续费')"
吴滔's avatar
吴滔 committed
76
              ></el-input>
我在何方's avatar
我在何方 committed
77 78 79
            </el-form-item> -->
<!--          </el-descriptions-item>
          <el-descriptions-item > -->
吴滔's avatar
吴滔 committed
80
            <el-form-item
我在何方's avatar
我在何方 committed
81 82
              :label="$t('备注')"
              style="margin-bottom: 0;margin-top: 20px;"
吴滔's avatar
吴滔 committed
83 84
              prop="remark"
            >
吴滔's avatar
吴滔 committed
85
              <el-input v-model="form.remark" :placeholder="$t('备注')"></el-input>
吴滔's avatar
吴滔 committed
86
            </el-form-item>
我在何方's avatar
我在何方 committed
87 88
          <!-- </el-descriptions-item> -->
        <!-- </el-descriptions> -->
89
      </el-card>
90
      <el-card class="card amountCard">
我在何方's avatar
我在何方 committed
91
        <div slot="header" class="card-title">{{ $t('应收明细') }}</div>
92 93 94 95 96 97 98 99
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            style="padding: 10px; margin-bottom: 10px"
吴滔's avatar
吴滔 committed
100
            >{{ $t('添加未收客户款项') }}</el-button
101 102 103
          >
        </el-col>
        <el-table v-loading="loadings" :data="list" border>
吴滔's avatar
吴滔 committed
104 105 106
          <el-table-column :label="$t('订单号')" align="center" prop="orderNo" />
          <el-table-column :label="$t('唛头')" align="center" prop="marks" />
          <el-table-column :label="$t('品名')" align="center" prop="title">
107
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
108
             {{ scope.row.titleZh?(scope.row.titleZh + "(" + scope.row.titleEn + ")"): ''}}
109 110
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
111
          <el-table-column :label="$t('箱数')" align="center" prop="num" />
112 113 114 115 116
            <el-table-column :label="$t('体积/重量')" align="center" prop="weight">
              <template slot-scope="scope">
                 {{ scope.row.volume}}/{{ scope.row.weight}}
                </template>
              </el-table-column>
吴滔's avatar
吴滔 committed
117
          <el-table-column :label="$t('收入类型')" align="center" prop="feeType">
118 119 120 121 122 123 124
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.FEE_TYPE"
                :value="scope.row.feeType"
              ></dict-tag>
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
125
          <el-table-column :label="$t('单价金额')" align="center" prop="unitPrice">
126
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
127 128
              <span>{{ scope.row.unitPrice }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
129 130
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
131
          <el-table-column :label="$t('总金额')" align="center" prop="totalAmount">
132
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
133
              <span>{{ scope.row.totalAmount }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
我在何方's avatar
我在何方 committed
134

我在何方's avatar
我在何方 committed
135
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
136 137
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
138
          <el-table-column :label="$t('优惠金额')" align="center">
吴滔's avatar
吴滔 committed
139
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
140
             <span> {{ scope.row.discountTotal ? `${scope.row.discountTotal}`:0}}</span>
我在何方's avatar
我在何方 committed
141 142
              {{getCurrencyLabel(scope.row.currencyId)}}
			  <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
吴滔's avatar
吴滔 committed
143
              <span v-if="scope.row.discountTotal">{{scope.row.discountRemark?('('+scope.row.discountRemark+')'): '' }}</span>
吴滔's avatar
吴滔 committed
144 145
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
146
          <el-table-column :label="$t('操作')" align="center">
吴滔's avatar
吴滔 committed
147
            <template slot-scope="scope">
吴滔's avatar
吴滔 committed
148 149
              <el-button v-if="scope.row.type !== 'total'" type="text" @click="addDiscount(scope.row, scope.$index)">{{ scope.row.discountTotal ? $t('修改优惠') : $t('新增优惠') }}</el-button>
              <el-button v-if="scope.row.type !== 'total'" type="text" @click="deleteListRow(scope.$index)">{{ $t('删除') }}</el-button>
吴滔's avatar
吴滔 committed
150 151
            </template>
          </el-table-column>
152
        </el-table>
我在何方's avatar
我在何方 committed
153 154
<!--        <el-descriptions :column="2" border class="card">
          <el-descriptions-item > -->
吴滔's avatar
吴滔 committed
155
            <el-form-item
我在何方's avatar
我在何方 committed
156 157
              :label="$t('是否需要开票')+':'"
              style="margin-bottom: 0;margin-top: 20px;"
158
              prop="openInvoice"
我在何方's avatar
我在何方 committed
159
              required
吴滔's avatar
吴滔 committed
160
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请选择是否需要开票') }"
吴滔's avatar
吴滔 committed
161 162
            >
              <el-select
163
                v-model="form.openInvoice"
吴滔's avatar
吴滔 committed
164
                :placeholder="$t('请选择是否需要开票')"
吴滔's avatar
吴滔 committed
165
              >
吴滔's avatar
吴滔 committed
166 167
                <el-option :value="1" :label="$t('是')"></el-option>
                <el-option :value="0" :label="$t('否')"></el-option>
吴滔's avatar
吴滔 committed
168 169
              </el-select>
            </el-form-item>
我在何方's avatar
我在何方 committed
170 171 172 173
            <el-form-item
              :label="$t('核销基准币种')+':'"
              style="margin-bottom: 0;margin-top: 20px;"
            >
我在何方's avatar
我在何方 committed
174 175
			{{getCurrencyLabel(showCurrencyId)}}
             <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="showCurrencyId" /> -->
我在何方's avatar
我在何方 committed
176 177
            </el-form-item>
<!--          </el-descriptions-item>
吴滔's avatar
吴滔 committed
178
          <el-descriptions-item :label="$t('核销基准币种')">
我在何方's avatar
我在何方 committed
179

180
          </el-descriptions-item>
我在何方's avatar
我在何方 committed
181
        </el-descriptions> -->
182 183
      </el-card>
      <el-card v-if="showInvoice" class="card">
吴滔's avatar
吴滔 committed
184
        <div slot="header" class="card-title">{{ $t('开票资料') }}</div>
185
        <el-descriptions :column="3" border>
吴滔's avatar
吴滔 committed
186
          <el-descriptions-item :label="$t('发票抬头')">
吴滔's avatar
吴滔 committed
187 188 189 190
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
191
              prop="invoice"
吴滔's avatar
吴滔 committed
192
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入发票抬头') }"
吴滔's avatar
吴滔 committed
193
            >
194 195 196
              <el-input v-model="form.invoice"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
197
          <el-descriptions-item :label="$t('纳税人识别号')">
198 199 200 201 202
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="taxpayer"
吴滔's avatar
吴滔 committed
203
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入纳税人识别号') }"
204 205 206 207
            >
              <el-input v-model="form.taxpayer"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
208
          <el-descriptions-item :label="$t('开户行')">
209 210 211 212 213
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="accountBank"
吴滔's avatar
吴滔 committed
214
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入开户行') }"
215 216 217 218
            >
              <el-input v-model="form.accountBank"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
219
          <el-descriptions-item :label="$t('账号')">
220 221 222 223 224
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="accountName"
吴滔's avatar
吴滔 committed
225
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入账号') }"
226 227 228 229
            >
              <el-input v-model="form.accountName"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
230
          <el-descriptions-item :label="$t('项目')">
231 232 233 234 235
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="projectName"
吴滔's avatar
吴滔 committed
236
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入项目') }"
237 238 239 240
            >
              <el-input v-model="form.projectName"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
241
          <el-descriptions-item :label="$t('税率%')">
242 243 244 245 246
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="taxRate"
吴滔's avatar
吴滔 committed
247
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入税率') }"
248 249 250 251
            >
              <el-input v-model="form.taxRate"></el-input>
            </el-form-item>
          </el-descriptions-item>
吴滔's avatar
吴滔 committed
252
          <el-descriptions-item :label="$t('开票地址/电话')">
253 254 255 256 257
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="addressPhone"
吴滔's avatar
吴滔 committed
258
              :rules="{ required: true, trigger: ['blur', 'change'], message: $t('请输入开票地址/电话') }"
259 260
            >
              <el-input v-model="form.addressPhone"></el-input>
吴滔's avatar
吴滔 committed
261 262 263
            </el-form-item>
          </el-descriptions-item>
        </el-descriptions>
264
      </el-card>
265
      <el-card class="card">
我在何方's avatar
我在何方 committed
266
        <div slot="header" class="card-title">{{ $t('收款信息') }}</div>
267
        <el-table :data="form.receiptAccountList" border :key="form.receiptAccountList.length">
吴滔's avatar
吴滔 committed
268
          <el-table-column :label="$t('应收币种')" align="center">
269
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
270
              {{getCurrencyLabel(scope.row.currencyId)}}
271 272
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
273
          <el-table-column :label="$t('应收金额')" align="center" prop="receivableAmount">
吴滔's avatar
吴滔 committed
274
            <template slot-scope="scope" v-if="scope.row.type !== 'total'">
275
              {{ `${NP.minus(scope.row.receivableAmount, scope.row.discountTotal || 0)}${scope.row.discountTotal > 0 ? `(${scope.row.receivableAmount} - ${scope.row.discountTotal})` : ''}` }}
吴滔's avatar
吴滔 committed
276 277
            </template>
          </el-table-column>
278 279
          <el-table-column align="center" width="220">
            <template #header>
我在何方's avatar
我在何方 committed
280
              {{ $t('核销基准币种') }}{{getCurrencyLabel(showCurrencyId)}}{{ $t('汇率') }}
281 282 283 284 285 286 287 288 289 290 291
            </template>
            <template slot-scope="scope">
              <template v-if="scope.row.type !== 'total'">
                <span v-if="showCurrencyId === scope.row.currencyId">{{ scope.row.writeOffRate }}</span>
                <el-form-item
                  v-else
                  label=""
                  label-width="0"
                  style="margin-bottom: 0"
                  :prop="`receiptAccountList.${scope.$index}.writeOffRate`"
                >
吴滔's avatar
吴滔 committed
292
                  <el-input v-model="scope.row.writeOffRate" @input="() => writeOffRateChange(scope.row, scope.$index)"></el-input>
293 294 295
                </el-form-item>
              </template>
              <template v-else>
我在何方's avatar
我在何方 committed
296
                {{ $t('应收总金额') }}	{{getCurrencyLabel(showCurrencyId)}}
297 298 299 300 301
              </template>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="writeOffAmount">
            <template #header>
我在何方's avatar
我在何方 committed
302
              {{ $t('核销基准金额') }}	{{getCurrencyLabel(showCurrencyId)}}
303 304
            </template>
          </el-table-column>
我在何方's avatar
我在何方 committed
305
          <el-table-column :label="$t('期望收款账户')" align="center">
306 307 308 309 310 311 312 313 314 315
            <template slot-scope="scope">
              <el-form-item
                v-if="scope.row.type !== 'total'"
                label=""
                label-width="0"
                style="margin-bottom: 0"
                :prop="`receiptAccountList.${scope.$index}.platformAccountId`"
              >
                <el-select
                  v-model="scope.row.platformAccountId"
吴滔's avatar
吴滔 committed
316
                  :placeholder="$t('请选择收款账户')"
317 318 319 320 321 322 323 324 325 326 327
                >
                  <el-option
                    v-for="item in bankData"
                    :key="item.id"
                    :label="item.baAccountName + '(' + item.baAccountNum + ')'"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </template>
          </el-table-column>
我在何方's avatar
我在何方 committed
328
          <el-table-column :label="$t('期望收款币种')" align="center">
329 330 331 332 333 334 335 336
            <template slot-scope="scope">
              <el-form-item
                v-if="scope.row.type !== 'total'"
                label=""
                label-width="0"
                style="margin-bottom: 0"
                :prop="`receiptAccountList.${scope.$index}.collectionCurrencyId`"
              >
我在何方's avatar
我在何方 committed
337 338 339 340 341 342 343 344 345 346 347 348
              <el-select
                v-model="scope.row.collectionCurrencyId"
                :placeholder="$t('请选择')"
                @change="val => currencyIdChange(val, scope.row, scope.$index)"
              >
                <el-option
                  v-for="item in currencyList"
                  :key="item.id"
                  :label="item.titleZh"
                  :value="item.id"
                />
              </el-select>
349 350 351
              </el-form-item>
            </template>
          </el-table-column>
我在何方's avatar
我在何方 committed
352
          <el-table-column :label="$t('期望收款汇率')" align="center">
353 354 355 356 357 358 359 360 361 362
            <template slot-scope="scope">
              <el-form-item
                v-if="scope.row.type !== 'total'"
                label=""
                label-width="0"
                style="margin-bottom: 0"
                :prop="`receiptAccountList.${scope.$index}.collectionRate`"
              >
                <el-input v-model="scope.row.collectionRate" @input="() => rateChange(scope.row, scope.$index)"></el-input>
              </el-form-item>
我在何方's avatar
我在何方 committed
363
              <span v-else>{{ $t('期望收费金额') }}</span>
364 365
            </template>
          </el-table-column>
我在何方's avatar
我在何方 committed
366
          <el-table-column :label="$t('期望收款金额')" align="center" prop="collectionAmount">
367
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
368
              <span v-if="scope.row.type !== 'total'">{{ scope.row.collectionAmount }}</span>
369
              <div v-else>
我在何方's avatar
我在何方 committed
370 371
                <div v-for="itemAmount in scope.row.collectionAmount">{{itemAmount.currencyName}}: {{ itemAmount.amount}}</div>
<!--                <div v-if="scope.row.collectionAmount[1]">{{ $t('人民币') }}: {{ scope.row.collectionAmount[1].toFixed(6) }}</div>
吴滔's avatar
吴滔 committed
372
                <div v-if="scope.row.collectionAmount[2]">{{ $t('奈拉') }}: {{ scope.row.collectionAmount[2].toFixed(6) }}</div>
我在何方's avatar
我在何方 committed
373
                <div v-if="scope.row.collectionAmount[3]">{{ $t('西非法郎') }}: {{ scope.row.collectionAmount[3].toFixed(6) }}</div> -->
374 375 376 377 378 379
              </div>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
            </template>
          </el-table-column>
        </el-table>
        <el-descriptions :column="2" border class="card">
吴滔's avatar
吴滔 committed
380
          <el-descriptions-item :label="$t('账单汇率有效期')">
381 382 383 384 385 386 387 388 389
            <el-form-item
              label=""
              label-width="0"
              style="margin-bottom: 0"
              prop="rateValidateDate"
            >
              <el-date-picker
                v-model="form.rateValidateDate"
                type="datetime"
吴滔's avatar
吴滔 committed
390
                value-format="yyyy-MM-dd HH:mm:ss"
吴滔's avatar
吴滔 committed
391
                :placeholder="$t('选择日期时间')">
392 393 394 395 396
              </el-date-picker>
            </el-form-item>
          </el-descriptions-item>
        </el-descriptions>
      </el-card>
397
    </el-form>
吴滔's avatar
吴滔 committed
398
    <div slot="footer" style="margin: 20px 0">
吴滔's avatar
吴滔 committed
399 400 401
      <el-button v-if="id==0||form.state==0" type="primary" :loading="saveBtnLoading" @click="submitForm(1)">{{ $t('保存') }}</el-button>
      <el-button v-else type="primary" :loading="saveBtnLoading" @click="$store.dispatch('tagsView/delCurrentView')">{{ $t('返回') }}</el-button>
      <el-button type="primary" :loading="saveBtnLoading" @click="submitForm(0)">{{ id&&form.state!=0 ? $t('修改') : $t('新增') }}</el-button>
402
    </div>
吴滔's avatar
吴滔 committed
403 404
    <el-dialog
      :visible.sync="open"
吴滔's avatar
吴滔 committed
405
      :title="$t('添加未收客户款项')"
吴滔's avatar
吴滔 committed
406 407
      width="80%"
      append-to-body
408
      @open="getList"
吴滔's avatar
吴滔 committed
409 410 411 412 413
    >
      <div>
        <!-- <div slot="header" class="card-title">添加未收客户款项</div> -->
        <!-- 搜索工作栏 -->
        <el-form
414
          v-if="open"
吴滔's avatar
吴滔 committed
415 416 417 418 419 420 421
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="80px"
        >
          <el-row>
吴滔's avatar
吴滔 committed
422
            <el-form-item :label="$t('始发城市')">
吴滔's avatar
吴滔 committed
423 424
              <el-select
                v-model="queryParams.departureId"
吴滔's avatar
吴滔 committed
425
                :placeholder="$t('请选择始发地')"
吴滔's avatar
吴滔 committed
426 427 428 429 430 431 432 433 434
              >
                <el-option
                  v-for="item in expoerCityList"
                  :label="item.titleZh"
                  :value="item.id"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
吴滔's avatar
吴滔 committed
435
            <el-form-item :label="$t('目的城市')">
吴滔's avatar
吴滔 committed
436 437
              <el-select
                v-model="queryParams.objectiveId"
吴滔's avatar
吴滔 committed
438
                :placeholder="$t('请选择始发地')"
吴滔's avatar
吴滔 committed
439 440 441 442 443 444 445 446 447
              >
                <el-option
                  v-for="item in importCityList"
                  :label="item.titleZh"
                  :value="item.id"
                  :key="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
吴滔's avatar
吴滔 committed
448
            <el-form-item :label="$t('运输方式')">
吴滔's avatar
吴滔 committed
449 450 451 452 453 454
              <dict-selector
                :type="DICT_TYPE.ECW_TRANSPORT_TYPE"
                v-model="queryParams.transportId"
                formatter="number"
              />
            </el-form-item>
吴滔's avatar
吴滔 committed
455
            <el-form-item :label="$t('出货渠道')">
吴滔's avatar
吴滔 committed
456 457
              <el-select
                v-model="queryParams.channelId"
吴滔's avatar
吴滔 committed
458
                :placeholder="$t('请选择出货渠道')"
吴滔's avatar
吴滔 committed
459 460 461 462 463 464 465 466 467 468 469
              >
                <el-option
                  v-for="item in channelList"
                  :label="item.nameZh"
                  :value="item.channelId"
                  :key="item.channelId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
吴滔's avatar
吴滔 committed
470
            <el-form-item :label="$t('报关方式')">
吴滔's avatar
吴滔 committed
471 472 473 474 475
              <dict-selector
                :type="DICT_TYPE.ECW_CUSTOMS_TYPE"
                v-model="queryParams.customsType"
              />
            </el-form-item>
吴滔's avatar
吴滔 committed
476
            <el-form-item :label="$t('控货')">
吴滔's avatar
吴滔 committed
477 478 479 480 481
              <dict-selector
                :type="DICT_TYPE.INFRA_BOOLEAN_STRING"
                v-model="queryParams.control"
              />
            </el-form-item>
吴滔's avatar
吴滔 committed
482
            <el-form-item :label="$t('客户名称')">
吴滔's avatar
吴滔 committed
483 484 485 486 487 488
              <customer-selector
                v-model="queryParams.consignorId"
                @change="consignor = $event"
              />
            </el-form-item>
          </el-row>
吴滔's avatar
吴滔 committed
489
          <el-form-item :label="$t('订单编号')" prop="orderNo">
吴滔's avatar
吴滔 committed
490 491
            <el-input
              v-model="queryParams.orderNo"
吴滔's avatar
吴滔 committed
492
              :placeholder="$t('请输入订单编号')"
吴滔's avatar
吴滔 committed
493 494 495 496
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
497

吴滔's avatar
吴滔 committed
498
          <el-form-item :label="$t('自编号')" prop="selfNo">
吴滔's avatar
吴滔 committed
499
            <el-input
吴滔's avatar
吴滔 committed
500
              v-model="queryParams.selfNo"
吴滔's avatar
吴滔 committed
501
              :placeholder="$t('请输入自编号')"
吴滔's avatar
吴滔 committed
502 503 504 505
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
506

吴滔's avatar
吴滔 committed
507 508
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery"
吴滔's avatar
吴滔 committed
509
              >{{$t('查询')}}</el-button
吴滔's avatar
吴滔 committed
510 511 512 513
            >
          </el-form-item>
        </el-form>
        <el-table
514
          ref="multipleTable"
吴滔's avatar
吴滔 committed
515 516 517 518
          v-loading="loading1"
          :data="orderData"
          border
          @selection-change="handleSelectionChange"
519 520
          row-key="id"
          height="calc(100vh - 480px)"
吴滔's avatar
吴滔 committed
521
        >
吴滔's avatar
吴滔 committed
522
          <el-table-column type="selection" width="55" :reserve-selection="true"> </el-table-column>
吴滔's avatar
吴滔 committed
523 524 525
          <el-table-column :label="$t('订单号')" align="center" prop="orderNo" />
          <el-table-column :label="$t('唛头')" align="center" prop="marks" />
          <el-table-column :label="$t('品名')" align="center" prop="title">
吴滔's avatar
吴滔 committed
526
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
527
              {{ scope.row.titleZh?(scope.row.titleZh + "(" + scope.row.titleEn + ")"): ''}}
吴滔's avatar
吴滔 committed
528 529
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
530
          <el-table-column :label="$t('箱数')" align="center" prop="num" />
531 532 533 534 535
          <el-table-column :label="$t('体积/重量')" align="center" prop="weight">
            <template slot-scope="scope">
               {{ scope.row.volume}}/{{ scope.row.weight}}
              </template>
            </el-table-column>
吴滔's avatar
吴滔 committed
536 537 538
          <el-table-column :label="$t('发货人')" align="center" prop="consignorName" />
          <el-table-column :label="$t('收货人')" align="center" prop="consigneeName" />
          <el-table-column :label="$t('订单状态')" align="center" prop="status">
吴滔's avatar
吴滔 committed
539 540 541 542 543 544 545
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.ORDER_STATUS"
                :value="scope.row.status"
              />
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
546
          <el-table-column :label="$t('收入类型')" align="center" prop="feeType">
吴滔's avatar
吴滔 committed
547 548 549 550 551 552 553
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.FEE_TYPE"
                :value="scope.row.feeType"
              ></dict-tag>
            </template>
          </el-table-column>
554
          <!-- <el-table-column label="单价美元" align="center" prop="unitPrice" /> -->
吴滔's avatar
吴滔 committed
555
          <el-table-column :label="$t('单价')" align="center" prop="unitPrice">
556
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
557 558
              <span>{{ scope.row.unitPrice }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
559 560
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
561
          <el-table-column :label="$t('总金额')" align="center" prop="totalAmount">
562
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
563 564
              <span>{{ scope.row.totalAmount }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
565 566
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
567 568 569 570 571 572 573 574 575 576
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.page"
          :limit.sync="queryParams.rows"
          @pagination="getList"
        />
        <!-- </el-card> -->
        <div slot="footer" class="dialog-footer">
吴滔's avatar
吴滔 committed
577 578
          <el-button type="primary" @click="saveSelectList">{{ $t('确认添加') }}</el-button>
          <el-button @click="hiddenDialog">{{ $t('取消') }}</el-button>
吴滔's avatar
吴滔 committed
579 580 581
        </div>
      </div>
    </el-dialog>
吴滔's avatar
吴滔 committed
582
    <el-dialog v-if="discountVisible" :visible.sync="discountVisible" :title="$t('优惠信息确认')" width="60%" append-to-body>
吴滔's avatar
吴滔 committed
583
      <el-form label-width="120px">
吴滔's avatar
吴滔 committed
584
        <el-form-item v-if="form.receiptNo" :label="$t('收款单号')">
吴滔's avatar
吴滔 committed
585 586 587
          {{ form.receiptNo }}
        </el-form-item>
        <el-table :data="[selectListRow]" border style="margin-bottom: 22px">
吴滔's avatar
吴滔 committed
588 589 590
          <el-table-column :label="$t('订单号')" align="center" prop="orderNo" />
          <el-table-column :label="$t('唛头')" align="center" prop="marks" />
          <el-table-column :label="$t('品名')" align="center" prop="title">
吴滔's avatar
吴滔 committed
591
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
592
              {{ scope.row.titleZh?(scope.row.titleZh + "(" + scope.row.titleEn + ")"): ''}}
吴滔's avatar
吴滔 committed
593 594
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
595
          <el-table-column :label="$t('箱数')" align="center" prop="num" />
596 597 598 599 600
          <el-table-column :label="$t('体积/重量')" align="center" prop="weight">
            <template slot-scope="scope">
               {{ scope.row.volume}}/{{ scope.row.weight}}
              </template>
            </el-table-column>
吴滔's avatar
吴滔 committed
601
          <el-table-column :label="$t('收入类型')" align="center" prop="feeType">
吴滔's avatar
吴滔 committed
602 603 604 605 606 607 608
            <template slot-scope="scope">
              <dict-tag
                :type="DICT_TYPE.FEE_TYPE"
                :value="scope.row.feeType"
              ></dict-tag>
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
609
          <el-table-column :label="$t('单价金额')" align="center" prop="unitPrice">
吴滔's avatar
吴滔 committed
610
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
611 612
              <span>{{ scope.row.unitPrice }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
吴滔's avatar
吴滔 committed
613 614
            </template>
          </el-table-column>
吴滔's avatar
吴滔 committed
615
          <el-table-column :label="$t('总金额')" align="center" prop="totalAmount">
吴滔's avatar
吴滔 committed
616
            <template slot-scope="scope">
我在何方's avatar
我在何方 committed
617 618
              <span>{{ scope.row.totalAmount }}{{getCurrencyLabel(scope.row.currencyId)}}</span>
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="scope.row.currencyId" /> -->
吴滔's avatar
吴滔 committed
619 620 621
            </template>
          </el-table-column>
        </el-table>
吴滔's avatar
吴滔 committed
622
        <el-form-item :label="$t('总金额')">
我在何方's avatar
我在何方 committed
623
          {{ selectListRow.totalAmount }}{{getCurrencyLabel(selectListRow.currencyId)}}
吴滔's avatar
吴滔 committed
624
        </el-form-item>
吴滔's avatar
吴滔 committed
625
        <el-form-item :label="$t('优惠金额')">
我在何方's avatar
我在何方 committed
626
          <el-input v-model="discountForm.discountTotal" type="number" min="0" :max="selectListRow.totalAmount" @input="checkDiscount" style="width: 300px" ></el-input>
我在何方's avatar
我在何方 committed
627 628
          &nbsp;&nbsp;{{getCurrencyLabel(selectListRow.currencyId)}}

吴滔's avatar
吴滔 committed
629
        </el-form-item>
吴滔's avatar
吴滔 committed
630
        <el-form-item :label="$t('优惠原因')">
吴滔's avatar
吴滔 committed
631 632
          <el-input v-model="discountForm.discountRemark" type="textarea" style="width: 300px"></el-input>
        </el-form-item>
吴滔's avatar
吴滔 committed
633
        <el-form-item :label="$t('优惠后')">
634
          {{ (selectListRow.totalAmount - (discountForm.discountTotal || 0)).toFixed(2)}}
我在何方's avatar
我在何方 committed
635
		  {{getCurrencyLabel(selectListRow.currencyId)}}
吴滔's avatar
吴滔 committed
636
        </el-form-item>
吴滔's avatar
吴滔 committed
637
        <el-form-item v-if="opnotice" :label="$t('操作人')">
吴滔's avatar
吴滔 committed
638 639
          {{ discountForm.author }}
        </el-form-item>
吴滔's avatar
吴滔 committed
640
        <el-form-item v-if="opnotice" :label="$t('操作时间')">
吴滔's avatar
吴滔 committed
641 642 643 644
          {{ discountForm.time }}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
吴滔's avatar
吴滔 committed
645 646
        <el-button type="primary" @click="saveDiscount">{{$t('提交')  }}</el-button>
        <el-button @click="cancelDiscount">{{ $t('取消') }}</el-button>
吴滔's avatar
吴滔 committed
647 648
      </div>
    </el-dialog>
649 650 651 652
  </div>
</template>

<script>
653
import { listSimpleUsers } from "@/api/system/user";
吴滔's avatar
吴滔 committed
654 655 656 657 658 659 660
import { DICT_TYPE } from "@/utils/dict";
import { getToken } from "@/utils/auth";
import CustomerSelector from "@/components/CustomerSelector";
import { getBankAccountPage } from "@/api/ecw/bankAccount";
import { listSimpleDepts } from "@/api/system/dept";
import { getChannelList } from "@/api/ecw/channel";
import { getTradeCityList } from "@/api/ecw/region";
吴滔's avatar
吴滔 committed
661
import { createReceipt, getReceivableList, getReceivableInfoByIds, getReceiptInfoByIds, getReceiptAccountList, getInvoicingItem, updateReceipt, updateReceivableDiscountById, getReceivableDiscountLogById } from "@/api/ecw/financial";
662 663
import {getCustomer} from '@/api/ecw/customer'
import NP from 'number-precision'
我在何方's avatar
我在何方 committed
664
  import {getOrder} from '@/api/ecw/order'
665 666
import { getCurrencyPage } from "@/api/ecw/currency";
import ret from "bluebird/js/release/util";
吴滔's avatar
吴滔 committed
667 668
import dayjs from "dayjs";
import { getUserProfile } from "@/api/system/user";
669

吴滔's avatar
吴滔 committed
670 671 672 673 674 675 676
export default {
  name: "CreatCollection",
  components: {
    CustomerSelector,
  },
  data() {
    return {
吴滔's avatar
吴滔 committed
677
      NP,
吴滔's avatar
吴滔 committed
678 679 680
      loadings: false,
      loading1: false,
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/app-api/file/upload", // 上传的图片服务器地址
681
      form: {
吴滔's avatar
吴滔 committed
682
        receiptAccountList: []
683
      },
吴滔's avatar
吴滔 committed
684 685
      creatorData: [],
      list: [],
686
      // fileList: [],
吴滔's avatar
吴滔 committed
687
      orderData: [],
我在何方's avatar
我在何方 committed
688
      opnotice:false,
吴滔's avatar
吴滔 committed
689
      dialogTableKey: 0,
690
      total: 0,
吴滔's avatar
吴滔 committed
691 692
      headers: {
        Authorization: "Bearer " + getToken(),
693
      },
吴滔's avatar
吴滔 committed
694 695 696 697 698 699
      loading: "",
      open: false,
      bankData: [],
      params: {
        page: 1,
        rows: 20,
700
      },
吴滔's avatar
吴滔 committed
701 702 703 704 705 706 707
      deptData: [],
      deptArr: [],
      oadings: false,
      channelList: [],
      queryParams: {
        page: 1,
        rows: 20,
708
      },
吴滔's avatar
吴滔 committed
709 710
      multipleSelection: [],
      tradeCityList: [],
711 712
      id: 0,
      receiptId: 0,
713
      currencyList: [],
吴滔's avatar
吴滔 committed
714 715 716 717
      saveBtnLoading: false,
      discountVisible: false,
      discountForm: {},
      selectListRow: {},
吴滔's avatar
吴滔 committed
718
      selectListIndex: 0,
我在何方's avatar
我在何方 committed
719
      flag: false,
吴滔's avatar
吴滔 committed
720 721
    };
  },
722
  async created() {
吴滔's avatar
吴滔 committed
723 724 725
    getUserProfile().then(res => {
      this.discountForm.author = res.data.username
    })
726 727
    // 获取汇率
    await getCurrencyPage(this.params).then(res => this.currencyList = res.data.list)
728

吴滔's avatar
吴滔 committed
729 730
    let that = this;
    if (that.$route.query.id) {
吴滔's avatar
吴滔 committed
731
      this.flag = true
吴滔's avatar
吴滔 committed
732
      this.id = this.$route.query.id;
我在何方's avatar
我在何方 committed
733
      console.log(this.id)
734
      getReceiptInfoByIds({ id: this.id }).then(res => {
吴滔's avatar
吴滔 committed
735
        res.data.rateValidateDate = dayjs(res.data.rateValidateDate).format('YYYY-MM-DD HH:mm:ss')
736 737
        this.form = Object.assign({}, this.form, res.data)
      })
吴滔's avatar
吴滔 committed
738
      await getInvoicingItem({ id: this.id }).then(res => {
739 740 741
        this.list = [...res.data]
      })
      getReceiptAccountList({ id: this.id }).then(res => {
742 743 744 745 746
        if (res.data.length > 0) {
          // totalAmount
          res.data = [...res.data, {
            type: 'total',
            writeOffAmount: res.data.reduce((total, currentValue) => NP.plus(total, currentValue.writeOffAmount || 0), 0),
我在何方's avatar
我在何方 committed
747
            collectionAmount: []
748 749
          }]
        }
750
        this.$set(this.form, 'receiptAccountList', [...res.data])
751
        this.$nextTick(() => {
我在何方's avatar
我在何方 committed
752 753 754 755
          // const dollarList = this.list.filter(v => v.currencyId === 1)
          // const discountDollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
          // const d = this.form.receiptAccountList.find(v => v.currencyId == 1)
          // d && (d.discountTotal = discountDollar)
吴滔's avatar
吴滔 committed
756

我在何方's avatar
我在何方 committed
757 758 759 760
          // const rmbList = this.list.filter(v => v.currencyId === 2)
          // const discountRmb = rmbList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
          // const r = this.form.receiptAccountList.find(v => v.currencyId == 2)
          // r && (r.discountTotal = discountRmb)
吴滔's avatar
吴滔 committed
761

我在何方's avatar
我在何方 committed
762 763 764 765
          // const nairaList = this.list.filter(v => v.currencyId === 3)
          // const discountNaira = nairaList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
          // const n = this.form.receiptAccountList.find(v => v.currencyId == 3)
          // n && (n.discountTotal = discountNaira)
吴滔's avatar
吴滔 committed
766

767 768
          this.form.receiptAccountList.forEach((item, index) => {
            this.rateChange(item, index)
吴滔's avatar
吴滔 committed
769
            // this.calculation()
770 771
          });
        })
772 773 774 775 776 777 778
      })
    }
    if (that.$route.query.receiptId && that.$route.query.receiptId !== '0') {
      this.receiptId = this.$route.query.receiptId;
      getReceivableInfoByIds({ id: this.receiptId }).then(res => {
        this.list = [{...res.data}]
        this.calculation()
我在何方's avatar
我在何方 committed
779 780 781

          getOrder(res.data.orderId).then(response => {
            // console.log(response.data)
782
            if(response.data.customerId) this.$set(this.form,'customerId',response.data.customerId)
我在何方's avatar
我在何方 committed
783
          })
784
      })
吴滔's avatar
吴滔 committed
785
    }
786 787

    // this.getList();
吴滔's avatar
吴滔 committed
788 789 790 791 792 793
    // if(that.$route.query.consignorId){
    //   this.queryParams.consignorId = this.$route.query.consignorId
    // }
    // if(that.$route.query.writeOffName){
    //   this.form.writeOffName = this.$route.query.writeOffName
    // }
794
    listSimpleUsers().then((res) => (that.creatorData = res.data));
吴滔's avatar
吴滔 committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
    getChannelList().then((res) => (that.channelList = res.data));
    getTradeCityList().then((res) => (that.tradeCityList = res.data));
    getBankAccountPage(that.params).then(
      (res) => (that.bankData = res.data.list)
    );
    listSimpleDepts().then((res) => {
      res.data.forEach((item) => {
        if (item.parentId == 0) {
          that.deptArr.push(item);
        } else {
          that.deptData.push(item);
        }
      });

      that.deptData.forEach((value) => {
        var dept = that.deptArr.filter((itt) => itt.id == value.parentId);
        if (dept.length > 0) {
          value.name = dept[0].name + " | " + value.name;
        }
      });
    });
  },
  computed: {
    expoerCityList() {
      return this.tradeCityList.filter((item) => item.type == 2);
    },
    importCityList() {
      return this.tradeCityList.filter((item) => item.type == 1);
    },
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
    showCurrencyId() {
      let fieldList = [];
      let groupList=[];
      this.list.map((element)=>{
          if(fieldList.indexOf(element['currencyId'])===-1){
              fieldList.push(element['currencyId'])
          }
      })
      for(let i=0;i<fieldList.length;i++){
          let arr = this.list.filter((element)=>{
              return element['currencyId']===fieldList[i];
          })
          groupList.push({
              currencyId:arr[0].currencyId,
              list:arr
          })
      }
      if (groupList.length === 1) return groupList[0].currencyId
      else return 1
    },
    showInvoice() {
      return this.form.openInvoice == 1
    }
吴滔's avatar
吴滔 committed
847 848
  },
  methods: {
我在何方's avatar
我在何方 committed
849 850 851 852 853
	  getCurrencyLabel(id){
	    var label = this.currencyList.filter(item=>item.id == id)
	    if(label.length>0) return label[0].titleZh
	    return ''
	  },
我在何方's avatar
我在何方 committed
854 855 856 857 858
    checkDiscount(e){
      if(e>this.selectListRow.totalAmount){
        this.discountForm.discountTotal = this.selectListRow.totalAmount
      }
    },
859 860 861 862
    currencyIdChange(val, row, index) {
      row.collectionCurrencyId = val
      if (val == row.currencyId) row.collectionRate = 1
      else {
我在何方's avatar
我在何方 committed
863 864 865 866 867 868 869
        // if (row.currencyId == 1 && val == 3) row.collectionRate = this.UStoRMB()
        // if (row.currencyId == 1 && val == 2) row.collectionRate = this.UStoNAN()
        // if (row.currencyId == 3 && val == 1) row.collectionRate = this.RMBtoUS()
        // if (row.currencyId == 3 && val == 2) row.collectionRate = this.RMBtoNAN()
        // if (row.currencyId == 2 && val == 1) row.collectionRate = this.NANtoUS()
        // if (row.currencyId == 2 && val == 3) row.collectionRate = this.NANtoRMB()
         row.collectionRate = NP.divide(this.currencyList.find(v => v.id === row.currencyId).huilv, this.currencyList.find(v => v.id === val).huilv).toFixed(6)
870
      }
我在何方's avatar
我在何方 committed
871

872 873
      this.rateChange(row, index)
    },
吴滔's avatar
吴滔 committed
874 875 876 877 878 879
    writeOffRateChange(row, index) {
      row.writeOffAmount = NP.times(row.writeOffRate || 0, NP.minus(row.receivableAmount, row.discountTotal))

      const writeOffAmountTotal = this.form.receiptAccountList.filter(v => v.type !== 'total').reduce((total, currentValue) => NP.plus(total, currentValue.writeOffAmount || 0), 0)
      this.form.receiptAccountList[this.form.receiptAccountList.length -1].writeOffAmount = writeOffAmountTotal
    },
880
    rateChange(row, index) {
我在何方's avatar
我在何方 committed
881 882
      console.log(row)
      row.receivableAmount && (row.collectionAmount = NP.times(row.collectionRate || 0, NP.minus(row.receivableAmount, row.discountTotal||0)).toFixed(6))
883 884 885 886
      this.form.receiptAccountList[index] = {...row}

      setTimeout(() => {
        // 收款总计
我在何方's avatar
我在何方 committed
887 888 889 890 891 892 893 894 895 896
        var amountList =[]
        this.currencyList.forEach((item,index)=>{
          var dollarList = this.form.receiptAccountList.filter(v => v.collectionCurrencyId == item.id)
          if(dollarList.length>0){
            var dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0).toFixed(6)
            amountList.push({currencyName:item.titleZh,amount:dollar})
          }
        })
        // const dollarList = this.form.receiptAccountList.filter(v => v.collectionCurrencyId == 1)
        // const dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0)
897

我在何方's avatar
我在何方 committed
898 899
        // const rmbList = this.form.receiptAccountList.filter(v => v.collectionCurrencyId == 3)
        // const rmb = rmbList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0)
900

我在何方's avatar
我在何方 committed
901 902 903 904 905
        // const nairaList = this.form.receiptAccountList.filter(v => v.collectionCurrencyId == 2)
        // const naira = nairaList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0)
        // const faList = this.form.receiptAccountList.filter(v => v.collectionCurrencyId == 6)
        // const fa = faList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0)
        this.form.receiptAccountList[this.form.receiptAccountList.length -1].collectionAmount = amountList
906 907 908
        this.$set(this.form, 'receiptAccountList', [...this.form.receiptAccountList])
      }, 100)
    },
909
    calculation() {
910 911
      const copyList = this.form.receiptAccountList
      this.form.receiptAccountList = []
我在何方's avatar
我在何方 committed
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
      this.currencyList.forEach((item,index)=>{
        var dollarList = this.list.filter(v => v.currencyId === item.id)
        if(dollarList.length>0){
          let dollar,discountDollar
            dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.totalAmount || 0), 0)
            discountDollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
            var t = copyList.find(v => v.currencyId == item.id)
            this.form.receiptAccountList.push(
              {
                discountTotal: discountDollar,
                currencyId: item.id,
                receivableAmount: dollar,
                writeOffRate: t?.writeOffRate || NP.divide(this.currencyList.find(v => v.id === item.id).huilv, this.currencyList.find(v => v.id === this.showCurrencyId).huilv).toFixed(6),
                platformAccountId: t?.platformAccountId || '',
                collectionCurrencyId: t?.collectionCurrencyId || item.id,
                collectionRate: t?.collectionRate || 1
              }
            )
            this.calculationCount(NP.minus(dollar, discountDollar), item.id)
        }
      })

      // let dollar,discountDollar
      // if (dollarList.length > 0) {
      //   dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.totalAmount || 0), 0)
      //   discountDollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
      //   const t = copyList.find(v => v.currencyId == 1)
      //   this.form.receiptAccountList = [
      //     {
      //       discountTotal: discountDollar,
      //       currencyId: 1,
      //       receivableAmount: dollar,
      //       writeOffRate: t?.writeOffRate || (this.showCurrencyId === 1 ? 1 : this.showCurrencyId === 2 ? this.UStoRMB() : this.UStoNAN()),
      //       platformAccountId: t?.platformAccountId || '',
      //       collectionCurrencyId: t?.collectionCurrencyId || 1,
      //       collectionRate: t?.collectionRate || 1
      //     }
      //   ]
      //   this.calculationCount(NP.minus(dollar, discountDollar), 1)
      // }
      // const rmbList = this.list.filter(v => v.currencyId === 2)
      // let rmb,discountRmb
      // if (rmbList.length > 0) {
      //   rmb = rmbList.reduce((total, currentValue) => NP.plus(total, currentValue.totalAmount || 0), 0)
      //   discountRmb = rmbList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
      //   const t = copyList.find(v => v.currencyId == 2)
      //   this.form.receiptAccountList = [
      //     ...this.form.receiptAccountList,
      //     {
      //       discountTotal: discountRmb,
      //       currencyId: 2,
      //       receivableAmount: rmb,
      //       writeOffRate: t?.writeOffRate || (this.showCurrencyId === 1 ? this.RMBtoUS() : this.showCurrencyId === 2 ? 1 : this.RMBtoNAN()),
      //       platformAccountId: t?.platformAccountId || '',
      //       collectionCurrencyId: t?.collectionCurrencyId || '',
      //       collectionRate: t?.collectionRate || ''
      //     }
      //   ]
      //   this.calculationCount(NP.minus(rmb, discountRmb), 2)
      // }
      // const nairaList = this.list.filter(v => v.currencyId === 3)
      // let naira,discountNaira
      // if (nairaList.length > 0) {
      //   naira = nairaList.reduce((total, currentValue) => NP.plus(total, currentValue.totalAmount || 0), 0)
      //   discountNaira = nairaList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
      //   const t = copyList.find(v => v.currencyId == 3)
      //   this.form.receiptAccountList = [
      //     ...this.form.receiptAccountList,
      //     {
      //       discountTotal: discountNaira,
      //       currencyId: 3,
      //       receivableAmount: naira,
      //       writeOffRate: t?.writeOffRate || (this.showCurrencyId === 1 ? this.NANtoUS() : this.showCurrencyId === 2 ? this.NANtoRMB() : 1),
      //       platformAccountId: t?.platformAccountId || '',
      //       collectionCurrencyId: t?.collectionCurrencyId || '',
      //       collectionRate: t?.collectionRate || '',
      //       collectionAmount:discountNaira
      //     }
      //   ]
      //   this.calculationCount(NP.minus(naira, discountNaira), 3)
      // }
993 994 995 996 997 998
      if (this.form.receiptAccountList.length > 0) {
        // totalAmount
        const totalt = this.form.receiptAccountList.reduce((total, currentValue) => NP.plus(total, currentValue.writeOffAmount || 0), 0)
        this.form.receiptAccountList = [...this.form.receiptAccountList, {
          type: 'total',
          writeOffAmount: totalt,
我在何方's avatar
我在何方 committed
999
          collectionAmount: [this.form.receiptAccountList.discountNaira, 0, 0]
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
        }]

        this.form.receivableTotalAmount = totalt
      }
      // receiptAccountList: [
          // { currencyId: 1, receivableAmount: 0, writeOffRate: 1, writeOffAmount: 999, platformAccountId: '', currencyId: '', rate: 1, collectionAmount: 0 },
          // { currencyId: 2, receivableAmount: 0, writeOffRate: 1, writeOffAmount: 999, platformAccountId: '', currencyId: '', rate: 1, collectionAmount: 0 },
          // { currencyId: 3, receivableAmount: 0, writeOffRate: 1, writeOffAmount: 999, platformAccountId: '', currencyId: '', rate: 1, collectionAmount: 0 },
        // ]

1010
      if (this.showCurrencyId === 1) { // 美元
1011 1012 1013 1014 1015 1016 1017
        // const usCount = NP.plus(dollar, NP.times(this.RMBtoUS(), rmb),  NP.times(this.NANtoUS(), naira))
        // this.form.receivableDetailList[0].rate = 1
        // this.form.receivableDetailList[0].amount = usCount
        // this.form.receivableDetailList[1].rate || (this.form.receivableDetailList[1].rate = this.UStoRMB())
        // this.form.receivableDetailList[2].rate || (this.form.receivableDetailList[2].rate = this.UStoNAN())
        // this.form.receivableTotalAmount = usCount
        // this.calculationCount(usCount)
1018
      } else if (this.showCurrencyId === 2) { // 人民币
1019 1020 1021 1022 1023 1024 1025
        // const rmbCount = NP.plus(rmb, NP.times(this.UStoRMB(), dollar),  NP.times(this.NANtoRMB(), naira))
        // this.form.receivableDetailList[1].rate = 1
        // this.form.receivableDetailList[1].amount = usCount
        // this.form.receivableDetailList[0].rate || (this.form.receivableDetailList[0].rate = this.RMBtoUS())
        // this.form.receivableDetailList[2].rate || (this.form.receivableDetailList[2].rate = this.RMBtoNAN())
        // this.form.receivableTotalAmount = rmbCount
        // this.calculationCount(rmbCount)
1026
      } else if (this.showCurrencyId === 3) { // 奈拉
1027 1028 1029 1030 1031 1032 1033
        // const nairaCount = NP.plus(naira, NP.times(this.UStoNAN(), dollar),  NP.times(this.RMBtoNAN(), rmb))
        // this.form.receivableDetailList[2].rate = 1
        // this.form.receivableDetailList[2].amount = nairaCount
        // this.form.receivableDetailList[0].rate || (this.form.receivableDetailList[0].rate = this.NANtoUS())
        // this.form.receivableDetailList[1].rate || (this.form.receivableDetailList[1].rate = this.NANtoRMB())
        // this.form.receivableTotalAmount = nairaCount
        // this.calculationCount(nairaCount)
1034
      }
1035 1036

      this.$set(this.form, 'receiptAccountList', [...this.form.receiptAccountList])
1037
    },
1038 1039 1040 1041 1042 1043
    calculationCount(usCount, type) {
      const index = this.form.receiptAccountList.findIndex(v => v.currencyId == type)
      const t = this.form.receiptAccountList[index]
      if (t) {
        t.writeOffAmount = NP.times(t.writeOffRate || 0, usCount)
        this.rateChange(t, index)
1044 1045 1046
      }
    },
    RMBtoUS() {
我在何方's avatar
我在何方 committed
1047
      return NP.divide(100, this.currencyList.find(v => v.titleEn === 'USD').huilv).toFixed(6)
1048 1049
    },
    NANtoUS() {
我在何方's avatar
我在何方 committed
1050
      return NP.times(this.RMBtoUS(), this.NANtoRMB()).toFixed(6)
1051 1052
    },
    UStoRMB() {
我在何方's avatar
我在何方 committed
1053
      return NP.divide(this.currencyList.find(v => v.titleEn === 'USD').huilv, 100).toFixed(6)
1054 1055
    },
    UStoNAN() {
我在何方's avatar
我在何方 committed
1056
      return NP.times(this.RMBtoNAN(), this.UStoRMB()).toFixed(6)
1057 1058
    },
    RMBtoNAN() {
我在何方's avatar
我在何方 committed
1059
      return NP.divide(100, this.currencyList.find(v => v.titleEn === 'NGN').huilv).toFixed(6)
1060 1061
    },
    NANtoRMB() {
我在何方's avatar
我在何方 committed
1062
      return NP.divide(this.currencyList.find(v => v.titleEn === 'NGN').huilv, 100).toFixed(6)
1063 1064
    },
    customerChange(value) {
吴滔's avatar
吴滔 committed
1065 1066 1067 1068
      if (this.flag) {
        this.flag = false
        return
      }
1069 1070 1071 1072
      this.form.customerName = value.name
      this.form.customerId && getCustomer(this.form.customerId).then(res => {
        this.form = {
          ...this.form,
吴滔's avatar
吴滔 committed
1073 1074 1075 1076 1077 1078 1079
          invoice: res.data.invoiceTitle,
          taxpayer: res.data.licenseNumber,
          accountBank: res.data.bank,
          accountName: res.data.bankNumber,
          projectName: res.data.project,
          taxRate: res.data.taxRate,
          addressPhone: `${res.data.billingAddress || ''}/${res.data.billingTell || ''}`,
1080 1081
        }
      })
吴滔's avatar
吴滔 committed
1082 1083 1084 1085 1086 1087 1088 1089 1090
    },
    cancelDiscount() {
      this.discountVisible = false
      this.discountForm = {}
      this.selectListRow = {}
    },
    addDiscount(row, index) {
      this.discountVisible = true
      this.selectListRow = { ...row }
我在何方's avatar
我在何方 committed
1091
      console.log(this.selectListRow)
吴滔's avatar
吴滔 committed
1092 1093 1094 1095 1096 1097 1098 1099
      this.selectListIndex = index
      this.$set(this.discountForm, 'time', dayjs().format('YYYY-MM-DD HH:mm:ss'))
      getReceivableDiscountLogById({ id: row.id }).then(res => {
        if (res.data?.creatorName) {
          this.$set(this.discountForm, 'time', dayjs(res.data.createTime).format('YYYY-MM-DD HH:mm:ss'))
          this.$set(this.discountForm, 'discountTotal', res.data.discountTotal)
          this.$set(this.discountForm, 'discountRemark', res.data.discountRemark)
          this.$set(this.discountForm, 'author', res.data.creatorName)
我在何方's avatar
我在何方 committed
1100 1101 1102
          this.opnotice = true
        }else{
          this.opnotice = false
吴滔's avatar
吴滔 committed
1103 1104 1105 1106 1107 1108
        }
      })
    },
    saveDiscount() {
      console.log(this.discountForm)
      // this.selectListRow.id
我在何方's avatar
我在何方 committed
1109
      if (this.discountForm.discountTotal === 0||!this.discountForm.discountTotal) {
吴滔's avatar
吴滔 committed
1110
        this.$modal.msgError(this.$t('优惠金额不能为空'));
我在何方's avatar
我在何方 committed
1111 1112 1113
        return
      }
      if (this.discountForm.discountRemark === 0||!this.discountForm.discountRemark) {
吴滔's avatar
吴滔 committed
1114
        this.$modal.msgError(this.$t('优惠原因不能为空'));
我在何方's avatar
我在何方 committed
1115 1116
        return
      }
吴滔's avatar
吴滔 committed
1117 1118 1119 1120 1121 1122 1123
      const params = {
        id: this.selectListRow.id,
        discountTotal: this.discountForm.discountTotal,
        discountRemark: this.discountForm.discountRemark,
        orderNo: this.selectListRow.orderNo,
        orderId: this.selectListRow.orderId,
      }
1124
       updateReceivableDiscountById(params).then(res => {
吴滔's avatar
吴滔 committed
1125
        if (this.selectListRow.discountTotal) {
吴滔's avatar
吴滔 committed
1126
          this.$modal.msgSuccess(this.$t('修改成功'));
吴滔's avatar
吴滔 committed
1127
        } else {
吴滔's avatar
吴滔 committed
1128
          this.$modal.msgSuccess(this.$t('新增成功'));
吴滔's avatar
吴滔 committed
1129
        }
我在何方's avatar
我在何方 committed
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
        // if(this.id>0){
        //    getInvoicingItem({ id: this.id }).then(res => {
        //     this.list = [...res.data]
        //     this.cancelDiscount()
        //     this.calculation()
        //   })
        // }else{
          setTimeout(()=>{
            getReceivableInfoByIds({ id: this.selectListRow.id }).then(res => {
              this.$set(this.list, this.selectListIndex, {...res.data})
              this.cancelDiscount()
              this.calculation()
            })
          },1000)


        // }


吴滔's avatar
吴滔 committed
1149
      })
吴滔's avatar
吴滔 committed
1150 1151 1152 1153 1154 1155 1156 1157 1158
    },
    getList() {
      this.loading1 = true;
      // 处理查询参数
      let params = { ...this.queryParams };
      this.addBeginAndEndTime(params, this.dateType, "createTime");
      // 执行查询
      getReceivableList(params).then((response) => {
        this.orderData = response.data.list;
吴滔's avatar
吴滔 committed
1159
        this.dialogTableKey ++
吴滔's avatar
吴滔 committed
1160 1161
        this.total = response.data.total;
        this.loading1 = false;
1162 1163 1164 1165 1166 1167
        this.$nextTick(() => {
          this.list.forEach(itm => {
            const t = this.orderData.find(v => v.id == itm.id)
            t && this.$refs.multipleTable.toggleRowSelection(t, true)
          })
        })
吴滔's avatar
吴滔 committed
1168 1169 1170 1171 1172 1173 1174 1175 1176
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
    },
    hiddenDialog() {
      this.open = false;
    },
1177
    submitForm(addType) {
我在何方's avatar
我在何方 committed
1178 1179
      const params = {...this.form}
      params.addType = addType
我在何方's avatar
我在何方 committed
1180

1181
      // params.receiptAccountList = params.receiptAccountList.map(v => Object.assign(v, {  }))
我在何方's avatar
我在何方 committed
1182

1183 1184
      if (this.list && this.list.length > 0) {
        params.receivableVOList = this.list
1185
      }else{
我在何方's avatar
我在何方 committed
1186
        this.saveBtnLoading = false
吴滔's avatar
吴滔 committed
1187
        this.$modal.msgError(this.$t('请添加未收客户款项'));
1188 1189
        return
      }
我在何方's avatar
我在何方 committed
1190

我在何方's avatar
我在何方 committed
1191
      // params.receiptAccountList.length = params.receiptAccountList.length - 1
我在何方's avatar
我在何方 committed
1192

我在何方's avatar
我在何方 committed
1193
      var saveStatus = true
我在何方's avatar
我在何方 committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
      params.receiptAccountList.forEach(v => {
        if(v.type!='total'){
          if(!v.platformAccountId){
            saveStatus = false
          }
          var bankname = this.bankData.filter(item=>item.id == v.platformAccountId)
          if(bankname.length>0){
            v.platformAccountName = bankname[0].baAccountName
            v.platformAccountNo = bankname[0].baAccountNum
            v.platformAccountBlankName = bankname[0].baBankName
          }
          delete v.discountTotal
          v.writeOffRate = Number(v.writeOffRate)
我在何方's avatar
我在何方 committed
1207
        }
我在何方's avatar
我在何方 committed
1208
      })
我在何方's avatar
我在何方 committed
1209 1210 1211 1212
      if(!saveStatus){
        this.$modal.msgError(this.$t('请添加收款账户'));
        return
      }
我在何方's avatar
我在何方 committed
1213 1214 1215
      delete params.receivableDetail


1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
      if (addType === 1) {
        let fieldsToValidate = ['customerId', 'departmentId', 'salesmanId']; // 部分字段校验 保存草稿用
        Promise.all(
          fieldsToValidate.map((field) => {
            return new Promise((resolve, reject) => {
              this.$refs['form'].validateField(field, (errorMessage) => {
                resolve(errorMessage);
              });
            });
          })
        ).then((errorMessages) => {
          let valid = errorMessages.every((errorMessage) => {
            return errorMessage == '';
          });
          if (valid) {
吴滔's avatar
吴滔 committed
1231
            this.saveBtnLoading = true
我在何方's avatar
我在何方 committed
1232
            params.receiptAccountList.splice(params.receiptAccountList.length - 1,1)
我在何方's avatar
我在何方 committed
1233
            if (this.id && this.id != 0) {
1234
              updateReceipt(params).then(res => {
吴滔's avatar
吴滔 committed
1235
                this.$modal.msgSuccess(this.$t('修改成功'));
我在何方's avatar
我在何方 committed
1236
                this.$store.dispatch('tagsView/delCurrentView')
吴滔's avatar
吴滔 committed
1237 1238
              }).finally(() => {
                this.saveBtnLoading = false
1239 1240
              })
            } else {
1241
              params.currencyId = this.showCurrencyId
1242
              createReceipt(params).then(res => {
吴滔's avatar
吴滔 committed
1243
                this.$modal.msgSuccess(this.$t('保存成功'));
我在何方's avatar
我在何方 committed
1244
                this.$store.dispatch('tagsView/delCurrentView')
吴滔's avatar
吴滔 committed
1245 1246
              }).finally(() => {
                this.saveBtnLoading = false
1247 1248 1249 1250 1251 1252 1253 1254
              })
            }
          }
        });
        return
      }
       this.$refs.form.validate ((valid)=>{
        if (valid) {
吴滔's avatar
吴滔 committed
1255
          this.saveBtnLoading = true
我在何方's avatar
我在何方 committed
1256
          params.receiptAccountList.splice(params.receiptAccountList.length - 1,1)
我在何方's avatar
我在何方 committed
1257
          if (this.id && this.id != 0) {
1258
            if(params.state==0) params.state = 1
1259
            updateReceipt(params).then(res => {
吴滔's avatar
吴滔 committed
1260
              this.$modal.msgSuccess(this.$t('修改成功'));
我在何方's avatar
我在何方 committed
1261
              this.$store.dispatch('tagsView/delCurrentView')
吴滔's avatar
吴滔 committed
1262 1263
            }).finally(() => {
              this.saveBtnLoading = false
1264 1265
            })
          } else {
1266
            params.currencyId = this.showCurrencyId
1267
            createReceipt(params).then(res => {
吴滔's avatar
吴滔 committed
1268
              this.$modal.msgSuccess(this.$t('新增成功'));
我在何方's avatar
我在何方 committed
1269
               this.$store.dispatch('tagsView/delCurrentView')
吴滔's avatar
吴滔 committed
1270 1271
            }).finally(() => {
              this.saveBtnLoading = false
1272 1273 1274 1275
            })
          }
        }
      })
吴滔's avatar
吴滔 committed
1276 1277 1278 1279 1280 1281 1282
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    saveSelectList() {
      this.list = this.multipleSelection
      this.open = false;
1283
      this.calculation()
吴滔's avatar
吴滔 committed
1284
    },
吴滔's avatar
吴滔 committed
1285 1286 1287 1288 1289
    deleteListRow(index) {
      const list = [...this.list]
      delete list[index]
      this.list = list.filter(v => v)
    },
吴滔's avatar
吴滔 committed
1290 1291 1292
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
吴滔's avatar
吴滔 committed
1293
      this.getList()
1294
    },
吴滔's avatar
吴滔 committed
1295 1296
  },
};
1297 1298
</script>

1299
<style scoped lang="scss">
吴滔's avatar
吴滔 committed
1300 1301 1302 1303
.card {
  margin-top: 20px;
}
.dialog-footer {
吴滔's avatar
吴滔 committed
1304 1305
  // padding: 40px;
  text-align: left;
吴滔's avatar
吴滔 committed
1306 1307 1308 1309 1310
}
.card-title {
  font-size: 18px;
  font-weight: bold;
}
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
::v-deep .el-descriptions-item__label {
  width: 200px;
}
.amountCard {
  ::v-deep .el-descriptions-item__label {
    width: 20%;
  }
  ::v-deep .el-descriptions-item__content {
    width: 30%;
  }
}
1322
</style>