orders-con.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. }
  97. },
  98. fail: function (res) {
  99. console.log('submit fail');
  100. }
  101. });
  102. } else {
  103. wx.request({
  104. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id + '&paytype=yue',
  105. method: 'get',
  106. success: function (res) {
  107. var data = res.data.data;
  108. if (res.data.code == 200) {
  109. wx.showToast({
  110. title: res.data.msg,
  111. icon: 'success',
  112. duration: 2000
  113. })
  114. setTimeout(function () {
  115. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  116. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  117. // url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  118. })
  119. }, 1200)
  120. } else {
  121. wx.showToast({
  122. title: res.data.msg,
  123. icon: 'none',
  124. duration: 2000
  125. })
  126. }
  127. },
  128. fail: function (res) {
  129. console.log('submit fail');
  130. }
  131. });
  132. }
  133. },
  134. fail(res) {
  135. console.log(res.errMsg)
  136. },
  137. // complete(res) {
  138. // setTimeout(function () {
  139. // wx.navigateTo({
  140. // url: '/pages/orders-list/orders-list',
  141. // })
  142. // }, 1500)
  143. // },
  144. })
  145. },
  146. //立即付款
  147. getPay: function (e) {
  148. var that = this;
  149. wx.request({
  150. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid + '&uni=' + e.target.dataset.id,
  151. method: 'get',
  152. success: function (res) {
  153. var data = res.data.data;
  154. if (res.data.code == 200 && res.data.data.status == 'WECHAT_PAY') {
  155. var jsConfig = res.data.data.result.jsConfig;
  156. console.log(jsConfig);
  157. wx.requestPayment({
  158. timeStamp: jsConfig.timeStamp,
  159. nonceStr: jsConfig.nonceStr,
  160. package: jsConfig.package,
  161. signType: jsConfig.signType,
  162. paySign: jsConfig.paySign,
  163. success: function (res) {
  164. wx.showToast({
  165. title: '支付成功',
  166. icon: 'success',
  167. duration: 1000,
  168. })
  169. setTimeout(function () {
  170. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  171. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  172. })
  173. }, 1200)
  174. },
  175. fail: function (res) {
  176. wx.showToast({
  177. title: '支付失败',
  178. icon: 'success',
  179. duration: 1000,
  180. })
  181. setTimeout(function () {
  182. wx.navigateTo({
  183. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  184. })
  185. }, 1200)
  186. },
  187. complete: function (res) {
  188. console.log(res);
  189. if (res.errMsg == 'requestPayment:cancel') {
  190. wx.showToast({
  191. title: '取消支付',
  192. icon: 'none',
  193. duration: 1000,
  194. })
  195. setTimeout(function () {
  196. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  197. url: '/pages/orders-list/orders-list?uid=' + app.globalData.uid
  198. })
  199. }, 1200)
  200. }
  201. },
  202. })
  203. } else if (res.data.code == 200) {
  204. wx.showToast({
  205. title: res.data.msg,
  206. icon: 'success',
  207. duration: 2000
  208. })
  209. setTimeout(function () {
  210. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  211. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  212. })
  213. }, 1200)
  214. } else {
  215. wx.showToast({
  216. title: res.data.msg,
  217. icon: 'none',
  218. duration: 2000
  219. })
  220. setTimeout(function () {
  221. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  222. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  223. })
  224. }, 1200)
  225. }
  226. },
  227. fail: function (res) {
  228. console.log('submit fail');
  229. }
  230. });
  231. },
  232. delOrder: function (e) {
  233. var header = {
  234. 'content-type': 'application/x-www-form-urlencoded'
  235. };
  236. var uni = e.currentTarget.dataset.uni;
  237. var that = this;
  238. wx.showModal({
  239. title: '确认删除订单?',
  240. content: '订单删除后将无法查看',
  241. success: function (res) {
  242. if (res.confirm) {
  243. wx.request({
  244. url: app.globalData.url + '/routine/auth_api/user_remove_order?uid=' + app.globalData.uid,
  245. data: { uni: uni },
  246. method: 'get',
  247. header: header,
  248. success: function (res) {
  249. if (res.data.code == 200) {
  250. wx.showToast({
  251. title: '成功',
  252. icon: 'success',
  253. duration: 2000
  254. })
  255. setTimeout(function () {
  256. wx.navigateTo({
  257. url: '/pages/orders-list/orders-list',
  258. })
  259. }, 1500)
  260. } else {
  261. wx.showToast({
  262. title: res.data.msg,
  263. icon: 'none',
  264. duration: 2000
  265. })
  266. }
  267. // that.setData({
  268. // ordercon: that.data.ordercon
  269. // });
  270. },
  271. fail: function (res) {
  272. console.log('submit fail');
  273. },
  274. complete: function (res) {
  275. console.log('submit complete');
  276. }
  277. });
  278. } else if (res.cancel) {
  279. console.log('用户点击取消')
  280. }
  281. }
  282. })
  283. },
  284. goTel: function (e) {
  285. console.log(e);
  286. wx.makePhoneCall({
  287. phoneNumber: e.currentTarget.dataset.tel //仅为示例,并非真实的电话号码
  288. })
  289. },
  290. goJoinPink: function (e) {
  291. var uni = e.currentTarget.dataset.uni;
  292. wx.navigateTo({
  293. url: '/pages/join-pink/index?id=' + uni,
  294. })
  295. },
  296. confirmOrder: function (e) {
  297. var header = {
  298. 'content-type': 'application/x-www-form-urlencoded'
  299. };
  300. var uni = e.currentTarget.dataset.uni;
  301. var that = this;
  302. wx.showModal({
  303. title: '确认收货',
  304. content: '为保障权益,请收到货确认无误后,再确认收货',
  305. success: function (res) {
  306. if (res.confirm) {
  307. wx.request({
  308. url: app.globalData.url + '/routine/auth_api/user_take_order?uid=' + app.globalData.uid,
  309. data: { uni: uni },
  310. method: 'get',
  311. header: header,
  312. success: function (res) {
  313. if (res.data.code == 200) {
  314. wx.navigateTo({
  315. url: '/pages/orders-list/orders-list?nowstatus=4',
  316. })
  317. } else {
  318. wx.showToast({
  319. title: res.data.msg,
  320. icon: 'none',
  321. duration: 2000
  322. })
  323. }
  324. that.setData({
  325. ordercon: that.data.ordercon
  326. });
  327. },
  328. fail: function (res) {
  329. console.log('submit fail');
  330. },
  331. complete: function (res) {
  332. console.log('submit complete');
  333. }
  334. });
  335. } else if (res.cancel) {
  336. console.log('用户点击取消')
  337. }
  338. }
  339. })
  340. },
  341. goIndex: function () {
  342. wx.switchTab({
  343. url: '/pages/index/index'
  344. })
  345. },
  346. /**
  347. * 生命周期函数--监听页面初次渲染完成
  348. */
  349. onReady: function () {
  350. },
  351. /**
  352. * 生命周期函数--监听页面显示
  353. */
  354. onShow: function () {
  355. },
  356. /**
  357. * 生命周期函数--监听页面隐藏
  358. */
  359. onHide: function () {
  360. },
  361. /**
  362. * 生命周期函数--监听页面卸载
  363. */
  364. onUnload: function () {
  365. },
  366. /**
  367. * 页面相关事件处理函数--监听用户下拉动作
  368. */
  369. onPullDownRefresh: function () {
  370. },
  371. /**
  372. * 页面上拉触底事件的处理函数
  373. */
  374. onReachBottom: function () {
  375. },
  376. /**
  377. * 用户点击右上角分享
  378. */
  379. onShareAppMessage: function () {
  380. }
  381. })