printPaymentVoucher.vue 12.5 KB
Newer Older
吴滔's avatar
吴滔 committed
1 2 3
<template>
  <div class="app-container" >
      <div id="print" style="font-size: 18px;">
吴滔's avatar
吴滔 committed
4
        <div style="text-align: center;font-weight: bold;font-size: 20px;">{{ $t('付款单') }}</div>
吴滔's avatar
吴滔 committed
5 6
        <div style="margin-top: 20px;">
          <div style="display: flex;width: 80%;align-items: center;margin-bottom: 10px;">
吴滔's avatar
吴滔 committed
7 8
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('付款单号') }}</div><span>{{ form.paymentNo || '-' }}</span></div>
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('最后付款日') }}</div> <span>{{ form.latestPayAt || '-' }}</span></div>
吴滔's avatar
吴滔 committed
9 10
          </div>
          <div style="display: flex;width: 80%;align-items: center;margin-bottom: 10px;">
吴滔's avatar
吴滔 committed
11
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('申请日期') }}</div> <span>{{ form.applicationAt || '-' }}</span></div>
我在何方's avatar
我在何方 committed
12 13 14 15
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('结算方式') }}</div><span>             <dict-tag
                :type="DICT_TYPE.CUSTOMER_BALANCE"
                v-model="form.settlementType"
              /></span></div>
吴滔's avatar
吴滔 committed
16 17
          </div>
          <div style="display: flex;width: 80%;align-items: center;margin-bottom: 10px;">
吴滔's avatar
吴滔 committed
18
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('付款公司') }}</div><span>{{ form.supplierName || '-' }}</span></div>
我在何方's avatar
我在何方 committed
19
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('银行户名') }}</div><span>{{ form.supplierBankAccountName || '-' }}</span></div>
吴滔's avatar
吴滔 committed
20 21
          </div>
          <div style="display: flex;width: 80%;align-items: center;margin-bottom: 10px;">
我在何方's avatar
我在何方 committed
22 23
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('银行名称') }}</div><span>{{ form.supplierBank|| '-' }}</span></div>
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('银行账号') }}</div><span>{{ form.supplierBankAccount || '-' }}</span></div>
吴滔's avatar
吴滔 committed
24 25
          </div>
          <!-- <div style="display: flex;width: 80%;align-items: center;margin-bottom: 10px;">
Marcus's avatar
Marcus committed
26 27
            <div style="flex:1"><div style="width: 120px;text-align: right;">{{ $t('水单号:') }}</div><span>{{form?form.accountBank:''}}</span></div>
            <div style="flex:1"><div style="width: 120px;text-align: right;">{{ $t('手续费:') }}</div><span>{{form?form.accountBank:''}}</span></div>
吴滔's avatar
吴滔 committed
28 29
          </div> -->
          <div style="display: flex;width: 80%;align-items: center;">
吴滔's avatar
吴滔 committed
30
            <div style="flex:1"><div style="width: 120px;text-align: right;display:inline-block;">{{ $t('备注') }}</div><span>{{ form.notes || '-' }}</span></div>
吴滔's avatar
吴滔 committed
31 32 33 34
          </div>
      </div>
      <table border="1" style="margin-top: 20px;width: 100%;text-align: center;border-collapse: collapse;line-height: 2 ">
          <tr>
吴滔's avatar
吴滔 committed
35
            <th style="width: 6%;">{{ $t('序号') }}</th>
我在何方's avatar
我在何方 committed
36
            <th style="width: 11%;">{{ $t('自编号') }}</th>
吴滔's avatar
吴滔 committed
37
            <th style="width: 15%;">{{ $t('费用类型') }}</th>
我在何方's avatar
我在何方 committed
38
            <th style="width: 10%;">{{ $t('币种') }}</th>
吴滔's avatar
吴滔 committed
39
            <th style="width: 10%;">{{ $t('汇率') }}</th>
我在何方's avatar
我在何方 committed
40
             <th style="width:10%;">{{ $t('税率') }}</th>
吴滔's avatar
吴滔 committed
41
            <th style="width: 15%;">{{ $t('发票号') }}</th>
我在何方's avatar
我在何方 committed
42 43
            <th style="width: 10%;">{{ $t('应付金额') }}</th>
            <th style="width: 10%;">{{ $t('申请金额') }}</th>
