create-order.vue 10 KB

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