personorder.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. tabs: [{
  17. title: '全部'
  18. },
  19. {
  20. title: '待消费'
  21. },
  22. {
  23. title: '待评价'
  24. },
  25. {
  26. title: '已完成'
  27. },
  28. ]
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: async function () {
  34. console.log(this)
  35. const isAuth = await app.isAuth()
  36. if (!isAuth) {
  37. wx.redirectTo({
  38. url: '/pages/prompt/prompt?page=' + this.route,
  39. })
  40. }
  41. },
  42. // 获取全部列表
  43. getAllOrderList: async function () {
  44. const self = this
  45. let pageNo = this.data.pageNo;
  46. let tabs = this.data.tabs;
  47. let pageSum = this.data.pageSum;
  48. // 获取全部订单
  49. var orderList = await orderApi.getAllOrderList(pageNo[0], 4);
  50. var list = orderList.list;
  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], 4, 2, 1);
  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.getOrderList(pageNo[2], 4, 2, 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], 4, 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. console.log(orderId)
  189. var status = e.currentTarget.dataset.status;
  190. var writeStatus = e.currentTarget.dataset.writestatus;
  191. wx.navigateTo({
  192. url: '../order/order?id=' + orderId,
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onReady: function () {
  199. },
  200. /**
  201. * 生命周期函数--监听页面显示
  202. */
  203. onShow: async function () {
  204. await this.getAllOrderList()
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom: async function () {
  225. console.log("到底啦")
  226. var self = this;
  227. let activeTab = this.data.activeTab;
  228. if (activeTab == 0) {
  229. console.log("all")
  230. let pageNo = this.data.pageNo;
  231. pageNo[0]++;
  232. self.setData({
  233. pageNo
  234. })
  235. if (self.data.pageNo[0] <= self.data.pageSum[0]) {
  236. await this.getAllOrderList()
  237. return
  238. }
  239. }
  240. if (activeTab == 1) {
  241. console.log("xiaofei")
  242. let pageNo = this.data.pageNo;
  243. pageNo[1]++;
  244. self.setData({
  245. pageNo
  246. })
  247. if (self.data.pageNo[1] <= self.data.pageNo[1]) {
  248. await this.getwriteOffOrderList()
  249. return
  250. }
  251. }
  252. if (activeTab == 2) {
  253. console.log("pingjia")
  254. let pageNo = this.data.pageNo;
  255. pageNo[2]++;
  256. self.setData({
  257. pageNo
  258. })
  259. if (self.data.pageNo[2] <= self.data.pageSum[2]) {
  260. await this.getcommentOffOrderList()
  261. return
  262. }
  263. }
  264. if (activeTab == 4) {
  265. let pageNo = this.data.pageNo;
  266. pageNo[3]++;
  267. self.setData({
  268. pageNo
  269. })
  270. if (self.data.pageNo[3] <= self.data.pageSum[3]) {
  271. await this.getfinishOrderList()
  272. return
  273. }
  274. }
  275. },
  276. /**
  277. * 用户点击右上角分享
  278. */
  279. onShareAppMessage: function () {
  280. },
  281. gotoComment: function (e) {
  282. var orderId = e.currentTarget.dataset.orderid;
  283. var shopId = e.currentTarget.dataset.shopid;
  284. var productId = e.currentTarget.dataset.productid;
  285. wx.navigateTo({
  286. url: '../commentinfo/commentinfo?id=' + orderId + '&shopId=' + shopId + '&productId=' + productId,
  287. })
  288. },
  289. // 再来一单
  290. buyAgain: function (e) {
  291. var shopId = e.currentTarget.dataset.shopid;
  292. var productId = e.currentTarget.dataset.productid;
  293. var productImg = e.currentTarget.dataset.productimg;
  294. var productName = e.currentTarget.dataset.productname;
  295. var price = e.currentTarget.dataset.price;
  296. wx.navigateTo({
  297. url: '../appointment/appointment?' + 'shopId=' + shopId + '&productId=' + productId + '&productImg=' + productImg + '&productName=' + productName + '&price=' + price,
  298. })
  299. }
  300. })