index.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp();
  4. const api = require('../../api/api');
  5. Page({
  6. data: {
  7. test: {
  8. name: "团长"
  9. },
  10. height: 0,
  11. tabs: [
  12. "订阅团长", "最近浏览", "我的订单"
  13. ],
  14. ordertabs: [
  15. "全部", "待支付", "待收货", "已完成", "退款/售后"
  16. ],
  17. orderindex: 0,
  18. zhong: 0, //当前tab索引
  19. dingyues: [], //订阅团长
  20. pintuan: [], //最近浏览
  21. orders: [], //我的订单
  22. showSearchPopup: false, //显示搜索弹窗
  23. keywords: '', //搜索关键字
  24. time: -1, //防抖时间
  25. goodName: '', //最近浏览搜索
  26. share_order_id: 0, //分享订单ID
  27. },
  28. onLoad(options) {
  29. let that = this;
  30. that.setData({
  31. height: app.globalData.height,
  32. enterType: Number(options.type)
  33. })
  34. // 获取我的订单列表
  35. wx.showLoading({
  36. title: '加载中',
  37. mask: true
  38. })
  39. wx.request({
  40. url: api.Member_order,
  41. header: {
  42. 'Authorization': wx.getStorageSync('token')
  43. },
  44. method: 'POST',
  45. success(res) {
  46. console.log(res);
  47. if (res.data.code === 1) {
  48. that.setData({
  49. orders: res.data.data
  50. })
  51. } else {
  52. wx.showToast({
  53. title: res.data.msg,
  54. mask: true,
  55. icon: 'none'
  56. })
  57. }
  58. },
  59. fail(err) {
  60. wx.showToast({
  61. title: '发起网络请求失败',
  62. icon: 'none',
  63. mask: true
  64. })
  65. },
  66. complete() {
  67. wx.hideLoading()
  68. }
  69. })
  70. },
  71. onShow() {
  72. let that = this;
  73. // 获取订阅团长列表
  74. wx.showLoading({
  75. title: '加载中',
  76. mask: true
  77. })
  78. wx.request({
  79. url: api.Head_list,
  80. header: {
  81. 'Authorization': wx.getStorageSync('token')
  82. },
  83. success(res) {
  84. console.log(res);
  85. if (res.data.code === 1) {
  86. that.setData({
  87. dingyues: res.data.data
  88. })
  89. } else {
  90. wx.showToast({
  91. title: res.data.msg,
  92. mask: true,
  93. icon: 'none'
  94. })
  95. }
  96. },
  97. fail(err) {
  98. wx.showToast({
  99. title: '发起网络请求失败',
  100. icon: 'none',
  101. mask: true
  102. })
  103. },
  104. complete() {
  105. wx.hideLoading()
  106. }
  107. })
  108. // 获取最近浏览列表
  109. wx.showLoading({
  110. title: '加载中',
  111. mask: true
  112. })
  113. wx.request({
  114. url: api.footprints,
  115. header: {
  116. 'Authorization': wx.getStorageSync('token')
  117. },
  118. method: 'POST',
  119. success(res) {
  120. console.log(res);
  121. if (res.data.code === 1) {
  122. that.setData({
  123. pintuan: res.data.data
  124. })
  125. } else {
  126. wx.showToast({
  127. title: res.data.msg,
  128. mask: true,
  129. icon: 'none'
  130. })
  131. }
  132. },
  133. fail(err) {
  134. wx.showToast({
  135. title: '发起网络请求失败',
  136. icon: 'none',
  137. mask: true
  138. })
  139. },
  140. complete() {
  141. wx.hideLoading()
  142. }
  143. })
  144. },
  145. /**
  146. * 用户点击右上角分享
  147. */
  148. onShareAppMessage: function () {
  149. let order_id = this.data.share_order_id; //订单ID
  150. return {
  151. title: '订单分享',
  152. path: '/pages/orderdetail/orderdetail?id=' + order_id,
  153. imageUrl: 'https://s4.ax1x.com/2021/12/29/TccgfK.jpg'
  154. }
  155. },
  156. // 标签页切换
  157. tabsbind(e) {
  158. this.setData({
  159. zhong: e.currentTarget.dataset.id
  160. })
  161. },
  162. // 订单标签切换
  163. ordertap(e) {
  164. let that = this;
  165. let oid = e.currentTarget.dataset.oid; //用户选中的标签
  166. let order_status = 0; //对应的订单状态
  167. if (oid === 0) {
  168. // 全部
  169. order_status = '';
  170. } else if (oid === 1) {
  171. // 待支付
  172. order_status = 0;
  173. } else if (oid === 2) {
  174. // 待取货
  175. order_status = 1;
  176. } else if (oid === 3) {
  177. // 已完成
  178. order_status = 2;
  179. } else if (oid === 4) {
  180. // 退款/售后
  181. order_status = 4;
  182. }
  183. if (oid === 0) {
  184. // 获取我的订单列表-全部
  185. wx.showLoading({
  186. title: '加载中',
  187. mask: true
  188. })
  189. wx.request({
  190. url: api.Member_order,
  191. header: {
  192. 'Authorization': wx.getStorageSync('token')
  193. },
  194. method: 'POST',
  195. success(res) {
  196. console.log(res);
  197. if (res.data.code === 1) {
  198. that.setData({
  199. orders: res.data.data,
  200. orderindex: oid
  201. })
  202. } else {
  203. wx.showToast({
  204. title: res.data.msg,
  205. mask: true,
  206. icon: 'none'
  207. })
  208. }
  209. },
  210. fail(err) {
  211. wx.showToast({
  212. title: '发起网络请求失败',
  213. icon: 'none',
  214. mask: true
  215. })
  216. },
  217. complete() {
  218. wx.hideLoading()
  219. }
  220. })
  221. } else {
  222. // 获取我的订单列表
  223. wx.showLoading({
  224. title: '加载中',
  225. mask: true
  226. })
  227. wx.request({
  228. url: api.Member_order,
  229. header: {
  230. 'Authorization': wx.getStorageSync('token')
  231. },
  232. method: 'POST',
  233. data: {
  234. order_status: order_status
  235. },
  236. success(res) {
  237. console.log(res);
  238. if (res.data.code === 1) {
  239. that.setData({
  240. orders: res.data.data,
  241. orderindex: oid
  242. })
  243. } else {
  244. wx.showToast({
  245. title: res.data.msg,
  246. mask: true,
  247. icon: 'none'
  248. })
  249. }
  250. },
  251. fail(err) {
  252. wx.showToast({
  253. title: '发起网络请求失败',
  254. icon: 'none',
  255. mask: true
  256. })
  257. },
  258. complete() {
  259. wx.hideLoading()
  260. }
  261. })
  262. }
  263. // this.setData({
  264. // orderindex: e.currentTarget.dataset.oid
  265. // })
  266. },
  267. // 输入最近浏览关键字
  268. inputGoodName(e) {
  269. let that = this;
  270. that.setData({
  271. goodName: e.detail.value
  272. })
  273. // 清除定时器
  274. clearTimeout(this.data.time);
  275. // 开启定时器
  276. this.data.time = setTimeout(() => {
  277. wx.showLoading({
  278. title: '搜索中',
  279. mask: true
  280. })
  281. wx.request({
  282. url: api.footprints,
  283. header: {
  284. 'Authorization': wx.getStorageSync('token')
  285. },
  286. method: 'POST',
  287. data: {
  288. name: that.data.goodName
  289. },
  290. success: (res) => {
  291. console.log(res);
  292. if (res.data.code === 1) {
  293. that.setData({
  294. pintuan: res.data.data
  295. })
  296. } else {
  297. wx.showToast({
  298. title: res.data.msg,
  299. mask: true,
  300. icon: 'none'
  301. })
  302. }
  303. },
  304. fail: (err) => {
  305. console.log(err);
  306. },
  307. complete: () => {
  308. wx.hideLoading()
  309. }
  310. })
  311. }, 500)
  312. },
  313. // 团长跳转
  314. navToTuanZhang(e) {
  315. let url = e.currentTarget.dataset.url;
  316. let id = e.currentTarget.dataset.id;
  317. wx.navigateTo({
  318. url: url + '&id=' + id
  319. })
  320. },
  321. // 拼团跳转
  322. navToPinTuanDetail(e) {
  323. let id = e.currentTarget.dataset.id;
  324. wx.navigateTo({
  325. url: '/pages/pintuandetail/pintuandetail?type=dingyue&id=' + id,
  326. })
  327. },
  328. // 订单跳转
  329. navToOrderDetail(e) {
  330. let id = e.currentTarget.dataset.id;
  331. let order_status = e.currentTarget.dataset.status;
  332. // console.log(order_status);
  333. if(order_status == 4) {
  334. wx.navigateTo({
  335. url: '/pages/confirmrefund/confirmrefund?id=' + id,
  336. })
  337. }else {
  338. wx.navigateTo({
  339. url: '/pages/orderdetail/orderdetail?id=' + id,
  340. })
  341. }
  342. },
  343. // 打开搜索框
  344. openSearchPopup() {
  345. this.setData({
  346. showSearchPopup: true
  347. })
  348. },
  349. // 关闭搜索框
  350. clsoeSearchPopup() {
  351. this.setData({
  352. showSearchPopup: false
  353. })
  354. },
  355. // 输入关键字
  356. inputKeyWords(e) {
  357. this.setData({
  358. keywords: e.detail.value
  359. })
  360. },
  361. // 搜索
  362. searchKeyWords() {
  363. let that = this;
  364. if (that.data.keywords == '') {
  365. wx.showToast({
  366. title: '请输入搜索关键字',
  367. mask: true,
  368. icon: 'none'
  369. })
  370. return
  371. }
  372. that.setData({
  373. orderindex: 0
  374. })
  375. wx.showLoading({
  376. title: '加载中',
  377. mask: true
  378. })
  379. wx.request({
  380. url: api.Member_order,
  381. header: {
  382. 'Authorization': wx.getStorageSync('token')
  383. },
  384. data: {
  385. gang_name: that.data.keywords
  386. },
  387. method: 'POST',
  388. success(res) {
  389. console.log(res);
  390. if (res.data.code === 1) {
  391. that.setData({
  392. orders: res.data.data,
  393. showSearchPopup: false
  394. })
  395. } else {
  396. wx.showToast({
  397. title: res.data.msg,
  398. mask: true,
  399. icon: 'none'
  400. })
  401. }
  402. },
  403. fail(err) {
  404. wx.showToast({
  405. title: '发起网络请求失败',
  406. icon: 'none',
  407. mask: true
  408. })
  409. },
  410. complete() {
  411. wx.hideLoading()
  412. }
  413. })
  414. },
  415. // 分享订单
  416. shareOrder(e) {
  417. this.setData({
  418. share_order_id: e.detail.value
  419. })
  420. }
  421. })