submitorder.vue 14 KB

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