personorder.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. // pages/personorder/personorder.js
  2. const app = getApp()
  3. import order from '../../api/order'
  4. import orderApi from '../../api/order'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. activeTab: 0,
  11. tabs: [],
  12. orderList: [],
  13. pageNo: [1, 1, 1, 1],
  14. pageSum: [],
  15. loadingEnd: false,
  16. statusFilter:['','未支付','已支付','已完成'],
  17. writeOffStatusFilter:['','待消费','已完成'],
  18. tabs: [{
  19. title: '全部'
  20. },
  21. {
  22. title: '已支付'
  23. },
  24. // {
  25. // title: '待评价'
  26. // },
  27. {
  28. title: '已完成'
  29. },
  30. ],
  31. tabh: 1220
  32. },
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: async function (options) {
  37. },
  38. // 获取全部列表
  39. getAllOrderList: async function (refresh = false) {
  40. const self = this
  41. let pageNo = this.data.pageNo;
  42. // if (!refresh) {
  43. // pageNo = [1,1,1,1]
  44. // }
  45. let tabs = this.data.tabs;
  46. let pageSum = this.data.pageSum;
  47. // 获取全部订单
  48. var orderList = await orderApi.getAllOrderList(pageNo[0], 4);
  49. var list = orderList.list;
  50. console.log(pageNo[0])
  51. if (!tabs[0].list) {
  52. tabs[0].list = []
  53. }
  54. if (pageNo[0] == 1) {
  55. tabs[0].list = list;
  56. } else {
  57. list.forEach((item, i, array) => {
  58. tabs[0].list.push(item)
  59. })
  60. }
  61. pageSum[0] = orderList.pageCount;
  62. this.setData({
  63. tabs,
  64. pageSum
  65. })
  66. // return list;
  67. },
  68. // 获取代消费列表
  69. getwriteOffOrderList: async function () {
  70. const self = this
  71. let pageNo = this.data.pageNo;
  72. let tabs = this.data.tabs;
  73. let pageSum = this.data.pageSum;
  74. // 获取已支付订单
  75. var orderList = await orderApi.getOrderList(pageNo[1], 10, 2, 1,0);
  76. var list = orderList.list;
  77. if (!tabs[1].list) {
  78. tabs[1].list = []
  79. }
  80. if (pageNo[1] == 1) {
  81. tabs[1].list = list;
  82. } else {
  83. list.forEach((item, i, array) => {
  84. tabs[1].list.push(item)
  85. })
  86. }
  87. pageSum[1] = orderList.pageCount;
  88. this.setData({
  89. tabs,
  90. pageSum
  91. })
  92. // return list;
  93. },
  94. // 获取待评价列表
  95. getcommentOffOrderList: async function () {
  96. const self = this
  97. let pageNo = this.data.pageNo;
  98. let tabs = this.data.tabs;
  99. let pageSum = this.data.pageSum;
  100. // 获取代消费订单
  101. var orderList = await orderApi.getDiscussOffOrderList(pageNo[2], 10, 5, 2);
  102. var list = orderList.list;
  103. if (!tabs[2].list) {
  104. tabs[2].list = []
  105. }
  106. if (pageNo[2] == 1) {
  107. let tabList = [];
  108. list.forEach((item, i, array) => {
  109. if (item.discussId == '') {
  110. tabList.push(item)
  111. }
  112. })
  113. tabs[2].list = tabList;
  114. } else {
  115. list.forEach((item, i, array) => {
  116. if (item.discussId == '') {
  117. tabs[2].list.push(item)
  118. }
  119. })
  120. }
  121. pageSum[2] = orderList.pageSum
  122. this.setData({
  123. tabs,
  124. pageSum
  125. })
  126. // return list;
  127. },
  128. // 获取已经完成的列表
  129. getfinishOrderList: async function () {
  130. const self = this
  131. let pageNo = this.data.pageNo;
  132. let tabs = this.data.tabs;
  133. let pageSum = this.data.pageSum;
  134. // 获取代消费订单
  135. var orderList = await orderApi.getOrderList(pageNo[3], 10, 2, 2,2);
  136. var list = orderList.list;
  137. if (!tabs[3].list) {
  138. tabs[3].list = []
  139. }
  140. if (pageNo[3] == 1) {
  141. tabs[3].list = list;
  142. } else {
  143. list.forEach((item, i, array) => {
  144. if (item.discussId != '') {
  145. tabs[3].list.push(item)
  146. }
  147. })
  148. }
  149. pageSum[3] = orderList.pageCount;
  150. this.setData({
  151. tabs,
  152. pageSum
  153. })
  154. // return list;
  155. },
  156. onTabClick(e) {
  157. const index = e.detail.index
  158. this.setData({
  159. activeTab: index
  160. })
  161. },
  162. onChange(e) {
  163. const index = e.detail.index
  164. this.setData({
  165. activeTab: index,
  166. pageNo: [1, 1, 1, 1]
  167. })
  168. if(index==0){
  169. this.getAllOrderList()
  170. return
  171. }
  172. if (index == 1) {
  173. this.getwriteOffOrderList()
  174. return
  175. }
  176. if (index == 2) {
  177. this.getcommentOffOrderList()
  178. return
  179. }
  180. if (index == 3) {
  181. this.getfinishOrderList()
  182. }
  183. },
  184. handleClick(e) {
  185. },
  186. showOrderInfo: async function (e) {
  187. var orderId = e.currentTarget.dataset.orderid;
  188. wx.navigateTo({
  189. url: '../order/order?id=' + orderId,
  190. })
  191. },
  192. startServer: async function (e) {
  193. var orderId = e.currentTarget.dataset.orderid;
  194. await orderApi.startServer(orderId)
  195. if (this.data.activeTab == 1){
  196. await this.getwriteOffOrderList()
  197. }else {
  198. await this.getAllOrderList()
  199. }
  200. wx.showToast({
  201. title: '服务开始',
  202. })
  203. },
  204. endServer: async function (e) {
  205. var orderId = e.currentTarget.dataset.orderid;
  206. await orderApi.endServer(orderId)
  207. if (this.data.activeTab == 1){
  208. await this.getwriteOffOrderList()
  209. }else {
  210. await this.getAllOrderList()
  211. }
  212. wx.showToast({
  213. title: '服务结束',
  214. })
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面显示
  223. */
  224. onShow: async function () {
  225. const isAuth = await app.isAuth()
  226. if (!isAuth) {
  227. wx.redirectTo({
  228. url: '/pages/prompt/prompt?page=' + this.route,
  229. })
  230. return
  231. }
  232. await this.getAllOrderList()
  233. let activeTab = this.data.activeTab;
  234. if(activeTab==2){
  235. await this.getcommentOffOrderList()
  236. }
  237. },
  238. /**
  239. * 生命周期函数--监听页面隐藏
  240. */
  241. onHide: function () {
  242. },
  243. /**
  244. * 生命周期函数--监听页面卸载
  245. */
  246. onUnload: function () {
  247. },
  248. /**
  249. * 页面相关事件处理函数--监听用户下拉动作
  250. */
  251. onPullDownRefresh: function () {
  252. },
  253. /**
  254. * 页面上拉触底事件的处理函数
  255. */
  256. onReachBottom: async function () {
  257. console.log("到底啦")
  258. var self = this;
  259. let activeTab = this.data.activeTab;
  260. if (activeTab == 0) {
  261. console.log("all")
  262. let pageNo = this.data.pageNo;
  263. pageNo[0]++;
  264. self.setData({
  265. pageNo
  266. })
  267. if (self.data.pageNo[0] <= self.data.pageSum[0]) {
  268. await this.getAllOrderList()
  269. return
  270. }
  271. }
  272. if (activeTab == 1) {
  273. console.log("xiaofei")
  274. let pageNo = this.data.pageNo;
  275. pageNo[1]++;
  276. self.setData({
  277. pageNo
  278. })
  279. if (self.data.pageNo[1] <= self.data.pageNo[1]) {
  280. await this.getwriteOffOrderList()
  281. return
  282. }
  283. }
  284. if (activeTab == 2) {
  285. console.log("pingjia")
  286. let pageNo = this.data.pageNo;
  287. pageNo[2]++;
  288. self.setData({
  289. pageNo
  290. })
  291. if (self.data.pageNo[2] <= self.data.pageSum[2]) {
  292. await this.getcommentOffOrderList()
  293. return
  294. }
  295. }
  296. if (activeTab == 4) {
  297. let pageNo = this.data.pageNo;
  298. pageNo[3]++;
  299. self.setData({
  300. pageNo
  301. })
  302. if (self.data.pageNo[3] <= self.data.pageSum[3]) {
  303. await this.getfinishOrderList()
  304. return
  305. }
  306. }
  307. },
  308. scroolBottom: async function () {
  309. console.log("到底啦")
  310. var self = this;
  311. let activeTab = this.data.activeTab;
  312. if (activeTab == 0) {
  313. console.log("all")
  314. let pageNo = this.data.pageNo;
  315. // pageNo[0]++;
  316. // self.setData({
  317. // pageNo
  318. // })
  319. if (self.data.pageNo[0] <= self.data.pageSum[0]) {
  320. pageNo[0]++;
  321. self.setData({
  322. pageNo
  323. })
  324. await this.getAllOrderList()
  325. return
  326. }
  327. }
  328. if (activeTab == 1) {
  329. console.log("xiaofei")
  330. let pageNo = this.data.pageNo;
  331. // pageNo[1]++;
  332. // self.setData({
  333. // pageNo
  334. // })
  335. if (self.data.pageNo[1] <= self.data.pageSum[1]) {
  336. pageNo[1]++;
  337. self.setData({
  338. pageNo
  339. })
  340. await this.getwriteOffOrderList()
  341. return
  342. }
  343. }
  344. if (activeTab == 2) {
  345. console.log("pingjia")
  346. let pageNo = this.data.pageNo;
  347. // pageNo[2]++;
  348. // self.setData({
  349. // pageNo
  350. // })
  351. if (self.data.pageNo[2] <= self.data.pageSum[2]) {
  352. pageNo[2]++;
  353. self.setData({
  354. pageNo
  355. })
  356. await this.getcommentOffOrderList()
  357. return
  358. }
  359. }
  360. if (activeTab == 4) {
  361. let pageNo = this.data.pageNo;
  362. // pageNo[3]++;
  363. // self.setData({
  364. // pageNo
  365. // })
  366. if (self.data.pageNo[3] <= self.data.pageSum[3]) {
  367. pageNo[3]++;
  368. self.setData({
  369. pageNo
  370. })
  371. await this.getfinishOrderList()
  372. return
  373. }
  374. }
  375. },
  376. /**
  377. * 用户点击右上角分享
  378. */
  379. onShareAppMessage: function () {
  380. },
  381. gotoComment: function (e) {
  382. var orderId = e.currentTarget.dataset.orderid;
  383. var shopId = e.currentTarget.dataset.shopid;
  384. var productId = e.currentTarget.dataset.productid;
  385. wx.navigateTo({
  386. url: '../commentinfo/commentinfo?id=' + orderId + '&shopId=' + shopId + '&productId=' + productId,
  387. })
  388. },
  389. // 再来一单
  390. buyAgain: function (e) {
  391. var shopId = e.currentTarget.dataset.shopid;
  392. var productId = e.currentTarget.dataset.productid;
  393. var productImg = e.currentTarget.dataset.productimg;
  394. var productName = e.currentTarget.dataset.productname;
  395. var price = e.currentTarget.dataset.price;
  396. wx.navigateTo({
  397. url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&productImg=' + productImg + '&productName=' + productName + '&price=' + price,
  398. })
  399. },
  400. payOrder: async function(e){
  401. console.log(e)
  402. let orderId = e.currentTarget.dataset.orderid;
  403. const data = {
  404. orderId
  405. }
  406. const rs = await orderApi.payOrderAgain(data)
  407. wx.requestPayment({
  408. timeStamp: rs.timeStamp,
  409. nonceStr: rs.nonceStr,
  410. package: rs.package,
  411. signType: rs.signType,
  412. paySign: rs.paySign,
  413. success: async function (res) {
  414. console.log(res)
  415. self.onLoad()
  416. },
  417. fail: async function (res) {
  418. self.onLoad()
  419. }
  420. })
  421. }
  422. })