create-order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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.$api.navigateTo(`/pages/user/order/order-payment?money=${data.payableAmount}`)
  162. // this.MiniWxPayFor(data)
  163. }).catch(error =>{
  164. this.$util.msg(error.msg,2000);
  165. })
  166. },
  167. async MiniWxPayFor(data){
  168. const wechatCode = await authorize.getCode('weixin')
  169. this.PayService.WeChatMiniWxPay(
  170. {
  171. payAmount:data.payableAmount*100,
  172. payWay:"WEIXIN",
  173. code:wechatCode,
  174. orderId:data.orderId
  175. }
  176. )
  177. .then(response =>{
  178. let PayInfo = JSON.parse(response.data.data.payInfo);
  179. this.WxRequestPayment(PayInfo)
  180. })
  181. .catch(error =>{
  182. this.$util.msg(error.msg,2000)
  183. })
  184. },
  185. WxRequestPayment(data){
  186. let self = this
  187. wx.requestPayment(
  188. {
  189. 'timeStamp': data.timeStamp,
  190. 'nonceStr': data.nonceStr,
  191. 'package': data.package,
  192. 'signType': data.signType,
  193. 'paySign': data.paySign,
  194. 'success':function(res){
  195. wx.reLaunch({url: '/pages/index/index'});
  196. },
  197. 'fail':function(res){
  198. console.log(res)
  199. console.log('ORDERID',self.orderInfo)
  200. self.$api.redirectTo(`/pages/user/order/success?data=${JSON.stringify({data:self.orderInfo})}`)
  201. },
  202. 'complete':function(res){
  203. }
  204. }
  205. )
  206. },
  207. },
  208. onShow() {
  209. let pages = getCurrentPages();
  210. let currPage = pages[pages.length-1];
  211. if(currPage.data.select =='select'){
  212. this.isAddress = true
  213. let SelectData = uni.getStorageSync('selectAddress');
  214. this.subParams.addressId = SelectData.addressId;
  215. this.addressData = SelectData
  216. }else{
  217. this.getAddressData()
  218. }
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. page {
  224. height: auto;
  225. background:#F7F7F7;
  226. }
  227. .btn-hover{
  228. background: #FFFFFF;
  229. }
  230. .animation{
  231. /* transition: transform 0.3s ease;*/
  232. transition-property: transform;
  233. transition-duration: 0.3s;
  234. transition-timing-function: ease;
  235. }
  236. .invoice-freight{
  237. width: 702rpx;
  238. padding: 0 24rpx;
  239. height: 86rpx;
  240. line-height: 86rpx;
  241. font-size: $font-size-28;
  242. color: $text-color;
  243. background: #FFFFFF;
  244. float: left;
  245. font-weight: bold;
  246. .freight-left{
  247. float: left;
  248. .icon-yunfeishuoming{
  249. height: 100%;
  250. padding: 0 15rpx;
  251. color: $color-system;
  252. font-weight: normal;
  253. }
  254. }
  255. .freight-right{
  256. float: right;
  257. color: #2A81FF;
  258. }
  259. }
  260. .invoice-balance{
  261. width: 702rpx;
  262. height: auto;
  263. padding:0 24rpx;
  264. background: #FFFFFF;
  265. float: left;
  266. margin-top: 24rpx;
  267. margin-bottom: 24rpx;
  268. .balabce-t{
  269. width: 100%;
  270. height: 86rpx;
  271. line-height: 86rpx;
  272. font-size: $font-size-28;
  273. color: $text-color;
  274. float: left;
  275. .balabce-t-le{
  276. float: left;
  277. font-weight: bold;
  278. }
  279. .balabce-t-ri{
  280. float: right;
  281. display: flex;
  282. align-items: center;
  283. .money{
  284. display: flex;
  285. float: left;
  286. }
  287. .checkbox-box{
  288. display: flex;
  289. width: 60rpx;
  290. float: left;
  291. height: 100%;
  292. font-size: $font-size-24;
  293. .checkbox{
  294. width: 40rpx;
  295. text-align: right;
  296. box-sizing: border-box;
  297. text-align: center;
  298. text-decoration: none;
  299. border-radius: 0;
  300. -webkit-tap-highlight-color: transparent;
  301. overflow: hidden;
  302. color: $color-system;
  303. padding: 5rpx;
  304. }
  305. }
  306. }
  307. }
  308. .balabce-b{
  309. width: 100%;
  310. float: left;
  311. overflow: hidden;
  312. .balabce-b-text{
  313. width: 100%;
  314. line-height: 58rpx;
  315. font-size: $font-size-24;
  316. color: #FF2A2A;
  317. text-align: right;
  318. float: right;
  319. }
  320. &.balabce-b--hide {
  321. padding: 0 0;
  322. height: 0px;
  323. line-height: 0px;
  324. }
  325. }
  326. }
  327. .footer{
  328. position: fixed;
  329. left: 0;
  330. bottom: 0;
  331. z-index: 995;
  332. display: flex;
  333. align-items: center;
  334. width: 100%;
  335. height: 110rpx;
  336. line-height: 110rpx;
  337. justify-content: space-between;
  338. font-size: $font-size-28;
  339. background-color: #FFFFFF;
  340. z-index: 998;
  341. color: $text-color;
  342. .footer-le{
  343. width:570rpx;
  344. height:100%;
  345. float: left;
  346. }
  347. .footer-count{
  348. float: left;
  349. padding-left: 24rpx;
  350. width:170rpx;
  351. box-sizing: border-box;
  352. font-size: $font-size-26;
  353. }
  354. .footer-price{
  355. float: right;
  356. text-align: right;
  357. color: $text-color;
  358. padding-right:20rpx;
  359. box-sizing: border-box;
  360. width: 370rpx;
  361. .sum{
  362. width: 100%;
  363. height: 110rpx;
  364. line-height: 110rpx;
  365. float: left;
  366. .price{
  367. font-size: $font-size-32;
  368. color: $color-system;
  369. }
  370. }
  371. }
  372. .footer-submit{
  373. display:flex;
  374. align-items:center;
  375. justify-content: center;
  376. width: 210rpx;
  377. height: 100%;
  378. box-sizing: border-box;
  379. padding: 15rpx 5rpx;
  380. .btn{
  381. width: 100%;
  382. height: 100%;
  383. color: #FFFFFF;
  384. background:$btn-confirm;
  385. font-size: $font-size-26;
  386. text-align: center;
  387. line-height: 80rpx;
  388. border-radius: 40rpx;
  389. &.disabled{
  390. background: #e4e8eb;
  391. color: #999999;
  392. }
  393. }
  394. }
  395. }
  396. .Rebate{
  397. width: 702rpx;
  398. height: auto;
  399. padding: 0 24rpx;
  400. background: #FFFFFF;
  401. float: left;
  402. margin-bottom: 24rpx;
  403. margin-bottom: 24rpx;
  404. line-height: 86rpx;
  405. .rebate-title{
  406. float: left;
  407. font-weight: bold;
  408. color: #333333;
  409. font-size: $font-size-28;
  410. }
  411. .iconfont{
  412. float: right;
  413. color: #b2b2b2;
  414. font-size: 40rpx;
  415. &.icon-yixuanze{
  416. color: $color-system;
  417. }
  418. }
  419. }
  420. </style>