operate.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import { FunCode } from "../../../../constants/enum/funcode"
  2. import { protoHeader, userid, isEncrypted, timetample } from "../../../../services/utils"
  3. import { sendMsgToMQ } from "../../../../services/api/common/index"
  4. import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast"
  5. // mMine/pages/invoice/operate/operate.ts
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. /// 1个人 2企业
  12. type: 1,
  13. /// 发票抬头
  14. inname: '',
  15. /// 税号
  16. inno: '',
  17. /// 开户银行
  18. bankname: '',
  19. /// 银行账号
  20. bankno: '',
  21. /// 企业地址
  22. inaddress: '',
  23. /// 企业电话
  24. inmobile: '',
  25. /// 自增id
  26. autoid: 0,
  27. /// 发票类型
  28. intypes: ["个人", "企业"],
  29. /// 是否发票类型
  30. show: false
  31. },
  32. /**
  33. * 返回上层视图
  34. */
  35. backToParent() {
  36. /// 返回上层视图
  37. wx.navigateBack()
  38. },
  39. /// 关闭地址选择组件
  40. onCancel(event: any) {
  41. const { index } = event.detail
  42. /// 关闭
  43. this.setData({ show: false, type: index+1 })
  44. },
  45. /// 合规性校验
  46. check(): boolean {
  47. /// 请输入发票抬头
  48. if (this.data.inname.length == 0) {
  49. Toast.fail('请输入发票抬头!')
  50. return false
  51. }
  52. /// 请输入纳税人识别号
  53. if (this.data.inno.length == 0 && this.data.type != 1) {
  54. Toast.fail('请输入纳税人识别号!')
  55. return false
  56. }
  57. return true
  58. },
  59. /**
  60. * 业务操作
  61. */
  62. userReceiptInfoReq() {
  63. /// 合规性校验
  64. if (!this.check()) { return }
  65. /// loding.....
  66. Toast.loading('操作请求中......')
  67. /// 参数信息
  68. const userInfo = { ClientSerialID: timetample(),
  69. UserID: userid(),
  70. UserName: this.data.inname,
  71. ReceiptType: this.data.type,
  72. TaxpayerID: this.data.inno,
  73. Address: this.data.inaddress,
  74. ReceiptBank: this.data.bankname,
  75. ReceiptAccount: this.data.bankno,
  76. ReceiptInfoId: this.data.autoid,
  77. ContactInfo: this.data.inmobile,
  78. Header: protoHeader(FunCode.UserReceiptInfoReq)
  79. }
  80. /// 发送请求
  81. sendMsgToMQ({
  82. data: {
  83. data: JSON.stringify(userInfo),
  84. funCodeReq: FunCode.UserReceiptInfoReq,
  85. funCodeRsp: FunCode.UserReceiptInfoReq,
  86. isEncrypted: isEncrypted()
  87. },
  88. success: (res) => {
  89. /// 操作失败
  90. if (res.code != 0) {
  91. Toast.fail('操作失败,原因:'+res.msg)
  92. return
  93. }
  94. /// 操作成功
  95. Toast.success('操作成功')
  96. /// 返回上层视图
  97. wx.navigateBack()
  98. },
  99. fail: (emsg) => {
  100. /// 操作失败
  101. Toast.fail('操作失败,原因:'+emsg)
  102. }, complete: () => {
  103. /// hideLoading
  104. Toast.clear()
  105. }
  106. })
  107. },
  108. /**
  109. * 删除发票信息
  110. */
  111. deleteUserReceiptInfoReqReq() {
  112. /// loding.....
  113. Toast.loading('删除操作请求中......')
  114. /// 参数信息
  115. const userInfo = {
  116. ReceiptInfoId: this.data.autoid,
  117. Header: protoHeader(FunCode.DelUserReceiptInfoReq)
  118. }
  119. /// 发送请求
  120. sendMsgToMQ({
  121. data: {
  122. data: JSON.stringify(userInfo),
  123. funCodeReq: FunCode.DelUserReceiptInfoReq,
  124. funCodeRsp: FunCode.DelUserReceiptInfoRsp,
  125. isEncrypted: isEncrypted()
  126. },
  127. success: (res) => {
  128. /// 操作失败
  129. if (res.code != 0) {
  130. Toast.fail('删除操作失败,原因:'+res.msg)
  131. return
  132. }
  133. /// 操作成功
  134. Toast.success('操作成功')
  135. /// 返回上层视图
  136. wx.navigateBack()
  137. },
  138. fail: (emsg) => {
  139. /// 操作失败
  140. Toast.fail('删除操作失败,原因:'+emsg)
  141. }, complete: () => {
  142. /// hideLoading
  143. Toast.clear()
  144. }
  145. })
  146. },
  147. /**
  148. * 按钮点击响应事件
  149. */
  150. onButtonPressed(e: any) {
  151. switch (e.target.id) {
  152. case "type-selsct": /// 类型选择
  153. /// 显示
  154. this.setData({ show: true })
  155. break;
  156. case 'delete': /// 删除
  157. this.deleteUserReceiptInfoReqReq()
  158. break;
  159. default:
  160. /// 发送业务操作
  161. this.userReceiptInfoReq()
  162. break;
  163. }
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad(options: any) {
  169. /// 传参信息
  170. const d: GuangZuan.WrUserReceiptInfo = JSON.parse(options.id ?? '')
  171. this.setData({
  172. inname: d.username,
  173. inmobile: d.contactinfo,
  174. inno: d.taxpayerid,
  175. autoid: d.autoid,
  176. inaddress: d.address,
  177. bankno: d.receiptaccount,
  178. bankname: d.receiptbank,
  179. type: d.receipttype
  180. })
  181. },
  182. /**
  183. * 生命周期函数--监听页面初次渲染完成
  184. */
  185. onReady() {
  186. },
  187. /**
  188. * 生命周期函数--监听页面显示
  189. */
  190. onShow() {
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide() {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload() {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh() {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom() {
  211. },
  212. /**
  213. * 用户点击右上角分享
  214. */
  215. onShareAppMessage() {
  216. }
  217. })