ordermanage.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. // pages/ordermanage/ordermanage.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '订单管理', //导航栏 中间的标题,
  12. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  13. },
  14. ordertabs: [
  15. "全部", "待支付", "待收货", "已完成", "退款/售后"
  16. ],
  17. orderindex: 0,
  18. // 组件参数
  19. showOneClickNotice: false,
  20. oneClickNoticeActions: [{
  21. name: '发送取货通知',
  22. subname: '通知所有已付款用户取货',
  23. className: 'actions-first-child'
  24. },
  25. {
  26. name: '通知付款',
  27. subname: '通知所有未付款订单用户付款'
  28. }
  29. ],
  30. showUpdateState: false,
  31. updateStateActions: [{
  32. name: '团员已支付',
  33. className: 'actions-first-child'
  34. },
  35. {
  36. name: '团员已取货',
  37. }
  38. ],
  39. pintuan: [], //拼团列表
  40. pintuandetail: {}, //拼团详情
  41. order_list: [], //拼团订单列表
  42. order_info: {}, //订单信息
  43. updateStatusID: 0, //更新状态id
  44. code_result: '', //扫码返回结果
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. let that = this;
  51. wx.showLoading({
  52. title: '加载中',
  53. mask: true
  54. })
  55. wx.request({
  56. url: api.OrderManagement_selection,
  57. header: {
  58. 'Authorization': wx.getStorageSync('token')
  59. },
  60. method: 'POST',
  61. success(res) {
  62. console.log(res);
  63. if (res.data.code === 1) {
  64. that.setData({
  65. pintuan: res.data.data,
  66. pintuandetail: res.data.data[0]
  67. })
  68. that.getOrderList()
  69. } else {
  70. wx.showToast({
  71. title: res.data.msg,
  72. mask: true,
  73. icon: 'none'
  74. })
  75. }
  76. },
  77. fail(err) {
  78. wx.showToast({
  79. title: '发起网络请求失败',
  80. icon: 'none',
  81. mask: true
  82. })
  83. },
  84. complete() {
  85. wx.hideLoading()
  86. }
  87. })
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. let that = this;
  99. let result = wx.getStorageSync('pintuan');
  100. if (result !== null) {
  101. this.setData({
  102. pintuandetail: result
  103. })
  104. wx.setStorageSync('pintuan', null)
  105. this.getOrderList()
  106. }
  107. if (that.data.code_result != '') {
  108. wx.showLoading({
  109. title: '扫码成功',
  110. mask: true
  111. })
  112. wx.request({
  113. url: api.Orderwrite,
  114. header: {
  115. 'Authorization': wx.getStorageSync('token')
  116. },
  117. data: {
  118. card_number: that.data.code_result,
  119. write_method: 0
  120. },
  121. method: 'POST',
  122. success(res) {
  123. wx.hideLoading()
  124. console.log(res);
  125. if (res.data.code === 1) {
  126. wx.showToast({
  127. title: '核销成功',
  128. })
  129. } else {
  130. wx.showToast({
  131. title: res.data.msg,
  132. mask: true,
  133. icon: 'none'
  134. })
  135. }
  136. },
  137. fail(err) {
  138. wx.hideLoading()
  139. wx.showToast({
  140. title: '发起网络请求失败',
  141. icon: 'none',
  142. mask: true
  143. })
  144. },
  145. complete() {
  146. that.setData({
  147. code_result: ''
  148. })
  149. // wx.hideLoading()
  150. }
  151. })
  152. }
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. },
  179. saoma() {
  180. wx.navigateTo({
  181. url: '/pages/verify/verify',
  182. })
  183. },
  184. // 页面跳转
  185. navToPage(e) {
  186. wx.navigateTo({
  187. url: e.currentTarget.dataset.url
  188. })
  189. },
  190. // 打开一键通知动作面板
  191. openOneClickNotice() {
  192. this.setData({
  193. showOneClickNotice: true
  194. })
  195. },
  196. // 关闭一键通知动作面板
  197. closeOneClickNotice() {
  198. this.setData({
  199. showOneClickNotice: false
  200. })
  201. },
  202. // 点击一键通知动作面板
  203. selectOneClickNotice(e) {
  204. let that = this;
  205. // this.setData({
  206. // showOneClickNotice: false
  207. // })
  208. if (e.detail.name == "发送取货通知") {
  209. wx.requestSubscribeMessage({
  210. tmplIds: ['hlRN3O8Ekh9oD10KK2Jt5_lT9zExhVVrYwi0ZHFy7Ss'],
  211. success(res) {
  212. console.log(res);
  213. wx.showLoading({
  214. title: '加载中',
  215. mask: true
  216. })
  217. wx.request({
  218. url: api.OrderManagement_pick_notice,
  219. header: {
  220. 'Authorization': wx.getStorageSync('token')
  221. },
  222. method: 'POST',
  223. data: {
  224. id: that.data.pintuandetail.id
  225. },
  226. success(res) {
  227. console.log(res);
  228. wx.hideLoading()
  229. if (res.data.code === 1) {
  230. wx.showToast({
  231. title: '发送成功',
  232. mask: true,
  233. success() {
  234. that.setData({
  235. showOneClickNotice: false
  236. })
  237. }
  238. })
  239. } else {
  240. wx.showToast({
  241. title: res.data.msg,
  242. mask: true,
  243. icon: 'none'
  244. })
  245. }
  246. },
  247. fail(err) {
  248. wx.hideLoading()
  249. wx.showToast({
  250. title: '发起网络请求失败',
  251. icon: 'none',
  252. mask: true
  253. })
  254. },
  255. complete() {
  256. // wx.hideLoading()
  257. }
  258. })
  259. }
  260. })
  261. } else if (e.detail.name == "通知付款") {
  262. wx.requestSubscribeMessage({
  263. tmplIds: ['0WYHpnlcJssWBW_725kZuDqw5Z6DBt8dCwjU2fQ9574'],
  264. success(res) {
  265. wx.showLoading({
  266. title: '加载中',
  267. mask: true
  268. })
  269. wx.request({
  270. url: api.OrderManagement_payment_order,
  271. header: {
  272. 'Authorization': wx.getStorageSync('token')
  273. },
  274. method: 'POST',
  275. data: {
  276. id: that.data.pintuandetail.id
  277. },
  278. success(res) {
  279. wx.hideLoading()
  280. console.log(res);
  281. if (res.data.code === 1) {
  282. wx.showToast({
  283. title: '发送成功',
  284. mask: true,
  285. success() {
  286. that.setData({
  287. showOneClickNotice: false
  288. })
  289. }
  290. })
  291. } else {
  292. wx.showToast({
  293. title: res.data.msg,
  294. mask: true,
  295. icon: 'none'
  296. })
  297. }
  298. },
  299. fail(err) {
  300. wx.hideLoading()
  301. wx.showToast({
  302. title: '发起网络请求失败',
  303. icon: 'none',
  304. mask: true
  305. })
  306. },
  307. complete() {
  308. // wx.hideLoading()
  309. }
  310. })
  311. }
  312. })
  313. }
  314. },
  315. // 打开更新状态动作面板
  316. openUpdateState() {
  317. this.setData({
  318. showUpdateState: true
  319. })
  320. },
  321. // 关闭更新状态动作面板
  322. closeUpdateState() {
  323. this.setData({
  324. showUpdateState: false
  325. })
  326. },
  327. // 点击更新状态动作面板
  328. selectUpdateState(e) {
  329. // console.log(e.detail.name);
  330. let that = this;
  331. if (e.detail.name == '团员已支付') {
  332. wx.showLoading({
  333. title: '加载中',
  334. mask: true
  335. })
  336. wx.request({
  337. url: api.OrderManagement_paid,
  338. header: {
  339. 'Authorization': wx.getStorageSync('token')
  340. },
  341. method: 'POST',
  342. data: {
  343. id: that.data.updateStatusID
  344. },
  345. success(res) {
  346. wx.hideLoading()
  347. console.log(res);
  348. if (res.data.code === 1) {
  349. wx.showToast({
  350. title: '发送成功',
  351. mask: true,
  352. success() {
  353. that.setData({
  354. showUpdateState: false
  355. })
  356. that.getOrderList()
  357. }
  358. })
  359. } else {
  360. wx.showToast({
  361. title: res.data.msg,
  362. mask: true,
  363. icon: 'none'
  364. })
  365. }
  366. },
  367. fail(err) {
  368. wx.hideLoading()
  369. wx.showToast({
  370. title: '发起网络请求失败',
  371. icon: 'none',
  372. mask: true
  373. })
  374. },
  375. complete() {
  376. // wx.hideLoading()
  377. }
  378. })
  379. } else if (e.detail.name == '团员已取货') {
  380. wx.showLoading({
  381. title: '加载中',
  382. mask: true
  383. })
  384. wx.request({
  385. url: api.OrderManagement_picked_up,
  386. header: {
  387. 'Authorization': wx.getStorageSync('token')
  388. },
  389. method: 'POST',
  390. data: {
  391. id: that.data.updateStatusID
  392. },
  393. success(res) {
  394. wx.hideLoading()
  395. console.log(res);
  396. if (res.data.code === 1) {
  397. wx.showToast({
  398. title: '发送成功',
  399. mask: true,
  400. success() {
  401. that.setData({
  402. showUpdateState: false
  403. })
  404. that.getOrderList()
  405. }
  406. })
  407. } else {
  408. wx.showToast({
  409. title: res.data.msg,
  410. mask: true,
  411. icon: 'none'
  412. })
  413. }
  414. },
  415. fail(err) {
  416. wx.hideLoading()
  417. wx.showToast({
  418. title: '发起网络请求失败',
  419. icon: 'none',
  420. mask: true
  421. })
  422. },
  423. complete() {
  424. // wx.hideLoading()
  425. }
  426. })
  427. }
  428. },
  429. // 跳转选择拼团
  430. navToSelectPinTuan() {
  431. wx.navigateTo({
  432. url: '/pages/pintuanchoose/pintuanchoose',
  433. })
  434. },
  435. // 获取订单列表
  436. getOrderList() {
  437. let that = this;
  438. wx.showLoading({
  439. title: '加载中',
  440. mask: true
  441. })
  442. wx.request({
  443. url: api.OrderManagement_list,
  444. header: {
  445. 'Authorization': wx.getStorageSync('token')
  446. },
  447. data: {
  448. id: that.data.pintuandetail.id
  449. },
  450. method: 'POST',
  451. success(res) {
  452. console.log(res);
  453. if (res.data.code === 1) {
  454. if (res.data.data == null) {
  455. that.setData({
  456. order_list: [],
  457. order_info: {}
  458. })
  459. } else {
  460. that.setData({
  461. order_list: res.data.data.order_list,
  462. order_info: res.data.data.order_info
  463. })
  464. }
  465. } else {
  466. wx.showToast({
  467. title: res.data.msg,
  468. mask: true,
  469. icon: 'none'
  470. })
  471. }
  472. },
  473. fail(err) {
  474. wx.showToast({
  475. title: '发起网络请求失败',
  476. icon: 'none',
  477. mask: true
  478. })
  479. },
  480. complete() {
  481. wx.hideLoading()
  482. }
  483. })
  484. },
  485. // 切换订单状态
  486. ordertap(e) {
  487. let that = this;
  488. let oid = e.currentTarget.dataset.oid; //用户选中的标签
  489. let order_status = 0; //对应的订单状态
  490. if (oid === 0) {
  491. // 全部
  492. order_status = '';
  493. } else if (oid === 1) {
  494. // 待支付
  495. order_status = 0;
  496. } else if (oid === 2) {
  497. // 待取货
  498. order_status = 1;
  499. } else if (oid === 3) {
  500. // 已完成
  501. order_status = 2;
  502. } else if (oid === 4) {
  503. // 退款/售后
  504. order_status = 4;
  505. }
  506. if (oid === 0) {
  507. wx.showLoading({
  508. title: '加载中',
  509. mask: true
  510. })
  511. wx.request({
  512. url: api.OrderManagement_list,
  513. header: {
  514. 'Authorization': wx.getStorageSync('token')
  515. },
  516. data: {
  517. id: that.data.pintuandetail.id
  518. },
  519. method: 'POST',
  520. success(res) {
  521. console.log(res);
  522. if (res.data.code === 1) {
  523. if (res.data.data == null) {
  524. that.setData({
  525. order_list: [],
  526. order_info: {},
  527. orderindex: oid
  528. })
  529. } else {
  530. that.setData({
  531. order_list: res.data.data.order_list,
  532. order_info: res.data.data.order_info,
  533. orderindex: oid
  534. })
  535. }
  536. } else {
  537. wx.showToast({
  538. title: res.data.msg,
  539. mask: true,
  540. icon: 'none'
  541. })
  542. }
  543. },
  544. fail(err) {
  545. wx.showToast({
  546. title: '发起网络请求失败',
  547. icon: 'none',
  548. mask: true
  549. })
  550. },
  551. complete() {
  552. wx.hideLoading()
  553. }
  554. })
  555. } else {
  556. wx.showLoading({
  557. title: '加载中',
  558. mask: true
  559. })
  560. wx.request({
  561. url: api.OrderManagement_list,
  562. header: {
  563. 'Authorization': wx.getStorageSync('token')
  564. },
  565. method: 'POST',
  566. data: {
  567. id: that.data.pintuandetail.id,
  568. order_status: order_status
  569. },
  570. success(res) {
  571. console.log(res);
  572. if (res.data.code === 1) {
  573. if (res.data.data == null) {
  574. that.setData({
  575. order_list: [],
  576. order_info: {},
  577. orderindex: oid
  578. })
  579. } else {
  580. that.setData({
  581. order_list: res.data.data.order_list,
  582. order_info: res.data.data.order_info,
  583. orderindex: oid
  584. })
  585. }
  586. } else {
  587. wx.showToast({
  588. title: res.data.msg,
  589. mask: true,
  590. icon: 'none'
  591. })
  592. }
  593. },
  594. fail(err) {
  595. wx.showToast({
  596. title: '发起网络请求失败',
  597. icon: 'none',
  598. mask: true
  599. })
  600. },
  601. complete() {
  602. wx.hideLoading()
  603. }
  604. })
  605. }
  606. },
  607. // 跳转订单详情
  608. navToOrderDetail(e) {
  609. let id = e.currentTarget.dataset.id;
  610. wx.navigateTo({
  611. url: '/pages/orderstatus/orderstatus?id=' + id,
  612. })
  613. },
  614. // 更新状态
  615. updateStatus(e) {
  616. this.setData({
  617. showUpdateState: true,
  618. updateStatusID: e.detail.id
  619. })
  620. }
  621. })