printVoucher.vue 17.1 KB
Newer Older
我在何方's avatar
我在何方 committed
1 2
<template>
  <div class="app-container" >
我在何方's avatar
我在何方 committed
3
      <div id="print" style="font-size: 18px;">
我在何方's avatar
我在何方 committed
4

我在何方's avatar
我在何方 committed
5 6 7 8 9
        <div style="position:relative;text-align: center;font-weight: bold;font-size: 26px;padding: 22px 0;border-top: 1px solid #666;border-left:1px solid #666;border-right: 1px solid #666;">
          <div style="position:absolute;left:4px;top:4px">{{$t('广州市捷道国际货运代理有限公司')}}
          </div>
          <span>{{$t('收款单')}}</span>
        </div>
10 11
          <table border="1" style="width: 100%;text-align: center;border-collapse: collapse; ">
            <tr>
12 13 14
              <td style="font-weight: bold;width:12.5%">{{$t('部门')}}</td>
              <td style="width:12.5%">{{form?form.departmentName:$t('')}}</td>
              <td style="font-weight: bold;width:12.5%">{{$t('客户名称')}}</td>
15
              <td colspan="2" style="width: 25%;">{{form.customerName||$t('')}}</td>
16
              <td style="font-weight: bold;width:12.5%">{{$t('收款日期')}}</td>
我在何方's avatar
我在何方 committed
17
              <td colspan="2" style="width: 25%;">{{form&&form.payedAt?parseTime(form.payedAt):$t('')}}</td>
18 19
            </tr>
            <tr>
20 21 22 23
              <td style="font-weight: bold;width:12.5%">{{$t('收款单号')}}</td>
              <td style="width:12.5%">{{form?form.receiptNo:$t('')}}</td>
              <td style="font-weight: bold;width:12.5%">{{$t('备注')}}</td>
              <td colspan="4" style="width: 50%;">{{form?form.remark:$t('')}}</td>
24 25 26 27 28 29
            </tr>
            <tr>
              <td colspan="8">Form/To:{{orderData.logisticsInfoDto?orderData.logisticsInfoDto.startTitleZh:''}}>{{orderData.logisticsInfoDto?orderData.logisticsInfoDto.destAddressZh:''}}</td>
            </tr>
            </table>
      <table border="1" style="width: 100%;text-align: center;border-collapse: collapse; border-top: 0;">
我在何方's avatar
我在何方 committed
30
          <tr>
31 32 33
            <th style="width: 12.5%;">{{$t('序号')}}</th>
            <th style="width: 12.5%;">{{$t('提单号')}}</th>
            <th style="width: 12.5%;">{{$t('订单号')}}</th>
我在何方's avatar
我在何方 committed
34
            <!-- <th style="width: 12.5%;">{{$t('品名')}}</th> -->
35 36
            <th style="width: 12.5%;">{{$t('收入类型')}}</th>
            <th style="width: 12.5%;">{{$t('币种')}}</th>
我在何方's avatar
我在何方 committed
37
            <th style="width: 12.5%;">{{$t('金额')}}</th>
38
            <th style="width: 12.5%;">{{$t('优惠金额')}}</th>
我在何方's avatar
我在何方 committed
39
          </tr>
我在何方's avatar
我在何方 committed
40
          <tr v-for="(item, index) in list" :key="item.id">
41
            <td>{{ index + 1 }}</td>
我在何方's avatar
我在何方 committed
42
            <td>{{ orderData.tidanNo||''}}</td>
43
            <td>{{ item.orderNo }}</td>
我在何方's avatar
我在何方 committed
44 45
            <!-- <td>{{ $i18n.locale=='zh_CN'?item.titleZh:item.titleEn }}</td> -->
            <td><dict-tag :value="item.feeType" :type="DICT_TYPE.RECEIPT_FEE_TYPE"></dict-tag></td>
我在何方's avatar
我在何方 committed
46
            <td>{{getCurrencyLabel(item.currencyId)}}</td>
我在何方's avatar
我在何方 committed
47
            <td> {{item.totalAmount}}</td>
48
            <td>{{ item.discountTotal||0 }}</td>
我在何方's avatar
我在何方 committed
49
          </tr>
50
          <tr v-for="(items, indexs) in receiptAccountList" :key="indexs">
