check-submit.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // pages/check-submit/check-submit.js
  2. Page({
  3. data: {
  4. mch_list: [],
  5. car_appoint_id:''
  6. },
  7. onLoad: function (options) {
  8. this.newSubmitPreview(options.data)
  9. this.setData({
  10. phone: options.phone
  11. })
  12. },
  13. newSubmitPreview: function(t){
  14. let data = JSON.parse(decodeURIComponent(t))
  15. console.log('预约接口数据',data)
  16. this.setData({
  17. car_appoint_id: data.car_appoint_id
  18. })
  19. // 最终数据
  20. let o = {
  21. mch_list:[]
  22. }
  23. // mch数据
  24. let mch = {
  25. goods_list:[]
  26. }
  27. // good_list数据
  28. let good_list = {
  29. attr:[]
  30. }
  31. // atrrId数据
  32. let attr = JSON.parse(data.goods.attr)
  33. let attr_id = attr[0].attr_list[0].attr_id
  34. let attr_group_id = attr[0].attr_list[0].attr_group_id
  35. // this.data.car_appoint_id = data.car_appoint_id
  36. good_list.goods_id = data.goods.id
  37. good_list.num = 1
  38. good_list.attr.push({
  39. attr_id:attr_id,
  40. attr_group_id:attr_group_id
  41. })
  42. mch.mch_id = data.goods.mch_id
  43. mch.goods_list.push(good_list)
  44. console.log(mch,'mch')
  45. o.mch_list = JSON.stringify([mch])
  46. let that = this
  47. getApp().request({
  48. url: getApp().api.order.new_submit_preview,
  49. method: "POST",
  50. data: o,
  51. success: function (res) {
  52. console.log(res,'下单')
  53. if(res.code == 0){
  54. res.data.mch_list[0].show = false
  55. res.data.mch_list[0].show_length = 0
  56. res.data.mch_list[0].offline = 0
  57. that.setData({
  58. mch_list: res.data.mch_list
  59. })
  60. }else{
  61. wx.showToast({
  62. icon: 'none',
  63. title: res.msg,
  64. })
  65. setTimeout(()=>{
  66. wx.navigateBack()
  67. },2000)
  68. }
  69. }
  70. })
  71. },
  72. pay: function(){
  73. let o = {
  74. mch_list:[]
  75. }
  76. o.mch_list = JSON.stringify(this.data.mch_list)
  77. o.car_appoint_id = this.data.car_appoint_id
  78. o.payment = 3
  79. o.phone = this.data.phone
  80. o.formId = undefined
  81. getApp().request({
  82. url: getApp().api.order.new_submit,
  83. method: "POST",
  84. data: o,
  85. success: function (res) {
  86. console.log(res,'下单sssss')
  87. getApp().request({
  88. url: getApp().api.order.pay_data,
  89. data: {
  90. order_id: res.data.order_id,
  91. pay_type: "WECHAT_PAY"
  92. },
  93. complete: function () {
  94. getApp().core.hideLoading()
  95. },
  96. success: function (t) {
  97. 0 == t.code && getApp().core.requestPayment({
  98. _res: t,
  99. timeStamp: t.data.timeStamp,
  100. nonceStr: t.data.nonceStr,
  101. package: t.data.package,
  102. signType: t.data.signType,
  103. paySign: t.data.paySign,
  104. success: function (t) {},
  105. fail: function (t) {},
  106. complete: function (t) {
  107. "requestPayment:fail" != t.errMsg && "requestPayment:fail cancel" != t.errMsg ? getApp().core.redirectTo({
  108. url: "/pages/order/order?status=2"
  109. }) : getApp().core.showModal({
  110. title: "提示",
  111. content: "订单尚未支付",
  112. showCancel: !1,
  113. confirmText: "确认",
  114. success: function (t) {
  115. t.confirm && getApp().core.redirectTo({
  116. url: "/pages/order/order?status=0"
  117. })
  118. }
  119. })
  120. }
  121. }), 1 == t.code && getApp().core.showToast({
  122. title: t.msg,
  123. image: "/images/icon-warning.png"
  124. })
  125. }
  126. })
  127. // getApp().request({
  128. // url: getApp().api.order.pay_data,
  129. // data: {
  130. // order_id: res.data.order_id,
  131. // pay_type: "WECHAT_PAY"
  132. // },
  133. // success: function (e) {
  134. // 0 == e.code ? (getApp().core.hideLoading(),
  135. // getApp().core.requestPayment({
  136. // _res: e,
  137. // timeStamp: e.data.timeStamp,
  138. // nonceStr: e.data.nonceStr,
  139. // package: e.data.package,
  140. // signType: e.data.signType,
  141. // paySign: e.data.paySign,
  142. // complete: function (e) {
  143. // "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? "requestPayment:ok" == e.errMsg && getApp().core.redirectTo({
  144. // url: "/pages/integral-mall/order/order?status=1"
  145. // }) : getApp().core.showModal({
  146. // title: "提示",
  147. // content: "订单尚未支付",
  148. // showCancel: !1,
  149. // confirmText: "确认"
  150. // })
  151. // }
  152. // })) : (getApp().core.hideLoading(), getApp().core.showModal({
  153. // title: "提示",
  154. // content: e.msg,
  155. // showCancel: !1,
  156. // confirmText: "确认"
  157. // }))
  158. // }
  159. // })
  160. }
  161. })
  162. },
  163. })