create-order.vue 11 KB

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