personorder.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // pages/personorder/personorder.js
  2. const app = getApp()
  3. import orderApi from '../../api/order'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. activeTab: 0,
  10. tabs: [],
  11. orderList: [],
  12. pageNo: [1, 1, 1, 1],
  13. pageSum: [],
  14. loadingEnd: false,
  15. tabs: [{
  16. title: '全部'
  17. },
  18. {
  19. title: '代消费'
  20. },
  21. {
  22. title: '待评价'
  23. },
  24. {
  25. title: '已完成'
  26. },
  27. ]
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: async function () {
  33. console.log(this)
  34. const isAuth = await app.isAuth()
  35. if (!isAuth) {
  36. wx.redirectTo({
  37. url: '/pages/prompt/prompt?page=' + this.route,
  38. })
  39. }
  40. },
  41. // 获取全部列表
  42. getAllOrderList: async function () {
  43. const self = this
  44. let pageNo = this.data.pageNo;
  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. if (!tabs[0].list) {
  51. tabs[0].list = []
  52. }
  53. if (pageNo[0] == 1) {
  54. tabs[0].list = list;
  55. } else {
  56. list.forEach((item, i, array) => {
  57. tabs[0].list.push(item)
  58. })
  59. }
  60. pageSum[0] = orderList.pageCount;
  61. this.setData({
  62. tabs,
  63. pageSum
  64. })
  65. // return list;
  66. },
  67. // 获取代消费列表
  68. getwriteOffOrderList: async function () {
  69. const self = this
  70. let pageNo = this.data.pageNo;
  71. let tabs = this.data.tabs;
  72. let pageSum = this.data.pageSum;
  73. // 获取代消费订单
  74. var orderList = await orderApi.getOrderList(pageNo[1], 4, 2, 1);
  75. var list = orderList.list;
  76. if (!tabs[1].list) {
  77. tabs[1].list = []
  78. }
  79. if (pageNo[1] == 1) {
  80. tabs[1].list = list;
  81. } else {
  82. list.forEach((item, i, array) => {
  83. tabs[1].list.push(item)
  84. })
  85. }
  86. pageSum[1] = orderList.pageCount;
  87. this.setData({
  88. tabs,
  89. pageSum
  90. })
  91. // return list;
  92. },
  93. // 获取待评价列表
  94. getcommentOffOrderList: async function () {
  95. const self = this
  96. let pageNo = this.data.pageNo;
  97. let tabs = this.data.tabs;
  98. let pageSum = this.data.pageSum;
  99. // 获取代消费订单
  100. var orderList = await orderApi.getOrderList(pageNo[2], 4, 2, 2);
  101. var list = orderList.list;
  102. if (!tabs[2].list) {
  103. tabs[2].list = []
  104. }
  105. if (pageNo[2] == 1) {
  106. let tabList = [];
  107. list.forEach((item, i, array) => {
  108. if (item.discussId == '') {
  109. tabList.push(item)
  110. }
  111. })
  112. tabs[2].list = tabList;
  113. } else {
  114. list.forEach((item, i, array) => {
  115. if (item.discussId == '') {
  116. tabs[2].list.push(item)
  117. }
  118. })
  119. }
  120. pageSum[2] = orderList.pageSum
  121. this.setData({
  122. tabs,
  123. pageSum
  124. })
  125. // return list;
  126. },
  127. // 获取已经完成的列表
  128. getfinishOrderList: async function () {
  129. const self = this
  130. let pageNo = this.data.pageNo;
  131. let tabs = this.data.tabs;
  132. let pageSum = this.data.pageSum;
  133. // 获取代消费订单
  134. var orderList = await orderApi.getOrderList(pageNo[3], 4, 2, 2);
  135. var list = orderList.list;
  136. if (!tabs[3].list) {
  137. tabs[3].list = []
  138. }
  139. if (pageNo[3] == 1) {
  140. tabs[3].list = list;
  141. } else {
  142. list.forEach((item, i, array) => {
  143. if (item.discussId != '') {
  144. tabs[3].list.push(item)
  145. }
  146. })
  147. }
  148. pageSum[3] = orderList.pageCount;
  149. this.setData({
  150. tabs,
  151. pageSum
  152. })
  153. // return list;
  154. },
  155. onTabClick(e) {
  156. const index = e.detail.index
  157. this.setData({
  158. activeTab: index
  159. })
  160. },
  161. onChange(e) {
  162. const index = e.detail.index
  163. this.setData({
  164. activeTab: index,
  165. pageNo: [1, 1, 1, 1]
  166. })
  167. if(index==0){
  168. this.getAllOrderList()
  169. return
  170. }
  171. if (index == 1) {
  172. this.getwriteOffOrderList()
  173. return
  174. }
  175. if (index == 2) {
  176. this.getcommentOffOrderList()
  177. return
  178. }
  179. if (index == 3) {
  180. this.getfinishOrderList()
  181. }
  182. },
  183. handleClick(e) {
  184. },
  185. showOrderInfo: async function (e) {
  186. var orderId = e.currentTarget.dataset.orderid;
  187. var status = e.currentTarget.dataset.status;
  188. var writeStatus = e.currentTarget.dataset.writestatus;
  189. if (status == 2 && writeStatus == 1) {
  190. wx.navigateTo({
  191. url: '../order/order?orderId=' + orderId,
  192. })
  193. return
  194. }
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow: async function () {
  205. await this.getAllOrderList()
  206. },
  207. /**
  208. * 生命周期函数--监听页面隐藏
  209. */
  210. onHide: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面卸载
  214. */
  215. onUnload: function () {
  216. },
  217. /**
  218. * 页面相关事件处理函数--监听用户下拉动作
  219. */
  220. onPullDownRefresh: function () {
  221. },
  222. /**
  223. * 页面上拉触底事件的处理函数
  224. */
  225. onReachBottom: async function () {
  226. console.log("到底啦")
  227. var self = this;
  228. let activeTab = this.data.activeTab;
  229. if (activeTab == 0) {
  230. console.log("all")
  231. let pageNo = this.data.pageNo;
  232. pageNo[0]++;
  233. self.setData({
  234. pageNo
  235. })
  236. if (self.data.pageNo[0] <= self.data.pageSum[0]) {
  237. await this.getAllOrderList()
  238. return
  239. }
  240. }
  241. if (activeTab == 1) {
  242. console.log("xiaofei")
  243. let pageNo = this.data.pageNo;
  244. pageNo[1]++;
  245. self.setData({
  246. pageNo
  247. })
  248. if (self.data.pageNo[1] <= self.data.pageNo[1]) {
  249. await this.getwriteOffOrderList()
  250. return
  251. }
  252. }
  253. if (activeTab == 2) {
  254. console.log("pingjia")
  255. let pageNo = this.data.pageNo;
  256. pageNo[2]++;
  257. self.setData({
  258. pageNo
  259. })
  260. if (self.data.pageNo[2] <= self.data.pageSum[2]) {
  261. await this.getcommentOffOrderList()
  262. return
  263. }
  264. }
  265. if (activeTab == 4) {
  266. let pageNo = this.data.pageNo;
  267. pageNo[3]++;
  268. self.setData({
  269. pageNo
  270. })
  271. if (self.data.pageNo[3] <= self.data.pageSum[3]) {
  272. await this.getfinishOrderList()
  273. return
  274. }
  275. }
  276. },
  277. /**
  278. * 用户点击右上角分享
  279. */
  280. onShareAppMessage: function () {
  281. },
  282. gotoComment: function (e) {
  283. var orderId = e.currentTarget.dataset.orderid;
  284. var shopId = e.currentTarget.dataset.shopid;
  285. var productId = e.currentTarget.dataset.productid;
  286. wx.navigateTo({
  287. url: '../commentinfo/commentinfo?id=' + orderId + '&shopId=' + shopId + '&productId=' + productId,
  288. })
  289. },
  290. // 再来一单
  291. buyAgain: function (e) {
  292. var shopId = e.currentTarget.dataset.shopid;
  293. var productId = e.currentTarget.dataset.productid;
  294. var productImg = e.currentTarget.dataset.productimg;
  295. var productName = e.currentTarget.dataset.productname;
  296. var price = e.currentTarget.dataset.price;
  297. wx.navigateTo({
  298. url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&productImg=' + productImg + '&productName=' + productName + '&price=' + price,
  299. })
  300. }
  301. })