submitorder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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" @click="selectAddr" v-if="logisticsType!=1">
  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"></u-icon>
  30. </view>
  31. <view class="page-wrap pickup-info" v-else>
  32. <view class="item u-flex u-row-between" @click="selectAddr">
  33. <view class="left">
  34. 提货人:
  35. <text>{{pickupInfo.pickupName}}</text>
  36. <text>{{pickupInfo.pickupMobile}}</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" @click="pickupTimeShow=true">
  43. <view class="left">
  44. 预约提货时间:
  45. <text>{{pickupInfo.pickupTime}}</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 u-flex">
  53. <text style="flex: 1;white-space: nowrap;">自提地点:</text>
  54. <text class="ellipsis-1">{{pickupInfo.pickupAddress}}</text>
  55. </view>
  56. <view class="right">
  57. <u-icon @click="goMap" :name="staticUrl+'/img/go-map-icon-y.png'" 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. <u-datetime-picker
  161. :show="pickupTimeShow"
  162. v-model="pickupTime"
  163. @cancel="pickupTimeShow=false"
  164. :formatter="formatter"
  165. mode="datetime"
  166. :minDate="new Date().getTime()"
  167. @confirm="confirmDate"
  168. ></u-datetime-picker>
  169. <!-- :maxDate="new Date().setDate(new Date().getDate() + 10)" -->
  170. </view>
  171. </template>
  172. <script>
  173. export default {
  174. data() {
  175. return {
  176. staticUrl:this.$commonConfig.staticUrl,
  177. cansubmit:true,
  178. fromPage:'',
  179. useIntegral:false,
  180. dataList:[],
  181. receiveId:'',
  182. receive:{},
  183. isDefaultAddr:false,
  184. orderInfo:{goodsList:[]},
  185. distribution:{},//物流信息
  186. totalAmount:null,//订单总金额
  187. payAmount:null,//订单支付金额
  188. userTotalBalance:null,//用户总余额
  189. userTotalCredit:null,//用户总积分
  190. orderTotalCredit:null,//订单需要的总积分
  191. receiveWayList:[],//
  192. selectReceiveIndex:0,
  193. logisticsType:0,//物流方式默认值
  194. pickupInfo:{
  195. pickupName:'',
  196. pickupMobile:'',
  197. pickupTime:'',
  198. pickupAddress:'',
  199. pickupLongitude:'',
  200. pickupLatitude:''
  201. },
  202. pickupTime:'',
  203. pickupTimeShow:false,
  204. }
  205. },
  206. onLoad(page) {
  207. console.log('page',page);
  208. // console.log('this.creditGoods',this.creditGoods);
  209. this.fromPage = page.fromPage;
  210. console.log('fromPage',this.fromPage);
  211. // if(this.cartGoods>0&&this.fromPage!='cart'){
  212. // console.log('fromPagecart',this.fromPage);
  213. // this.orderInfo.goodsList = this.cartGoods;
  214. // }
  215. // if(this.creditGoods.length>0&&this.fromPage=='creditOrder'){
  216. // console.log('fromPagecreditOrder',this.fromPage);
  217. // this.orderInfo.goodsList = this.creditGoods;
  218. // }
  219. this.orderInfo.goodsList = this.cartGoods;
  220. console.log('this.buyNowGoods',this.buyNowGoods);
  221. if(this.buyNowGoods.length>0&&this.fromPage=='productdetails'){
  222. console.log('fromPagecart',this.fromPage);
  223. this.orderInfo.goodsList = this.buyNowGoods;
  224. }
  225. this.settlement();
  226. // 默认提货时间
  227. let now = Number(new Date());
  228. this.pickupInfo.pickupTime = uni.$u.timeFormat(now, 'yyyy-mm-dd hh:MM:ss');
  229. this.pickupTime = now;
  230. //商行信息
  231. this.getIntro();
  232. },
  233. onUnload() {
  234. this.$u.vuex('buyNowGoods',[]);
  235. console.log('this.buyNowGoods',this.buyNowGoods);
  236. },
  237. onShow() {
  238. if(this.fromPage=='addrlist'){
  239. this.settlement()
  240. }
  241. // console.log('cartGoods===',this.cartGoods);
  242. },
  243. watch: {
  244. selectReceiveIndex: {
  245. handler: function(newValue, oldValue) {
  246. this.logisticsType = this.receiveWayList[newValue];
  247. },
  248. immediate: true
  249. }
  250. },
  251. computed: {
  252. totalWeight() {
  253. let that = this;
  254. return this.orderInfo.goodsList.reduce((total, item) => {
  255. let weight = null;
  256. weight = item.weight
  257. total += weight * item.quantity;
  258. return total;
  259. }, 0);
  260. }
  261. },
  262. methods: {
  263. formatter(type, value) {
  264. if (type === 'year') {
  265. return `${value}年`
  266. }
  267. if (type === 'month') {
  268. return `${value}月`
  269. }
  270. if (type === 'day') {
  271. return `${value}日`
  272. }
  273. return value
  274. },
  275. confirmDate(e){
  276. this.pickupTimeShow = false;
  277. this.pickupInfo.pickupTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
  278. this.pickupTime = e.value;
  279. // console.log('pickupTime',this.pickupInfo.pickupTime);
  280. },
  281. getIntro(){
  282. this.$u.api.xsGetIntro().then(res=>{
  283. // console.log('xsGetIntro',res.data);
  284. this.pickupInfo.pickupAddress = res.data.shopAddress;
  285. this.pickupInfo.pickupLongitude = res.data.shopLongitude;
  286. this.pickupInfo.pickupLatitude = res.data.shopLatitude;
  287. }).catch(err=>{
  288. console.log('xsGetIntro',err.data);
  289. })
  290. },
  291. goMap(){
  292. uni.openLocation({
  293. latitude:this.pickupInfo.pickupLatitude, //维度
  294. longitude: this.pickupInfo.pickupLongitude, //经度
  295. name: "商行地址", //目的地定位名称
  296. scale: 15, //缩放比例
  297. address: this.pickupInfo.pickupAddress //导航详细地址
  298. })
  299. },
  300. leftClick(e){
  301. console.log('leftClick',e);
  302. },
  303. integralCheckboxChange(e){
  304. this.useIntegral = e[0] && e[0] === 'integral' ? true : false;
  305. },
  306. selectAddr(){
  307. uni.$u.route('/center/addrlist', {
  308. from: 'submitorder',
  309. // backUrl:'/shopping/submitorder'
  310. });
  311. },
  312. // getAddrList(){
  313. // this.$u.api.addrList().then(res=>{
  314. // this.theAddr = res.data.rows;
  315. // let defaultAddress;
  316. // let firstAddress = res.data.rows[0];
  317. // res.data.rows.forEach(address => {
  318. // if (address.ifDefault) { // 如果有默认地址标识
  319. // defaultAddress = address;
  320. // this.isDefaultAddr = true;
  321. // }
  322. // });
  323. // if (!defaultAddress) { // 如果没有默认地址标识
  324. // defaultAddress = firstAddress;
  325. // }
  326. // this.theAddr = defaultAddress;
  327. // }).catch(err=>{
  328. // console.log('getAddrList',err.data);
  329. // })
  330. // },
  331. // 改变商品数量
  332. changeQuantity(index, value) {
  333. // console.log('goodsList',this.orderInfo.goodsList);
  334. // console.log('index',index);
  335. // console.log('value',value);
  336. this.orderInfo.goodsList[index].quantity = value.value;
  337. this.settlement();
  338. },
  339. settlement(){
  340. let orderType = 1;
  341. // console.log('settlement',this.selectGoods);
  342. let param = {
  343. receiveId:this.receive.id
  344. };
  345. if(this.fromPage == 'creditOrder'){
  346. orderType = 2
  347. }
  348. param.orderType = orderType;
  349. param.goodsList = this.orderInfo.goodsList.map(item=>{
  350. return {goodsId:item.id||item.goodsId,quantity:item.quantity}
  351. });
  352. console.log('param',param);
  353. this.$u.api.getSettlement(param).then(res=>{
  354. console.log('res',res.data);
  355. this.setData(res.data)
  356. }).catch(err=>{
  357. console.log('getSettlement',err);
  358. })
  359. },
  360. setData(originData){
  361. console.log('originData',originData);
  362. let dataType = typeof originData;
  363. let jsonData;
  364. if(dataType=='string'){
  365. jsonData = JSON.parse(originData);
  366. }else{
  367. jsonData = originData
  368. }
  369. let {
  370. receive,
  371. distribution,
  372. totalAmount,
  373. payAmount,
  374. userTotalBalance,
  375. userTotalCredit,
  376. logisticsType,
  377. orderTotalCredit } = jsonData || {};
  378. this.receiveWayList = logisticsType.split(",");//支持的物流方式
  379. // console.log('orderTotalCredit',orderTotalCredit);
  380. // console.log('receive',receive);
  381. this.orderInfo = jsonData;
  382. this.receive = receive;
  383. this.distribution = distribution;//物流信息
  384. this.totalAmount = totalAmount;//订单总金额
  385. this.payAmount = payAmount;// 订单支付金额
  386. this.userTotalBalance = userTotalBalance;// 用户总余额
  387. this.userTotalCredit = userTotalCredit;// 用户总积分
  388. this.orderTotalCredit = orderTotalCredit;//订单需要的总积分
  389. // pickupInfo
  390. this.pickupInfo.pickupName = receive.receiveName;
  391. this.pickupInfo.pickupMobile = receive.receivePhone;
  392. // console.log('pickupInfo',this.pickupInfo);
  393. },
  394. submitOrder(){
  395. let that = this;
  396. this.cansubmit = false;
  397. let orderType = 1;
  398. let param = {
  399. receiveId:this.receive.id,
  400. distribution:this.distribution,
  401. logisticsType:this.logisticsType,
  402. pickupInfo:this.pickupInfo,
  403. };
  404. if(this.fromPage == 'creditOrder'){
  405. orderType = 2
  406. }
  407. param.orderType = orderType;
  408. param.goodsList = this.orderInfo.goodsList.map(item=>{
  409. return {goodsId:item.id,quantity:item.quantity}
  410. })
  411. console.log('submitOrder param',param);
  412. //获取经纬度
  413. uni.getLocation({
  414. type: 'gcj02',
  415. success: (res) => {
  416. param.latitude = res.latitude;
  417. param.longitude = res.longitude;
  418. that.$u.api.submitOrder(param).then(res=>{
  419. console.log('res',res.data);
  420. that.cansubmit = true;
  421. if(res.data.payAmount>0){
  422. uni.$u.route('/shopping/pay', {
  423. orderId: res.data.orderId,
  424. fromPage:that.fromPage,
  425. payAmount:res.data.payAmount
  426. });
  427. }else{
  428. uni.$u.route('/shopping/paysuccess', {
  429. fromPage:'nocash'
  430. });
  431. }
  432. }).catch(err=>{
  433. that.cansubmit = true;
  434. console.log('submitOrder',err);
  435. })
  436. },
  437. });
  438. },
  439. selectReceiveWay(index){
  440. this.selectReceiveIndex = index;
  441. console.log('selectReceiveWay index',index);
  442. console.log('selectReceiveWay',this.receiveWayList[index]);
  443. console.log('pickupInfo',this.pickupInfo);
  444. }
  445. }
  446. }
  447. </script>
  448. <style>
  449. page{
  450. background-color: #F5F5F5;
  451. /* padding-top: 50px; */
  452. }
  453. </style>
  454. <style lang="scss" scoped>
  455. .page-wrap{
  456. background-color: #fff;
  457. margin-bottom: 20rpx;
  458. }
  459. .addr{
  460. .top{
  461. margin-bottom: 16rpx;
  462. font-size: 26rpx;
  463. color: #999;
  464. .label{
  465. background-color: #FFEBEB;
  466. border: 1px solid #FF5F62;
  467. color: #FF5F62;
  468. padding: 5rpx 20rpx;
  469. border-radius: 30rpx;
  470. margin-right: 10rpx;
  471. }
  472. }
  473. .center{
  474. margin-bottom: 10rpx;
  475. font-size: 30rpx;
  476. color: #333;
  477. line-height: 50rpx;
  478. font-weight: 600;
  479. }
  480. .bottom{
  481. font-size: 30rpx;
  482. color: #666;
  483. }
  484. }
  485. .order-reduced{
  486. .reduced-item{
  487. &:not(:last-child){
  488. margin-bottom: 30rpx;
  489. padding-bottom: 30rpx;
  490. }
  491. .label{
  492. border-radius: 2px;
  493. border: 1px solid #FF3C3F;
  494. margin-left: 20rpx;
  495. font-size: 20rpx;
  496. color: #FF3C3F;
  497. padding: 0 10rpx;
  498. }
  499. }
  500. .integral{
  501. .num{
  502. font-size: 30rpx;
  503. color: #02AB35;
  504. font-weight: 600;
  505. margin-left: 30rpx;
  506. margin-right: 16rpx;
  507. }
  508. .tip{
  509. font-size: 24rpx;
  510. color: #999;
  511. }
  512. .price{
  513. margin-right: 10rpx;
  514. }
  515. }
  516. }
  517. .total{
  518. .total-item{
  519. &:not(:last-child){
  520. margin-bottom: 30rpx;
  521. padding-bottom: 30rpx;
  522. }
  523. .right{
  524. font-weight: 600;
  525. }
  526. }
  527. .gray{
  528. font-size: 24rpx;
  529. margin-left: 15rpx;
  530. }
  531. }
  532. .cart-bottom{
  533. height: 98rpx;
  534. .inner{
  535. position: fixed;
  536. background-color: #fff;
  537. height: 98rpx;
  538. left: 0;
  539. right: 0;
  540. bottom: 0;
  541. padding: 0 20rpx;
  542. .total-price{
  543. font-size: 30rpx;
  544. color: #333;
  545. font-weight: 600;
  546. margin-left: 30rpx;
  547. }
  548. .btn{
  549. height: 80rpx;
  550. line-height: 80rpx;
  551. border-radius: 50rpx;
  552. padding: 0 50rpx;
  553. background-color: #FF3C3F;
  554. color: #fff;
  555. text-align: center;
  556. &.gray{
  557. background-color: #ddd;
  558. color: #999;
  559. }
  560. }
  561. }
  562. }
  563. .product{
  564. .text{
  565. .name{
  566. height: auto;
  567. }
  568. .info{
  569. font-size: 24rpx;
  570. font-weight: 400;
  571. color: #666666;
  572. }
  573. }
  574. }
  575. .receive-way{
  576. margin-top: 20rpx;
  577. font-size: 30rpx;
  578. font-weight: 400;
  579. color: #333333;
  580. .til{
  581. }
  582. .way-item{
  583. margin-left: 50rpx;
  584. .icon{
  585. width: 30rpx;
  586. height: 30rpx;
  587. border-radius: 50%;
  588. box-sizing: border-box;
  589. border: 2px solid #ccc;
  590. margin-right: 10rpx;
  591. }
  592. &.select{
  593. .icon{
  594. background-color: #00A447;
  595. border-color: #00A447;
  596. }
  597. }
  598. }
  599. }
  600. .pickup-info{
  601. padding: 0 30rpx;
  602. .item{
  603. padding: 30rpx 0;
  604. font-size: 30rpx;
  605. font-weight: 400;
  606. color: #333333;
  607. line-height: 42rpx;
  608. &:not(:last-of-type){
  609. border-bottom: 1px solid #eee;
  610. }
  611. }
  612. }
  613. </style>