create-order.vue 10 KB

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