ticketHand.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. // pages/ticketHand/ticketHand.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: '', // 个人信息
  9. customerType: 2, //(默认企业2,个人1)
  10. invoiceCategory: 1, //发票种类
  11. zsfs: 0, //征税方式
  12. seller: '', //销方信息
  13. buyer: '', //购方信息
  14. bankName: '', //银行名称
  15. remark: '', //备注说明
  16. spreadFlag: false, //购方填写项的展开收起
  17. payees: ['手动输入'], //收款人
  18. payeesIndex: '',
  19. payeesText: '',
  20. reviewers: ['手动输入'], //复核人
  21. reviewersIndex: '',
  22. reviewersText: '',
  23. drawers: ['手动输入'], //开票人
  24. drawersIndex: '',
  25. drawersText: '',
  26. proList: [{ //产品列表
  27. price: '',
  28. taxRate: '',
  29. taxRateArr: [], // 税率数组
  30. taxRateArrIndex: 0, //选中税率下标
  31. noRatePrice: '', //不含税单价
  32. noRateTotal: '', //不含税金额
  33. totalMoney: '', //价税合计
  34. totalRate: '', //合计税额
  35. quantity: '',
  36. spreadFlag: false
  37. }],
  38. moneyTotal: 0, //价税合计
  39. noRateTotal: 0, //合计金额(不含税)
  40. rateTotal: 0, //合计税额
  41. curValue: 1, //接收方式
  42. interactTypeDetail: '',
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. this.getUser()
  49. },
  50. //发票对象
  51. selectObj(e) {
  52. let customerType = e.detail.value
  53. this.setData({
  54. customerType
  55. })
  56. },
  57. //发票种类
  58. selectCate(e) {
  59. let invoiceCategory = e.detail.value
  60. this.setData({
  61. invoiceCategory
  62. })
  63. },
  64. //征税方式
  65. selectZs(e) {
  66. let zsfs = e.detail.value
  67. this.setData({
  68. zsfs
  69. })
  70. },
  71. //销方企业信息(当前登录用户的默认企业信息)
  72. getUser() {
  73. this.setData({
  74. userInfo: utils.getInfo(),
  75. seller: utils.getCurrEntInfo()
  76. })
  77. let payees = this.data.payees
  78. if (this.data.seller.payees) {
  79. let arr = this.data.seller.payees.split(',')
  80. payees = payees.concat(arr)
  81. this.setData({
  82. payees
  83. })
  84. }
  85. let reviewers = this.data.reviewers
  86. if (this.data.seller.reviewers) {
  87. let arr = this.data.seller.reviewers.split(',')
  88. reviewers = reviewers.concat(arr)
  89. this.setData({
  90. reviewers
  91. })
  92. }
  93. let drawers = this.data.drawers
  94. if (this.data.seller.drawers) {
  95. let arr = this.data.seller.drawers.split(',')
  96. arr.push(this.data.userInfo.userName)
  97. drawers = drawers.concat(arr)
  98. this.setData({
  99. drawers
  100. })
  101. }
  102. // utils.getCompany().then(res => {
  103. // let result = res.data
  104. // this.setData({
  105. // seller: result
  106. // })
  107. // let payees = this.data.payees
  108. // if (result.payees) {
  109. // let arr = result.payees.split(',')
  110. // payees = payees.concat(arr)
  111. // this.setData({
  112. // payees
  113. // })
  114. // }
  115. // let reviewers = this.data.reviewers
  116. // if (result.reviewers) {
  117. // let arr = result.reviewers.split(',')
  118. // reviewers = reviewers.concat(arr)
  119. // this.setData({
  120. // reviewers
  121. // })
  122. // }
  123. // })
  124. },
  125. //购方信息
  126. toSearch() {
  127. wx.navigateTo({
  128. url: '/pages/search/search'
  129. })
  130. },
  131. spreadBuyer() {
  132. this.setData({
  133. spreadFlag: !this.data.spreadFlag
  134. })
  135. },
  136. //收款人,复核人, 开票人
  137. setPayees(e) {
  138. let index = Number(e.detail.value)
  139. this.setData({
  140. payeesIndex: index
  141. })
  142. },
  143. getPayees(e) {
  144. let value = e.detail.value
  145. this.setData({
  146. payeesText: value
  147. })
  148. },
  149. setReviewers(e) {
  150. let index = Number(e.detail.value)
  151. this.setData({
  152. reviewersIndex: index
  153. })
  154. },
  155. setDrawers(e) {
  156. let index = Number(e.detail.value)
  157. this.setData({
  158. drawersIndex: index
  159. })
  160. },
  161. getReviewers(e) {
  162. let value = e.detail.value
  163. this.setData({
  164. reviewersText: value
  165. })
  166. },
  167. getDrawers(e) {
  168. let value = e.detail.value
  169. this.setData({
  170. drawersText: value
  171. })
  172. },
  173. //查询商品
  174. toSearchPro(e) {
  175. let index = e.currentTarget.dataset.index
  176. wx.navigateTo({
  177. url: `/pages/searchPro/searchPro?index=${index}`
  178. })
  179. },
  180. //计算发票总金额、总税额
  181. calcMoney() {
  182. let list = this.data.proList
  183. let moneyTotal = 0
  184. let noRateTotal = 0
  185. let rateTotal = 0
  186. for (let i = 0; i < list.length; i++) {
  187. //计算不含税单价、不含税项目金额、价税合计金额
  188. if (list[i].price !== null && list[i].price !== '' && list[i].quantity) {
  189. list[i].noRatePrice = parseFloat(list[i].price / (1 + (list[i].taxRate ? list[i].taxRate : 0))).toFixed(6)
  190. list[i].noRateTotal = parseFloat(list[i].noRatePrice * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
  191. list[i].totalMoney = parseFloat(list[i].price * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
  192. //税额计算公式:价税合计金额/(1+税率)*税率
  193. list[i].totalRate = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0)) * (list[i].taxRate ? list[i].taxRate : 0)).toFixed(2)
  194. } else {
  195. list[i].totalMoney = 0
  196. list[i].noRateTotal = 0
  197. list[i].totalRate = 0
  198. }
  199. //总的相加
  200. moneyTotal += Number(list[i].totalMoney)
  201. noRateTotal += Number(list[i].noRateTotal)
  202. rateTotal += Number(list[i].totalRate)
  203. }
  204. this.setData({
  205. moneyTotal: parseFloat(moneyTotal).toFixed(2),
  206. noRateTotal: parseFloat(noRateTotal).toFixed(2),
  207. rateTotal: parseFloat(rateTotal).toFixed(2),
  208. proList: list
  209. })
  210. },
  211. //选择接收方式
  212. selectType(e) {
  213. let curValue = e.detail.value
  214. let interactTypeDetail = ''
  215. if (curValue === 1) {
  216. if (this.data.buyer.email) {
  217. interactTypeDetail = this.data.buyer.email
  218. }
  219. }
  220. if (curValue === 2) {
  221. if (this.data.buyer.customerMobile) {
  222. interactTypeDetail = this.data.buyer.customerMobile
  223. }
  224. }
  225. if (curValue === 3) {
  226. interactTypeDetail = '微信卡包'
  227. }
  228. if (curValue === 4) {
  229. interactTypeDetail = '支付宝发票管家'
  230. }
  231. this.setData({
  232. curValue,
  233. interactTypeDetail
  234. })
  235. },
  236. //提交开票
  237. submitData() {
  238. //购方信息
  239. let buyer = this.data.buyer
  240. if (!buyer.customerName) {
  241. utils.toast('发票抬头不能为空')
  242. return
  243. } else {
  244. if (utils.trimAll(buyer.customerName) === '') {
  245. utils.toast('发票抬头不能为空')
  246. return
  247. }
  248. }
  249. if (this.data.customerType === 2) {
  250. if (!buyer.entTaxId) {
  251. utils.toast('税号不能为空')
  252. return
  253. } else {
  254. if (utils.trimAll(buyer.entTaxId) === '') {
  255. utils.toast('税号不能为空')
  256. return
  257. }
  258. }
  259. }
  260. let entTaxIdLen = utils.trimAll(buyer.entTaxId).length
  261. if (entTaxIdLen !== 0 && entTaxIdLen !== 15 && entTaxIdLen !== 18 && entTaxIdLen !== 20) {
  262. utils.toast('税号长度不正确')
  263. return
  264. }
  265. //产品信息
  266. let proList = this.data.proList
  267. let proListSubmit = []
  268. for (let i = 0; i < proList.length; i++) {
  269. if (proList[i].totalMoney && proList[i].productName) {
  270. proListSubmit.push(proList[i])
  271. }
  272. }
  273. let COMMON_FPKJ_XMXX = []
  274. if (proListSubmit.length <= 0) {
  275. utils.toast('商品信息不能为空')
  276. return
  277. } else {
  278. for (let i = 0; i < proListSubmit.length; i++) {
  279. let item = {
  280. "SPHH": i+1,
  281. "FPHXZ": 0,
  282. "SPBM": proListSubmit[i].taxationCateCode,
  283. "ZXBM": '',
  284. "YHZCBS": proListSubmit[i].preferentialFlag,
  285. "LSLBS": proListSubmit[i].zeroRateFlag,
  286. "ZZSTSGL": proListSubmit[i].preferentialType,
  287. "XMMC": proListSubmit[i].productName,
  288. "GGXH": proListSubmit[i].specsModel,
  289. "DW": proListSubmit[i].unit,
  290. "XMJE": proListSubmit[i].noRateTotal,
  291. "SL": proListSubmit[i].taxRate,
  292. "SE": proListSubmit[i].totalRate
  293. }
  294. // 如果数量为存在并且不为0则传递参数
  295. if (proListSubmit[i].quantity) {
  296. item.XMSL = proListSubmit[i].quantity
  297. }
  298. // 如果不含税单价存在(为0也可以)则传递参数
  299. if (proListSubmit[i].noRatePrice !== '') {
  300. item.XMDJ = proListSubmit[i].noRatePrice
  301. }
  302. COMMON_FPKJ_XMXX.push(item)
  303. }
  304. }
  305. //接收方式
  306. let interactTypeDetail = utils.trimAll(this.data.interactTypeDetail)
  307. if (interactTypeDetail === '') {
  308. utils.toast('接收方式不能为空')
  309. return
  310. } else {
  311. if (this.data.curValue === 1) {
  312. if (!utils.testEmail(interactTypeDetail)) {
  313. utils.toast('接收方式请填写正确的邮箱')
  314. return
  315. }
  316. }
  317. if (this.data.curValue === 2) {
  318. if (!utils.testMobile(interactTypeDetail)) {
  319. utils.toast('接收方式请填写正确的手机号码')
  320. return
  321. }
  322. }
  323. }
  324. //复核人,收款人, 开票人
  325. let SKR = ''
  326. let payeesIndex = this.data.payeesIndex
  327. if (payeesIndex !== '') {
  328. if (payeesIndex === 0) {
  329. SKR = utils.trimAll(this.data.payeesText)
  330. } else {
  331. SKR = this.data.payees[payeesIndex]
  332. }
  333. }
  334. let FHR = ''
  335. let reviewersIndex = this.data.reviewersIndex
  336. if (reviewersIndex !== '') {
  337. if (reviewersIndex === 0) {
  338. FHR = utils.trimAll(this.data.reviewersText)
  339. } else {
  340. FHR = this.data.reviewers[reviewersIndex]
  341. }
  342. }
  343. let KPR = ''
  344. let drawersIndex = this.data.drawersIndex
  345. if (drawersIndex !== '') {
  346. if (drawersIndex === 0) {
  347. KPR = utils.trimAll(this.data.drawersText)
  348. } else {
  349. KPR = this.data.drawers[drawersIndex]
  350. }
  351. }
  352. //参数
  353. let params = {
  354. mobile: this.data.userInfo.mobile,
  355. reqChannel: 5,
  356. invoiceWay: 1,
  357. interactType: this.data.curValue,
  358. interactTypeDetail: utils.trimAll(this.data.interactTypeDetail),
  359. cmdParam: {
  360. "REQUEST_COMMON_FPKJ": {
  361. "SBLX": this.data.seller.defaultDeviceInfo.deviceType,
  362. "SBBH": this.data.seller.defaultDeviceInfo.taxDiscId,
  363. "KPLX": 0,
  364. "FPZL": this.data.invoiceCategory,
  365. "TTLX": this.data.customerType,
  366. "KPF_NSRSBH": this.data.seller.entTaxId,
  367. "KPF_MC": this.data.seller.entName,
  368. "KPF_DZ": this.data.seller.entAddress,
  369. "KPF_DH": this.data.seller.entPhone,
  370. "KPF_YHZH": this.data.seller.bankAccountNumber,
  371. "KPF_KHHMC": this.data.seller.bankName,
  372. "SPF_NSRSBH": utils.trimAll(this.data.buyer.entTaxId),
  373. "SPF_MC": this.data.buyer.customerName ? utils.trimAll(this.data.buyer.customerName) : null,
  374. "SPF_DH": this.data.buyer.contactPhone ? utils.trimAll(this.data.buyer.contactPhone) : null,
  375. "SPF_DZ": this.data.buyer.address ? utils.trimAll(this.data.buyer.address) : null,
  376. "SPF_YHZH": this.data.buyer.bankAccount ? utils.trimAll(this.data.buyer.bankAccount) : null,
  377. "SPF_KHHMC": this.data.buyer.bankName ? utils.trimAll(this.data.buyer.bankName) : null,
  378. "KPR": KPR,
  379. "SKR": SKR,
  380. "FHR": FHR,
  381. "JSHJ": this.data.moneyTotal,
  382. "HJJE": this.data.noRateTotal,
  383. "HJSE": this.data.rateTotal,
  384. "BZ": utils.trimAll(this.data.remark),
  385. "TSPZ": '00',
  386. "COMMON_FPKJ_XMXXS": {
  387. "COMMON_FPKJ_XMXX": COMMON_FPKJ_XMXX
  388. }
  389. }
  390. }
  391. }
  392. utils.axios({
  393. method: 'post',
  394. url: '/sys/invoice/save',
  395. data: params,
  396. sendBefore() {
  397. wx.showLoading({
  398. title: '提交开票中...',
  399. mask: true
  400. })
  401. },
  402. complete() {
  403. wx.hideLoading()
  404. },
  405. success: res => {
  406. wx.setStorageSync('wxCode', res.data)
  407. wx.navigateTo({
  408. url: '/pages/ticketHand/ticketResult?invoiceReqFlowNo=' + res.data.invoiceReqFlowNo
  409. })
  410. }
  411. })
  412. },
  413. //添加商品
  414. addTicket() {
  415. let proList = this.data.proList
  416. proList.push({
  417. price: '',
  418. taxRate: '',
  419. taxRateArr: [],
  420. taxRateArrIndex: 0,
  421. noRatePrice: '',
  422. noRateTotal: '',
  423. totalMoney: '',
  424. totalRate: '',
  425. quantity: '',
  426. spreadFlag: false
  427. })
  428. this.setData({
  429. proList
  430. })
  431. },
  432. // 获取商品编号税率
  433. getTaxRate(prevIndex, taxCateCode, taxRate) {
  434. let params = {
  435. taxCateCode,
  436. entTaxId: wx.getStorageSync('entTaxId')
  437. }
  438. utils.axios({
  439. method: 'get',
  440. url: '/sys/entInfo/rates',
  441. data: params,
  442. sendBefore() { },
  443. complete() { },
  444. success: res => {
  445. let index = prevIndex
  446. let proList = this.data.proList
  447. let result = res.data
  448. for (let i = 0; i < result.length; i++) {
  449. result[i] = Number(result[i])
  450. if (result[i] === taxRate) {
  451. proList[prevIndex].taxRateArrIndex = i
  452. }
  453. }
  454. proList[prevIndex].taxRateArr = result
  455. this.setData({
  456. proList
  457. })
  458. this.calcMoney()
  459. }
  460. })
  461. },
  462. setRate(e) {
  463. let index = e.currentTarget.dataset.index
  464. let proList = this.data.proList
  465. proList[index].taxRateArrIndex = e.detail.value
  466. proList[index].taxRate = proList[index].taxRateArr[proList[index].taxRateArrIndex]
  467. this.setData({
  468. proList
  469. })
  470. this.calcMoney()
  471. },
  472. //单个商品展开收起
  473. spread(e) {
  474. let index = e.currentTarget.dataset.index
  475. this.setData({
  476. [`proList[${index}].spreadFlag`]: !this.data.proList[index].spreadFlag
  477. })
  478. },
  479. delete(e) {
  480. let index = e.currentTarget.dataset.index
  481. let proList = this.data.proList
  482. proList.splice(index, 1)
  483. this.setData({
  484. proList
  485. })
  486. this.calcMoney()
  487. },
  488. //购物车加
  489. add(e) {
  490. let proList = this.data.proList
  491. let index = e.currentTarget.dataset.index
  492. let curNum = proList[index].quantity
  493. curNum++
  494. let str = 'proList[' + index + '].quantity'
  495. this.setData({
  496. [str]: curNum
  497. })
  498. this.calcMoney()
  499. },
  500. //购物车减
  501. minus(e) {
  502. let proList = this.data.proList
  503. let index = e.currentTarget.dataset.index
  504. let curNum = proList[index].quantity
  505. curNum--
  506. if (curNum <= 0) {
  507. curNum = 0
  508. }
  509. let str = 'proList[' + index + '].quantity'
  510. this.setData({
  511. [str]: curNum
  512. })
  513. this.calcMoney()
  514. },
  515. //input输入框
  516. inputNum(e) {
  517. let index = e.currentTarget.dataset.index
  518. let str = 'proList[' + index + '].quantity'
  519. this.setData({
  520. [str]: Number(e.detail)
  521. })
  522. this.calcMoney()
  523. },
  524. //以下是获取表单信息的函数
  525. getTotalMoney(e) {
  526. let moneyTotal = 0
  527. let noRateTotal = 0
  528. let rateTotal = 0
  529. let list = this.data.proList
  530. let index = Number(e.currentTarget.dataset.index)
  531. let totalMoney = e.detail.value
  532. list[index].totalMoney = parseFloat(Number(totalMoney)).toFixed(2)
  533. if (list[index].quantity) {
  534. list[index].price = list[index].totalMoney / list[index].quantity
  535. list[index].noRatePrice = parseFloat(list[index].price / (1 + (list[index].taxRate ? list[index].taxRate : 0))).toFixed(6)
  536. } else {
  537. list[index].price = ''
  538. list[index].noRatePrice = ''
  539. }
  540. for (let i = 0; i < list.length; i++) {
  541. //计算不含税单价、不含税项目金额、价税合计金额
  542. if (list[i].totalMoney) {
  543. list[i].noRateTotal = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0))).toFixed(2)
  544. if (i !== index) {
  545. list[i].totalMoney = parseFloat(list[i].price * (list[i].quantity ? list[i].quantity : 0)).toFixed(2)
  546. }
  547. //税额计算公式:价税合计金额/(1+税率)*税率
  548. list[i].totalRate = parseFloat(list[i].totalMoney / (1 + (list[i].taxRate ? list[i].taxRate : 0)) * (list[i].taxRate ? list[i].taxRate : 0)).toFixed(2)
  549. }
  550. //总的相加
  551. moneyTotal += Number(list[i].totalMoney)
  552. noRateTotal += Number(list[i].noRateTotal)
  553. rateTotal += Number(list[i].totalRate)
  554. }
  555. this.setData({
  556. moneyTotal: parseFloat(moneyTotal).toFixed(2),
  557. noRateTotal: parseFloat(noRateTotal).toFixed(2),
  558. rateTotal: parseFloat(rateTotal).toFixed(2),
  559. proList: list
  560. })
  561. },
  562. getPrice(e) {
  563. let proList = this.data.proList
  564. let index = Number(e.currentTarget.dataset.index)
  565. let price = e.detail.value
  566. proList[index].price = price
  567. this.setData({
  568. proList
  569. })
  570. this.calcMoney()
  571. },
  572. getcustomerName(e) {
  573. this.setData({
  574. ['buyer.customerName']: e.detail.value
  575. })
  576. },
  577. getentTaxId(e) {
  578. this.setData({
  579. ['buyer.entTaxId']: e.detail.value
  580. })
  581. },
  582. getMobile(e) {
  583. this.setData({
  584. ['buyer.contactPhone']: e.detail.value
  585. })
  586. },
  587. getAddress(e) {
  588. this.setData({
  589. ['buyer.address']: e.detail.value
  590. })
  591. },
  592. getBankName(e) {
  593. this.setData({
  594. bankName: e.detail.value
  595. })
  596. },
  597. getBankAccount(e) {
  598. this.setData({
  599. ['buyer.bankAccount']: e.detail.value
  600. })
  601. },
  602. getremark(e) {
  603. this.setData({
  604. remark: e.detail.value
  605. })
  606. },
  607. getDetail(e) {
  608. this.setData({
  609. interactTypeDetail: e.detail.value
  610. })
  611. },
  612. /**
  613. * 生命周期函数--监听页面初次渲染完成
  614. */
  615. onReady: function () {
  616. },
  617. /**
  618. * 生命周期函数--监听页面显示
  619. */
  620. onShow: function () {
  621. },
  622. /**
  623. * 生命周期函数--监听页面隐藏
  624. */
  625. onHide: function () {
  626. },
  627. /**
  628. * 生命周期函数--监听页面卸载
  629. */
  630. onUnload: function () {
  631. },
  632. /**
  633. * 页面相关事件处理函数--监听用户下拉动作
  634. */
  635. onPullDownRefresh: function () {
  636. },
  637. /**
  638. * 页面上拉触底事件的处理函数
  639. */
  640. onReachBottom: function () {
  641. },
  642. /**
  643. * 用户点击右上角分享
  644. */
  645. onShareAppMessage: function () {
  646. return {
  647. title: '诺信云',
  648. path: '/pages/index/index'
  649. }
  650. }
  651. })