submitOrder.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. // pages/groupmeallist/submitOrder/submitOrder.js
  2. import storeGoods from '../../../api/storeGoods'
  3. const cache = require('../../../utils/cache.js');
  4. const user = require('../../../utils/user.js');
  5. import base from '../../../utils/base'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. orderGoodList: [{}, {}, {}, {}],
  12. store: {},
  13. phone: '',
  14. storeWay: '',
  15. addressvaule: '',
  16. addressId: '',
  17. coupon: '',
  18. couponSn: '',
  19. hallFood: '',
  20. invoiceValue: '',
  21. invoiceId: '',
  22. hidden: true,
  23. inputValue: '',
  24. remark: '',
  25. showAllSku: false,
  26. isShowPannel: false,
  27. forSelectList: [],
  28. discoutTitle: '',
  29. couponSn: '',
  30. orderMode: '',
  31. discountPriceY: ''
  32. },
  33. //全部显示和收起
  34. handleFlodExtend() {
  35. this.setData({
  36. showAllSku: !this.data.showAllSku
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. let coupon = options.coupon
  44. if (coupon != null) {
  45. let jsoncoupon = JSON.parse(coupon)
  46. this.setData({
  47. coupon: jsoncoupon,
  48. couponSn: jsoncoupon.sn
  49. })
  50. }
  51. let invoiceValue = options.invoiceValue
  52. let invoiceId = options.invoiceId
  53. if (invoiceValue != null && invoiceId != null) {
  54. this.setData({
  55. invoiceValue: invoiceValue,
  56. invoiceId: invoiceId
  57. })
  58. }
  59. let addressvaule = options.addressvalue
  60. let addressId = options.addressId
  61. if (addressvaule != null && addressId != null) {
  62. let address = {
  63. addressvaule: addressvaule,
  64. addressId: addressId
  65. }
  66. // 设置地址缓存
  67. cache.setaddress(address)
  68. this.setData({
  69. addressvaule: addressvaule,
  70. addressId: addressId
  71. })
  72. }
  73. },
  74. /**
  75. * 取消
  76. */
  77. cancel: function () {
  78. this.setData({
  79. hidden: true,
  80. inputValue: '',
  81. remark: '',
  82. });
  83. },
  84. /**
  85. * 提交
  86. */
  87. confirm: function (e) {
  88. let inputValue = e.detail.value
  89. this.setData({
  90. hidden: true,
  91. inputValue: inputValue,
  92. remark: inputValue,
  93. });
  94. },
  95. /**
  96. * 备注
  97. */
  98. getReason: function (e) {
  99. this.setData({
  100. inputValue: e.detail.value
  101. })
  102. },
  103. remarkShow() {
  104. this.setData({
  105. hidden: false,
  106. // inputValue: '',
  107. // remark: '',
  108. });
  109. },
  110. /**
  111. * 生命周期函数--监听页面初次渲染完成
  112. */
  113. onReady: function () {
  114. },
  115. listenInput(e) {
  116. this.setData({
  117. phone: e.detail.value
  118. })
  119. },
  120. // 提交订单
  121. submitOrder() {
  122. console.log("进入创建订单方法")
  123. let parms = {}
  124. if (!this.data.isValid) {
  125. app.showToast("购物车无商品")
  126. return
  127. }
  128. // parms={
  129. // mobile:cache.getMobile(),
  130. // storeId:cache.getStoreId(),
  131. // couponSn:this.data.couponSn,
  132. // dinnerType:this.data.storeWay,
  133. // addressId:this.data.addressId,
  134. // invoiceId:this.data.invoiceId,
  135. // phone:this.data.phone,
  136. // remark:this.data.remark
  137. // }
  138. storeGoods.creatOrder({
  139. mobile: cache.getMobile(),
  140. storeId: cache.getStoreId(),
  141. couponSn: this.data.couponSn,
  142. dinnerType: this.data.storeWay,
  143. addressId: this.data.addressId,
  144. invoiceId: this.data.invoiceId,
  145. phone: this.data.phone,
  146. remark: this.data.remark
  147. }).then(res => {
  148. if (res.code == 200 && res.data.state != -2) {
  149. // 唤起收银台
  150. this.goToPay(res.data)
  151. } else if (res.data.state != -2) {
  152. wx.redirectTo({
  153. url: '/pages/userOrderList/userOrderList',
  154. })
  155. }
  156. }).catch(_ => {
  157. // this.setData({
  158. // isShowPannel: true
  159. // })
  160. this.tapSex()
  161. console.log(_)
  162. })
  163. },
  164. tapSex:function(res){
  165. var that = this
  166. wx.showModal({
  167. title: '提示',
  168. content: '订单创建失败,确认之后返回购物栏',
  169. showCancel: false,
  170. confirmText:'确认',
  171. success(res){
  172. if(res.confirm){
  173. that.goToStoreGoods()
  174. }
  175. }
  176. })
  177. },
  178. goToPay(order) {
  179. const storeInfo = cache.getCurrStore()
  180. console.log(user.getUserInfo().openid,)
  181. console.log(storeInfo)
  182. storeGoods.getPayParams({
  183. orderSn: order.orderSn,
  184. payCode: storeInfo.payCode,
  185. openId: user.getUserInfo().openid,
  186. isOrderPayment: true,
  187. orderInfoPath: "../orderDetail/orderDetail?sn=" + order.orderSn,
  188. productDetailPath: "../storeGoods/storeGoods",
  189. }).then(res => {
  190. if (res.code == 200) {
  191. this.rousePayment(res.data, order)
  192. }
  193. }).catch(_ => {
  194. console.log(_)
  195. })
  196. },
  197. rousePayment(payParam, order) {
  198. wx.requestOrderPayment({
  199. timeStamp: payParam.wxPrePay.timeStamp,
  200. package: payParam.wxPrePay.pack,
  201. nonceStr: payParam.wxPrePay.nonceStr,
  202. signType: payParam.wxPrePay.signType,
  203. paySign: payParam.wxPrePay.paySign,
  204. orderInfo:payParam.orderInfo,
  205. success: function (res) {
  206. //支付成功,跳转领取成功页面
  207. console.log("支付成功,跳到订单详情页面")
  208. OrderApi.getPayStatus(order.orderSn);
  209. app.showToast("支付成功")
  210. wx.redirectTo({
  211. url: '../orderDetail/orderDetail?sn=' + order.orderSn,
  212. })
  213. },
  214. fail: function (res) {
  215. app.showToast("支付失败")
  216. wx.redirectTo({
  217. url: '../orderDetail/orderDetail?sn=' + order.orderSn,
  218. })
  219. }
  220. })
  221. },
  222. /**
  223. * 生命周期函数--监听页面显示
  224. */
  225. onShow: function () {
  226. let store = cache.getCurrStore();
  227. console.log(store)
  228. let storeWay = cache.getStoreWay();
  229. let address = cache.getaddress();
  230. if (address != null) {
  231. this.setData({
  232. addressvaule: address.addressvaule,
  233. addressId: address.addressId,
  234. })
  235. }
  236. if (store != null) {
  237. this.setData({
  238. store: store,
  239. storeWay: storeWay,
  240. hallFood: store.hallFood
  241. })
  242. }
  243. this.loadCartData();
  244. this.getUseConfirmOrderCoupon()
  245. },
  246. //发票列表
  247. gotoinvoice() {
  248. wx.redirectTo({
  249. url: '../invoicesList/invoicesList?way=' + 'order',
  250. })
  251. },
  252. // 自动获取手机号
  253. getPhone() {
  254. let phone = cache.getMobile()
  255. this.setData({
  256. phone: phone
  257. })
  258. },
  259. // 选择收货地址
  260. chooseAdress() {
  261. wx.redirectTo({
  262. url: '../address/address?isreturn=' + 'true',
  263. })
  264. },
  265. getUseConfirmOrderCoupon() {
  266. storeGoods.orderCouponForSelect({
  267. storeId: cache.getStoreId(),
  268. mobile: cache.getMobile(),
  269. // tableId: 1
  270. }).then(res => {
  271. if (res.code == 200) {
  272. this.setData({
  273. forSelectList: res.data
  274. })
  275. }
  276. }).catch(_ => {
  277. // // this.setData({
  278. // // isShowPannel: true
  279. // // })
  280. // this.tapSex()
  281. console.log(_)
  282. })
  283. },
  284. //选择卡券
  285. gotoselectcoupon() {
  286. wx.navigateTo({
  287. url: '../couponlist/couponlist',
  288. })
  289. },
  290. /**
  291. * 加载购物车数据
  292. */
  293. loadCartData() {
  294. storeGoods.getCartData(cache.getStoreId(), cache.getMobile(), null, this.data.couponSn, ).then(res => {
  295. if (res.code == 200) {
  296. this.cartDataMapToView(res.data)
  297. }
  298. }).catch(_ => {
  299. console.log(_)
  300. })
  301. },
  302. cartDataMapToView(data) {
  303. var isShowCartPannel = true;
  304. if (base.isEmpty(data.skuList) || data.skuList.length == 0) {
  305. isShowCartPannel = false
  306. data.totalPriceY = "0.00"
  307. data.totalNum = 0
  308. }
  309. // let skuList = data.skuList || []
  310. // skuList.forEach(sku => {
  311. // if (!base.isEmpty(sku.specList)) {
  312. // let specValueList = []
  313. // sku.specList.forEach(spec => {
  314. // specValueList.push(spec.specValue)
  315. // })
  316. // sku.specDes = specValueList.join("、")
  317. // } else {
  318. // sku.specDes = ""
  319. // }
  320. // sku.allFee = base.fenToYuan(sku.num * sku.price)
  321. // sku.allOriFee = base.fenToYuan(sku.num * sku.oriPrice)
  322. // })
  323. this.setData({
  324. isValid: data.skuList.length > 0,
  325. skuList: data.skuList,
  326. areaName: data.areaName,
  327. tableCode: data.tableCode,
  328. totalNum: data.totalNum,
  329. totalOriPriceY: data.totalOriPriceY,
  330. totalPriceY: data.totalPriceY - data.discountPriceY,
  331. totalPrice: data.totalPrice,
  332. totalOriPrice: data.totalOriPrice,
  333. discountPriceY: data.discountPriceY
  334. })
  335. },
  336. // 详情和收起
  337. changeCollapseOrDetail: function (e) {
  338. let idx = e.currentTarget.dataset.idx;
  339. var that = this;
  340. that.data.skuList[idx].show = !that.data.skuList[idx].show
  341. that.setData({
  342. skuList: that.data.skuList
  343. });
  344. console.log("购物车详情");
  345. console.log(that.data.skuList);
  346. },
  347. /**
  348. * 生命周期函数--监听页面隐藏
  349. */
  350. onHide: function () {
  351. },
  352. /**
  353. * 生命周期函数--监听页面卸载
  354. */
  355. onUnload: function () {
  356. },
  357. /**
  358. * 页面相关事件处理函数--监听用户下拉动作
  359. */
  360. onPullDownRefresh: function () {
  361. },
  362. /**
  363. * 页面上拉触底事件的处理函数
  364. */
  365. onReachBottom: function () {
  366. },
  367. /**
  368. * 用户点击右上角分享
  369. */
  370. onShareAppMessage: function () {
  371. }
  372. })