order-confirm.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. // pages/order-confirm/order-confirm.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. cartArr: [
  9. { "name": "微信", "icon": "icon-weixinzhifu", value:'weixin'},
  10. { "name": "余额支付", "icon": "icon-yuezhifu", value: 'yue' },
  11. // { "name": "线下付款", "icon": "icon-wallet", value: 'offline' },
  12. // { "name": "到店自提", "icon": "icon-dianpu", value: 'ziti' },
  13. ],
  14. cartInfo : [],
  15. cartId : '',
  16. priceGroup :[],
  17. orderKey:'',
  18. seckillId:0,
  19. BargainId:0,
  20. combinationId:0,
  21. pinkId:0,
  22. offlinePostage : 0,
  23. integralRatio: 1,
  24. usableCoupon : [],
  25. userInfo : [],
  26. url: app.globalData.urlImages,
  27. addressId:0,
  28. couponId:0,
  29. couponPrice:'',
  30. couponInfo:[],
  31. addressInfo:[],
  32. mark:'',
  33. payType:'weixin',
  34. useIntegral:''
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. app.setBarColor();
  41. app.setUserInfo();
  42. var that = this;
  43. if (options.pinkId){
  44. that.setData({
  45. pinkId: options.pinkId
  46. })
  47. }
  48. if (options.addressId){
  49. that.setData({
  50. addressId: options.addressId
  51. });
  52. }
  53. if (options.couponId) {
  54. that.setData({
  55. couponId: options.couponId
  56. });
  57. }
  58. if (options.id == ''){
  59. wx.showToast({
  60. title: '请选择要购买的商品',
  61. icon: 'none',
  62. duration: 1000,
  63. })
  64. setTimeout(function(){
  65. that.toBuy();
  66. },1100)
  67. }else{
  68. this.getConfirm(options.id);
  69. }
  70. that.getaddressInfo();
  71. that.getCouponRope();
  72. },
  73. bindHideKeyboard:function(e){
  74. this.setData({
  75. mark: e.detail.value
  76. })
  77. },
  78. radioChange:function(e){
  79. this.setData({
  80. payType: e.currentTarget.dataset.value
  81. })
  82. },
  83. subOrder:function(e){
  84. var that = this;
  85. var header = {
  86. 'content-type': 'application/x-www-form-urlencoded',
  87. };
  88. if (that.data.payType == ''){
  89. wx.showToast({
  90. title: '请选择支付方式',
  91. icon: 'none',
  92. duration: 1000,
  93. })
  94. } else if (!that.data.addressId){
  95. wx.showToast({
  96. title: '请选择收货地址',
  97. icon: 'none',
  98. duration: 1000,
  99. })
  100. } else {
  101. wx.request({
  102. url: app.globalData.url + '/routine/auth_api/create_order?uid=' + app.globalData.uid +'&key='+ that.data.orderKey,
  103. method: 'POST',
  104. header: header,
  105. data: {
  106. addressId: that.data.addressId,
  107. formId: e.detail.formId,
  108. couponId: that.data.couponId,
  109. payType: that.data.payType,
  110. useIntegral: that.data.useIntegral,
  111. bargainId: that.data.BargainId,
  112. combinationId: that.data.combinationId,
  113. pinkId: that.data.pinkId,
  114. seckill_id: that.data.seckillId,
  115. mark: that.data.mark
  116. },
  117. success: function (res) {
  118. var data = res.data.data;
  119. if (res.data.code == 200 && res.data.data.status == 'SUCCESS'){
  120. wx.showToast({
  121. title: res.data.msg,
  122. icon: 'success',
  123. duration: 1000,
  124. })
  125. setTimeout(function () {
  126. wx.navigateTo({
  127. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  128. })
  129. }, 1200)
  130. } else if (res.data.code == 200 && res.data.data.status == 'ORDER_EXIST') {
  131. wx.showToast({
  132. title: res.data.msg,
  133. icon: 'none',
  134. duration: 1000,
  135. })
  136. setTimeout(function () {
  137. wx.navigateTo({
  138. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  139. })
  140. }, 1200)
  141. } else if (res.data.code == 200 && res.data.data.status == 'ORDER_EXIST') {
  142. wx.showToast({
  143. title: res.data.msg,
  144. icon: 'none',
  145. duration: 1000,
  146. })
  147. setTimeout(function () {
  148. wx.navigateTo({
  149. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  150. })
  151. }, 1200)
  152. }else if (res.data.code == 200 && res.data.data.status == 'EXTEND_ORDER'){
  153. wx.showToast({
  154. title: res.data.msg,
  155. icon: 'none',
  156. duration: 1000,
  157. })
  158. setTimeout(function () {
  159. wx.navigateTo({
  160. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  161. })
  162. }, 1200)
  163. } else if (res.data.code == 200 && res.data.data.status == 'WECHAT_PAY'){
  164. var jsConfig = res.data.data.result.jsConfig;
  165. wx.requestPayment({
  166. timeStamp: jsConfig.timeStamp,
  167. nonceStr: jsConfig.nonceStr,
  168. package: jsConfig.package,
  169. signType: jsConfig.signType,
  170. paySign: jsConfig.paySign,
  171. success: function(res) {
  172. wx.showToast({
  173. title: '支付成功',
  174. icon: 'success',
  175. duration: 1000,
  176. })
  177. setTimeout(function () {
  178. wx.navigateTo({
  179. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  180. })
  181. }, 1200)
  182. },
  183. fail: function(res) {
  184. wx.showToast({
  185. title: '支付失败',
  186. icon: 'none',
  187. duration: 1000,
  188. })
  189. setTimeout(function () {
  190. wx.navigateTo({
  191. url: '/pages/orders-con/orders-con?order_id='+data.result.orderId
  192. })
  193. }, 1200)
  194. },
  195. complete: function(res) {
  196. if (res.errMsg == 'requestPayment:cancel') {
  197. wx.showToast({
  198. title: '取消支付',
  199. icon: 'none',
  200. duration: 1000,
  201. })
  202. setTimeout(function () {
  203. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  204. url: '/pages/orders-con/orders-con?order_id=' + data.result.orderId
  205. })
  206. }, 1200)
  207. }
  208. },
  209. })
  210. }else{
  211. wx.showToast({
  212. title: res.data.msg,
  213. icon: 'none',
  214. duration: 1000,
  215. })
  216. }
  217. }
  218. })
  219. }
  220. },
  221. getCouponRope:function(){
  222. var that = this;
  223. if (that.data.couponId){
  224. wx.request({
  225. url: app.globalData.url + '/routine/auth_api/get_coupon_rope?uid=' + app.globalData.uid,
  226. method: 'GET',
  227. data: {
  228. couponId: that.data.couponId
  229. },
  230. success: function (res) {
  231. if (res.data.code == 200) {
  232. that.setData({
  233. couponInfo: res.data.data,
  234. couponPrice: '-' + res.data.data.coupon_price
  235. })
  236. }else{
  237. that.setData({
  238. couponInfo: [],
  239. couponPrice: ''
  240. })
  241. }
  242. }
  243. })
  244. }
  245. },
  246. getaddressInfo:function(){
  247. var that = this;
  248. if (that.data.addressId){
  249. wx.request({
  250. url: app.globalData.url + '/routine/auth_api/get_user_address?uid=' + app.globalData.uid,
  251. method: 'GET',
  252. data:{
  253. addressId: that.data.addressId
  254. },
  255. success: function (res) {
  256. if (res.data.code == 200) {
  257. that.setData({
  258. addressInfo:res.data.data
  259. })
  260. }
  261. }
  262. })
  263. }else{
  264. wx.request({
  265. url: app.globalData.url + '/routine/auth_api/user_default_address?uid=' + app.globalData.uid,
  266. method: 'GET',
  267. success: function (res) {
  268. if (res.data.code == 200) {
  269. that.setData({
  270. addressInfo: res.data.data,
  271. addressId: res.data.data.id
  272. })
  273. }
  274. }
  275. })
  276. }
  277. },
  278. getAddress: function () {
  279. var that = this;
  280. var header = {
  281. 'content-type': 'application/x-www-form-urlencoded'
  282. };
  283. wx.request({
  284. url: app.globalData.url + '/routine/auth_api/user_address_list?uid=' + app.globalData.uid,
  285. method: 'POST',
  286. header: header,
  287. success: function (res) {
  288. if (res.data.code == 200) {
  289. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  290. url: '/pages/address/address?cartId=' + that.data.cartId + '&pinkId=' + that.data.pinkId + '&couponId=' + that.data.couponId
  291. })
  292. }
  293. }
  294. })
  295. },
  296. getCoupon:function(){
  297. var that = this;
  298. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  299. url: '/pages/coupon-status/coupon-status?cartId=' + that.data.cartId + '&totalPrice=' + that.data.priceGroup.totalPrice + '&pinkId=' + that.data.pinkId + '&addressId=' + that.data.addressId
  300. })
  301. },
  302. toBuy:function(){
  303. wx.switchTab({
  304. url: '/pages/buycar/buycar'
  305. });
  306. },
  307. toAddress: function () {
  308. var that = this;
  309. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  310. url: '/pages/addaddress/addaddress?cartId=' + that.data.cartId + '&pinkId=' + that.data.pinkId + '&couponId=' + that.data.couponId
  311. })
  312. },
  313. getConfirm: function (cartIdsStr){
  314. var that = this;
  315. var header = {
  316. 'content-type': 'application/x-www-form-urlencoded',
  317. };
  318. wx.request({
  319. url: app.globalData.url + '/routine/auth_api/confirm_order?uid=' + app.globalData.uid,
  320. method: 'POST',
  321. data: {
  322. cartId: cartIdsStr
  323. },
  324. header: header,
  325. success: function (res) {
  326. if(res.data.code == 200){
  327. that.setData({
  328. userInfo: res.data.data.userInfo,
  329. cartInfo: res.data.data.cartInfo,
  330. integralRatio: res.data.data.integralRatio,
  331. offlinePostage: res.data.data.offlinePostage,
  332. orderKey: res.data.data.orderKey,
  333. priceGroup: res.data.data.priceGroup,
  334. cartId: res.data.data.cartId,
  335. seckillId: res.data.data.seckill_id,
  336. usableCoupon: res.data.data.usableCoupon
  337. })
  338. that.getBargainId();
  339. }
  340. }
  341. })
  342. },
  343. getBargainId:function(){
  344. var that = this;
  345. var cartINfo = that.data.cartInfo;
  346. var BargainId = 0;
  347. var combinationId = 0;
  348. cartINfo.forEach(function (value, index, cartINfo){
  349. BargainId = cartINfo[index].bargain_id,
  350. combinationId = cartINfo[index].combination_id
  351. })
  352. that.setData({
  353. BargainId: BargainId,
  354. combinationId:combinationId
  355. })
  356. console.log(that.data.BargainId);
  357. console.log(that.data.seckillId);
  358. console.log(that.data.combinationId);
  359. },
  360. /**
  361. * 生命周期函数--监听页面初次渲染完成
  362. */
  363. onReady: function () {
  364. },
  365. /**
  366. * 生命周期函数--监听页面显示
  367. */
  368. onShow: function () {
  369. },
  370. /**
  371. * 生命周期函数--监听页面隐藏
  372. */
  373. onHide: function () {
  374. },
  375. /**
  376. * 生命周期函数--监听页面卸载
  377. */
  378. onUnload: function () {
  379. },
  380. /**
  381. * 页面相关事件处理函数--监听用户下拉动作
  382. */
  383. onPullDownRefresh: function () {
  384. },
  385. /**
  386. * 页面上拉触底事件的处理函数
  387. */
  388. onReachBottom: function () {
  389. },
  390. /**
  391. * 用户点击右上角分享
  392. */
  393. onShareAppMessage: function () {
  394. }
  395. })