orders-con.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. getPay:function(e){
  44. var that = this;
  45. wx.request({
  46. url: app.globalData.url + '/routine/auth_api/pay_order?uid=' + app.globalData.uid +'&uni='+e.target.dataset.id,
  47. method: 'get',
  48. success: function (res) {
  49. var data = res.data.data;
  50. if (res.data.code == 200 && res.data.data.status == 'WECHAT_PAY') {
  51. var jsConfig = res.data.data.result.jsConfig;
  52. console.log(jsConfig);
  53. wx.requestPayment({
  54. timeStamp: jsConfig.timeStamp,
  55. nonceStr: jsConfig.nonceStr,
  56. package: jsConfig.package,
  57. signType: jsConfig.signType,
  58. paySign: jsConfig.paySign,
  59. success: function (res) {
  60. wx.showToast({
  61. title: '支付成功',
  62. icon: 'success',
  63. duration: 1000,
  64. })
  65. setTimeout(function () {
  66. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  67. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  68. })
  69. }, 1200)
  70. },
  71. fail: function (res) {
  72. wx.showToast({
  73. title: '支付失败',
  74. icon: 'success',
  75. duration: 1000,
  76. })
  77. // setTimeout(function () {
  78. // wx.navigateTo({
  79. // url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  80. // })
  81. // }, 1200)
  82. },
  83. complete: function (res) {
  84. console.log(res);
  85. if (res.errMsg == 'requestPayment:cancel') {
  86. wx.showToast({
  87. title: '取消支付',
  88. icon: 'none',
  89. duration: 1000,
  90. })
  91. // setTimeout(function () {
  92. // wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  93. // url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  94. // })
  95. // }, 1200)
  96. }
  97. },
  98. })
  99. } else if (res.data.code == 200){
  100. wx.showToast({
  101. title: res.data.msg,
  102. icon: 'success',
  103. duration: 2000
  104. })
  105. setTimeout(function () {
  106. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  107. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  108. })
  109. }, 1200)
  110. }else{
  111. wx.showToast({
  112. title: res.data.msg,
  113. icon: 'none',
  114. duration: 2000
  115. })
  116. setTimeout(function () {
  117. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  118. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  119. })
  120. }, 1200)
  121. }
  122. },
  123. fail: function (res) {
  124. console.log('submit fail');
  125. }
  126. });
  127. },
  128. delOrder:function(e){
  129. var header = {
  130. 'content-type': 'application/x-www-form-urlencoded'
  131. };
  132. var uni = e.currentTarget.dataset.uni;
  133. var that = this;
  134. wx.showModal({
  135. title: '确认删除订单?',
  136. content: '订单删除后将无法查看',
  137. success: function (res) {
  138. if (res.confirm) {
  139. wx.request({
  140. url: app.globalData.url + '/routine/auth_api/user_remove_order?uid=' + app.globalData.uid,
  141. data: { uni: uni },
  142. method: 'get',
  143. header: header,
  144. success: function (res) {
  145. if (res.data.code == 200) {
  146. wx.showToast({
  147. title: '成功',
  148. icon: 'success',
  149. duration: 2000
  150. })
  151. setTimeout(function(){
  152. wx.navigateTo({
  153. url: '/pages/orders-list/orders-list',
  154. })
  155. },1500)
  156. } else {
  157. wx.showToast({
  158. title: res.data.msg,
  159. icon: 'none',
  160. duration: 2000
  161. })
  162. }
  163. // that.setData({
  164. // ordercon: that.data.ordercon
  165. // });
  166. },
  167. fail: function (res) {
  168. console.log('submit fail');
  169. },
  170. complete: function (res) {
  171. console.log('submit complete');
  172. }
  173. });
  174. } else if (res.cancel) {
  175. console.log('用户点击取消')
  176. }
  177. }
  178. })
  179. },
  180. goTel:function(e){
  181. console.log(e);
  182. wx.makePhoneCall({
  183. phoneNumber: e.currentTarget.dataset.tel //仅为示例,并非真实的电话号码
  184. })
  185. },
  186. goJoinPink:function(e){
  187. var uni = e.currentTarget.dataset.uni;
  188. wx.navigateTo({
  189. url: '/pages/join-pink/index?id=' + uni,
  190. })
  191. },
  192. confirmOrder:function(e){
  193. var header = {
  194. 'content-type': 'application/x-www-form-urlencoded'
  195. };
  196. var uni = e.currentTarget.dataset.uni;
  197. var that = this;
  198. wx.showModal({
  199. title: '确认收货',
  200. content: '为保障权益,请收到货确认无误后,再确认收货',
  201. success: function (res) {
  202. if (res.confirm) {
  203. wx.request({
  204. url: app.globalData.url + '/routine/auth_api/user_take_order?uid=' + app.globalData.uid,
  205. data: { uni: uni },
  206. method: 'get',
  207. header: header,
  208. success: function (res) {
  209. if(res.data.code==200){
  210. wx.navigateTo({
  211. url: '/pages/orders-list/orders-list?nowstatus=4',
  212. })
  213. }else{
  214. wx.showToast({
  215. title: res.data.msg,
  216. icon: 'none',
  217. duration: 2000
  218. })
  219. }
  220. that.setData({
  221. ordercon: that.data.ordercon
  222. });
  223. },
  224. fail: function (res) {
  225. console.log('submit fail');
  226. },
  227. complete: function (res) {
  228. console.log('submit complete');
  229. }
  230. });
  231. } else if (res.cancel) {
  232. console.log('用户点击取消')
  233. }
  234. }
  235. })
  236. },
  237. goIndex:function(){
  238. wx.switchTab({
  239. url: '/pages/index/index'
  240. })
  241. },
  242. /**
  243. * 生命周期函数--监听页面初次渲染完成
  244. */
  245. onReady: function () {
  246. },
  247. /**
  248. * 生命周期函数--监听页面显示
  249. */
  250. onShow: function () {
  251. },
  252. /**
  253. * 生命周期函数--监听页面隐藏
  254. */
  255. onHide: function () {
  256. },
  257. /**
  258. * 生命周期函数--监听页面卸载
  259. */
  260. onUnload: function () {
  261. },
  262. /**
  263. * 页面相关事件处理函数--监听用户下拉动作
  264. */
  265. onPullDownRefresh: function () {
  266. },
  267. /**
  268. * 页面上拉触底事件的处理函数
  269. */
  270. onReachBottom: function () {
  271. },
  272. /**
  273. * 用户点击右上角分享
  274. */
  275. onShareAppMessage: function () {
  276. }
  277. })