我在何方's avatar
我在何方 committed
51
            <td>{{getCurrencyLabel(items.currencyId)}}{{$t('应收合计')}}</td>
52
            <td ><span v-if="items.discountTotal>0">{{ `${items.receivableAmount - items.discountTotal }(${items.receivableAmount} - ${items.discountTotal})` }}</span>
我在何方's avatar
我在何方 committed
53
            <span v-else>{{ `${items.receivableAmount}` }}</span>
54
            </td>
55
            <td>{{$t('汇率')}}</td>
56
            <td>{{ items.collectionRate}}</td>
我在何方's avatar
我在何方 committed
57
            <td>{{$t('收款金额')}}({{getCurrencyLabel(items.collectionCurrencyId)}})</td>
58
            <td colspan="3">{{ items.collectionAmount}}</td>
我在何方's avatar
我在何方 committed
59 60
          </tr>
        </table>
我在何方's avatar
我在何方 committed
61
        <div style="text-align: center;border-left:1px solid #666;border-right: 1px solid #666;height: 36px;line-height: 36px;">
62
           {{$t('银行信息')}}
我在何方's avatar
我在何方 committed
63
        </div>
我在何方's avatar
我在何方 committed
64
        <div style="display: flex;align-items: center;border-top: 1px solid #666;border-left:1px solid #666;border-right: 1px solid #666;" v-for="(bankTiem,index) in detailed" :key="index">
65
          <div style="padding:6px 0;width: 12.5%;text-align: center;border-right: 1px solid #666;" >
66 67
            <p style="margin: 0;word-break: break-all;">{{$t('户名')}}{{bankTiem.accountName}}</p>
            <p style="margin: 0;word-break: break-all;">{{$t('银行名称')}}{{bankTiem.accountBankName||''}}</p>
我在何方's avatar
我在何方 committed
68
            <p style="margin: 0;word-break: break-all;">A/C NO{{bankTiem.accountNo}}</p>
我在何方's avatar
我在何方 committed
69 70
          </div>
          <div style="padding:6px 0;width: 87.5%;text-align: center;">
我在何方's avatar
我在何方 committed
71
            <p style="margin: 0;">{{$t('实收')}}{{getCurrencyLabel(bankTiem.currencyId)}}{{bankTiem.amount}}{{getCurrencyFuhao(bankTiem.currencyId)}}</p>
72
            <!-- <p style="margin: 0;">未收:¥{{bankTiem.noReceipt}}</p> -->
我在何方's avatar
我在何方 committed
73 74 75
          </div>
        </div>
        <div style="display: flex;align-items: center;border: 1px solid #666;">
76
          <div style="font-weight: bold;width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;">{{$t('主管')}}</div>
我在何方's avatar
我在何方 committed
77
          <div style="width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;"></div>
78
          <div style="font-weight: bold;width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;">{{$t('会计')}}</div>
我在何方's avatar
我在何方 committed
79
          <div style="width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;"></div>
80
          <div style="font-weight: bold;width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;">{{$t('出纳')}}</div>
我在何方's avatar
我在何方 committed
81
          <div style="width: 12.5%;text-align: center;height: 36px;line-height: 36px;border-right: 1px solid #666;"></div>
82
          <div style="font-weight: bold;width: 12.5%;text-align: center;border-right: 1px solid #666;height: 36px;line-height: 36px;">{{$t('经手人')}}</div>
我在何方's avatar
我在何方 committed
83 84
          <div style="width: 12.5%;text-align: center;height: 36px;line-height: 36px;"></div>
        </div>
我在何方's avatar
我在何方 committed
85 86
      </div>
      <div slot="footer" class="card">
87
        <el-button type="primary" @click="print">{{ $t('确定打印') }}</el-button>
我在何方's avatar
我在何方 committed
88 89 90 91 92
      </div>
  </div>
</template>

<script>
93
  import { listSimpleUsers } from "@/api/system/user"
我在何方's avatar
我在何方 committed
94 95 96 97 98 99
  import {DICT_TYPE} from  '@/utils/dict'
  import CustomerSelector from '@/components/CustomerSelector'
  import { getBankAccountPage } from "@/api/ecw/bankAccount";
  import { listSimpleDepts } from "@/api/system/dept"
  import { getReceipt} from "@/api/ecw/receipt";
  import lodop from '@/utils/lodop'
