addbill.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <view class="content">
  3. <view v-for="(item,index) in form.contractDrafts" :key="index">
  4. <view class="addtitle flex6">
  5. <text class="ty">汇票{{index+1}}</text>
  6. <text class="tde" @click="deleBill(index)">删除</text>
  7. </view>
  8. <view class="listitem">
  9. <text class="lys">汇票名称</text>
  10. <view class="inbox">
  11. <input type="text" v-model="item.name" placeholder="请输入汇票的名称" placeholder-style="color:#BEBDBB" />
  12. </view>
  13. </view>
  14. <view class="listitem">
  15. <text class="lys">汇票号码</text>
  16. <view class="inbox">
  17. <input type="text" v-model="item.draftNo" placeholder="请输入汇票的号码"
  18. placeholder-style="color:#BEBDBB" />
  19. </view>
  20. </view>
  21. <view class="listitem">
  22. <text class="lys">兑换人</text>
  23. <view class="chosbox">
  24. <uni-data-select v-model="item.acceptor" :localdata="range1" @change="changeacPerson"
  25. :showas="false" :plname="'搜索兑换人名称'"></uni-data-select>
  26. </view>
  27. </view>
  28. <view class="listitem">
  29. <text class="lys">出票人</text>
  30. <view class="chosbox">
  31. <uni-data-select v-model="item.drawers" :localdata="range2" @change="changedrPerson"
  32. :plname="'搜索出票人名称'"></uni-data-select>
  33. </view>
  34. </view>
  35. <view class="listitem">
  36. <text class="lys">金额</text>
  37. <view class="inbox">
  38. <input type="digit" v-model="item.money" placeholder="请输入汇票的金额" placeholder-style="color:#BEBDBB"
  39. @blur="getMoney" @input="getMoneyIndex(index)" />
  40. </view>
  41. </view>
  42. <view class="listitem">
  43. <text class="lys">承兑日期</text>
  44. <view class="calender" @click="openTime(index,1)">
  45. <view class="canicon">
  46. <image src="../../static/img/canlen.png" mode="aspectFill"></image>
  47. </view>
  48. <text>{{item.acceptDate}}</text>
  49. </view>
  50. </view>
  51. <view class="listitem">
  52. <text class="lys">出票日期</text>
  53. <view class="calender" @click="openTime(index,2)">
  54. <view class="canicon">
  55. <image src="../../static/img/canlen.png" mode="aspectFill"></image>
  56. </view>
  57. <text>{{item.issueDate}}</text>
  58. </view>
  59. </view>
  60. <view class="listitem">
  61. <text class="lys">汇票到期日</text>
  62. <view class="calender" @click="openTime(index,3)">
  63. <view class="canicon">
  64. <image src="../../static/img/canlen.png" mode="aspectFill"></image>
  65. </view>
  66. <text>{{item.expireDate}}</text>
  67. </view>
  68. </view>
  69. <view class="listitem">
  70. <text class="lys">预计贴现日</text>
  71. <view class="calender" @click="openTime(index,4)">
  72. <view class="canicon">
  73. <image src="../../static/img/canlen.png" mode="aspectFill"></image>
  74. </view>
  75. <text>{{item.expectDiscountDate}}</text>
  76. </view>
  77. </view>
  78. <view class="listitem">
  79. <text class="lys">最高贷款额度</text>
  80. <view class="inbox">
  81. <input type="text" v-model="item.loanLimit" placeholder="自动计算得出" placeholder-style="color:#1F242A"
  82. disabled="true" />
  83. </view>
  84. </view>
  85. <view class="flex4">
  86. <view class="listitem">
  87. <text class="lys">服务费率</text>
  88. <view class="inbox">
  89. <input type="digit" v-model="item.serviceRate" placeholder="显示对于费率"
  90. placeholder-style="color:#BEBDBB" @blur="getserviceRate"
  91. @input="getserviceRateIndex(index)" />
  92. </view>
  93. </view>
  94. <view class="listitem">
  95. <text class="lys">服务费</text>
  96. <view class="inbox">
  97. <input type="text" v-model="item.serviceMoney" placeholder="自动计算得出"
  98. placeholder-style="color:#BEBDBB" disabled="true" />
  99. </view>
  100. </view>
  101. </view>
  102. <view class="flex4">
  103. <view class="listitem">
  104. <text class="lys">利率</text>
  105. <view class="inbox">
  106. <input type="digit" v-model="item.interestRate" placeholder="显示对于利率"
  107. placeholder-style="color:#BEBDBB" @blur="getinterestRate"
  108. @input="getinterestRateIndex(index)" />
  109. </view>
  110. </view>
  111. <view class="listitem">
  112. <text class="lys">利息</text>
  113. <view class="inbox">
  114. <input type="text" v-model="item.interest" placeholder="自动计算得出"
  115. placeholder-style="color:#BEBDBB" disabled="true" />
  116. </view>
  117. </view>
  118. </view>
  119. <view class="listitem">
  120. <view class="" style="display: flex;align-content: center;">
  121. <text class="lys">上传附件</text>
  122. <text
  123. style="font-size: 24rpx; color:#D05C39;padding-top: 45rpx;padding-left: 20rpx;">*支持上传pdf、jpg/jpeg、png格式</text>
  124. </view>
  125. <view class="inbox" style="border: none;padding-bottom: 0;" @click="checkIndex(index)">
  126. <u-upload :fileList="item.picUrling" @afterRead="afterRead" @delete="deletePic" :name="index+4"
  127. multiple :maxCount="10" width="100" height="100"></u-upload>
  128. </view>
  129. </view>
  130. </view>
  131. <view class="addnewbill" @click="addNewBill">
  132. + 新增汇票
  133. </view>
  134. <view class="safebt"></view>
  135. <view class="newbill flex1">
  136. <view class="newbillbtn">
  137. <text>确认上传</text>
  138. </view>
  139. </view>
  140. <u-datetime-picker :show="dateshow" mode="date" @confirm="confirm" @cancel="closeDate" v-model="start">
  141. </u-datetime-picker>
  142. </view>
  143. </template>
  144. <script>
  145. let that
  146. import {
  147. mainUrl
  148. } from '@/http/baseUrl.js';
  149. import calllips from "@/componet/calllips/calllips.vue"
  150. export default {
  151. components: {
  152. calllips
  153. },
  154. data() {
  155. return {
  156. editall: false,
  157. quan: false,
  158. dateshow: false,
  159. opdanum: '',
  160. state: '',
  161. index: 0,
  162. start: Number(new Date()),
  163. fileList1: [],
  164. fileList2: [],
  165. fileList3: [],
  166. fileList4: [],
  167. allindex: 0,
  168. form: {
  169. name: '',
  170. supplierId: '',
  171. invoicePics: [],
  172. pics: [],
  173. tradePics: [],
  174. contractDrafts: [{
  175. name: '',
  176. draftNo: '',
  177. acceptor: '',
  178. acceptorId: '',
  179. drawersId: '',
  180. drawers: '',
  181. money: '',
  182. acceptDate: '',
  183. issueDate: '',
  184. expireDate: '',
  185. loanLimit: '',
  186. expectDiscountDate: '',
  187. picUrls: [],
  188. picUrling: [],
  189. serviceRate: '',
  190. interestRate: '',
  191. interest: '',
  192. serviceMoney: '',
  193. limitTime: 0,
  194. expectDiscountDateTime: 0,
  195. expectDiscountDate: 0
  196. }, ],
  197. },
  198. range1: [],
  199. range2: [],
  200. myindex: 0,
  201. sindex: 0,
  202. rindex: 0
  203. }
  204. },
  205. onLoad() {
  206. that = this
  207. if(o.obj){
  208. this.form.contractDrafts=JSON.parse(o.obj)
  209. }
  210. this.init()
  211. this.form.supplierId = uni.getStorageSync('supplierId')
  212. // console.log(this.form.supplierId,778)
  213. this.loadTime()
  214. },
  215. onshow(){
  216. },
  217. methods: {
  218. loadTime() {
  219. let myDate = new Date()
  220. // let wk = Date.parse(new Date());
  221. let wk = myDate.getTime()
  222. console.log(wk)
  223. let yy = String(myDate.getFullYear())
  224. // let mm = myDate.getMonth() + 1
  225. let mm = String(myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1)
  226. let dd = String(myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate())
  227. let nowDate = yy + '-' + mm + '-' + dd
  228. this.form.contractDrafts.forEach(item => {
  229. item.acceptDate = nowDate
  230. item.issueDate = nowDate
  231. item.expireDate = nowDate
  232. item.expectDiscountDate = nowDate
  233. item.expectDiscountDateTime = wk
  234. item.issueDateTime = wk
  235. let nTime = item.expectDiscountDateTime - item.issueDateTime
  236. item.limitTime = Math.floor(nTime / 86400000) + 1;
  237. })
  238. },
  239. init() {
  240. // 承兑人列表
  241. uni.$u.http.post('/api/Acceptor/search', {
  242. }, {
  243. custom: {
  244. auth: true
  245. }
  246. }).then((res) => {
  247. uni.hideLoading()
  248. this.range1 = res.result
  249. // for(let i in this.range1){
  250. // }
  251. this.range1.forEach((item, index) => {
  252. this.range1[index].value = index
  253. this.range1[index].text = item.name
  254. })
  255. }).catch((err) => {})
  256. // 出票人列表
  257. uni.$u.http.post('/api/Drawer/search', {
  258. }, {
  259. custom: {
  260. auth: true
  261. }
  262. }).then((res) => {
  263. uni.hideLoading()
  264. this.range2 = res.result
  265. this.range2.forEach((item, index) => {
  266. this.range2[index].value = index
  267. this.range2[index].text = item.name
  268. })
  269. }).catch((err) => {})
  270. },
  271. deleBill(index){
  272. uni.showModal({
  273. title:"提示",
  274. content:"是否确认删除?",
  275. success:(res)=>{
  276. if (res.confirm) {
  277. that.form.contractDrafts.splice(index,1)
  278. }
  279. }
  280. })
  281. },
  282. getinterestRateIndex(index) {
  283. this.rindex = index
  284. },
  285. getinterestRate(event) {
  286. this.form.contractDrafts[this.rindex].interestRate = Number(event.detail.value)
  287. this.getloanLimt(this.rindex)
  288. this.getInterMoney(this.rindex)
  289. this.getSerMoney(this.rindex)
  290. },
  291. getserviceRateIndex(index) {
  292. this.sindex = index
  293. },
  294. getserviceRate(event) {
  295. this.form.contractDrafts[this.sindex].serviceRate = Number(event.detail.value)
  296. this.getloanLimt(this.sindex)
  297. this.getInterMoney(this.sindex)
  298. this.getSerMoney(this.sindex)
  299. },
  300. getMoneyIndex(index) {
  301. this.myindex = index
  302. },
  303. getMoney(event) {
  304. this.form.contractDrafts[this.myindex].money = Number(event.detail.value)
  305. this.getloanLimt(this.myindex)
  306. this.getSerMoney(this.myindex)
  307. this.getInterMoney(this.myindex)
  308. },
  309. getloanLimt(i) {
  310. if (this.form.contractDrafts[i].money && this.form.contractDrafts[i].serviceRate && this.form
  311. .contractDrafts[i].interestRate) {
  312. this.form.contractDrafts[i].loanLimit = (this.form.contractDrafts[i].money / (this.form.contractDrafts[
  313. i].serviceRate + this.form.contractDrafts[i].interestRate) * this.form.contractDrafts[i]
  314. .limitTime / 360 + 1).toFixed(2)
  315. }
  316. },
  317. getSerMoney(i) {
  318. if (this.form.contractDrafts[i].money && this.form.contractDrafts[i].serviceRate && this.form
  319. .contractDrafts[i].interestRate) {
  320. this.form.contractDrafts[i].serviceMoney = ((this.form.contractDrafts[i].money / (this.form
  321. .contractDrafts[i].serviceRate + this.form.contractDrafts[i].interestRate) * this.form
  322. .contractDrafts[i].limitTime / 360 + 1) * this.form.contractDrafts[i].serviceRate * this
  323. .form.contractDrafts[i].limitTime / 360).toFixed(2)
  324. }
  325. },
  326. getInterMoney(i) {
  327. if (this.form.contractDrafts[i].money && this.form.contractDrafts[i].serviceRate && this.form
  328. .contractDrafts[i].interestRate) {
  329. this.form.contractDrafts[i].interest = ((this.form.contractDrafts[i].money / (this.form.contractDrafts[
  330. i].serviceRate + this.form.contractDrafts[i].interestRate) * this.form.contractDrafts[
  331. i].limitTime / 360 + 1) * this.form.contractDrafts[i].interestRate * this.form
  332. .contractDrafts[i].limitTime / 360).toFixed(2)
  333. }
  334. },
  335. upAll() {
  336. uni.showModal({
  337. title: '提示',
  338. content: '是否上传合同?',
  339. success: function(res) {
  340. if (res.confirm) {
  341. let form = that.form
  342. form.contractDrafts.forEach(i => {
  343. if (i.name.length == 0) {
  344. that.$toast('请输入汇票名称')
  345. return
  346. }
  347. if (i.draftNo.length == 0) {
  348. that.$toast('请输入汇票号码')
  349. return
  350. }
  351. if (i.acceptor.length == 0) {
  352. that.$toast('请选择承兑人')
  353. return
  354. }
  355. if (i.drawers.length == 0) {
  356. that.$toast('请选择出票人')
  357. return
  358. }
  359. if (i.money.length == 0) {
  360. that.$toast('请输入金额')
  361. return
  362. }
  363. if (i.serviceRate.length == 0) {
  364. that.$toast('请输入服务费率')
  365. return
  366. }
  367. if (i.interestRate.length == 0) {
  368. that.$toast('请输入利率')
  369. return
  370. }
  371. if (i.picUrls.length == 0) {
  372. that.$toast('请上传附件')
  373. return
  374. }
  375. })
  376. that.range2.forEach(item => {
  377. form.contractDrafts.forEach(i => {
  378. if (that.range2[i.drawers].name == item.name) {
  379. i.drawersId = item.id
  380. }
  381. })
  382. })
  383. that.range1.forEach(item => {
  384. form.contractDrafts.forEach(i => {
  385. if (that.range1[i.acceptor].name == item.name) {
  386. i.acceptorId = item.id
  387. }
  388. })
  389. })
  390. form.contractDrafts.forEach(item=>{
  391. item.picUrling.forEach(i=>{
  392. item.picUrls.push(i.url)
  393. })
  394. })
  395. uni.showLoading()
  396. uni.$u.http.post('/api/Contract/addContractDraft', form.contractDrafts, {
  397. custom: {
  398. auth: true
  399. }
  400. }).then((res) => {
  401. uni.hideLoading()
  402. that.$toast("合同上传成功")
  403. }).catch((err) => {
  404. uni.hideLoading()
  405. that.$toast(err.msg)
  406. console.log(err)
  407. })
  408. } else if (res.cancel) {}
  409. }
  410. });
  411. },
  412. addNewBill() {
  413. let form = [{
  414. name: '',
  415. draftNo: '',
  416. acceptor: '',
  417. acceptorId: '',
  418. drawersId: '',
  419. drawers: '',
  420. money: '',
  421. acceptDate: '',
  422. issueDate: '',
  423. expireDate: '',
  424. loanLimit: '',
  425. expectDiscountDate: '',
  426. picUrls: [],
  427. picUrling: [],
  428. serviceRate: '',
  429. interestRate: '',
  430. interest: '',
  431. serviceMoney: '',
  432. limitTime: 0,
  433. expectDiscountDateTime: 0,
  434. expectDiscountDate: 0
  435. }]
  436. let myDate = new Date()
  437. // let wk = Date.parse(new Date());
  438. let wk = myDate.getTime()
  439. console.log(wk)
  440. let yy = String(myDate.getFullYear())
  441. // let mm = myDate.getMonth() + 1
  442. let mm = String(myDate.getMonth() + 1 < 10 ? '0' + (myDate.getMonth() + 1) : myDate.getMonth() + 1)
  443. let dd = String(myDate.getDate() < 10 ? '0' + myDate.getDate() : myDate.getDate())
  444. let nowDate = yy + '-' + mm + '-' + dd
  445. form.forEach(item => {
  446. item.acceptDate = nowDate
  447. item.issueDate = nowDate
  448. item.expireDate = nowDate
  449. item.expectDiscountDate = nowDate
  450. item.expectDiscountDateTime = wk
  451. item.issueDateTime = wk
  452. let nTime = item.expectDiscountDateTime - item.issueDateTime
  453. item.limitTime = Math.floor(nTime / 86400000) + 1;
  454. })
  455. this.form.contractDrafts.push(form[0])
  456. },
  457. changeacPerson(e) {
  458. this.acceptor = e
  459. },
  460. changedrPerson(e) {
  461. this.drawers = e
  462. },
  463. openTime(index, value) {
  464. this.dateshow = true
  465. this.index = index
  466. this.opdanum = value
  467. },
  468. closeDate() {
  469. this.dateshow = false
  470. },
  471. confirm(e) {
  472. const timeFormat = uni.$u.timeFormat
  473. let form = this.form.contractDrafts
  474. if (this.opdanum == 1) {
  475. form[this.index].acceptDate = timeFormat(e.value, 'yyyy-mm-dd')
  476. } else if (this.opdanum == 2) {
  477. form[this.index].issueDateTime = e.value
  478. form[this.index].issueDate = timeFormat(e.value, 'yyyy-mm-dd')
  479. } else if (this.opdanum == 3) {
  480. form[this.index].expireDate = timeFormat(e.value, 'yyyy-mm-dd')
  481. } else if (this.opdanum == 4) {
  482. form[this.index].expectDiscountDateTime = e.value
  483. let nTime = form[this.index].expectDiscountDateTime - form[this.index].issueDateTime
  484. form[this.index].limitTime = Math.floor(nTime / 86400000) + 1;
  485. form[this.index].expectDiscountDate = timeFormat(e.value, 'yyyy-mm-dd')
  486. }
  487. // console.log(this.index, this.opdanum)
  488. this.dateshow = false
  489. },
  490. change(e) {
  491. console.log("e:", e);
  492. },
  493. open(e) {
  494. // console.log('open', e)
  495. },
  496. close(e) {
  497. // console.log('close', e)
  498. },
  499. change(e) {
  500. // console.log('change', e)
  501. },
  502. checkIndex(index) {
  503. this.allindex = index
  504. console.log(index)
  505. },
  506. // 删除图片
  507. deletePic(event) {
  508. if (event.name == 4) {
  509. this.form.contractDrafts[this.allindex].picUrling.splice(event.index, 1)
  510. } else {
  511. this[`fileList${event.name}`].splice(event.index, 1)
  512. }
  513. },
  514. // 新增图片
  515. async afterRead(event) {
  516. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  517. if (event.name >= 4) {
  518. let lists = [].concat(event.file)
  519. let icurls = this.form.contractDrafts[this.allindex].picUrling
  520. let fileListLen = icurls.length
  521. lists.map((item) => {
  522. icurls.push({
  523. ...item,
  524. status: 'uploading',
  525. message: '上传中'
  526. })
  527. })
  528. for (let i = 0; i < lists.length; i++) {
  529. const result = await this.uploadFilePromise(lists[i].url)
  530. let obj = {
  531. }
  532. console.log(result)
  533. let item = icurls[fileListLen]
  534. icurls.splice(fileListLen, 1, Object.assign(item, {
  535. status: 'success',
  536. message: '',
  537. url: result
  538. }))
  539. fileListLen++
  540. }
  541. } else {
  542. let lists = [].concat(event.file)
  543. let fileListLen = this[`fileList${event.name}`].length
  544. lists.map((item) => {
  545. this[`fileList${event.name}`].push({
  546. ...item,
  547. status: 'uploading',
  548. message: '上传中'
  549. })
  550. })
  551. for (let i = 0; i < lists.length; i++) {
  552. const result = await this.uploadFilePromise(lists[i].url)
  553. let item = this[`fileList${event.name}`][fileListLen]
  554. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  555. status: 'success',
  556. message: '',
  557. url: result
  558. }))
  559. fileListLen++
  560. }
  561. }
  562. },
  563. uploadFilePromise(url) {
  564. return new Promise((resolve, reject) => {
  565. let a = uni.uploadFile({
  566. url: mainUrl + '/api/File', // 仅为示例,非真实的接口地址
  567. filePath: url,
  568. name: 'File',
  569. header: {
  570. "User-Agent": "apifox/1.0.0 (https://www.apifox.cn)"
  571. },
  572. formData: {
  573. File: JSON.stringify(url),
  574. },
  575. success: (res) => {
  576. console.log(res)
  577. let request = JSON.parse(res.data)
  578. setTimeout(() => {
  579. resolve(request.data.file)
  580. }, 1000)
  581. }
  582. });
  583. })
  584. },
  585. }
  586. }
  587. </script>
  588. <style lang="scss">
  589. .content {
  590. padding: 0 30rpx;
  591. box-sizing: border-box;
  592. }
  593. .addtitle {
  594. font-weight: 600;
  595. padding-top: 58rpx;
  596. font-size: 36rpx;
  597. .ty {
  598. color: #D8AB5A;
  599. }
  600. .tde {
  601. color: #D05C39;
  602. }
  603. }
  604. .listitem {
  605. .lys {
  606. display: block;
  607. font-size: 32rpx;
  608. font-weight: 600;
  609. padding-top: 40rpx;
  610. padding-bottom: 30rpx;
  611. }
  612. .inbox {
  613. padding-bottom: 20rpx;
  614. width: 100%;
  615. font-size: 30rpx;
  616. border-bottom: 1rpx solid #E8E8E8;
  617. }
  618. .chosbox {
  619. border-radius: 20rpx;
  620. // border: 1rpx solid #BEBDBB;
  621. }
  622. .calender {
  623. border-radius: 20rpx;
  624. width: 690rpx;
  625. height: 80rpx;
  626. border-radius: 20rpx;
  627. border: 1rpx solid #BEBDBB;
  628. display: flex;
  629. align-items: center;
  630. padding-left: 30rpx;
  631. font-size: 32rpx;
  632. box-sizing: border-box;
  633. .canicon {
  634. width: 34rpx;
  635. height: 34rpx;
  636. margin-right: 20rpx;
  637. image {
  638. width: 100%;
  639. height: 100%;
  640. }
  641. }
  642. }
  643. }
  644. .addnewbill {
  645. width: 200rpx;
  646. height: 78rpx;
  647. border-radius: 45rpx;
  648. border: 1rpx solid #E8E8E8;
  649. line-height: 78rpx;
  650. text-align: center;
  651. margin-top: 50rpx;
  652. margin-bottom: 200rpx;
  653. }
  654. </style>