submitorder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. title="提交订单"
  5. :placeholder="true"
  6. @leftClick="leftClick"
  7. :autoBack="true"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="addr page-wrap u-flex u-row-between">
  12. <view class="left">
  13. <view class="top">
  14. <text class="label" v-if="orderInfo.receive.ifDefault">默认</text>{{receive.address}}
  15. </view>
  16. <view class="center">{{receive.receiveAdress}}</view>
  17. <view class="bottom">{{receive.receiveName}} {{receive.receivePhone}}</view>
  18. </view>
  19. <u-icon name="arrow-right" color="#676767" size="20" @click="selectAddr"></u-icon>
  20. </view>
  21. <!-- <view class="payway page-wrap u-flex u-row-between">
  22. <view class="left">支付方式</view>
  23. <view class="u-flex">
  24. 微信支付
  25. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  26. </view>
  27. </view> -->
  28. <view class="order-product page-wrap">
  29. <view class="product u-flex" v-for="(item,index) in orderInfo.goodsList" :key="item.id">
  30. <u--image :showLoading="true" :src="item.mainImg" width="180rpx" height="180rpx"></u--image>
  31. <view class="text">
  32. <view class="up">
  33. <view class="name ellipsis-2">{{item.goodsName}}</view>
  34. <view class="info">
  35. {{item.specification}}
  36. {{item.unit}}
  37. </view>
  38. </view>
  39. <view class="down u-flex u-row-between">
  40. <view class="left">
  41. <view class="" v-if="vuex_member_info.priceType>1">
  42. <text class="price">¥ <text class="price-num">{{item.vipPrice}}</text></text>
  43. <text class="vip-icon">VIP</text>
  44. <text class="original-price gray line-through">¥ {{item.salePrice}}</text>
  45. </view>
  46. <view class="" v-else>
  47. <text class="price">¥ <text class="price-num">{{item.salePrice}}</text></text>
  48. </view>
  49. </view>
  50. <u-number-box
  51. v-if="fromPage!='creditOrder'"
  52. v-model="item.quantity"
  53. :max="item.stock"
  54. :asyncChange="true"
  55. @change="changeQuantity(index, $event)" integer>
  56. </u-number-box>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="page-wrap order-reduced">
  62. <!-- <view class="reduced-item u-flex u-row-between u-border-bottom">
  63. <view class="left">
  64. <text>优惠券</text>
  65. <text class="label">已选一张</text>
  66. </view>
  67. <view class="right u-flex">
  68. <text class="price red">-¥ <text class="price-num">1000</text></text>
  69. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  70. </view>
  71. </view> -->
  72. <view class="reduced-item integral u-flex u-row-between" v-if="orderTotalCredit">
  73. <view class="left">
  74. <text>积分</text>
  75. <!-- <text class="num">3676</text> -->
  76. <!-- <text class="tip">满1000可用</text> -->
  77. </view>
  78. <view class="right u-flex">
  79. <text class="price red" >- <text class="price-num">{{orderTotalCredit}}</text></text>
  80. <!-- <u-checkbox-group @change="integralCheckboxChange">
  81. <u-checkbox shape="circle" activeColor="#02AB35" name="integral" ></u-checkbox>
  82. </u-checkbox-group> -->
  83. </view>
  84. </view>
  85. </view>
  86. <view class="page-wrap total">
  87. <view class="total-item u-flex u-row-between u-border-bottom">
  88. <view class="left">
  89. 商品金额
  90. </view>
  91. <view class="right red">
  92. ¥ {{totalAmount}}
  93. </view>
  94. </view>
  95. <view class="total-item u-flex u-row-between">
  96. <view class="left">
  97. 运费
  98. <text class="gray">总重:{{totalWeight}}</text>
  99. </view>
  100. <view class="right red">
  101. <text v-if="distribution.distributionPrice">+ ¥ {{distribution.distributionPrice}}</text>
  102. <text v-else>免运费</text>
  103. </view>
  104. </view>
  105. </view>
  106. <view class="cart-bottom">
  107. <view class="inner u-flex u-row-between">
  108. <view class="left u-flex">
  109. <view class="total-price">
  110. 待支付:<text class="red">¥ {{payAmount + distribution.distributionPrice}}</text>
  111. </view>
  112. </view>
  113. <view class="btn gray" v-if="orderTotalCredit&&userTotalCredit<orderTotalCredit">积分不够</view>
  114. <view class="" v-else>
  115. <view class="btn" v-if="cansubmit" @click="submitOrder">去结算</view>
  116. <view class="btn gray" v-else>去结算</view>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </template>
  122. <script>
  123. export default {
  124. data() {
  125. return {
  126. cansubmit:true,
  127. fromPage:'',
  128. useIntegral:false,
  129. dataList:[],
  130. receiveId:'',
  131. receive:{},
  132. isDefaultAddr:false,
  133. orderInfo:{goodsList:[]},
  134. distribution:{},//物流信息
  135. totalAmount:null,//订单总金额
  136. payAmount:null,//订单支付金额
  137. userTotalBalance:null,//用户总余额
  138. userTotalCredit:null,//用户总积分
  139. orderTotalCredit:null,//订单需要的总积分
  140. }
  141. },
  142. onLoad(page) {
  143. console.log('page',page);
  144. // console.log('this.creditGoods',this.creditGoods);
  145. this.fromPage = page.fromPage;
  146. console.log('fromPage',this.fromPage);
  147. // if(this.cartGoods>0&&this.fromPage!='cart'){
  148. // console.log('fromPagecart',this.fromPage);
  149. // this.orderInfo.goodsList = this.cartGoods;
  150. // }
  151. // if(this.creditGoods.length>0&&this.fromPage=='creditOrder'){
  152. // console.log('fromPagecreditOrder',this.fromPage);
  153. // this.orderInfo.goodsList = this.creditGoods;
  154. // }
  155. this.orderInfo.goodsList = this.cartGoods;
  156. console.log('this.buyNowGoods',this.buyNowGoods);
  157. if(this.buyNowGoods.length>0&&this.fromPage=='productdetails'){
  158. console.log('fromPagecart',this.fromPage);
  159. this.orderInfo.goodsList = this.buyNowGoods;
  160. }
  161. this.settlement();
  162. },
  163. onUnload() {
  164. this.$u.vuex('buyNowGoods',[]);
  165. console.log('this.buyNowGoods',this.buyNowGoods);
  166. },
  167. onShow() {
  168. if(this.fromPage=='addrlist'){
  169. this.settlement()
  170. }
  171. // console.log('cartGoods===',this.cartGoods);
  172. },
  173. computed: {
  174. totalWeight() {
  175. let that = this;
  176. return this.orderInfo.goodsList.reduce((total, item) => {
  177. let weight = null;
  178. weight = item.weight
  179. total += weight * item.quantity;
  180. return total;
  181. }, 0);
  182. }
  183. },
  184. methods: {
  185. leftClick(e){
  186. console.log('leftClick',e);
  187. },
  188. integralCheckboxChange(e){
  189. this.useIntegral = e[0] && e[0] === 'integral' ? true : false;
  190. },
  191. selectAddr(){
  192. uni.$u.route('/center/addrlist', {
  193. from: 'submitorder',
  194. // backUrl:'/shopping/submitorder'
  195. });
  196. },
  197. // getAddrList(){
  198. // this.$u.api.addrList().then(res=>{
  199. // this.theAddr = res.data.rows;
  200. // let defaultAddress;
  201. // let firstAddress = res.data.rows[0];
  202. // res.data.rows.forEach(address => {
  203. // if (address.ifDefault) { // 如果有默认地址标识
  204. // defaultAddress = address;
  205. // this.isDefaultAddr = true;
  206. // }
  207. // });
  208. // if (!defaultAddress) { // 如果没有默认地址标识
  209. // defaultAddress = firstAddress;
  210. // }
  211. // this.theAddr = defaultAddress;
  212. // }).catch(err=>{
  213. // console.log('getAddrList',err.data);
  214. // })
  215. // },
  216. // 改变商品数量
  217. changeQuantity(index, value) {
  218. // console.log('goodsList',this.orderInfo.goodsList);
  219. // console.log('index',index);
  220. // console.log('value',value);
  221. this.orderInfo.goodsList[index].quantity = value.value;
  222. this.settlement();
  223. },
  224. settlement(){
  225. let orderType = 1;
  226. // console.log('settlement',this.selectGoods);
  227. let param = {
  228. receiveId:this.receive.id
  229. };
  230. if(this.fromPage == 'creditOrder'){
  231. orderType = 2
  232. }
  233. param.orderType = orderType;
  234. param.goodsList = this.orderInfo.goodsList.map(item=>{
  235. return {goodsId:item.id||item.goodsId,quantity:item.quantity}
  236. });
  237. console.log('param',param);
  238. this.$u.api.getSettlement(param).then(res=>{
  239. console.log('res',res.data);
  240. this.setData(res.data)
  241. }).catch(err=>{
  242. console.log('getSettlement',err);
  243. })
  244. },
  245. setData(originData){
  246. console.log('originData',originData);
  247. let dataType = typeof originData;
  248. let jsonData;
  249. if(dataType=='string'){
  250. jsonData = JSON.parse(originData);
  251. }else{
  252. jsonData = originData
  253. }
  254. let {
  255. receive,
  256. distribution,
  257. totalAmount,
  258. payAmount,
  259. userTotalBalance,
  260. userTotalCredit,
  261. orderTotalCredit } = jsonData || {};
  262. console.log('orderTotalCredit',orderTotalCredit);
  263. this.orderInfo = jsonData;
  264. this.receive = receive;
  265. this.distribution = distribution;//物流信息
  266. this.totalAmount = totalAmount;//订单总金额
  267. this.payAmount = payAmount;// 订单支付金额
  268. this.userTotalBalance = userTotalBalance;// 用户总余额
  269. this.userTotalCredit = userTotalCredit;// 用户总积分
  270. this.orderTotalCredit = orderTotalCredit;//订单需要的总积分
  271. },
  272. submitOrder(){
  273. let that = this;
  274. this.cansubmit = false;
  275. let orderType = 1;
  276. let param = {
  277. receiveId:this.receive.id,
  278. distribution:this.distribution,
  279. };
  280. if(this.fromPage == 'creditOrder'){
  281. orderType = 2
  282. }
  283. param.orderType = orderType;
  284. param.goodsList = this.orderInfo.goodsList.map(item=>{
  285. return {goodsId:item.id,quantity:item.quantity}
  286. })
  287. //获取经纬度
  288. uni.getLocation({
  289. type: 'gcj02',
  290. success: (res) => {
  291. param.latitude = res.latitude;
  292. param.longitude = res.longitude;
  293. that.$u.api.submitOrder(param).then(res=>{
  294. console.log('res',res.data);
  295. that.cansubmit = true;
  296. if(res.data.payAmount>0){
  297. uni.$u.route('/shopping/pay', {
  298. orderId: res.data.orderId,
  299. fromPage:that.fromPage,
  300. payAmount:res.data.payAmount
  301. });
  302. }else{
  303. uni.$u.route('/shopping/paysuccess', {
  304. fromPage:'nocash'
  305. });
  306. }
  307. }).catch(err=>{
  308. that.cansubmit = true;
  309. console.log('submitOrder',err);
  310. })
  311. },
  312. });
  313. }
  314. }
  315. }
  316. </script>
  317. <style>
  318. page{
  319. background-color: #F5F5F5;
  320. /* padding-top: 50px; */
  321. }
  322. </style>
  323. <style lang="scss" scoped>
  324. .page-wrap{
  325. background-color: #fff;
  326. margin-bottom: 20rpx;
  327. }
  328. .addr{
  329. .top{
  330. margin-bottom: 16rpx;
  331. font-size: 26rpx;
  332. color: #999;
  333. .label{
  334. background-color: #FFEBEB;
  335. border: 1px solid #FF5F62;
  336. color: #FF5F62;
  337. padding: 5rpx 20rpx;
  338. border-radius: 30rpx;
  339. margin-right: 10rpx;
  340. }
  341. }
  342. .center{
  343. margin-bottom: 10rpx;
  344. font-size: 30rpx;
  345. color: #333;
  346. line-height: 50rpx;
  347. font-weight: 600;
  348. }
  349. .bottom{
  350. font-size: 30rpx;
  351. color: #666;
  352. }
  353. }
  354. .order-reduced{
  355. .reduced-item{
  356. &:not(:last-child){
  357. margin-bottom: 30rpx;
  358. padding-bottom: 30rpx;
  359. }
  360. .label{
  361. border-radius: 2px;
  362. border: 1px solid #FF3C3F;
  363. margin-left: 20rpx;
  364. font-size: 20rpx;
  365. color: #FF3C3F;
  366. padding: 0 10rpx;
  367. }
  368. }
  369. .integral{
  370. .num{
  371. font-size: 30rpx;
  372. color: #02AB35;
  373. font-weight: 600;
  374. margin-left: 30rpx;
  375. margin-right: 16rpx;
  376. }
  377. .tip{
  378. font-size: 24rpx;
  379. color: #999;
  380. }
  381. .price{
  382. margin-right: 10rpx;
  383. }
  384. }
  385. }
  386. .total{
  387. .total-item{
  388. &:not(:last-child){
  389. margin-bottom: 30rpx;
  390. padding-bottom: 30rpx;
  391. }
  392. .right{
  393. font-weight: 600;
  394. }
  395. }
  396. .gray{
  397. font-size: 24rpx;
  398. margin-left: 15rpx;
  399. }
  400. }
  401. .cart-bottom{
  402. height: 98rpx;
  403. .inner{
  404. position: fixed;
  405. background-color: #fff;
  406. height: 98rpx;
  407. left: 0;
  408. right: 0;
  409. bottom: 0;
  410. padding: 0 20rpx;
  411. .total-price{
  412. font-size: 30rpx;
  413. color: #333;
  414. font-weight: 600;
  415. margin-left: 30rpx;
  416. }
  417. .btn{
  418. height: 80rpx;
  419. line-height: 80rpx;
  420. border-radius: 50rpx;
  421. padding: 0 50rpx;
  422. background-color: #FF3C3F;
  423. color: #fff;
  424. text-align: center;
  425. &.gray{
  426. background-color: #ddd;
  427. color: #999;
  428. }
  429. }
  430. }
  431. }
  432. .product{
  433. .text{
  434. .name{
  435. height: auto;
  436. }
  437. .info{
  438. font-size: 24rpx;
  439. font-weight: 400;
  440. color: #666666;
  441. }
  442. }
  443. }
  444. </style>