applyInvoice.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // miniprogram/pages/ticketGet/applyInvoice.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. invoiceDateBegin: "",
  10. invoiceDateEnd: "",
  11. invoiceType: [],
  12. invoiceTypeIndex: '',
  13. invoiceTypes: [],
  14. invoiceTypeIndexs: '',
  15. invoiceStatus: '3',
  16. certType: [],
  17. certTypeIndex: '',
  18. getWay: ["自行领取", '快递配送'],
  19. getWayIndex: '0',
  20. getWayStatus: '',
  21. number: '', //申领数量
  22. certNo: '', //证件号码
  23. claimant: '', //经办人
  24. remark: '发票申领', //备注
  25. tabIndex: 0,
  26. userInfo: '',
  27. company: '',
  28. handleStatusType: ['申领中', '成功', '失败'],
  29. handleStatusTypeIndex: '',
  30. handleStatusTypeInfo: '',
  31. invoiceData: {},
  32. selectInvoiceType: {},
  33. selectInvoiceTypeCode: '',
  34. selectInvoiceTypeName: {},
  35. selectInvoiceTypeNameCode: '',
  36. addressee: '',
  37. receivingAddress: '',
  38. mobilePhone: '',
  39. fixedTelephone: '',
  40. postalCode: ''
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. this.getUser()
  47. },
  48. //获取企业信息(当前登录用户的默认企业信息)
  49. getUser() {
  50. this.setData({
  51. userInfo: utils.getInfo(),
  52. company:utils.getCurrEntInfo()
  53. })
  54. this.getInvoiceInfo()
  55. // utils.getCompany().then(res => {
  56. // let result = res.data
  57. // this.setData({
  58. // company: result
  59. // })
  60. // this.getInvoiceInfo()
  61. // })
  62. },
  63. //获取申领信息
  64. getInvoiceInfo() {
  65. let params = {
  66. entTaxId: this.data.company.entTaxId,
  67. deviceType: this.data.company.defaultDeviceInfo.deviceType,
  68. taxDiscId: this.data.company.defaultDeviceInfo.taxDiscId,
  69. }
  70. utils.axios({
  71. method: 'get',
  72. url: '/sys/invoicePurchase/preInfo',
  73. data: params,
  74. sendBefore() {
  75. wx.showLoading({
  76. title: '加载中...'
  77. })
  78. },
  79. complete() {
  80. wx.hideLoading()
  81. wx.stopPullDownRefresh()
  82. },
  83. success: res => {
  84. console.log("测试数据");
  85. console.log(res);
  86. this.setData({
  87. invoiceData: res.data
  88. })
  89. let data = []
  90. res.data.pzhdInfos.forEach((item) => {
  91. let dataJason = {
  92. id: item.invoiceCateCode,
  93. name: item.invoiceCateName
  94. }
  95. let i = 0
  96. data.forEach((invoiceType) => {
  97. if (dataJason.id === invoiceType.id) {
  98. i++
  99. }
  100. })
  101. if (i === 0) {
  102. data.push(dataJason)
  103. }
  104. })
  105. this.setData({
  106. invoiceType: data
  107. })
  108. let certificates = []
  109. res.data.papers.forEach((item) => {
  110. let dataJason = {
  111. id: item.paperType,
  112. name: item.paperTypeChn
  113. }
  114. certificates.push(dataJason)
  115. })
  116. this.setData({
  117. certType: certificates,
  118. certNo: res.data.operatorInfos[0].paperNumber,
  119. claimant: res.data.operatorInfos[0].operatorName
  120. })
  121. if (res.data.operatorInfos.length > 0) {
  122. let id = res.data.operatorInfos[0].paperType
  123. this.data.certType.forEach((item, i) => {
  124. if (item.id === id) {
  125. this.setData({
  126. certTypeIndex: i
  127. })
  128. return
  129. }
  130. })
  131. }
  132. }
  133. })
  134. },
  135. //发票类型
  136. setInvoiceType(e) {
  137. let value = Number(e.detail.value)
  138. this.setData({
  139. invoiceTypeIndex: value,
  140. selectInvoiceType: this.data.invoiceType[value]
  141. })
  142. let data = []
  143. this.data.invoiceData.pzhdInfos.forEach((item) => {
  144. if (this.data.invoiceType[value].name === item.invoiceCateName) {
  145. let dataJason = {
  146. id: item.invoiceKindCode,
  147. name: item.invoiceKindName
  148. }
  149. data.push(dataJason)
  150. }
  151. })
  152. this.setData({
  153. invoiceTypes: data
  154. })
  155. },
  156. //发票类型名称
  157. setInvoiceTypeName(e) {
  158. let value = Number(e.detail.value)
  159. this.setData({
  160. invoiceTypeIndexs: value,
  161. selectInvoiceTypeName: this.data.invoiceTypes[value]
  162. })
  163. },
  164. //以下是表单信息
  165. getnumber(e) {
  166. this.setData({
  167. number: e.detail.value
  168. })
  169. },
  170. getcertNo(e) {
  171. this.setData({
  172. certNo: e.detail.value
  173. })
  174. },
  175. getclaimant(e) {
  176. this.setData({
  177. claimant: e.detail.value
  178. })
  179. },
  180. getaddressee(e) {
  181. this.setData({
  182. addressee: e.detail.value
  183. })
  184. },
  185. getreceivingAddress(e) {
  186. this.setData({
  187. receivingAddress: e.detail.value
  188. })
  189. },
  190. getmobilePhone(e) {
  191. this.setData({
  192. mobilePhone: e.detail.value
  193. })
  194. },
  195. getfixedTelephone(e) {
  196. this.setData({
  197. fixedTelephone: e.detail.value
  198. })
  199. },
  200. getpostalCode(e) {
  201. this.setData({
  202. postalCode: e.detail.value
  203. })
  204. },
  205. //申领
  206. submitData() {
  207. if (this.data.invoiceTypeIndex === '') {
  208. utils.toast('发票类别不能为空')
  209. return
  210. }
  211. if (this.data.invoiceTypeIndexs === '') {
  212. utils.toast('发票种类不能为空')
  213. return
  214. }
  215. if (this.data.number === '') {
  216. utils.toast('申领数量不能为空')
  217. return
  218. }
  219. if (this.data.certTypeIndex === '') {
  220. utils.toast('证件类型不能为空')
  221. return
  222. }
  223. if (this.data.certNo === '') {
  224. utils.toast('证件号码不能为空')
  225. return
  226. }
  227. if (this.data.claimant === '') {
  228. utils.toast('经办人不能为空')
  229. return
  230. }
  231. if (this.data.getWayIndex === '') {
  232. utils.toast('领票方式不能为空')
  233. return
  234. }
  235. if (this.data.getWayStatus === 2) {
  236. if (this.data.addressee === '') {
  237. utils.toast('收件人不能为空')
  238. return
  239. }
  240. if (this.data.receivingAddress === '') {
  241. utils.toast('快递地址不能为空')
  242. return
  243. }
  244. if (this.data.mobilePhone === '') {
  245. utils.toast('移动电话不能为空')
  246. return
  247. }
  248. if (this.data.fixedTelephone === '') {
  249. utils.toast('固定电话不能为空')
  250. return
  251. }
  252. if (this.data.postalCode === '') {
  253. utils.toast('邮政编码不能为空')
  254. return
  255. }
  256. }
  257. if (this.data.remark === '') {
  258. utils.toast('申请说明不能为空')
  259. return
  260. }
  261. let params = {
  262. entTaxId: this.data.company.entTaxId,
  263. deviceType: this.data.company.defaultDeviceInfo.deviceType,
  264. taxDiscId: this.data.company.defaultDeviceInfo.taxDiscId,
  265. invoiceKindCode: this.data.invoiceTypes[this.data.invoiceTypeIndex].id,
  266. invoiceKindName: this.data.invoiceTypes[this.data.invoiceTypeIndex].name,
  267. invoiceCateCode: this.data.invoiceType[this.data.invoiceTypeIndexs].id,
  268. invoiceCateName: this.data.invoiceType[this.data.invoiceTypeIndexs].name,
  269. applyNum: utils.trimAll(this.data.number),
  270. operatorName: utils.trimAll(this.data.claimant),
  271. paperType: this.data.certType[this.data.certTypeIndex].id,
  272. paperTypeChn: this.data.certType[this.data.certTypeIndex].name,
  273. paperNumber: utils.trimAll(this.data.certNo),
  274. remark: utils.trimAll(this.data.remark),
  275. getWay: this.data.getWayStatus,
  276. receiverName: utils.trimAll(this.data.addressee),
  277. receiverAddress: utils.trimAll(this.data.receivingAddress),
  278. mobilePhoneNumber: utils.trimAll(this.data.mobilePhone),
  279. zipCode: utils.trimAll(this.data.postalCode),
  280. fixedPhoneNumber: utils.trimAll(this.data.fixedTelephone),
  281. mobile: this.data.userInfo.mobile,
  282. reqChannel: 5
  283. }
  284. utils.axios({
  285. method: 'post',
  286. url: '/sys/invoicePurchase/apply',
  287. data: params,
  288. sendBefore() {
  289. wx.showLoading({
  290. title: '申领中...',
  291. mask: true
  292. })
  293. },
  294. complete() {
  295. wx.hideLoading()
  296. },
  297. success: res => {
  298. utils.toast('申领成功')
  299. this.toBack()
  300. }
  301. })
  302. },
  303. //领取方式
  304. setGetWay(e) {
  305. let value = Number(e.detail.value)
  306. let status = ''
  307. if (value === 0) {
  308. status = 1
  309. }
  310. if (value === 1) {
  311. status = 2
  312. }
  313. this.setData({
  314. getWayIndex: value,
  315. getWayStatus: status
  316. })
  317. },
  318. /**
  319. * 生命周期函数--监听页面初次渲染完成
  320. */
  321. onReady: function () {
  322. },
  323. /**
  324. * 生命周期函数--监听页面显示
  325. */
  326. onShow: function () {
  327. },
  328. /**
  329. * 生命周期函数--监听页面隐藏
  330. */
  331. onHide: function () {
  332. },
  333. /**
  334. * 生命周期函数--监听页面卸载
  335. */
  336. onUnload: function () {
  337. },
  338. /**
  339. * 页面相关事件处理函数--监听用户下拉动作
  340. */
  341. onPullDownRefresh: function () {
  342. },
  343. /**
  344. * 页面上拉触底事件的处理函数
  345. */
  346. onReachBottom: function () {
  347. },
  348. /**
  349. * 用户点击右上角分享
  350. */
  351. onShareAppMessage: function () {
  352. }
  353. })