You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
5.2 KiB

1 year ago
  1. // pages/rentDetail/rentDetail.js
  2. const moment = require('../../utils/moment')
  3. const WXAPI = require('../../utils/request')
  4. const QR = require('../../utils/qrcode-base64/weapp-qrcode.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. leases:[],
  11. payment:[],
  12. qrcodeStatus:false,
  13. codeUrl:''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.getApartmentCardInfoMethods()
  20. // let imgData = QR.drawImg('weixin://wxpay/bizpayurl?pr=ke2McSTzz', {
  21. // size: 500
  22. // })
  23. // wx.previewMedia({
  24. // sources: [{url:imgData,type:'image'}], // 需要预览的资源列表
  25. // current: 0, // 当前显示的资源序号
  26. // url: imgData // 当前预览资源的url链接
  27. // })
  28. // this.setData({
  29. // codeUrl:imgData,
  30. // })
  31. },
  32. // 支付
  33. payMentMethods(){
  34. wx.setStorageSync('leases', this.data.leases)
  35. wx.navigateTo({
  36. url: '/pages/paymentInterface/paymentInterface?type=2'
  37. })
  38. return
  39. let deviceinfoList = wx.getStorageSync('deviceinfoList')
  40. var data = {
  41. description: "交租",
  42. productName: "交租",
  43. total: parseInt(this.data.leases.expand.rent)*100,//parseInt(this.data.leases.expand.rent)*100,
  44. userId: deviceinfoList[0].cardId,
  45. cardId:deviceinfoList[0].cardId,
  46. openid:wx.getStorageSync('openid'),
  47. appid:'wx20de9fe5943934a1',
  48. uid:1,
  49. eid:0
  50. }
  51. WXAPI.miniPrepayOrder(data).then(res=>{
  52. wx.requestPayment({
  53. timeStamp: res.data.data.timeStamp,
  54. appid: res.data.data.appId,
  55. nonceStr: res.data.data.nonceStr,
  56. package: res.data.data.package,
  57. signType: res.data.data.signType,
  58. totalFee: parseInt(this.data.leases.expand.rent)*100,
  59. paySign: res.data.data.paySign,
  60. success (res1) {
  61. wx.showToast({
  62. title: "支付成功",
  63. duration: 2000,
  64. icon: 'success'
  65. })
  66. let dataOne={
  67. code: "wx/updatePrepayStatus",
  68. signature:wx.getStorageSync('signature'),
  69. data: {
  70. orderNo: res.data.data.orderNo,
  71. status:0
  72. }
  73. }
  74. WXAPI.sendCommandOne(dataOne).then(res2=>{
  75. })
  76. },
  77. fail (res1) {
  78. wx.showToast({
  79. title: "支付失败",
  80. duration: 2000,
  81. icon: 'none'
  82. })
  83. let dataOne={}
  84. if(res1.errMsg == 'requestPayment:fail cancel'){
  85. dataOne={
  86. code: "wx/updatePrepayStatus",
  87. signature:wx.getStorageSync('signature'),
  88. data: {
  89. orderNo: res.data.data.orderNo,
  90. status:8
  91. }
  92. }
  93. }else{
  94. dataOne={
  95. code: "wx/updatePrepayStatus",
  96. signature:wx.getStorageSync('signature'),
  97. data: {
  98. orderNo: res.data.data.orderNo,
  99. status:6
  100. }
  101. }
  102. }
  103. WXAPI.sendCommandOne(dataOne).then(res2=>{
  104. })
  105. }
  106. })
  107. })
  108. },
  109. // 获取合同信息
  110. getApartmentCardInfoMethods(){
  111. let deviceinfoList = wx.getStorageSync('deviceinfoList')
  112. if(deviceinfoList[0].cardId){
  113. let data={
  114. signature:wx.getStorageSync('signature'),
  115. id:deviceinfoList[0].cardId,
  116. }
  117. WXAPI.getApartmentCardInfo(data).then(res=>{
  118. if(res.success){
  119. let leases = res.data.leases
  120. let payment = res.data.payment
  121. if(leases.length>0){
  122. let getdate = new Date()
  123. let year = getdate.getFullYear()
  124. let month = getdate.getMonth()+1
  125. let leasesObject = leases[leases.length-1]
  126. leasesObject.signingTime = moment(leasesObject.signingTime).format('YYYY-MM-DD')
  127. leasesObject.contractTime = moment(leasesObject.contractTime).format('YYYY-MM-DD')
  128. leasesObject.expand=JSON.parse(leasesObject.expand)
  129. leasesObject.paymentDate = year+'-'+month+'-01'
  130. this.setData({
  131. leases:leases[leases.length-1],
  132. payment:payment
  133. })
  134. }else{
  135. wx.showToast({
  136. title: "还未签订合同",
  137. duration: 2000,
  138. icon: 'none'
  139. })
  140. }
  141. }else{
  142. wx.showToast({
  143. title: "获取合同信息失败",
  144. duration: 2000,
  145. icon: 'none'
  146. })
  147. }
  148. })
  149. }else{
  150. wx.showToast({
  151. title: "还未有对应合同",
  152. duration: 2000,
  153. icon: 'none'
  154. })
  155. }
  156. },
  157. /**
  158. * 生命周期函数--监听页面初次渲染完成
  159. */
  160. onReady: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面显示
  164. */
  165. onShow: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })