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.

351 lines
9.9 KiB

1 year ago
  1. // pages/paymentInterface/paymentInterface.js
  2. const WXAPI = require('../../utils/request')
  3. const moment = require('../../utils/moment')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. radio:'0',
  10. leases:{},
  11. type:''
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. if(options.type){
  18. this.setData({
  19. type:options.type
  20. })
  21. }
  22. let leases = wx.getStorageSync('leases')
  23. leases.timePeriod = moment(leases.signingTime).format('YYYY-MM-DD')+'~'+moment(leases.contractTime).format('YYYY-MM-DD')
  24. leases.dueDate = moment(leases.dueDate).format('YYYY-MM-DD')
  25. this.setData({
  26. leases
  27. })
  28. },
  29. onClick(event) {
  30. const { name } = event.currentTarget.dataset;
  31. this.setData({
  32. radio: name,
  33. });
  34. },
  35. payMentMethods(){
  36. let deviceinfoList = wx.getStorageSync('deviceinfoList')
  37. if(this.data.type == 1){
  38. let leases =this.data.leases
  39. let userInfo = wx.getStorageSync('userInfo')
  40. var data = {
  41. description: "交租",
  42. productName: "交租",
  43. total: parseInt(leases.monthRent)*100,//parseInt(this.data.leases.expand.rent)*100,
  44. userId: leases.cardId,
  45. cardId:leases.cardId,
  46. openid:wx.getStorageSync('openid'),
  47. appid:'wx20de9fe5943934a1',
  48. uid:userInfo.id,
  49. eid:userInfo.enterpriseId,
  50. orderType:1,
  51. payType:this.data.radio,
  52. expand:JSON.stringify({
  53. phone:leases.phone,
  54. nickname:leases.name
  55. })
  56. }
  57. WXAPI.miniPrepayOrder(data).then(res=>{
  58. if(res.data.success){
  59. if(this.data.radio == '0'){
  60. if(parseInt(leases.monthRent) === 0){
  61. wx.showToast({
  62. title: "支付成功",
  63. duration: 2000,
  64. icon: 'success'
  65. })
  66. let dataOne={
  67. code: "wx/updatePrepayStatus",
  68. cardId:leases.cardId,
  69. signature:wx.getStorageSync('signature'),
  70. data: {
  71. orderNo: res.data.data.orderNo,
  72. status:0
  73. }
  74. }
  75. WXAPI.sendCommandOne(dataOne).then(res2=>{
  76. wx.navigateTo({
  77. url: '/pages/rentManagement/rentManagement',
  78. })
  79. })
  80. return false;
  81. }
  82. wx.requestPayment({
  83. timeStamp: res.data.data.timeStamp,
  84. appid: res.data.data.appId,
  85. nonceStr: res.data.data.nonceStr,
  86. package: res.data.data.package,
  87. signType: res.data.data.signType,
  88. totalFee: parseInt(leases.monthRent)*100,
  89. paySign: res.data.data.paySign,
  90. success (res1) {
  91. wx.showToast({
  92. title: "支付成功",
  93. duration: 2000,
  94. icon: 'success'
  95. })
  96. let dataOne={
  97. code: "wx/updatePrepayStatus",
  98. cardId:leases.cardId,
  99. signature:wx.getStorageSync('signature'),
  100. data: {
  101. orderNo: res.data.data.orderNo,
  102. status:0
  103. }
  104. }
  105. WXAPI.sendCommandOne(dataOne).then(res2=>{
  106. wx.navigateTo({
  107. url: '/pages/rentManagement/rentManagement',
  108. })
  109. })
  110. },
  111. fail (res1) {
  112. wx.showToast({
  113. title: "支付失败",
  114. duration: 2000,
  115. icon: 'none'
  116. })
  117. let dataOne={}
  118. if(res1.errMsg == 'requestPayment:fail cancel'){
  119. dataOne={
  120. code: "wx/updatePrepayStatus",
  121. signature:wx.getStorageSync('signature'),
  122. data: {
  123. orderNo: res.data.data.orderNo,
  124. status:8
  125. }
  126. }
  127. }else{
  128. dataOne={
  129. code: "wx/updatePrepayStatus",
  130. cardId:leases.cardId,
  131. signature:wx.getStorageSync('signature'),
  132. data: {
  133. orderNo: res.data.data.orderNo,
  134. status:6
  135. }
  136. }
  137. }
  138. WXAPI.sendCommandOne(dataOne).then(res2=>{
  139. })
  140. }
  141. })
  142. }else{
  143. let dataOne={
  144. code: "wx/updatePrepayStatus",
  145. data: {
  146. orderNo: res.data.data.orderNo,
  147. status:0
  148. }
  149. }
  150. WXAPI.sendCommand(dataOne).then(res2=>{
  151. if(res2.success){
  152. wx.navigateTo({
  153. url: '/pages/rentManagement/rentManagement',
  154. })
  155. wx.showToast({
  156. title: "支付成功",
  157. duration: 2000,
  158. icon: 'success'
  159. })
  160. }else{
  161. wx.showToast({
  162. title: res2.message,
  163. duration: 2000,
  164. icon: 'error'
  165. })
  166. }
  167. })
  168. }
  169. }else{
  170. wx.showToast({
  171. title: `支付失败:${res.data.msg}`,
  172. duration: 2000,
  173. icon: 'success'
  174. })
  175. }
  176. })
  177. }else if(this.data.type == 2){
  178. let leases =this.data.leases
  179. if(this.data.radio == ''){
  180. wx.showToast({
  181. title: '请选择支付方式',
  182. icon:'none',
  183. duration:2000
  184. })
  185. }
  186. var data = {
  187. description: "交租",
  188. productName: "交租",
  189. total: parseInt(this.data.leases.monthRent)*100,//parseInt(this.data.leases.expand.rent)*100,
  190. userId: deviceinfoList[0].cardId,
  191. cardId:deviceinfoList[0].cardId,
  192. openid:wx.getStorageSync('openid'),
  193. appid:'wx20de9fe5943934a1',
  194. uid:1,
  195. eid:this.data.leases.enterpriseId,
  196. payType:this.data.radio,
  197. orderType:1,
  198. expand:JSON.stringify({
  199. phone:this.data.leases.phone,
  200. nickname:this.data.leases.name
  201. })
  202. }
  203. WXAPI.miniPrepayOrder(data).then(res=>{
  204. if(parseInt(leases.monthRent) === 0){
  205. wx.showToast({
  206. title: "支付成功",
  207. duration: 2000,
  208. icon: 'success'
  209. })
  210. let dataOne={
  211. code: "wx/updatePrepayStatus",
  212. signature:wx.getStorageSync('signature'),
  213. cardId:this.data.leases.cardId,
  214. data: {
  215. orderNo: res.data.data.orderNo,
  216. status:0
  217. }
  218. }
  219. WXAPI.sendCommandOne(dataOne).then(res2=>{
  220. wx.showToast({
  221. title: '支付成功',
  222. duration:2000
  223. })
  224. wx.navigateTo({
  225. url: '/pages/rentDetail/rentDetail',
  226. })
  227. })
  228. }else{
  229. wx.requestPayment({
  230. timeStamp: res.data.data.timeStamp,
  231. appid: res.data.data.appId,
  232. nonceStr: res.data.data.nonceStr,
  233. package: res.data.data.package,
  234. signType: res.data.data.signType,
  235. totalFee: parseInt(this.data.leases.monthRentt)*100,
  236. paySign: res.data.data.paySign,
  237. success (res1) {
  238. wx.showToast({
  239. title: "支付成功",
  240. duration: 2000,
  241. icon: 'success'
  242. })
  243. let dataOne={
  244. code: "wx/updatePrepayStatus",
  245. signature:wx.getStorageSync('signature'),
  246. cardId:this.data.leases.cardId,
  247. data: {
  248. orderNo: res.data.data.orderNo,
  249. status:0
  250. }
  251. }
  252. WXAPI.sendCommandOne(dataOne).then(res2=>{
  253. wx.showToast({
  254. title: '支付成功',
  255. duration:2000
  256. })
  257. wx.navigateTo({
  258. url: '/pages/rentDetail/rentDetail',
  259. })
  260. })
  261. },
  262. fail (res1) {
  263. wx.showToast({
  264. title: "支付失败",
  265. duration: 2000,
  266. icon: 'none'
  267. })
  268. let dataOne={}
  269. if(res1.errMsg == 'requestPayment:fail cancel'){
  270. dataOne={
  271. code: "wx/updatePrepayStatus",
  272. signature:wx.getStorageSync('signature'),
  273. data: {
  274. orderNo: res.data.data.orderNo,
  275. status:8
  276. }
  277. }
  278. }else{
  279. dataOne={
  280. code: "wx/updatePrepayStatus",
  281. signature:wx.getStorageSync('signature'),
  282. cardId:this.data.leases.cardId,
  283. data: {
  284. orderNo: res.data.data.orderNo,
  285. status:6
  286. }
  287. }
  288. }
  289. WXAPI.sendCommandOne(dataOne).then(res2=>{
  290. wx.navigateTo({
  291. url: '/pages/rentDetail/rentDetail',
  292. })
  293. })
  294. }
  295. })
  296. }
  297. })
  298. }
  299. },
  300. /**
  301. * 生命周期函数--监听页面初次渲染完成
  302. */
  303. onReady: function () {
  304. },
  305. /**
  306. * 生命周期函数--监听页面显示
  307. */
  308. onShow: function () {
  309. },
  310. /**
  311. * 生命周期函数--监听页面隐藏
  312. */
  313. onHide: function () {
  314. },
  315. /**
  316. * 生命周期函数--监听页面卸载
  317. */
  318. onUnload: function () {
  319. },
  320. /**
  321. * 页面相关事件处理函数--监听用户下拉动作
  322. */
  323. onPullDownRefresh: function () {
  324. },
  325. /**
  326. * 页面上拉触底事件的处理函数
  327. */
  328. onReachBottom: function () {
  329. },
  330. /**
  331. * 用户点击右上角分享
  332. */
  333. onShareAppMessage: function () {
  334. }
  335. })