store-order.js 4.6 KB

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