吴滔's avatar
吴滔 committed
44 45 46 47 48 49 50 51 52 53
          </tr>
          <tr v-for="(item, index) in list" :key="index">
            <td>{{ index + 1 }}</td>
            <td>{{ item.payableNo }}</td>
            <td>
              <dict-tag
                :type="DICT_TYPE.FEE_TYPE"
                :value="item.feeType"
              ></dict-tag>
            </td>
我在何方's avatar
我在何方 committed
54 55
            <td>{{getCurrencyLabel(item.currencyId)}}
              <!-- <dict-tag :type="DICT_TYPE.BOX_SHIPPING_PRICE_UNIT" :value="item.currencyId" /> -->
吴滔's avatar
吴滔 committed
56 57
            </td>
            <td>{{ item.exchangeRate }}</td>
我在何方's avatar
我在何方 committed
58
            <td>{{ item.taxRate }}</td>
吴滔's avatar
吴滔 committed
59 60 61 62 63
            <td>{{ item.invoiceNumber }}</td>
            <td>{{ item.totalAmount }}</td>
            <td>{{ item.total }}</td>
          </tr>
          <tr>
吴滔's avatar
吴滔 committed
64
            <td colspan="2">{{ $t('合计(大写)') }}</td>
吴滔's avatar
吴滔 committed
65
            <td colspan="2">{{ convertCurrency(totalMoney()) }}</td>
吴滔's avatar
吴滔 committed
66
            <td colspan="2">{{ $t('合计付款') }}</td>
吴滔's avatar
吴滔 committed
67 68 69 70 71
            <td>{{ totalMoney() }}</td>
          </tr>
        </table>
        <div style="margin-top: 20px;">
          <div style="display: flex;width: 100%;align-items: center;">
吴滔's avatar
吴滔 committed
72 73 74 75
            <div style="flex:1"><span style="width: 120px;">{{ $t('主管') }}</span></div>
            <div style="flex:1"><span style="width: 120px;">{{ $t('会计') }}</span></div>
            <div style="flex:1"><span style="width: 120px;">{{ $t('出纳') }}</span></div>
            <div style="flex:1"><span style="width: 120px;">{{ $t('经手人') }}</span></div>
吴滔's avatar
吴滔 committed
76 77 78 79
          </div>
        </div>
      </div>
      <div slot="footer" class="card">
80
        <el-button type="primary" @click="print">{{ $t('确定打印') }}</el-button>
吴滔's avatar
吴滔 committed
81 82 83 84 85 86 87 88 89 90 91 92
      </div>
  </div>
</template>

<script>
  import { userList } from "@/api/system/user"
  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 { getPaymentInfoByIds, getPaymentItem } from "@/api/ecw/financial"
我在何方's avatar
我在何方 committed
93
  import { getCurrencyPage } from "@/api/ecw/currency";
