ticketMake.js 16 KB

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