zhanw.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. item.occupyBeginTime = item.occupyBeginTime.substr(0,19)
  132. item.occupyEndTime = item.occupyEndTime.substr(0,19)
  133. // 状态翻译
  134. if(item.status==3){
  135. item.occupyStatusCN = '未支付'
  136. }else if(item.status==4){
  137. item.occupyStatusCN = '已支付'
  138. }else if(item.status==6){
  139. item.occupyStatusCN = '已取消'
  140. }else if(item.status==7){
  141. item.occupyStatusCN = '已退款'
  142. };
  143. let customerServiceFlag = false;
  144. let cancleBtnFlag= false;
  145. let height= 'h3';
  146. if(item.status==3){
  147. customerServiceFlag = true;
  148. }
  149. if(item.status==3 || item.status == 4){
  150. cancleBtnFlag = true;
  151. }
  152. item.customerServiceFlag = customerServiceFlag;
  153. item.cancleBtnFlag = cancleBtnFlag;
  154. item.height = height;
  155. //console.log(item.chargPile);
  156. } catch (err) {
  157. //在这里处理错误
  158. }
  159. });
  160. },
  161. startTimeOrder(charginglogs) {
  162. if (charginglogs && 0 != charginglogs.length) {
  163. charginglogs.sort(function(ma, mb) {
  164. return mb.chargstarttime.localeCompare(ma.chargstarttime);
  165. });
  166. }
  167. },
  168. customerServiceBtn(e){
  169. let parkId = e.currentTarget.dataset.idx;
  170. wx.makePhoneCall({
  171. phoneNumber: this.data.servicetel
  172. })
  173. },
  174. payOrder(e) {
  175. log.info('[订单支付]', '[用户触发支付订单]');
  176. wx.showLoading({
  177. title: '支付中...',
  178. mask: true
  179. });
  180. let parkId = e.currentTarget.dataset.idx;
  181. let that = this;
  182. let userId = wx.getStorageSync('userInfo').userId
  183. this.queryOccupyById(userId,parkId).then(res=> {
  184. wx.hideLoading();
  185. let {
  186. order,
  187. } = that.data;
  188. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login请求]');
  189. wx.login({
  190. success(res) {
  191. console.log(res);
  192. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应]',res);
  193. if (res.code) {
  194. // 发起网络请求
  195. log.info('[订单支付]', '[服务端订单支付]', '[请求]', {
  196. outTradeNo: order.orderId, //订单号
  197. totalFee: order.occupyFee, //钱
  198. code: res.code,
  199. user_id: userId
  200. });
  201. wx.request({
  202. url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/occupyFeeOrderPayfor',
  203. data: {
  204. outTradeNo: order.orderId, //订单号
  205. totalFee: order.occupyFee, //钱
  206. code: res.code,
  207. user_id: userId
  208. },
  209. method: 'POST',
  210. header: {
  211. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  212. },
  213. success(res1) {
  214. let {
  215. data
  216. } = res1;
  217. log.info('[订单支付]', '[服务端订单支付]', '[响应]', data);
  218. console.log(res1);
  219. if (data && data.code == 200) {
  220. if (data.result) {
  221. //wx.showModal({
  222. // showCancel: false,
  223. // content: '请微信支付'
  224. // });
  225. log.info('[订单支付]', '[余额不足微信支付]','[请求]',{
  226. timeStamp: data.result.timeStamp,
  227. nonceStr: data.result.nonceStr,
  228. package: data.result.package,
  229. signType: data.result.signType,
  230. paySign: data.result.paySign});
  231. wx.requestPayment({
  232. timeStamp: data.result.timeStamp,
  233. nonceStr: data.result.nonceStr,
  234. package: data.result.package,
  235. signType: data.result.signType,
  236. paySign: data.result.paySign,
  237. success(res2) {
  238. log.info('[订单支付]', '[余额不足微信支付成功]', '[响应]', res2);
  239. log.info('[订单支付]', '[微信支付成功回调服务端]', '[请求]', {
  240. //chargPileId,
  241. //userId,
  242. orderid: order.orderId
  243. });
  244. wx.hideLoading();
  245. wx.showModal({
  246. showCancel: false,
  247. content: '支付订单成功',
  248. confirmColor:'#00AADD',
  249. success(res) {
  250. if (res.confirm) {
  251. that.resetListZero();
  252. that.getPage();
  253. }
  254. }
  255. });
  256. },
  257. fail(res3) {
  258. wx.hideLoading();
  259. log.info('[订单支付]', '[余额不足微信支付]', '[fail]', res3);
  260. console.log(res3);
  261. }
  262. });
  263. } else {
  264. wx.hideLoading();
  265. that.setData({
  266. orderFlag: true
  267. });
  268. wx.showModal({
  269. showCancel: false,
  270. content: data.msg,
  271. confirmColor:'#00AADD',
  272. });
  273. }
  274. log.info('[订单支付]', '[服务端订单支付]', '[余额支付成功]', data);
  275. } else {
  276. wx.hideLoading();
  277. wx.showModal({
  278. showCancel: false,
  279. content: data.msg,
  280. confirmColor:'#00AADD',
  281. });
  282. log.info('[订单支付]', '[服务端订单支付]', '[失败data null||data.code<>200]', data);
  283. }
  284. }
  285. });
  286. } else {
  287. wx.hideLoading();
  288. console.log('登录失败!' + res.errMsg);
  289. log.info('[订单支付]', '[用户触发支付订单]', '[wx.login响应失败code null]', res);
  290. }
  291. }
  292. });
  293. })
  294. },
  295. queryOccupyById(userId,parkId) {
  296. return new Promise((resolve, reject) => {
  297. let that = this;
  298. wx.request({
  299. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/queryOccupyById',
  300. data: {
  301. userId: userId,
  302. id:parkId,
  303. searchIndex: 3 // 未支付
  304. },
  305. method: 'POST',
  306. success(res) {
  307. if (res.data.code == 200) {
  308. console.log("更具订单号插叙",res.data.result);
  309. that.setData({
  310. order:res.data.result
  311. })
  312. resolve(res.data.result);
  313. }else{
  314. resolve(res.data);
  315. }
  316. },
  317. fail(err) {
  318. console.error('请求失败', err);
  319. reject(err);
  320. }
  321. });
  322. });
  323. },
  324. cancleBtn(e){
  325. let that = this
  326. let reservId = e.currentTarget.dataset.idx;
  327. let userInfo = wx.getStorageSync('userInfo');
  328. let isLogin = wx.getStorageSync('isLogin');
  329. wx.showModal({
  330. title: '提示',
  331. confirmColor: '#00AADD',
  332. content: '若对当前占位费订单有疑问,请拨打客服电话4009608068,工作时间:08:00-18:00',
  333. complete: (res) => {
  334. // 可以在这里添加回调逻辑
  335. if (res.confirm) {
  336. console.log('用户点击了确认按钮');
  337. }else{
  338. console.log('用户点击了取消按钮');
  339. }
  340. }
  341. });
  342. },
  343. cancelM:function(e){
  344. this.setData({
  345. hiddenmodalput: true,
  346. })
  347. },
  348. iName: function (e) {
  349. this.setData({
  350. name:e.detail.value
  351. })
  352. },
  353. iPhoneNum: function (e) {
  354. this.setData({
  355. phoneNum: e.detail.value
  356. })
  357. },
  358. /**
  359. * 生命周期函数--监听页面初次渲染完成
  360. */
  361. onReady: function() {
  362. },
  363. /**
  364. * 生命周期函数--监听页面显示
  365. */
  366. onShow: function() {
  367. },
  368. /**
  369. * 生命周期函数--监听页面隐藏
  370. */
  371. onHide: function() {
  372. },
  373. /**
  374. * 生命周期函数--监听页面卸载
  375. */
  376. onUnload: function() {
  377. },
  378. /**
  379. * 页面相关事件处理函数--监听用户下拉动作
  380. */
  381. onPullDownRefresh: function() {
  382. },
  383. /**
  384. * 页面上拉触底事件的处理函数
  385. */
  386. onReachBottom: function() {
  387. },
  388. bindScrollTolowerEvent: function(){
  389. this.getPage();
  390. },
  391. /**
  392. * 用户点击右上角分享
  393. */
  394. onShareAppMessage: function() {
  395. }
  396. })