100 101
  import NP from 'number-precision'
  import {getOrder} from '@/api/ecw/order'
我在何方's avatar
我在何方 committed
102
  import { getCurrencyPage } from "@/api/ecw/currency";
103
  import { getReceiptInfoByIds, getInvoicingItem,getReceiptAccountList,getReceivableItem} from "@/api/ecw/financial";
我在何方's avatar
我在何方 committed
104 105 106 107 108 109 110 111 112 113

  export default {
    name: "PrintVoucher",
  components: {
     CustomerSelector
  },
    data() {
      return {
        loadings: false,
        form:{},
我在何方's avatar
我在何方 committed
114
        title:this.$t('收款单'),
我在何方's avatar
我在何方 committed
115
         // creatorData:[],
我在何方's avatar
我在何方 committed
116 117 118 119 120 121 122
         list:[],
         fileList:[],
         bankData:[],
         params:{
           page:1,
           rows:20,
         },
123
         receiptAccountList:[],
我在何方's avatar
我在何方 committed
124 125
         deptData:[],
         deptArr:[],
126
         id:0,
我在何方's avatar
我在何方 committed
127
         orderData:{},
128
         detailed:[],
我在何方's avatar
我在何方 committed
129 130
         date:'',
		 currencyList:[]
我在何方's avatar
我在何方 committed
131 132
      }
    },
133
    async created() {
我在何方's avatar
我在何方 committed
134
      let that = this
我在何方's avatar
我在何方 committed
135 136
      // listSimpleUsers().then(res =>that.creatorData = res.data)
      // getBankAccountPage(that.params).then(res =>that.bankData = res.data.list)
我在何方's avatar
我在何方 committed
137
	  await getCurrencyPage(this.params).then(res => this.currencyList = res.data.list)
138
      await listSimpleDepts().then(res =>{
我在何方's avatar
我在何方 committed
139 140 141 142 143 144
        res.data.forEach((item)=>{
          if(item.parentId==0){

            that.deptArr.push(item)

          }
145 146
          that.deptData.push(item)
          
我在何方's avatar
我在何方 committed
147 148 149 150 151 152 153 154 155 156
        })

        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
           }

        })
      })
157 158 159
      if(that.$route.query.id){
        that.id = that.$route.query.id
        that.getCollectionData()
160
        that.getList()
161 162
        getInvoicingItem({id: this.id}).then(res => {
          this.list = res.data
163
          if(this.list.length>0) this.getOrder(this.list[0].orderId)
164 165
        })
      }
166
     getReceiptAccountList({ id: this.id }).then(res => {
167 168 169 170 171 172 173 174
        // 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),
        //     collectionAmount: [0, 0, 0]
        //   }]
        // }
175
        // 收款总计
176 177
        // const dollarList = res.data.filter(v => v.collectionCurrencyId == 1)
        // const dollar = dollarList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount || 0), 0)
178

179 180
        // const rmbList = res.data.filter(v => v.collectionCurrencyId == 2)
        // const rmb = rmbList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount || 0), 0)
181

182 183
        // const nairaList = res.data.filter(v => v.collectionCurrencyId == 3)
        // const naira = nairaList.reduce((total, currentValue) => NP.plus(total, currentValue.collectionAmount || 0), 0)
184

185
        // res.data[res.data.length -1].collectionAmount = [dollar, rmb, naira]
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        // this.$set(this.form, 'receiptAccountList', [...this.form.receiptAccountList])

        const dollarListByList = this.list.filter(v => v.currencyId === 1)
        const discountDollar = dollarListByList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
        const d = res.data.find(v => v.currencyId == 1)
        d && (d.discountTotal = discountDollar)

        const rmbListByList = this.list.filter(v => v.currencyId === 2)
        const discountRmb = rmbListByList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
        const r = res.data.find(v => v.currencyId == 2)
        r && (r.discountTotal = discountRmb)

        const nairaListByList = this.list.filter(v => v.currencyId === 3)
        const discountNaira = nairaListByList.reduce((total, currentValue) => NP.plus(total, currentValue.discountTotal || 0), 0)
        const n = res.data.find(v => v.currencyId == 3)
        n && (n.discountTotal = discountNaira)

203 204
        console.log(res.data)
        this.$set(this, 'receiptAccountList', [...res.data])
205 206 207 208 209 210 211
        this.$nextTick(() => {
          // this.form.receiptAccountList.forEach((item, index) => {
          //   this.rateChange(item, index)
          // });
        })
      })

