create-order.vue 14 KB

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