吴滔's avatar
吴滔 committed
94 95 96 97 98 99 100 101 102 103 104
  import lodop from '@/utils/lodop'

  export default {
    name: "PrintVoucher",
  components: {
     CustomerSelector
  },
    data() {
      return {
        loadings: false,
        form:{},
我在何方's avatar
我在何方 committed
105
        title:this.$t('收款单'),
吴滔's avatar
吴滔 committed
106 107 108 109 110 111 112 113 114 115
         creatorData:[],
         list:[],
         fileList:[],
         bankData:[],
         params:{
           page:1,
           rows:20,
         },
        //  deptData:[],
        //  deptArr:[],
我在何方's avatar
我在何方 committed
116 117
         id:0,
		  currencyList:[]
吴滔's avatar
吴滔 committed
118 119 120 121 122 123 124 125
      }
    },
    created() {
      let that = this
      if(that.$route.query.id){
        that.id = that.$route.query.id
        that.getCollectionData()
      }
我在何方's avatar
我在何方 committed
126
	  getCurrencyPage(this.params).then(res => this.currencyList = res.data.list)
吴滔's avatar
吴滔 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
      userList('salesman').then(res =>that.creatorData = 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
      //      }

      //   })
      // })
    },
    methods: {
我在何方's avatar
我在何方 committed
150 151
		getCurrencyLabel(id){
		  var label = this.currencyList.filter(item=>item.id == id)
我在何方's avatar
我在何方 committed
152
		  if(label.length>0) return this.$i18n.locale=='zh_CN'?label[0].titleZh:label[0].titleEn
我在何方's avatar
我在何方 committed
153 154
		  return ''
		},
吴滔's avatar
吴滔 committed
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
      getCollectionData(){
        let that = this
        getPaymentInfoByIds({id:that.id}).then(res =>{
          that.form = {
            ...res.data,
            latestPayAt: this.parseTime(res.data.latestPayAt, '{y}-{m}-{d}'),
            applicationAt: this.parseTime(res.data.applicationAt, '{y}-{m}-{d}')
          }
        })
        getPaymentItem({ id: this.id }).then(res => {
          this.list = [...res.data]
        })
      },
      print(){
        lodop().then(LODOP => {
          LODOP.PRINT_INIT();
          LODOP.SET_PRINT_STYLE("FontSize",18);
          LODOP.SET_PRINT_STYLE("Bold",1);
          // LODOP.ADD_PRINT_TEXT(50,231,260,39,"打印页面部分内容");
          // 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);
          LODOP.PRINT();
          // this.$alert('已发起打印任务');
          // LODOP.PREVIEW(); // 预览
          /* LODOP.PRINTA(); // 选择打印机
            // 直接打印 */
          console.log('打印哦')
        }).catch(err => {
          console.error('lodop异常', err)
吴滔's avatar
吴滔 committed
185
          alert(this.$t('请检查LODOP打印控件是否安装并启动'));
吴滔's avatar
吴滔 committed
186 187 188 189
        })
      },
      findBank(val) {
        const t = this.bankData.find(v => v.id == val)
我在何方's avatar
我在何方 committed
190
        console.log(t)
吴滔's avatar
吴滔 committed
191 192 193 194
        return t || {}
      },
      totalMoney() {
        const t = this.list.map(v => v.total).reduce((prev, curr) => {
我在何方's avatar
我在何方 committed
195
          return parseFloat(prev) + parseFloat(curr);
吴滔's avatar
吴滔 committed
196 197 198 199 200
        }, 0)
        return t
      },
      convertCurrency(money) {
        //汉字的数字
201
        var cnNums = new Array(this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''), this.$t(''));
吴滔's avatar
吴滔 committed
202
        //基本单位
203
        var cnIntRadice = new Array('', this.$t(''), this.$t(''), this.$t(''));
吴滔's avatar
吴滔 committed
204
        //对应整数部分扩展单位
205
        var cnIntUnits = new Array('', this.$t(''), this.$t('亿'), this.$t(''));
吴滔's avatar
吴滔 committed
206
        //对应小数部分单位
207
        var cnDecUnits = new Array(this.$t(''), this.$t(''), this.$t(''), this.$t(''));
吴滔's avatar
吴滔 committed
208
        //整数金额时后面跟的字符
Marcus's avatar
Marcus committed
209
        var cnInteger = this.$t('');
吴滔's avatar
吴滔 committed
210
        //整型完以后的单位
Marcus's avatar
Marcus committed
211
        var cnIntLast = this.$t('');
吴滔's avatar
吴滔 committed
212 213 214 215 216 217 218 219 220 221
        //最大处理的数字
        var maxNum = 999999999999999.9999;
        //金额整数部分
        var integerNum;
        //金额小数部分
        var decimalNum;
        //输出的中文金额字符串
        var chineseStr = '';
        //分离金额后用的数组,预定义
        var parts;
我在何方's avatar
我在何方 committed
222
        // 传入的参数为空情况
吴滔's avatar
吴滔 committed
223 224 225 226 227 228 229
        if(money === '') {
          return '';
        }
        money = parseFloat(money)
        if(money >= maxNum){
          return ''
        }
我在何方's avatar
我在何方 committed
230
        // 传入的参数为0情况
吴滔's avatar
吴滔 committed
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
        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
265
              chineseStr += cnIntUnits[q];
吴滔's avatar
吴滔 committed
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
            }
          }
          // 最后+ 元
          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 == ''){
          chineseStr += cnNums[0] + cnIntLast + cnInteger;
        }else if(decimalNum == ''){
          chineseStr += cnInteger;
        }
        return chineseStr
      },
    },

  }
</script>

<style scoped id="printStyle">
  .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>