orderTabs.js 7.5 KB

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