yuyt.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // pages/ucenter/charginglog/charginglog.js
  2. let Util = require("../../../utils/util");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchIndex:-1,
  9. reservUserOrderList: [],
  10. pagesize:10,
  11. pagenum:1,
  12. total:-1,
  13. loadTotal: 0,
  14. dataLoading: false,
  15. finishedLoadTap: 0,
  16. finishedLoadShowTimes: 0,
  17. chongdianzhuangmingcheng: false,
  18. chongdianzhuangbianhao: false,
  19. chongdianshichang: false,
  20. chongdiankaishijieshu: false,
  21. customerServiceFlag: false,
  22. cancleBtnFlag: false,
  23. servicetel: getApp().globalData.helpPhoneNum,
  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 reservUserOrderList = []
  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. reservUserOrderList,
  57. pagesize,
  58. pagenum,
  59. total,
  60. loadTotal,
  61. dataLoading,
  62. finishedLoadTap,
  63. finishedLoadShowTimes,
  64. })
  65. },
  66. getPage(){
  67. // console.info(this.data.reservUserOrderList.length + " MMM " + this.data.total)
  68. if(this.data.reservUserOrderList.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. let that = this;
  94. wx.request({
  95. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ReservUserOrder',
  96. data: {
  97. userId: wx.getStorageSync('userInfo').userId,
  98. searchIndex: that.data.searchIndex<0?null:that.data.searchIndex,
  99. pagenum: this.data.pagenum++,
  100. pagesize: 10,
  101. },
  102. method: 'POST',
  103. success(res) {
  104. console.log(res);
  105. if (res.data.result.rows) {
  106. let {
  107. rows: reservUserOrderList
  108. } = res.data.result;
  109. // that.startTimeOrder(charginglogs);
  110. that.formatCharginglogs(reservUserOrderList);
  111. wx.hideLoading()
  112. that.setData({
  113. reservUserOrderList: that.data.reservUserOrderList.concat(reservUserOrderList),
  114. total: res.data.result.total,
  115. dataLoading: false
  116. });
  117. }
  118. }
  119. });
  120. },
  121. formatCharginglogs(formatCharginglogs) {
  122. formatCharginglogs.forEach((item, index) => {
  123. try {
  124. // 时间截取
  125. item.reservChargeStartTime = item.reservChargeStartTime.substr(0,16)
  126. item.reservChargeEndTime = item.reservChargeEndTime.substr(0,16)
  127. // 状态翻译
  128. if(item.reservStatus==0){
  129. item.reservStatusCN = '待履约'
  130. }else if(item.reservStatus==1){
  131. item.reservStatusCN = '已取消'
  132. }else if(item.reservStatus==2){
  133. item.reservStatusCN = '已履约'
  134. }else if(item.reservStatus==3){
  135. item.reservStatusCN = '已违约'
  136. }else if(item.reservStatus==4){
  137. item.reservStatusCN = '已纠正'
  138. };
  139. // 判断标记为 chongdianzhuangmingcheng chongdianzhuangbianhao chongdianshichang chongdiankaishijieshu
  140. let chongdianzhuangmingcheng = false
  141. let chongdianzhuangbianhao = false
  142. let chongdianshichang = false
  143. let chongdiankaishijieshu = false
  144. let chongdianfeiyong = false
  145. let customerServiceFlag = false;
  146. let cancleBtnFlag= false;
  147. let height= 'h4';
  148. if(item.reservStatus==2){
  149. // 已履约
  150. if(item?.pileLog?.transstatus == 3){
  151. if(item?.pileLog?.chargPileId == item?.reservPile?.chargPileId){
  152. chongdianzhuangmingcheng = false
  153. chongdianzhuangbianhao = false
  154. chongdianshichang = true
  155. chongdiankaishijieshu = true
  156. chongdianfeiyong = true
  157. height= 'h1';
  158. }else{
  159. chongdianzhuangmingcheng = true
  160. chongdianzhuangbianhao = true
  161. chongdianshichang = true
  162. chongdiankaishijieshu = true
  163. chongdianfeiyong = true
  164. height= 'h2';
  165. }
  166. }else{
  167. if(item?.pileLog?.chargPileId == item?.reservPile?.chargPileId){
  168. chongdianzhuangmingcheng = false
  169. chongdianzhuangbianhao = false
  170. chongdianshichang = false
  171. chongdiankaishijieshu = false
  172. chongdianfeiyong = false
  173. height= 'h4';
  174. }else{
  175. chongdianzhuangmingcheng = true
  176. chongdianzhuangbianhao = true
  177. chongdianshichang = false
  178. chongdiankaishijieshu = false
  179. chongdianfeiyong = false
  180. height= 'h3';
  181. }
  182. }
  183. }
  184. if(item.reservStatus==3){
  185. customerServiceFlag = true;
  186. }
  187. if(item.reservStatus==0){
  188. cancleBtnFlag = true;
  189. }
  190. item.chongdianzhuangmingcheng = chongdianzhuangmingcheng;
  191. item.chongdianzhuangbianhao = chongdianzhuangbianhao;
  192. item.chongdianshichang = chongdianshichang;
  193. item.chongdiankaishijieshu = chongdiankaishijieshu;
  194. item.chongdianfeiyong = chongdianfeiyong;
  195. item.customerServiceFlag = customerServiceFlag;
  196. item.cancleBtnFlag = cancleBtnFlag;
  197. item.height = height;
  198. //console.log(item.chargPile);
  199. } catch (err) {
  200. //在这里处理错误
  201. }
  202. try {
  203. let chargePile = item.pileLog;
  204. console.info(chargePile)
  205. let startDate = Util.parseDate(chargePile.chargstarttime);
  206. let endDate = Util.parseDate(chargePile.chargendtime)
  207. let totalTime = Math.round((endDate.getTime() - startDate.getTime()) / 60000);
  208. let totalTimeHour = Math.floor(totalTime / 60);
  209. let totalTimeMinute = totalTime % 60;
  210. let startTime = startDate.getFullYear() + "年" + Util.formatNumber(startDate.getMonth() + 1) + '月' + Util.formatNumber(startDate.getDate()) + '日 ' + Util.formatNumber(startDate.getHours()) + ':' + Util.formatNumber(startDate.getMinutes()) + ':' + Util.formatNumber(startDate.getSeconds());
  211. let endTime = endDate.getFullYear() + "年" + Util.formatNumber(endDate.getMonth() + 1) + '月' + Util.formatNumber(endDate.getDate()) + '日 ' + Util.formatNumber(endDate.getHours()) + ':' + Util.formatNumber(endDate.getMinutes()) + ':' + Util.formatNumber(endDate.getSeconds());
  212. totalTime = Util.formatNumber(totalTimeHour) + "时" + Util.formatNumber(totalTimeMinute) + "分";
  213. chargePile.startTime = startTime;
  214. chargePile.endTime = endTime;
  215. chargePile.totalTime = totalTime;
  216. chargePile.chargallmoney = chargePile.chargallmoney.toFixed(2);
  217. chargePile.chargservice = chargePile.chargservice.toFixed(2);
  218. chargePile.chargmoney = chargePile.chargmoney.toFixed(2);
  219. //console.log(chargePile.chargPile);
  220. } catch (err) {
  221. //在这里处理错误
  222. }
  223. });
  224. },
  225. startTimeOrder(charginglogs) {
  226. if (charginglogs && 0 != charginglogs.length) {
  227. charginglogs.sort(function(ma, mb) {
  228. return mb.chargstarttime.localeCompare(ma.chargstarttime);
  229. });
  230. }
  231. },
  232. customerServiceBtn(){
  233. wx.makePhoneCall({
  234. phoneNumber: this.data.servicetel
  235. })
  236. },
  237. cancleBtn(e){
  238. let that = this
  239. let reservId = e.currentTarget.dataset.idx;
  240. let userInfo = wx.getStorageSync('userInfo');
  241. let isLogin = wx.getStorageSync('isLogin');
  242. wx.showModal({
  243. title: '提示',
  244. content: '是否取消预约',
  245. complete: (res) => {
  246. if (res.cancel) {
  247. }
  248. if (res.confirm) {
  249. wx.request({
  250. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/canelReserv?userName=' + userInfo.loginName + '&reservId=' + reservId,
  251. data: {
  252. },
  253. method: 'POST',
  254. success(res) {
  255. console.info(res)
  256. // TODO 重新加载页面
  257. that.resetListZero();
  258. that.getPage();
  259. }
  260. });
  261. }
  262. }
  263. })
  264. },
  265. /**
  266. * 生命周期函数--监听页面初次渲染完成
  267. */
  268. onReady: function() {
  269. },
  270. /**
  271. * 生命周期函数--监听页面显示
  272. */
  273. onShow: function() {
  274. },
  275. /**
  276. * 生命周期函数--监听页面隐藏
  277. */
  278. onHide: function() {
  279. },
  280. /**
  281. * 生命周期函数--监听页面卸载
  282. */
  283. onUnload: function() {
  284. },
  285. /**
  286. * 页面相关事件处理函数--监听用户下拉动作
  287. */
  288. onPullDownRefresh: function() {
  289. },
  290. /**
  291. * 页面上拉触底事件的处理函数
  292. */
  293. onReachBottom: function() {
  294. },
  295. bindScrollTolowerEvent: function(){
  296. this.getPage();
  297. },
  298. /**
  299. * 用户点击右上角分享
  300. */
  301. onShareAppMessage: function() {
  302. }
  303. })