create-order.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="container order clearfix" :style="{ paddingBottom: isIphoneX ? '170rpx' : '134rpx' }">
  3. <!-- 地址选择 v-if="isAddress" -->
  4. <choice-address ref="choiceAddress" :addressData="addressData"></choice-address>
  5. <!-- 商品 -->
  6. <goodsList
  7. ref="goods"
  8. v-if="isRequest"
  9. :goodsData="goodsData"
  10. @handleGoodList="handChangeInputGoodsList"
  11. ></goodsList>
  12. <!-- 选择优惠券 TODO-->
  13. <view class="select-coupon" @click="couponVisible = true">
  14. <view class="left-title">优惠券</view>
  15. <view class="right-content">
  16. <view class="coupon-amount">-¥20.00</view> <view class="iconfont icon-chakangengduo"></view>
  17. </view>
  18. </view>
  19. <!-- 优惠券列表 TODO-->
  20. <cm-coupon-list title="优惠券" listType="use" :visible="couponVisible" @close="closeCouponList"></cm-coupon-list>
  21. <!-- 运费 -->
  22. <seller-freight ref="freight" v-if="isRequest" :freightDatas="freightData"> </seller-freight>
  23. <!-- 底部 -->
  24. <view class="footer" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0rpx' }">
  25. <view class="footer-le">
  26. <view class="footer-count">
  27. <text>共{{ allCount }}件商品</text>
  28. </view>
  29. <view class="footer-price">
  30. <view class="sum" :class="totalFullReduction == 0 ? 'none' : ''"
  31. >总价:<text class="price">¥{{ payAllPrice | NumFormat }}</text></view
  32. >
  33. </view>
  34. </view>
  35. <view class="footer-submit" @click.stop="orderSubmitMit">
  36. <view class="btn" :class="isSubLoading ? 'disabled' : ''">提交订单</view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import authorize from '@/common/authorize.js'
  43. import choiceAddress from '@/components/cm-module/createOrder/address'
  44. import goodsList from '@/components/cm-module/createOrder/goodsList'
  45. import sellerFreight from '@/components/cm-module/createOrder/sellerFreight'
  46. import CmCouponList from '@/components/cm-module/cm-coupon-list/cm-coupon-list'
  47. export default {
  48. components: {
  49. choiceAddress,
  50. goodsList,
  51. sellerFreight,
  52. CmCouponList
  53. },
  54. data() {
  55. return {
  56. couponVisible: false,
  57. isSubLoading: false,
  58. productIds: '', //获取上一级页面商品信息
  59. productCount: '', //获取上一级页面商品数量
  60. allCount: 1, //订单提交总数量
  61. totalOriginalPrice: 0, //订单总原价(划线部分)
  62. totalFullReduction: 0, //满减金额
  63. payAllPrice: 0.0, //订单提交总金额
  64. allPrice: 0.0, //订单总金额
  65. townId: '', //区ID
  66. isRequest: false, //是否加载完成渲染子组件
  67. isFreight: false, //是否加载完成渲染子组件
  68. isAddress: false, //是否加载完成地址
  69. ischecked: false, //是否勾选余额
  70. addressData: {}, //初始化地址信息
  71. goodsData: [], //初始化商品信息
  72. freightData: {}, //邮费数据
  73. isIphoneX: this.$store.getters.isIphoneX,
  74. productsList: [],
  75. params: {
  76. userId: 0
  77. },
  78. subParams: {
  79. userId: 0,
  80. orderInfo: [], //提交的商品信息
  81. addressId: 0,
  82. cartType: 0,
  83. payInfo: {
  84. orderShouldPayFee: 0
  85. }
  86. },
  87. orderInfo: ''
  88. }
  89. },
  90. onLoad(option) {
  91. //商品数据
  92. let data = JSON.parse(option.data)
  93. this.allCount = data.data.allCount
  94. console.log(data)
  95. if (option.type == 'prodcut') {
  96. this.subParams.cartType = 2
  97. this.params.productCount = data.data.productCount
  98. this.params.productId = data.data.productId
  99. this.params.heUserId = data.data.heUserId ? data.data.heUserId : 0
  100. } else {
  101. this.subParams.cartType = 1
  102. this.params.cartIds = data.data.cartIds
  103. }
  104. this.$api.getStorage().then(resolve => {
  105. this.params.userId = this.subParams.userId = resolve.userId ? resolve.userId : 0
  106. this.getInitCrearOrder(this.params)
  107. })
  108. },
  109. filters: {
  110. NumFormat(value) {
  111. //处理金额
  112. return Number(value).toFixed(2)
  113. }
  114. },
  115. methods: {
  116. closeCouponList(){
  117. this.couponVisible = false
  118. },
  119. getInitCrearOrder(params) {
  120. //确认订单初始化信息
  121. this.OrderService.QueryOrderConfirm(params)
  122. .then(response => {
  123. let data = response.data
  124. let productIds = []
  125. this.isRequest = true
  126. this.goodsData = data.shopList
  127. console.log(this.goodsData)
  128. // this.totalFullReduction = data.totalFullReduction
  129. // this.totalOriginalPrice = data.totalFullReduction + data.totalPrice
  130. this.allPrice = this.payAllPrice = data.totalPrice
  131. this.subParams.payInfo.orderShouldPayFee = this.payAllPrice.toFixed(2)
  132. console.log('this.subParams.payInfo.orderShouldPayFee', this.subParams.payInfo.orderShouldPayFee)
  133. })
  134. .catch(error => {
  135. this.$util.msg(error.msg, 2000)
  136. })
  137. },
  138. getAddressData() {
  139. //获取地址信息
  140. this.$api.getStorage().then(resolve => {
  141. this.UserService.QueryAddressList({ pageNum: 1, pageSize: 1, userId: resolve.userId }).then(
  142. response => {
  143. this.isAddress = true
  144. this.addressData = {}
  145. if (response.data.list != '') {
  146. this.subParams.addressId = response.data.list[0].addressId
  147. this.townId = response.data.list[0].townId
  148. this.addressData = response.data.list[0]
  149. } else {
  150. this.addressData = this.addressData
  151. }
  152. }
  153. )
  154. })
  155. },
  156. handChangeInputGoodsList(data) {
  157. //对应供应商的留言信息
  158. this.goodsData = data
  159. },
  160. orderSubmitMit() {
  161. //提交订单
  162. if (this.isSubLoading) {
  163. return
  164. }
  165. if (this.subParams.addressId == '') {
  166. this.$util.msg('请先添加收货地址~', 2000)
  167. return
  168. }
  169. // 处理商品信息及留言
  170. this.subParams.orderInfo = this.goodsData.map(el => {
  171. let productInfo = []
  172. el.productList.forEach(pros => {
  173. productInfo.push({
  174. productId: pros.productId,
  175. productNum: pros.productCount,
  176. heUserId: pros.heUserId
  177. })
  178. })
  179. return { shopId: el.shopId, note: el.note ? el.note : '', productInfo: productInfo }
  180. })
  181. console.log(this.subParams)
  182. this.isSubLoading = true
  183. this.OrderService.CreatedOrderSubmit(this.subParams)
  184. .then(response => {
  185. const data = response.data
  186. this.orderInfo = response.data
  187. setTimeout(() => {
  188. this.isSubLoading = false
  189. }, 2000)
  190. this.MiniWxPayFor(data)
  191. })
  192. .catch(error => {
  193. this.$util.msg(error.msg, 2000)
  194. })
  195. },
  196. MiniWxPayFor(data) {
  197. this.PayService.PayOrderOnLineSwitch().then(response => {
  198. if (response.data === 1) {
  199. this.WeChatMiniWxPay(data)
  200. } else {
  201. this.$api.navigateTo(`/pages/user/order/order-payment?money=${data.payableAmount}`)
  202. }
  203. })
  204. },
  205. async WeChatMiniWxPay(data) {
  206. const wechatCode = await authorize.getCode('weixin')
  207. this.PayService.WeChatMiniWxPay({
  208. payAmount: data.payableAmount * 100,
  209. payWay: 'WEIXIN',
  210. code: wechatCode,
  211. orderId: data.orderId
  212. })
  213. .then(response => {
  214. let PayInfo = JSON.parse(response.data.data.payInfo)
  215. this.WxRequestPayment(PayInfo)
  216. })
  217. .catch(error => {
  218. this.$util.msg(error.msg, 2000)
  219. })
  220. },
  221. WxRequestPayment(data) {
  222. let self = this
  223. wx.requestPayment({
  224. timeStamp: data.timeStamp,
  225. nonceStr: data.nonceStr,
  226. package: data.package,
  227. signType: data.signType,
  228. paySign: data.paySign,
  229. success: function(res) {
  230. wx.reLaunch({ url: '/pages/tabBar/index/index' })
  231. },
  232. fail: function(res) {
  233. console.log(res)
  234. console.log('ORDERID', self.orderInfo)
  235. self.$api.redirectTo(`/pages/user/order/success?data=${JSON.stringify({ data: self.orderInfo })}`)
  236. },
  237. complete: function(res) {}
  238. })
  239. }
  240. },
  241. onShow() {
  242. let pages = getCurrentPages()
  243. let currPage = pages[pages.length - 1]
  244. if (currPage.data.select == 'select') {
  245. this.isAddress = true
  246. let SelectData = uni.getStorageSync('selectAddress')
  247. this.subParams.addressId = SelectData.addressId
  248. this.addressData = SelectData
  249. } else {
  250. this.getAddressData()
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. page {
  257. height: auto;
  258. background: #f7f7f7;
  259. }
  260. .btn-hover {
  261. background: #ffffff;
  262. }
  263. .animation {
  264. /* transition: transform 0.3s ease;*/
  265. transition-property: transform;
  266. transition-duration: 0.3s;
  267. transition-timing-function: ease;
  268. }
  269. .invoice-freight {
  270. width: 702rpx;
  271. padding: 0 24rpx;
  272. height: 86rpx;
  273. line-height: 86rpx;
  274. font-size: $font-size-28;
  275. color: $text-color;
  276. background: #ffffff;
  277. float: left;
  278. font-weight: bold;
  279. .freight-left {
  280. float: left;
  281. .icon-yunfeishuoming {
  282. height: 100%;
  283. padding: 0 15rpx;
  284. color: $color-system;
  285. font-weight: normal;
  286. }
  287. }
  288. .freight-right {
  289. float: right;
  290. color: #2a81ff;
  291. }
  292. }
  293. .select-coupon {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. padding: 0 24rpx;
  298. margin: 24rpx 0;
  299. height: 90rpx;
  300. background: #fff;
  301. .left-title {
  302. font-weight: bold;
  303. color: #333333;
  304. font-size: 28rpx;
  305. }
  306. .right-content {
  307. display: flex;
  308. justify-content: flex-start;
  309. align-items: center;
  310. .coupon-amount {
  311. font-size: 28rpx;
  312. color: #ff457b;
  313. margin-right: 12rpx;
  314. }
  315. .iconfont {
  316. font-size: 28rpx;
  317. color: #b2b2b2;
  318. }
  319. }
  320. }
  321. .invoice-balance {
  322. width: 702rpx;
  323. height: auto;
  324. padding: 0 24rpx;
  325. background: #ffffff;
  326. float: left;
  327. margin-top: 24rpx;
  328. margin-bottom: 24rpx;
  329. .balabce-t {
  330. width: 100%;
  331. height: 86rpx;
  332. line-height: 86rpx;
  333. font-size: $font-size-28;
  334. color: $text-color;
  335. float: left;
  336. .balabce-t-le {
  337. float: left;
  338. font-weight: bold;
  339. }
  340. .balabce-t-ri {
  341. float: right;
  342. display: flex;
  343. align-items: center;
  344. .money {
  345. display: flex;
  346. float: left;
  347. }
  348. .checkbox-box {
  349. display: flex;
  350. width: 60rpx;
  351. float: left;
  352. height: 100%;
  353. font-size: $font-size-24;
  354. .checkbox {
  355. width: 40rpx;
  356. text-align: right;
  357. box-sizing: border-box;
  358. text-align: center;
  359. text-decoration: none;
  360. border-radius: 0;
  361. -webkit-tap-highlight-color: transparent;
  362. overflow: hidden;
  363. color: $color-system;
  364. padding: 5rpx;
  365. }
  366. }
  367. }
  368. }
  369. .balabce-b {
  370. width: 100%;
  371. float: left;
  372. overflow: hidden;
  373. .balabce-b-text {
  374. width: 100%;
  375. line-height: 58rpx;
  376. font-size: $font-size-24;
  377. color: #ff2a2a;
  378. text-align: right;
  379. float: right;
  380. }
  381. &.balabce-b--hide {
  382. padding: 0 0;
  383. height: 0px;
  384. line-height: 0px;
  385. }
  386. }
  387. }
  388. .footer {
  389. position: fixed;
  390. left: 0;
  391. bottom: 0;
  392. z-index: 995;
  393. display: flex;
  394. align-items: center;
  395. width: 100%;
  396. height: 110rpx;
  397. line-height: 110rpx;
  398. justify-content: space-between;
  399. font-size: $font-size-28;
  400. background-color: #ffffff;
  401. z-index: 998;
  402. color: $text-color;
  403. .footer-le {
  404. width: 570rpx;
  405. height: 100%;
  406. float: left;
  407. }
  408. .footer-count {
  409. float: left;
  410. padding-left: 24rpx;
  411. width: 170rpx;
  412. box-sizing: border-box;
  413. font-size: $font-size-26;
  414. }
  415. .footer-price {
  416. float: right;
  417. text-align: right;
  418. color: $text-color;
  419. padding-right: 20rpx;
  420. box-sizing: border-box;
  421. width: 370rpx;
  422. .sum {
  423. width: 100%;
  424. height: 110rpx;
  425. line-height: 110rpx;
  426. float: left;
  427. .price {
  428. font-size: $font-size-32;
  429. color: $color-system;
  430. }
  431. }
  432. }
  433. .footer-submit {
  434. display: flex;
  435. align-items: center;
  436. justify-content: center;
  437. width: 210rpx;
  438. height: 100%;
  439. box-sizing: border-box;
  440. padding: 15rpx 5rpx;
  441. .btn {
  442. width: 100%;
  443. height: 100%;
  444. color: #ffffff;
  445. background: $btn-confirm;
  446. font-size: $font-size-26;
  447. text-align: center;
  448. line-height: 80rpx;
  449. border-radius: 40rpx;
  450. &.disabled {
  451. background: #e4e8eb;
  452. color: #999999;
  453. }
  454. }
  455. }
  456. }
  457. .Rebate {
  458. width: 702rpx;
  459. height: auto;
  460. padding: 0 24rpx;
  461. background: #ffffff;
  462. float: left;
  463. margin-bottom: 24rpx;
  464. margin-bottom: 24rpx;
  465. line-height: 86rpx;
  466. .rebate-title {
  467. float: left;
  468. font-weight: bold;
  469. color: #333333;
  470. font-size: $font-size-28;
  471. }
  472. .iconfont {
  473. float: right;
  474. color: #b2b2b2;
  475. font-size: 40rpx;
  476. &.icon-yixuanze {
  477. color: $color-system;
  478. }
  479. }
  480. }
  481. </style>