CollectionBankDetail.vue 12.3 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
<template>
  <div class="app-container">
      <el-descriptions :column="4" >
        <el-descriptions-item :label="$t('收款单编号')">{{ form.receiptNo }}</el-descriptions-item>
        <el-descriptions-item :label="$t('客户')">{{ form.customerName }}</el-descriptions-item>
        <el-descriptions-item :label="$t('创建时间')">
          <template >
            <span>{{ parseTime(form.createTime, '{y}-{m}-{d}') }}</span>
          </template></el-descriptions-item>
        <el-descriptions-item :label="$t('业务员')">{{ form.salesmanName }}</el-descriptions-item>
        <el-descriptions-item v-if="reason" :label="$t('申请理由')">{{reason}}</el-descriptions-item>
      </el-descriptions>
    <div class="btn">
      <el-table ref="multipleTable" :data="detailed" border row-key="id">
              <!-- <el-table-column :label="$t('序号')" type="index" align="center" width="50"></el-table-column> -->
              <el-table-column :label="$t('收款账户')" align="center" prop="accountName" />
              <el-table-column :label="$t('实收金额')" align="center" prop="amount" />
              <el-table-column :label="$t('实收币种')" align="center" prop="marks">
                <template slot-scope="scope">
                  {{getCurrencyLabel(scope.row.currencyId)}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('汇率')" align="center" prop="rate" />
              <el-table-column align="center" prop="writeOffAmount" >
                <template #header>
                  {{ $t('兑核销基准金额') }}{{getCurrencyLabel(showCurrencyId)}}
                </template>
              </el-table-column>
              <el-table-column :label="$t('实收日期')" align="center" prop="amountDate">
              </el-table-column>
              <el-table-column :label="$t('水单号')" align="center" prop="billNo" />
              <el-table-column :label="$t('水单附件')" align="center" prop="attr">
                <template slot-scope="scope" v-if="scope.row.attr">
                  <div v-for="(v, i) in scope.row.attr" :key="i"><el-link :href="v.url" type="primary" target="_blank">{{ v.name }}</el-link></div>
                </template>
              </el-table-column>
            </el-table>
    </div>
    <div class="btn">
      <el-button
        size="mini"
        type="primary"
        @click="$router.push('/financial/receiptDetail?id=' + receiptId)"
        >{{ $t('查看收款单')}}</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="openAddDialog=true"
          >{{ $t('查看银行实收明细')}}</el-button>
    </div>
    <el-dialog v-if="openAddDialog" :visible.sync="openAddDialog" :title="this.$t('银行实收明细详情')" width="50%" append-to-body>
          <div style="padding: 0 24px">
            <el-form ref="addForm" :model="addForm" label-width="250px">
              <el-form-item :label="$t('收款单号')+':'">{{ form.receiptNo }}</el-form-item>
              <el-form-item :label="$t('剩余应收金额')+':'">
                <template >
                  <div v-if="surplusData.length==0">0</div>
                  <div v-else>
                    <div v-for="(amount, currency) in surplusData" :key="currency">
                       <span v-if="amount"> {{amount}}{{getCurrencyLabel(currency)}}</span>
                    </div>
                  </div>
                </template>

              </el-form-item>
              <el-form-item :label="$t('收款账户')+':'" prop="accountNo">
                <span>{{ addForm.accountNo }}</span>
              </el-form-item>
              <el-form-item :label="$t('实收日期')+':'" prop="amountDate">
                <span>{{ addForm.amountDate }}</span>
              </el-form-item>
              <div style="display: flex;">
                <el-form-item :label="$t('实收')+':'" prop="amount"><span>{{ addForm.amount }}</span></el-form-item>
                <el-form-item
                  label-width="0px"
                  prop="currencyId"
                >
                <el-select
                  v-model="addForm.currencyId"
                  :placeholder="$t('请选择')"
                  :disabled="true"
                  @change="val => currencyIdChange(val)"
                >
                  <el-option
                    v-for="item in currencyList"
                    :key="item.id"
                    :label="$i18n.locale=='zh_CN'?item.titleZh:item.titleEn"
                    :value="item.id"
                  />
                </el-select>
                  <!-- <dict-selector v-if="!isView" :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" v-model="addForm.currencyId" @change="val => currencyIdChange(val)"/> -->
                  <!-- <span v-else>{{ addForm.currencyId }}</span> -->
                  <!-- <dict-tag v-else :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="addForm.currencyId" /> -->
                </el-form-item>
              </div>
              <el-form-item
                v-if="showCurrencyId != addForm.currencyId"
                prop="rate"
              >
                <template slot="label">
                <span :title="$t('实收币种与核销基准币种一样时,无需填写汇率,不一样需要填写汇率')">{{ $t('兑核销基准币种汇率') }}{{getCurrencyLabel(showCurrencyId)}}</span>
                </template>
                <span>{{ addForm.rate}}</span>
              </el-form-item>
              <el-form-item
                v-if="showCurrencyId != addForm.currencyId"
              >
                <template slot="label">
                  {{ $t('兑核销基准币种金额') }}{{getCurrencyLabel(showCurrencyId)}}:
                </template>
                <span>{{ addForm.writeOffAmount?parseFloat(addForm.writeOffAmount).toFixed(6):'' }}</span>
              </el-form-item>
              <el-form-item
                :label="$t('水单附件')+':'"
                prop="attr"
              >
                <div v-if="addForm.attr.length>0">
                  <div v-for="(v, i) in addForm.attr" :key="i"><el-link :href="v.url" type="primary" target="_blank">{{ v.name }}</el-link></div>
                </div>
                <div v-else>{{$t('')}}</div>
              </el-form-item>
              <el-form-item :label="$t('水单号')+':'" prop="billNo">
                <span>{{ addForm.billNo }}</span>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
  </div>
</template>

<script>

import { getCustomer } from '@/api/ecw/customer'
import {
  getReceiptInfoByIds,
  getReceivableItem,
  getInvoicingItem,
  getReceiptAccountList,
  getReceiptApprove
} from "@/api/ecw/financial";
import { getCurrencyPage } from "@/api/ecw/currency";
import NP from 'number-precision'


export default {
  props:{
      id: [String, Number],
  },
  data() {
    return {
      form: {},
      currencyList:[],
      list:[],
      detailed: [],
      detatilData:[],
      showCurrencyId:0,
      surplusData:[],
      openAddDialog:false,
      collectionAmount: [],
      addForm:{},
      receiptId:0,
      receiptItemId:0,
      reason:'',
      receiptAccountList:[]
    }
  },
  watch:{
      id(){
          this.getCurrencyData()
      },
      currencyList(){
        this.getData()
      },
      form(){
        this.getList()
        this.getListData()
      },
  },
  created() {
      if(this.id){
        this.getCurrencyData()
      }
  },
  methods: {
    getData(){
      getReceiptApprove(this.id).then(res => {
          if(res.data.receiptId){
            this.receiptId = res.data.receiptId
            this.receiptItemId = res.data.receiptItemId
            this.reason = res.data.reason
             this.getReceiptInfo()
          }
      })

    },
    // 获取汇率
   getCurrencyData(){
     getCurrencyPage(this.params).then(res => {this.currencyList = res.data.list})
   },
   getList() {
     getReceivableItem({ id: this.receiptId }).then(res => {
       this.detatilData = res.data.map(v => ({
         ...v,
         amountDate: this.parseTime(v.amountDate, '{y}-{m}-{d}'),
         accountNo: +v.accountNo,
         rate:parseFloat(v.rate).toFixed(6),
         attr: v.attr ? v.attr.split(',').map(t => ({ name: t.slice(t.lastIndexOf('/') + 1), url: t })) : []
       }))
       this.addForm = this.detatilData.find(v=>v.id==this.receiptItemId)
       this.detailed = []
       this.detailed.push(this.addForm)
       this.getCollectionData()
     })
     
   },
   getReceiptInfo(){
       getReceiptInfoByIds({ id: this.receiptId }).then(res => {
        this.form = res.data
        getCustomer(this.form.customerId).then(res => {
          this.form.customerName = res?.data?.name
        })
      })
    },
    getCurrencyLabel(id){
      var label = this.currencyList.filter(item=>item.id == id)
      if(label.length>0) return this.$i18n.locale=='zh_CN'?label[0].titleZh:label[0].titleEn
      return ''
    },
    getListData(){
      getInvoicingItem({ id: this.receiptId }).then(res => {

        this.list = [...res.data]
        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
          })
        }
        this.showCurrencyId = 1
        if (groupList.length === 1) this.showCurrencyId = groupList[0].currencyId
      })
    },
    getCollectionData(){
      getReceiptAccountList({ id: this.receiptId }).then(res => {
        var n
        // 收款总计
        var amountList =[]
        this.currencyList.forEach((item,index)=>{
          var nairaListByList = this.list.filter(v => v.currencyId === item.id)
          if(nairaListByList.length>0){
            var discountNaira = nairaListByList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
            n = res.data.find(v => v.currencyId == item.id)
            n && (n.discountTotal = discountNaira)
          }
          var dollarList = res.data.filter(v => v.collectionCurrencyId == item.id)

          if(dollarList.length>0){
            var dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount), 0).toFixed(2)
             amountList.push({currencyId:item.id,currencyNameEn:item.titleEn,currencyNameZh:item.titleZh,amount:dollar})
          }

        })
        this.$set(this,'collectionAmount',amountList)
        this.handleAddReceiptItem()
      })
      },
    handleAddReceiptItem() {
      // 已收
      let recepted = []
      this.detatilData.forEach(item => {
          if(!recepted[item.currencyId]){
            recepted[item.currencyId] = item.amount
          }else recepted[item.currencyId] = NP.plus(recepted[item.currencyId], item.amount)
      })
      // 应收
      let collom = []
      // 从期望收费金额中提取应收币种和金额
         this.collectionAmount.forEach(item => {
           collom[item.currencyId] = item.amount
         })
      console.log(recepted)
        recepted.forEach((amount,currency)=>{
          if(amount){
            if(collom[currency]){
              if((collom[currency]-amount)!=0) this.surplusData[currency] = +parseFloat((collom[currency]-amount).toPrecision(12))
            }else{
              this.surplusData[currency] = -amount
            }
          }

        })
         console.log(collom)
        collom.forEach((amount,currency)=>{
          if(amount){
            if(!this.surplusData[currency]){
              if(recepted[currency]){
               if((amount-recepted[currency])!=0)  this.surplusData[currency] = +parseFloat((amount-recepted[currency]).toPrecision(12))
              }else{
              this.surplusData[currency] = amount
            }
            }
          }
        })
        console.log(this.surplusData)
    },
  }
}
</script>

<style scoped lang="scss">
  .btn{
    margin-top: 20px;
  }
  .app-container {
    ::v-deep .el-descriptions-item__label {
      font-size:16px;
      font-weight:600;
    }
    ::v-deep .el-descriptions-item__content {
      font-size:16px;
      font-weight:600;
    }
  }
</style>