我在何方's avatar
我在何方 committed
212 213
    },
    methods: {
我在何方's avatar
我在何方 committed
214 215
		getCurrencyLabel(id){
		  var label = this.currencyList.filter(item=>item.id == id)
我在何方's avatar
我在何方 committed
216
		  if(label.length>0) return this.$i18n.locale=='zh_CN'?label[0].titleZh:label[0].titleEn
我在何方's avatar
我在何方 committed
217 218
		  return ''
		},
我在何方's avatar
我在何方 committed
219 220 221 222 223
    getCurrencyFuhao(id){
      var label = this.currencyList.filter(item=>item.id == id)
      if(label.length>0) return label[0].fuhao
      return ''
    },
224 225
      getList() {
        getReceivableItem({ id: this.id }).then(res => {
我在何方's avatar
我在何方 committed
226
          this.detailed = res.data
227 228 229 230 231 232
          this.detailed.forEach(item=>{
            if(!this.date){
              this.date = item.amountDate
            }else if(this.date<item.amountDate){
              this.date = item.amountDate
            }
我在何方's avatar
我在何方 committed
233
          })
234
        })
235
      },
我在何方's avatar
我在何方 committed
236 237
      getCollectionData(){
        let that = this
238
        getReceiptInfoByIds({id:that.id}).then(res =>{
我在何方's avatar
我在何方 committed
239
          that.form = res.data
240
          that.form.departmentName = that.deptData.find(v => v.id == that.form.departmentId).name
我在何方's avatar
我在何方 committed
241 242
        })
      },
我在何方's avatar
我在何方 committed
243 244 245 246 247 248 249 250 251 252
      getRecep(id){
        var total = 0
        if(id){
          var data = this.detailed.filter(item=>item.currencyId==id)
            data.forEach(item => {
            total = NP.plus(total, item.writeOffAmount)
          })
        }
        return total
      },
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
      handleAddReceiptItem() {
        let recepted = []
        this.detailed.forEach(item => {
            if(!recepted[item.currencyId]){
              recepted[item.currencyId] = item.amount
            }else recepted[item.currencyId] = NP.plus(recepted[item.currencyId], item.amount)
        })
        console.log('rece',recepted)
        let collom = []
        this.receiptAccountList.forEach(item => {
              if(recepted[item.currencyId]){
                item.noReceipt = +parseFloat(item.receivableAmount-recepted[item.currencyId])
              }
        })
      },
268 269 270 271
      getOrder(orderId){
        getOrder(orderId).then(response => {
          this.orderData = response.data
        });
我在何方's avatar
我在何方 committed
272
      },
我在何方's avatar
我在何方 committed
273 274
      print(){
          lodop().then(LODOP => {
我在何方's avatar
我在何方 committed
275
              LODOP.PRINT_INIT();
我在何方's avatar
我在何方 committed
276 277 278
              LODOP.SET_PRINT_STYLE("FontSize",18);
              LODOP.SET_PRINT_STYLE("Bold",1);
              // LODOP.ADD_PRINT_TEXT(50,231,260,39,"打印页面部分内容");
我在何方's avatar
我在何方 committed
279 280 281
              // var stylePrint = "<style>table th,td{padding:0;margin:0;border:1px solid #000000;border-collapse:collapse;}</style>"
              var htmlContent = "<body>"+document.getElementById("print").innerHTML+"</body>"
              LODOP.ADD_PRINT_HTM("6mm", "6mm", "RightMargin:6mm", "BottomMargin:6mm", htmlContent);
我在何方's avatar
我在何方 committed
282 283 284 285 286 287 288 289
              LODOP.PRINT();
              // this.$alert('已发起打印任务');
              // LODOP.PREVIEW(); // 预览
              /* LODOP.PRINTA(); // 选择打印机
               // 直接打印 */
              console.log('打印哦')
          }).catch(err => {
              console.error('lodop异常', err)
吴滔's avatar
吴滔 committed
290
              alert(this.$t('请检查LODOP打印控件是否安装并启动'));
我在何方's avatar
我在何方 committed
291
          })
292 293 294 295 296 297 298 299 300
      },
      totalMoney() {
        const t = this.list.map(v => v.actualAmount).reduce((prev, curr) => {
          return prev + curr;
        }, 0)
        return t
      },
      convertCurrency(money) {
        //汉字的数字
Marcus's avatar
Marcus committed
301
        var cnNums = new Array('', this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), '');
302
        //基本单位
Marcus's avatar
Marcus committed
303
        var cnIntRadice = new Array('', this.$t(''), this.$t(''), '');
304
        //对应整数部分扩展单位
Marcus's avatar
Marcus committed
305
        var cnIntUnits = new Array('', this.$t(''), this.$t('亿'), '');
306
        //对应小数部分单位
Marcus's avatar
Marcus committed
307
        var cnDecUnits = new Array('', this.$t(''), this.$t(''), '');
308
        //整数金额时后面跟的字符
Marcus's avatar
Marcus committed
309
        var cnInteger = this.$t('');
310
        //整型完以后的单位
Marcus's avatar
Marcus committed
311
        var cnIntLast = this.$t('');
312 313 314 315 316 317 318 319 320 321
        //最大处理的数字
        var maxNum = 999999999999999.9999;
        //金额整数部分
        var integerNum;
        //金额小数部分
        var decimalNum;
        //输出的中文金额字符串
        var chineseStr = '';
        //分离金额后用的数组,预定义
        var parts;
我在何方's avatar
我在何方 committed
322
        // 传入的参数为空情况
323 324 325 326 327 328 329
        if(money === '') {
          return '';
        }
        money = parseFloat(money)
        if(money >= maxNum){
          return ''
        }
我在何方's avatar
我在何方 committed
330
        // 传入的参数为0情况
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        if (money === 0) {
          chineseStr = cnNums[0] + cnIntLast + cnInteger;
          return chineseStr
        }
        // 转为字符串
        money = money.toString();
        // indexOf 检测某字符在字符串中首次出现的位置 返回索引值(从0 开始) -1 代表无
        if (money.indexOf('.') == -1) {
          integerNum = money;
          decimalNum = ''
        }else{
          parts = money.split('.');
          integerNum = parts[0];
          decimalNum = parts[1].substr(0,4);
        }
        //转换整数部分
        if(parseInt(integerNum,10) > 0){
          let zeroCount  = 0;
          let IntLen = integerNum.length
          for(let i = 0; i < IntLen; i++){
            let n = integerNum.substr(i,1);
            let p = IntLen - i - 1;
            let q = p / 4;
            let m = p % 4;
            if( n == '0'){
              zeroCount ++ ;
            }else{
              if(zeroCount > 0){
                  chineseStr += cnNums[0]
              }
              zeroCount = 0;
              chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
            }
            if(m == 0 && zeroCount < 4){
我在何方's avatar
我在何方 committed
365
              chineseStr += cnIntUnits[q];
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
            }
          }
          // 最后+ 元
          chineseStr += cnIntLast;
        }
        // 转换小数部分
        if(decimalNum != ''){
          let decLen = decimalNum.length;
          for(let i = 0; i <decLen; i++){
            let n = decimalNum.substr(i,1);
            if(n != '0'){
              chineseStr += cnNums[Number(n)] + cnDecUnits[i]
            }
          }
        }
        if(chineseStr == ''){
我在何方's avatar
我在何方 committed
382
          chineseStr = cnNums[0] + cnIntLast + cnInteger
383 384 385 386 387
        }else if(decimalNum == ''){
          chineseStr += cnInteger;
        }
        return chineseStr
      },
我在何方's avatar
我在何方 committed
388 389 390 391 392
    },

  }
</script>

我在何方's avatar
我在何方 committed
393
<style scoped id="printStyle">
我在何方's avatar
我在何方 committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
  .card{
    margin-top: 20px;
  }
  .dialog-footer{
    padding: 40px;
  }
  .card-title{
      font-size: 18px;
      font-weight: bold;
      text-align: center;
  }
  .header{
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .lastRow{
    border-top:1px solid #dfe6ec;
    display: flex;
    width: 100%;
    height: 44px;
    text-align: center;
    align-items: center;
  }
  .lastRow div{
    height: 44px;
    line-height: 44px;
    border-right:1px solid #dfe6ec;
  }
</style>