排队支付小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

440 lines
11 KiB

  1. // order.js
  2. var api = require('../../api.js');
  3. var app = getApp();
  4. var is_no_more = false;
  5. var is_loading = false;
  6. var pageSize = 5;
  7. var pageNum = 1;
  8. var utils = require('../../utils.js');
  9. var util = require('../../utils/util.js');
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. imgServer: api.default.img_server,
  16. status: -1,
  17. order_list: [],
  18. show_no_data_tip: false,
  19. hide: 1,
  20. qrcode: "",
  21. key:""
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function(options) {
  27. var page = this;
  28. is_no_more = false;
  29. is_loading = false;
  30. page.data.key = ""
  31. pageNum = 1;
  32. pageSize = 1000;
  33. page.loadOrderList(options.status || -1);
  34. var pages = getCurrentPages();
  35. if (pages.length < 9) {
  36. page.setData({
  37. show_index: true,
  38. });
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. // this.loadOrderList(this.data.status);
  46. },
  47. formSubmit: function (e) {
  48. var page = this;
  49. pageNum = 1;
  50. page.data.key = e.detail.value.search;
  51. page.loadOrderList(page.data.status);
  52. }
  53. ,
  54. loadOrderList: function(status) {
  55. var access_token = wx.getStorageSync("access_token");
  56. if (status == undefined)
  57. status = -1;
  58. var page = this;
  59. page.setData({
  60. status: status,
  61. });
  62. wx.showLoading({
  63. title: "正在加载",
  64. mask: true,
  65. });
  66. app.request({
  67. url: api.order.list,
  68. data: {
  69. userid: access_token,
  70. pageNum: pageNum,
  71. pageSize: pageSize,
  72. key:page.data.key,
  73. status: page.data.status,
  74. },
  75. success: function(res) {
  76. console.log(res)
  77. if (res.code == 200) {
  78. page.setData({
  79. order_list: res.data.list,
  80. });
  81. if (res.data.total > pageSize) {
  82. is_no_more = false
  83. pageNum++
  84. } else {
  85. is_no_more = true
  86. }
  87. }
  88. page.setData({
  89. show_no_data_tip: (page.data.order_list.length == 0),
  90. });
  91. },
  92. complete: function() {
  93. wx.hideLoading();
  94. }
  95. });
  96. },
  97. statusChange: function(e) {
  98. var page = this;
  99. pageNum = 1;
  100. is_no_more = false;
  101. is_loading = false;
  102. var status = e.currentTarget.dataset.status
  103. page.setData({
  104. status: status
  105. });
  106. page.loadOrderList(status)
  107. },
  108. onReachBottom: function() {
  109. var access_token = wx.getStorageSync("access_token");
  110. var page = this;
  111. if (is_loading || is_no_more)
  112. return;
  113. is_loading = true;
  114. app.request({
  115. url: api.order.list,
  116. data: {
  117. userid: access_token,
  118. pageNum: pageNum,
  119. pageSize: pageSize,
  120. key:page.data.key,
  121. status: page.data.status,
  122. },
  123. success: function(res) {
  124. console.log(res)
  125. if (res.code == 200) {
  126. var order_list = page.data.order_list.concat(res.data.list);
  127. page.setData({
  128. order_list: order_list,
  129. });
  130. if (res.data.total > order_list.length) {
  131. is_no_more = false
  132. pageNum++
  133. } else {
  134. is_no_more = true
  135. }
  136. }
  137. },
  138. complete: function() {
  139. is_loading = false;
  140. }
  141. });
  142. },
  143. orderPay: function(e) {
  144. wx.showLoading({
  145. title: "正在提交",
  146. mask: true,
  147. });
  148. app.request({
  149. url: api.order.pay_data,
  150. data: {
  151. order_id: e.currentTarget.dataset.id,
  152. pay_type: "WECHAT_PAY",
  153. },
  154. complete: function() {
  155. wx.hideLoading();
  156. },
  157. success: function(res) {
  158. console.log(res);
  159. if (res.code == 200) {
  160. wx.requestPayment({
  161. timeStamp: res.data.timeStamp,
  162. nonceStr: res.data.nonceStr,
  163. package: res.data.package,
  164. signType: res.data.signType,
  165. paySign: res.data.paySign,
  166. success: function(e) {
  167. console.log("success");
  168. console.log(e);
  169. wx.requestSubscribeMessage({
  170. tmplIds: ['bPgXd4I-7E-GYafPJSNJEAQMuptkU_SYG1OscN7MM0o'],
  171. success(res) {
  172. console.log(res)
  173. },
  174. fail(error) {
  175. console.log(error)
  176. }
  177. });
  178. },
  179. fail: function(e) {
  180. console.log("fail");
  181. console.log(e);
  182. },
  183. complete: function(e) {
  184. console.log("complete");
  185. console.log(e);
  186. if (e.errMsg == "requestPayment:fail" || e.errMsg == "requestPayment:fail cancel") { //支付失败转到待支付订单列表
  187. wx.showModal({
  188. title: "提示",
  189. content: "订单尚未支付",
  190. showCancel: false,
  191. confirmText: "确认",
  192. success: function(res) {
  193. if (res.confirm) {
  194. wx.redirectTo({
  195. url: "/pages/order/order?status=9",
  196. });
  197. }
  198. }
  199. });
  200. return;
  201. }
  202. wx.redirectTo({
  203. url: "/pages/order/order?status=9",
  204. });
  205. },
  206. });
  207. }
  208. if (res.code == 1) {
  209. wx.showToast({
  210. title: res.msg,
  211. image: "/images/icon-warning.png",
  212. });
  213. }
  214. }
  215. });
  216. },
  217. onShareAppMessage: function (e) {
  218. var page = this;
  219. console.log("+++++++++");
  220. console.log(e);
  221. var res = {
  222. path: "/pages/order-detail-daifu/order-detail-daifu?id="
  223. + e.target.dataset.id,
  224. success: function (e) {
  225. console.log(e);
  226. share_count++;
  227. if (share_count == 1)
  228. app.shareSendCoupon(page);
  229. },
  230. title: "帮我代付一下,江湖救急~",
  231. imageUrl: "https://lovehomelive.oss-cn-beijing.aliyuncs.com/ic_logo.png",
  232. };
  233. return res;
  234. },
  235. toPay: function(e) {
  236. //获取支付数据
  237. app.request({
  238. url: api.order.pay_data,
  239. data: {
  240. id: e.currentTarget.dataset.id,
  241. payType: 2,
  242. },
  243. success: function(res) {
  244. console.log(res);
  245. if (res.code == 200) {
  246. //发起支付
  247. wx.requestPayment({
  248. timeStamp: res.data.timeStamp,
  249. nonceStr: res.data.nonceStr,
  250. package: res.data.package,
  251. signType: res.data.signType,
  252. paySign: res.data.paySign,
  253. success: function(e) {
  254. console.log('1');
  255. console.log(e);
  256. wx.requestSubscribeMessage({
  257. tmplIds: ['bPgXd4I-7E-GYafPJSNJEAQMuptkU_SYG1OscN7MM0o'],
  258. success(res) {
  259. console.log(res)
  260. },
  261. fail(error) {
  262. console.log(error)
  263. }
  264. });
  265. wx.redirectTo({
  266. url: "/pages/order/order?status=3",
  267. });
  268. },
  269. fail: function(e) {
  270. console.log('2');
  271. console.log(e);
  272. },
  273. complete: function(e) {
  274. console.log('3');
  275. console.log(e);
  276. if (e.errMsg == "requestPayment:fail" || e.errMsg == "requestPayment:fail cancel") { //支付失败转到待支付订单列表
  277. wx.showModal({
  278. title: "提示",
  279. content: "订单尚未支付",
  280. showCancel: false,
  281. confirmText: "确认",
  282. success: function(res) {
  283. if (res.confirm) {
  284. wx.redirectTo({
  285. url: "/pages/order/order?status=2",
  286. });
  287. }
  288. }
  289. });
  290. return;
  291. }
  292. if (e.errMsg == "requestPayment:ok") {
  293. return;
  294. }
  295. },
  296. });
  297. return;
  298. }
  299. if (res.code == 1) {
  300. wx.showToast({
  301. title: res.msg,
  302. image: "/images/icon-warning.png",
  303. });
  304. return;
  305. }
  306. }
  307. });
  308. },
  309. orderRevoke: function(e) {
  310. var page = this;
  311. wx.showModal({
  312. title: "提示",
  313. content: "是否取消该订单?",
  314. cancelText: "否",
  315. confirmText: "是",
  316. success: function(res) {
  317. if (res.cancel)
  318. return true;
  319. if (res.confirm) {
  320. wx.showLoading({
  321. title: "操作中",
  322. });
  323. app.request({
  324. url: api.order.revoke,
  325. data: {
  326. orderId: e.currentTarget.dataset.id,
  327. },
  328. success: function(res) {
  329. wx.hideLoading();
  330. page.loadOrderList(page.data.status);
  331. }
  332. });
  333. }
  334. }
  335. });
  336. },
  337. orderConfirm: function (e) {
  338. var page = this;
  339. wx.requestSubscribeMessage({
  340. tmplIds: ['LYqmtO9TqZNW4MUcdIjfZ6id2t_LheP98foMtJA92j4','CKLCPm5agmZHhhXItoo7foFN_S_5bt2CWiw-_-OvIVw'],
  341. success(res) {
  342. page.orderConfirm2(e);
  343. console.log(res)
  344. }
  345. })
  346. },
  347. orderConfirm2: function(e) {
  348. var page = this;
  349. wx.showModal({
  350. title: "提示",
  351. content: "是否确认已收到货?",
  352. cancelText: "否",
  353. confirmText: "是",
  354. success: function(res) {
  355. if (res.cancel)
  356. return true;
  357. if (res.confirm) {
  358. wx.showLoading({
  359. title: "操作中",
  360. });
  361. app.request({
  362. url: api.order.confirm,
  363. data: {
  364. orderId: e.currentTarget.dataset.id,
  365. },
  366. success: function(res) {
  367. wx.hideLoading();
  368. wx.showToast({
  369. title: res.msg,
  370. });
  371. if (res.code == 200) {
  372. page.loadOrderList(3);
  373. }
  374. }
  375. });
  376. }
  377. }
  378. });
  379. },
  380. orderQrcode: function(e) {
  381. var page = this;
  382. var order_list = page.data.order_list;
  383. var index = e.target.dataset.index;
  384. wx.showLoading({
  385. title: "正在加载",
  386. mask: true,
  387. });
  388. if (page.data.order_list[index].offline_qrcode) {
  389. page.setData({
  390. hide: 0,
  391. qrcode: page.data.order_list[index].offline_qrcode
  392. });
  393. wx.hideLoading();
  394. } else {
  395. app.request({
  396. url: api.order.get_qrcode,
  397. data: {
  398. order_no: order_list[index].order_no
  399. },
  400. success: function(res) {
  401. page.setData({
  402. hide: 0,
  403. qrcode: res.data.url
  404. });
  405. },
  406. complete: function() {
  407. wx.hideLoading();
  408. }
  409. });
  410. }
  411. },
  412. hide: function(e) {
  413. this.setData({
  414. hide: 1
  415. });
  416. }
  417. });