orderTabs.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. // pages/order_tabs/orderTabs.js
  2. const getReq = require('./../../config.js').getReq
  3. import recordSource from '../../utils/recordSource'
  4. let app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. hasmore: false,
  11. orders: [],
  12. addTimes: [],
  13. curpage: 1,
  14. tabs: [
  15. {
  16. name: "全部",
  17. type: ""
  18. },
  19. {
  20. name: "待付款",
  21. type: 'state_new'
  22. },
  23. {
  24. name: "待发货",
  25. type: 'state_pay'
  26. },
  27. {
  28. name: "待收货",
  29. type: 'state_send'
  30. },
  31. {
  32. name: "已收货",
  33. type: 'state_success'
  34. }
  35. ],
  36. selectedIndex: 0,
  37. state_type: '',
  38. tabs_title: '',
  39. loading: false,
  40. fromSource: '',
  41. firstLoad: true
  42. },
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function (options) {
  47. let state_type = options.state_type || this.data.state_type;
  48. switch (state_type) {
  49. case '': {
  50. this.setData({
  51. selectedIndex: 0,
  52. state_type,
  53. tabs_title: '全部'
  54. })
  55. break;
  56. }
  57. case 'state_new': {
  58. this.setData({
  59. selectedIndex: 1,
  60. state_type,
  61. tabs_title: '待付款'
  62. })
  63. break;
  64. }
  65. case 'state_pay': {
  66. this.setData({
  67. selectedIndex: 2,
  68. state_type,
  69. tabs_title: '待发货'
  70. })
  71. break;
  72. }
  73. case 'state_send': {
  74. this.setData({
  75. selectedIndex: 3,
  76. state_type,
  77. tabs_title: '待收货'
  78. })
  79. break;
  80. }
  81. case 'state_success': {
  82. this.setData({
  83. selectedIndex: 4,
  84. state_type,
  85. tabs_title: '已收货'
  86. })
  87. break;
  88. }
  89. }
  90. this.req_datas(state_type);
  91. },
  92. req_datas(type) {
  93. let fromSource = recordSource(app, `act=member_order&op=list&page=15&curpage=${this.data.curpage}&state_type=${type}&client_type=mini`)
  94. this.setData({
  95. loading: true,
  96. fromSource: app.globalData.fromSource
  97. });
  98. wx.showLoading({
  99. title: '加载中',
  100. });
  101. if (type != this.data.state_type) {
  102. this.setData({
  103. hasmore: false,
  104. orders: [],
  105. addTimes: [],
  106. curpage: 1,
  107. state_type: type
  108. });
  109. }
  110. let self = this;
  111. getReq({
  112. act: 'member_order',
  113. op: 'list',
  114. page: 15,
  115. curpage: this.data.curpage,
  116. state_type: type,
  117. from: fromSource
  118. }, function (res) {
  119. let orders = res.datas.orders;
  120. let addTimes = [];
  121. let hasmore = false;
  122. let curpage = self.data.curpage
  123. for (let item of orders) {
  124. addTimes.push(self.timeFormat(item.order_info.add_time));
  125. }
  126. if (res.datas.mobile_page.hasmore) {
  127. hasmore = true;
  128. curpage = self.data.curpage + 1;
  129. }
  130. else {
  131. hasmore = false;
  132. }
  133. self.setData({
  134. hasmore,
  135. curpage,
  136. orders: self.data.orders.concat(orders),
  137. addTimes: self.data.addTimes.concat(addTimes),
  138. loading: false,
  139. firstLoad: false
  140. });
  141. wx.hideLoading();
  142. })
  143. },
  144. /**
  145. * 生命周期函数--监听页面初次渲染完成
  146. */
  147. onReady: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. if(!this.data.firstLoad) {
  154. app.setFromSource(this.data.fromSource)
  155. }
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload: function () {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh: function () {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom: function () {
  176. if (this.data.hasmore) {
  177. this.req_datas(this.data.state_type);
  178. }
  179. },
  180. timeFormat(time) {
  181. let date = new Date(time * 1000);
  182. let year = date.getFullYear();
  183. let month = date.getMonth() + 1;
  184. let day = date.getDate();
  185. return `${year}-${month}-${day}`;
  186. },
  187. selectTab(e) {
  188. let index = e.target.dataset.index;
  189. let type = e.target.dataset.type;
  190. if (type == this.data.state_type) {
  191. return;
  192. }
  193. else {
  194. switch (type) {
  195. case '': {
  196. this.setData({
  197. selectedIndex: index,
  198. tabs_title: '全部'
  199. })
  200. break;
  201. }
  202. case 'state_new': {
  203. this.setData({
  204. selectedIndex: index,
  205. tabs_title: '待付款'
  206. })
  207. break;
  208. }
  209. case 'state_pay': {
  210. this.setData({
  211. selectedIndex: index,
  212. tabs_title: '待发货'
  213. })
  214. break;
  215. }
  216. case 'state_send': {
  217. this.setData({
  218. selectedIndex: index,
  219. tabs_title: '待收货'
  220. })
  221. break;
  222. }
  223. case 'state_success': {
  224. this.setData({
  225. selectedIndex: index,
  226. tabs_title: '已收货'
  227. })
  228. break;
  229. }
  230. }
  231. this.req_datas(type);
  232. }
  233. },
  234. change_order_state(action, order_id, index) {
  235. let self = this;
  236. getReq({
  237. act: 'member_order',
  238. op: 'change_state',
  239. act_type: action,
  240. order_id: order_id
  241. }, function (res) {
  242. if (res.code != 200) {
  243. wx.showToast({
  244. title: res.message,
  245. icon: 'none'
  246. })
  247. }
  248. else {
  249. let orders = self.data.orders;
  250. let addTimes = self.data.addTimes;
  251. orders.splice(index, 1);
  252. addTimes.splice(index, 1);
  253. self.setData({
  254. orders,
  255. addTimes
  256. })
  257. }
  258. })
  259. },
  260. order_action(e) {
  261. const action = e.target.dataset.action;
  262. const order_id = e.target.dataset.orderid;
  263. const order_sn = e.target.dataset.sordersn;
  264. const pay_sn = e.target.dataset.paysn;
  265. const index = e.target.dataset.index;
  266. let self = this;
  267. switch (action) {
  268. case "if_delete": {
  269. wx.showModal({
  270. title: "提示",
  271. content: "您确定要删除该订单吗?",
  272. success: function (res) {
  273. if (res.confirm) {
  274. self.change_order_state(action, order_id, index);
  275. }
  276. else if (res.cancel) {
  277. return;
  278. }
  279. }
  280. })
  281. break;
  282. }
  283. case "if_deliver": {
  284. let url = encodeURIComponent("https://passport.lrlz.com/mobile/index.php?act=member_order&op=search_deliver&order_id=");
  285. wx.navigateTo({
  286. url: `/pages/webView/webView?url=${url}${order_id}`
  287. })
  288. break;
  289. }
  290. case "if_cancel": {
  291. wx.showModal({
  292. title: "提示",
  293. content: "您确定要取消该订单吗?",
  294. success: function (res) {
  295. if (res.confirm) {
  296. self.change_order_state(action, order_id, index);
  297. }
  298. else if (res.cancel) {
  299. return;
  300. }
  301. }
  302. })
  303. break;
  304. }
  305. case "if_receive": {
  306. wx.showModal({
  307. title: "提示",
  308. content: "您确定收货吗?",
  309. success: function (res) {
  310. if (res.confirm) {
  311. self.change_order_state(action, order_id, index);
  312. }
  313. else if (res.cancel) {
  314. return;
  315. }
  316. }
  317. })
  318. break;
  319. }
  320. case "if_payment": {
  321. wx.navigateTo({
  322. url: `/pages/orderPaySn/orderPaySn?pay_sn=${pay_sn}`
  323. })
  324. }
  325. }
  326. }
  327. })