orderTabs.js 8.3 KB

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