zhanw.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // pages/ucenter/zhanw/zhanw.js
  2. let Util = require("../../../utils/util");
  3. let log = require('../../../utils/log.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. searchIndex:-1,
  10. occupyFeeOrderList: [],
  11. pagesize:10,
  12. pagenum:1,
  13. total:-1,
  14. loadTotal: 0,
  15. dataLoading: false,
  16. finishedLoadTap: 0,
  17. finishedLoadShowTimes: 0,
  18. customerServiceFlag: false,
  19. cancleBtnFlag: false,
  20. servicetel: getApp().globalData.helpPhoneNum,
  21. orderid: null,
  22. userId: null,
  23. order: {},
  24. },
  25. switchBar(e){
  26. let searchIndex = e.currentTarget.dataset.idx;
  27. this.setData({
  28. searchIndex
  29. })
  30. this.resetListZero();
  31. this.getPage();
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function(options) {
  37. let userInfo = wx.getStorageSync('userInfo');
  38. let isLogin = wx.getStorageSync('isLogin');
  39. let that = this;
  40. // 页面显示
  41. if (userInfo && isLogin) {
  42. this.resetListZero();
  43. this.getPage();
  44. }
  45. },
  46. resetListZero(){
  47. let occupyFeeOrderList = []
  48. let pagesize = 10
  49. let pagenum = 1
  50. let total = -1
  51. let loadTotal = 0
  52. let dataLoading = false
  53. let finishedLoadTap = 0
  54. let finishedLoadShowTimes = 0
  55. this.setData({
  56. occupyFeeOrderList,
  57. pagesize,
  58. pagenum,
  59. total,
  60. loadTotal,
  61. dataLoading,
  62. finishedLoadTap,
  63. finishedLoadShowTimes,
  64. })
  65. },
  66. getPage(){
  67. // console.info(this.data.occupyFeeOrderList.length + " MMM " + this.data.total)
  68. if(this.data.occupyFeeOrderList.length == this.data.total){
  69. this.setData({
  70. finishedLoadTap:this.data.finishedLoadTap+1
  71. })
  72. if(this.data.finishedLoadTap>0 && this.data.finishedLoadShowTimes==0){
  73. this.setData({
  74. finishedLoadShowTimes:this.data.finishedLoadShowTimes+1
  75. })
  76. wx.showToast({
  77. title: '全部加载完毕',
  78. icon: 'success',
  79. duration: 2000
  80. })
  81. }
  82. return
  83. }
  84. if(this.data.dataLoading){
  85. return
  86. }
  87. this.setData({
  88. dataLoading: true
  89. })
  90. wx.showLoading({
  91. title: '数据加载中....',
  92. })
  93. this.queryOccupyFeeOrder();
  94. },
  95. queryOccupyFeeOrder(){
  96. let that = this;
  97. wx.request({
  98. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyFeeOrder',
  99. data: {
  100. userId: wx.getStorageSync('userInfo').userId,
  101. searchIndex: that.data.searchIndex<0?-1:that.data.searchIndex,
  102. pagenum: this.data.pagenum++,
  103. pagesize: 10,
  104. },
  105. method: 'POST',
  106. success(res) {
  107. console.log("占位费",res);
  108. if (res.data.code == 200) {
  109. let {
  110. rows: occupyFeeOrderList
  111. } = res.data.result;
  112. // that.startTimeOrder(charginglogs);
  113. that.formatCharginglogs(occupyFeeOrderList);
  114. wx.hideLoading()
  115. that.setData({
  116. occupyFeeOrderList: that.data.occupyFeeOrderList.concat(occupyFeeOrderList),
  117. total: res.data.result.total,
  118. dataLoading: false
  119. });
  120. }else{
  121. wx.hideLoading()
  122. }
  123. }
  124. });
  125. },
  126. formatCharginglogs(formatCharginglogs) {
  127. formatCharginglogs.forEach((item, index) => {
  128. try {
  129. // console.log("item",item);
  130. // 时间截取
  131. if (item.occupyBeginTime != null && item.occupyEndTime != null) {
  132. item.occupyBeginTime = item.occupyBeginTime.substr(0,19)
  133. item.occupyEndTime = item.occupyEndTime.substr(0,19)
  134. }
  135. // 状态翻译
  136. if(item.status==3){
  137. item.occupyStatusCN = '未支付'
  138. }else if(item.status==4){
  139. item.occupyStatusCN = '已支付'
  140. }else if(item.status==6){
  141. item.occupyStatusCN = '已取消'
  142. }else if(item.status==7){
  143. item.occupyStatusCN = '已退款'
  144. };
  145. let customerServiceFlag = false;
  146. let cancleBtnFlag= false;
  147. let height= 'h3';
  148. if(item.status==3){
  149. customerServiceFlag = true;
  150. }
  151. if(item.status==3 || item.status == 4){
  152. cancleBtnFlag = true;
  153. }
  154. item.customerServiceFlag = customerServiceFlag;
  155. item.cancleBtnFlag = cancleBtnFlag;
  156. item.height = height;
  157. //console.log(item.chargPile);
  158. } catch (err) {
  159. //在这里处理错误
  160. }
  161. });
  162. },
  163. startTimeOrder(charginglogs) {
  164. if (charginglogs && 0 != charginglogs.length) {
  165. charginglogs.sort(function(ma, mb) {
  166. return mb.chargstarttime.localeCompare(ma.chargstarttime);
  167. });
  168. }
  169. },
  170. customerServiceBtn(e){
  171. let parkId = e.currentTarget.dataset.idx;
  172. wx.makePhoneCall({
  173. phoneNumber: this.data.servicetel
  174. })
  175. },
  176. payOrder(e) {
  177. log.info('[订单支付]', '[用户触发支付订单]');
  178. wx.showLoading({
  179. title: '支付中...',
  180. mask: true
  181. });
  182. let parkId = e.currentTarget.dataset.idx;
  183. let that = this;
  184. let userId = wx.getStorageSync('userInfo').userId
  185. this.queryOccupyById(userId,parkId).then(res=> {
  186. wx.hideLoading();
  187. let {
  188. order,
  189. } = that.data;
  190. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login请求]');
  191. wx.login({
  192. success(res) {
  193. console.log(res);
  194. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应]',res);
  195. if (res.code) {
  196. // 发起网络请求
  197. log.info('[订单支付]', '[服务端订单支付]', '[请求]', {
  198. outTradeNo: order.orderId, //订单号
  199. totalFee: order.occupyFee, //钱
  200. code: res.code,
  201. user_id: userId
  202. });
  203. wx.request({
  204. url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/occupyFeeOrderPayfor',
  205. data: {
  206. outTradeNo: order.orderId, //订单号
  207. totalFee: order.occupyFee, //钱
  208. code: res.code,
  209. user_id: userId
  210. },
  211. method: 'POST',
  212. header: {
  213. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  214. },
  215. success(res1) {
  216. let {
  217. data
  218. } = res1;
  219. log.info('[订单支付]', '[服务端订单支付]', '[响应]', data);
  220. console.log(res1);
  221. if (data && data.code == 200) {
  222. if (data.result) {
  223. //wx.showModal({
  224. // showCancel: false,
  225. // content: '请微信支付'
  226. // });
  227. log.info('[订单支付]', '[余额不足微信支付]','[请求]',{
  228. timeStamp: data.result.timeStamp,
  229. nonceStr: data.result.nonceStr,
  230. package: data.result.package,
  231. signType: data.result.signType,
  232. paySign: data.result.paySign});
  233. wx.requestPayment({
  234. timeStamp: data.result.timeStamp,
  235. nonceStr: data.result.nonceStr,
  236. package: data.result.package,
  237. signType: data.result.signType,
  238. paySign: data.result.paySign,
  239. success(res2) {
  240. log.info('[订单支付]', '[余额不足微信支付成功]', '[响应]', res2);
  241. log.info('[订单支付]', '[微信支付成功回调服务端]', '[请求]', {
  242. //chargPileId,
  243. //userId,
  244. orderid: order.orderId
  245. });
  246. wx.hideLoading();
  247. wx.showModal({
  248. showCancel: false,
  249. content: '支付订单成功',
  250. confirmColor:'#00AADD',
  251. success(res) {
  252. if (res.confirm) {
  253. that.resetListZero();
  254. that.getPage();
  255. }
  256. }
  257. });
  258. },
  259. fail(res3) {
  260. wx.hideLoading();
  261. log.info('[订单支付]', '[余额不足微信支付]', '[fail]', res3);
  262. console.log(res3);
  263. }
  264. });
  265. } else {
  266. wx.hideLoading();
  267. that.setData({
  268. orderFlag: true
  269. });
  270. wx.showModal({
  271. showCancel: false,
  272. content: data.msg,
  273. confirmColor:'#00AADD',
  274. success(res) {
  275. if (res.confirm) {
  276. that.resetListZero();
  277. that.getPage();
  278. }
  279. }
  280. });
  281. }
  282. log.info('[订单支付]', '[服务端订单支付]', '[余额支付成功]', data);
  283. } else {
  284. wx.hideLoading();
  285. wx.showModal({
  286. showCancel: false,
  287. content: data.msg,
  288. confirmColor:'#00AADD',
  289. });
  290. log.info('[订单支付]', '[服务端订单支付]', '[失败data null||data.code<>200]', data);
  291. }
  292. }
  293. });
  294. } else {
  295. wx.hideLoading();
  296. console.log('登录失败!' + res.errMsg);
  297. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应失败code null]', res);
  298. }
  299. }
  300. });
  301. })
  302. },
  303. queryOccupyById(userId,parkId) {
  304. return new Promise((resolve, reject) => {
  305. let that = this;
  306. wx.request({
  307. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyById',
  308. data: {
  309. userId: userId,
  310. id:parkId,
  311. searchIndex: 3 // 未支付
  312. },
  313. method: 'POST',
  314. success(res) {
  315. if (res.data.code == 200) {
  316. console.log("更具订单号插叙",res.data.result);
  317. that.setData({
  318. order:res.data.result
  319. })
  320. resolve(res.data.result);
  321. }else{
  322. resolve(res.data);
  323. }
  324. },
  325. fail(err) {
  326. console.error('请求失败', err);
  327. reject(err);
  328. }
  329. });
  330. });
  331. },
  332. cancleBtn(e){
  333. let that = this
  334. let reservId = e.currentTarget.dataset.idx;
  335. let userInfo = wx.getStorageSync('userInfo');
  336. let isLogin = wx.getStorageSync('isLogin');
  337. wx.showModal({
  338. title: '提示',
  339. confirmColor: '#00AADD',
  340. confirmText: '联系客服',
  341. content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-17:00',
  342. complete: (res) => {
  343. // 可以在这里添加回调逻辑
  344. if (res.confirm) {
  345. wx.makePhoneCall({
  346. phoneNumber: '4009608068' // 替换为实际的客服电话
  347. });
  348. console.log('用户点击了确认按钮');
  349. }else{
  350. console.log('用户点击了取消按钮');
  351. }
  352. }
  353. });
  354. },
  355. cancelM:function(e){
  356. this.setData({
  357. hiddenmodalput: true,
  358. })
  359. },
  360. iName: function (e) {
  361. this.setData({
  362. name:e.detail.value
  363. })
  364. },
  365. iPhoneNum: function (e) {
  366. this.setData({
  367. phoneNum: e.detail.value
  368. })
  369. },
  370. /**
  371. * 生命周期函数--监听页面初次渲染完成
  372. */
  373. onReady: function() {
  374. },
  375. /**
  376. * 生命周期函数--监听页面显示
  377. */
  378. onShow: function() {
  379. },
  380. /**
  381. * 生命周期函数--监听页面隐藏
  382. */
  383. onHide: function() {
  384. },
  385. /**
  386. * 生命周期函数--监听页面卸载
  387. */
  388. onUnload: function() {
  389. },
  390. /**
  391. * 页面相关事件处理函数--监听用户下拉动作
  392. */
  393. onPullDownRefresh: function() {
  394. },
  395. /**
  396. * 页面上拉触底事件的处理函数
  397. */
  398. onReachBottom: function() {
  399. },
  400. bindScrollTolowerEvent: function(){
  401. this.getPage();
  402. },
  403. /**
  404. * 用户点击右上角分享
  405. */
  406. onShareAppMessage: function() {
  407. }
  408. })