orders-con.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. // pages/orders-con/orders-con.js
  2. var app = getApp();
  3. var wxh = require('../../utils/wxh.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. url: app.globalData.urlImages
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (e) {
  15. app.setBarColor();
  16. app.globalData.openPages = '/pages/orders-con/orders-con?order_id=' + e.order_id;
  17. app.setUserInfo();
  18. var header = {
  19. 'content-type': 'application/x-www-form-urlencoded'
  20. };
  21. var uni = e.order_id;
  22. var that = this;
  23. wx.showLoading({ title: "正在加载中……" });
  24. wx.request({
  25. url: app.globalData.url + '/routine/auth_api/get_order?uid=' + app.globalData.uid,
  26. data: { uni: uni },
  27. method: 'get',
  28. header: header,
  29. success: function (res) {
  30. wx.hideLoading();
  31. that.setData({
  32. ordercon: res.data.data
  33. });
  34. },
  35. fail: function (res) {
  36. console.log('submit fail');
  37. },
  38. complete: function (res) {
  39. console.log('submit complete');
  40. }
  41. });
  42. },
  43. //选择付款方式
  44. checkPay: function (e) {
  45. var that = this;
  46. wx.showActionSheet({
  47. itemList: ['微信支付', '余额支付'],
  48. success(res) {
  49. // console.log(res.tapIndex)
  50. if (res.tapIndex == 0) {//微信支付
  51. wx.request({
  52. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id + '&paytype=weixin',
  53. method: 'get',
  54. success: function (res) {
  55. var data = res.data.data;
  56. if (res.data.code == 200) {
  57. var jsConfig = res.data.data.result.jsConfig;
  58. // console.log(jsConfig);
  59. wx.requestPayment({
  60. timeStamp: jsConfig.timestamp,
  61. nonceStr: jsConfig.nonceStr,
  62. package: jsConfig.package,
  63. signType: jsConfig.signType,
  64. paySign: jsConfig.paySign,
  65. success: function (res) {
  66. wx.showToast({
  67. title: '支付成功',
  68. icon: 'success',
  69. duration: 1000,
  70. })
  71. setTimeout(function () {
  72. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面
  73. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  74. // url: '/pages/orders-con/orders-con?order_id=' + data.result.order_id
  75. })
  76. }, 1200)
  77. },
  78. fail: function (res) {
  79. wx.showToast({
  80. title: '取消支付',
  81. icon: 'success',
  82. duration: 1000,
  83. })
  84. },
  85. complete: function (res) {
  86. console.log(res);
  87. if (res.errMsg == 'requestPayment:cancel') {
  88. wx.showToast({
  89. title: '取消支付',
  90. icon: 'none',
  91. duration: 1000,
  92. })
  93. }
  94. },
  95. })
  96. }else{
  97. wx.showToast({
  98. title: res.data.msg,
  99. icon: 'fail',
  100. duration: 2000
  101. })
  102. }
  103. },
  104. fail: function (res) {
  105. console.log('submit fail');
  106. }
  107. });
  108. } else {
  109. wx.request({
  110. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id + '&paytype=yue',
  111. method: 'get',
  112. success: function (res) {
  113. var data = res.data.data;
  114. if (res.data.code == 200) {
  115. wx.showToast({
  116. title: res.data.msg,
  117. icon: 'success',
  118. duration: 2000
  119. })
  120. setTimeout(function () {
  121. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  122. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  123. // url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  124. })
  125. }, 1200)
  126. } else {
  127. wx.showToast({
  128. title: res.data.msg,
  129. icon: 'none',
  130. duration: 2000
  131. })
  132. }
  133. },
  134. fail: function (res) {
  135. console.log('submit fail');
  136. }
  137. });
  138. }
  139. },
  140. fail(res) {
  141. console.log(res.errMsg)
  142. },
  143. // complete(res) {
  144. // setTimeout(function () {
  145. // wx.navigateTo({
  146. // url: '/pages/orders-list/orders-list',
  147. // })
  148. // }, 1500)
  149. // },
  150. })
  151. },
  152. //立即付款
  153. getPay: function (e) {
  154. var that = this;
  155. wx.request({
  156. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id,
  157. method: 'get',
  158. success: function (res) {
  159. var data = res.data.data;
  160. if (res.data.code == 200 && res.data.data.status == 'WECHAT_PAY') {
  161. var jsConfig = res.data.data.result.jsConfig;
  162. console.log(jsConfig);
  163. wx.requestPayment({
  164. timeStamp: jsConfig.timestamp,
  165. nonceStr: jsConfig.nonceStr,
  166. package: jsConfig.package,
  167. signType: jsConfig.signType,
  168. paySign: jsConfig.paySign,
  169. success: function (res) {
  170. wx.showToast({
  171. title: '支付成功',
  172. icon: 'success',
  173. duration: 1000,
  174. })
  175. setTimeout(function () {
  176. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  177. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  178. })
  179. }, 1200)
  180. },
  181. fail: function (res) {
  182. wx.showToast({
  183. title: '支付失败',
  184. icon: 'success',
  185. duration: 1000,
  186. })
  187. setTimeout(function () {
  188. wx.navigateTo({
  189. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  190. })
  191. }, 1200)
  192. },
  193. complete: function (res) {
  194. console.log(res);
  195. if (res.errMsg == 'requestPayment:cancel') {
  196. wx.showToast({
  197. title: '取消支付',
  198. icon: 'none',
  199. duration: 1000,
  200. })
  201. setTimeout(function () {
  202. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  203. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  204. })
  205. }, 1200)
  206. }
  207. },
  208. })
  209. } else if (res.data.code == 200) {
  210. wx.showToast({
  211. title: res.data.msg,
  212. icon: 'success',
  213. duration: 2000
  214. })
  215. setTimeout(function () {
  216. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  217. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  218. })
  219. }, 1200)
  220. } else {
  221. wx.showToast({
  222. title: res.data.msg,
  223. icon: 'none',
  224. duration: 2000
  225. })
  226. setTimeout(function () {
  227. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  228. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  229. })
  230. }, 1200)
  231. }
  232. },
  233. fail: function (res) {
  234. console.log('submit fail');
  235. }
  236. });
  237. },
  238. delOrder: function (e) {
  239. var header = {
  240. 'content-type': 'application/x-www-form-urlencoded'
  241. };
  242. var uni = e.currentTarget.dataset.uni;
  243. var that = this;
  244. wx.showModal({
  245. title: '确认删除订单?',
  246. content: '订单删除后将无法查看',
  247. success: function (res) {
  248. if (res.confirm) {
  249. wx.request({
  250. url: app.globalData.url + '/routine/auth_api/user_remove_order?uid=' + app.globalData.uid,
  251. data: { uni: uni },
  252. method: 'get',
  253. header: header,
  254. success: function (res) {
  255. if (res.data.code == 200) {
  256. wx.showToast({
  257. title: '成功',
  258. icon: 'success',
  259. duration: 2000
  260. })
  261. setTimeout(function () {
  262. wx.navigateTo({
  263. url: '/pages/orders-list/orders-list',
  264. })
  265. }, 1500)
  266. } else {
  267. wx.showToast({
  268. title: res.data.msg,
  269. icon: 'none',
  270. duration: 2000
  271. })
  272. }
  273. // that.setData({
  274. // ordercon: that.data.ordercon
  275. // });
  276. },
  277. fail: function (res) {
  278. console.log('submit fail');
  279. },
  280. complete: function (res) {
  281. console.log('submit complete');
  282. }
  283. });
  284. } else if (res.cancel) {
  285. console.log('用户点击取消')
  286. }
  287. }
  288. })
  289. },
  290. goTel: function (e) {
  291. console.log(e);
  292. wx.makePhoneCall({
  293. phoneNumber: e.currentTarget.dataset.tel //仅为示例,并非真实的电话号码
  294. })
  295. },
  296. goJoinPink: function (e) {
  297. var uni = e.currentTarget.dataset.uni;
  298. wx.navigateTo({
  299. url: '/pages/join-pink/index?id=' + uni,
  300. })
  301. },
  302. confirmOrder: function (e) {
  303. var header = {
  304. 'content-type': 'application/x-www-form-urlencoded'
  305. };
  306. var uni = e.currentTarget.dataset.uni;
  307. var that = this;
  308. wx.showModal({
  309. title: '确认收货',
  310. content: '为保障权益,请收到货确认无误后,再确认收货',
  311. success: function (res) {
  312. if (res.confirm) {
  313. wx.request({
  314. url: app.globalData.url + '/routine/auth_api/user_take_order?uid=' + app.globalData.uid,
  315. data: { uni: uni },
  316. method: 'get',
  317. header: header,
  318. success: function (res) {
  319. if (res.data.code == 200) {
  320. wx.navigateTo({
  321. url: '/pages/orders-list/orders-list?nowstatus=4',
  322. })
  323. } else {
  324. wx.showToast({
  325. title: res.data.msg,
  326. icon: 'none',
  327. duration: 2000
  328. })
  329. }
  330. that.setData({
  331. ordercon: that.data.ordercon
  332. });
  333. },
  334. fail: function (res) {
  335. console.log('submit fail');
  336. },
  337. complete: function (res) {
  338. console.log('submit complete');
  339. }
  340. });
  341. } else if (res.cancel) {
  342. console.log('用户点击取消')
  343. }
  344. }
  345. })
  346. },
  347. goIndex: function () {
  348. wx.switchTab({
  349. url: '/pages/index/index'
  350. })
  351. },
  352. goAgain:function(e){
  353. var that = this;
  354. var uni = e.currentTarget.dataset.uni;
  355. wx.request({
  356. url: app.globalData.url + '/routine/auth_api/again_order?uid=' + app.globalData.uid,
  357. data: { uni: uni },
  358. method: 'get',
  359. success: function (res) {
  360. if (res.data.code == 200) {
  361. wx.navigateTo({
  362. url: '/pages/order-confirm/order-confirm?id=' + res.data.data,
  363. })
  364. } else {
  365. wx.showToast({
  366. title: res.data.msg,
  367. icon: 'none',
  368. duration: 2000
  369. })
  370. }
  371. }
  372. });
  373. },
  374. /**
  375. * 生命周期函数--监听页面初次渲染完成
  376. */
  377. onReady: function () {
  378. },
  379. /**
  380. * 生命周期函数--监听页面显示
  381. */
  382. onShow: function () {
  383. },
  384. /**
  385. * 生命周期函数--监听页面隐藏
  386. */
  387. onHide: function () {
  388. },
  389. /**
  390. * 生命周期函数--监听页面卸载
  391. */
  392. onUnload: function () {
  393. },
  394. /**
  395. * 页面相关事件处理函数--监听用户下拉动作
  396. */
  397. onPullDownRefresh: function () {
  398. },
  399. /**
  400. * 页面上拉触底事件的处理函数
  401. */
  402. onReachBottom: function () {
  403. },
  404. /**
  405. * 用户点击右上角分享
  406. */
  407. onShareAppMessage: function () {
  408. }
  409. })