submitorder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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" v-if="logisticsType!=1">
  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>{{distribution.ifDistribution!=1?'该区域不支持配送':'免运费'}}</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">¥ {{logisticsType==1?payAmount: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="(logisticsType!=1?distribution.ifDistribution==1:true)&&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. // console.log('selectReceiveIndex',newValue);
  247. // this.logisticsType = this.receiveWayList[newValue];
  248. // console.log('logisticsType',this.logisticsType);
  249. // if(this.orderInfo.goodsList.length>0){
  250. // this.settlement();
  251. // }
  252. // },
  253. // immediate: true
  254. // }
  255. },
  256. computed: {
  257. totalWeight() {
  258. let that = this;
  259. return this.orderInfo.goodsList.reduce((total, item) => {
  260. let weight = null;
  261. weight = item.weight
  262. total += weight * item.quantity;
  263. return total;
  264. }, 0);
  265. }
  266. },
  267. methods: {
  268. formatter(type, value) {
  269. if (type === 'year') {
  270. return `${value}年`
  271. }
  272. if (type === 'month') {
  273. return `${value}月`
  274. }
  275. if (type === 'day') {
  276. return `${value}日`
  277. }
  278. return value
  279. },
  280. confirmDate(e){
  281. this.pickupTimeShow = false;
  282. this.pickupInfo.pickupTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
  283. this.pickupTime = e.value;
  284. // console.log('pickupTime',this.pickupInfo.pickupTime);
  285. },
  286. getIntro(){
  287. this.$u.api.xsGetIntro().then(res=>{
  288. // console.log('xsGetIntro',res.data);
  289. this.pickupInfo.pickupAddress = res.data.shopAddress;
  290. this.pickupInfo.pickupLongitude = res.data.shopLongitude;
  291. this.pickupInfo.pickupLatitude = res.data.shopLatitude;
  292. }).catch(err=>{
  293. console.log('xsGetIntro',err.data);
  294. })
  295. },
  296. goMap(){
  297. uni.openLocation({
  298. latitude:this.pickupInfo.pickupLatitude, //维度
  299. longitude: this.pickupInfo.pickupLongitude, //经度
  300. name: "商行地址", //目的地定位名称
  301. scale: 15, //缩放比例
  302. address: this.pickupInfo.pickupAddress //导航详细地址
  303. })
  304. },
  305. leftClick(e){
  306. console.log('leftClick',e);
  307. },
  308. integralCheckboxChange(e){
  309. this.useIntegral = e[0] && e[0] === 'integral' ? true : false;
  310. },
  311. selectAddr(){
  312. uni.$u.route('/center/addrlist', {
  313. from: 'submitorder',
  314. // backUrl:'/shopping/submitorder'
  315. });
  316. },
  317. // getAddrList(){
  318. // this.$u.api.addrList().then(res=>{
  319. // this.theAddr = res.data.rows;
  320. // let defaultAddress;
  321. // let firstAddress = res.data.rows[0];
  322. // res.data.rows.forEach(address => {
  323. // if (address.ifDefault) { // 如果有默认地址标识
  324. // defaultAddress = address;
  325. // this.isDefaultAddr = true;
  326. // }
  327. // });
  328. // if (!defaultAddress) { // 如果没有默认地址标识
  329. // defaultAddress = firstAddress;
  330. // }
  331. // this.theAddr = defaultAddress;
  332. // }).catch(err=>{
  333. // console.log('getAddrList',err.data);
  334. // })
  335. // },
  336. // 改变商品数量
  337. changeQuantity(index, value) {
  338. // console.log('goodsList',this.orderInfo.goodsList);
  339. // console.log('index',index);
  340. // console.log('value',value);
  341. this.orderInfo.goodsList[index].quantity = value.value;
  342. this.settlement();
  343. },
  344. settlement(){
  345. let orderType = 1;//1,正常订单,2积分订单
  346. // console.log('settlement',this.selectGoods);
  347. let param = {
  348. receiveId:this.receive.id
  349. };
  350. if(this.fromPage == 'creditOrder'){
  351. orderType = 2
  352. }
  353. param.orderType = orderType;
  354. // param.logisticsType = this.logisticsType;
  355. param.goodsList = this.orderInfo.goodsList.map(item=>{
  356. return {goodsId:item.id||item.goodsId,quantity:item.quantity}
  357. });
  358. console.log('param',param);
  359. this.$u.api.getSettlement(param).then(res=>{
  360. console.log('res',res.data);
  361. this.setData(res.data)
  362. }).catch(err=>{
  363. console.log('getSettlement',err);
  364. })
  365. },
  366. setData(originData){
  367. console.log('originData',originData);
  368. let dataType = typeof originData;
  369. let jsonData;
  370. if(dataType=='string'){
  371. jsonData = JSON.parse(originData);
  372. }else{
  373. jsonData = originData
  374. }
  375. let {
  376. receive,
  377. distribution,
  378. totalAmount,
  379. payAmount,
  380. userTotalBalance,
  381. userTotalCredit,
  382. logisticsType,
  383. orderTotalCredit } = jsonData || {};
  384. this.receiveWayList = logisticsType.split(",");//支持的物流方式
  385. this.logisticsType = this.receiveWayList[this.selectReceiveIndex];
  386. // console.log('orderTotalCredit',orderTotalCredit);
  387. // console.log('receive',receive);
  388. this.orderInfo = jsonData;
  389. this.receive = receive;
  390. this.distribution = distribution;//物流信息
  391. this.totalAmount = totalAmount;//订单总金额
  392. this.payAmount = payAmount;// 订单支付金额
  393. this.userTotalBalance = userTotalBalance;// 用户总余额
  394. this.userTotalCredit = userTotalCredit;// 用户总积分
  395. this.orderTotalCredit = orderTotalCredit;//订单需要的总积分
  396. // pickupInfo
  397. this.pickupInfo.pickupName = receive.receiveName;
  398. this.pickupInfo.pickupMobile = receive.receivePhone;
  399. // console.log('pickupInfo',this.pickupInfo);
  400. },
  401. submitOrder(){
  402. let that = this;
  403. this.cansubmit = false;
  404. let orderType = 1;
  405. let param = {
  406. receiveId:this.receive.id,
  407. distribution:this.distribution,
  408. logisticsType:this.logisticsType,
  409. pickupInfo:this.pickupInfo,
  410. };
  411. if(this.fromPage == 'creditOrder'){
  412. orderType = 2
  413. }
  414. param.orderType = orderType;
  415. param.goodsList = this.orderInfo.goodsList.map(item=>{
  416. return {goodsId:item.id,quantity:item.quantity}
  417. })
  418. console.log('submitOrder param',param);
  419. //获取经纬度
  420. uni.getLocation({
  421. type: 'gcj02',
  422. success: (res) => {
  423. param.latitude = res.latitude;
  424. param.longitude = res.longitude;
  425. that.$u.api.submitOrder(param).then(res=>{
  426. console.log('res',res.data);
  427. that.cansubmit = true;
  428. if(res.data.payAmount>0){
  429. uni.$u.route('/shopping/pay', {
  430. orderId: res.data.orderId,
  431. fromPage:that.fromPage,
  432. payAmount:res.data.payAmount
  433. });
  434. }else{
  435. uni.$u.route('/shopping/paysuccess', {
  436. fromPage:'nocash'
  437. });
  438. }
  439. }).catch(err=>{
  440. that.cansubmit = true;
  441. console.log('submitOrder',err);
  442. })
  443. },
  444. fail: (err) => {
  445. console.log('getLocationfail',err);
  446. that.cansubmit = true;
  447. uni.$u.toast('请允许获取地理位置,以便更好的服务')
  448. },
  449. complete(e) {
  450. console.log('getLocation complete',e);
  451. }
  452. });
  453. },
  454. selectReceiveWay(index){
  455. this.selectReceiveIndex = index;
  456. this.logisticsType = this.receiveWayList[index];
  457. // console.log('logisticsType',this.logisticsType);
  458. // if(this.orderInfo.goodsList.length>0){
  459. // this.settlement();
  460. // }
  461. // console.log('selectReceiveWay index',index);
  462. // console.log('selectReceiveWay',this.receiveWayList[index]);
  463. // console.log('pickupInfo',this.pickupInfo);
  464. }
  465. }
  466. }
  467. </script>
  468. <style>
  469. page{
  470. background-color: #F5F5F5;
  471. /* padding-top: 50px; */
  472. }
  473. </style>
  474. <style lang="scss" scoped>
  475. .page-wrap{
  476. background-color: #fff;
  477. margin-bottom: 20rpx;
  478. }
  479. .addr{
  480. .top{
  481. margin-bottom: 16rpx;
  482. font-size: 26rpx;
  483. color: #999;
  484. .label{
  485. background-color: #FFEBEB;
  486. border: 1px solid #FF5F62;
  487. color: #FF5F62;
  488. padding: 5rpx 20rpx;
  489. border-radius: 30rpx;
  490. margin-right: 10rpx;
  491. }
  492. }
  493. .center{
  494. margin-bottom: 10rpx;
  495. font-size: 30rpx;
  496. color: #333;
  497. line-height: 50rpx;
  498. font-weight: 600;
  499. }
  500. .bottom{
  501. font-size: 30rpx;
  502. color: #666;
  503. }
  504. }
  505. .order-reduced{
  506. .reduced-item{
  507. &:not(:last-child){
  508. margin-bottom: 30rpx;
  509. padding-bottom: 30rpx;
  510. }
  511. .label{
  512. border-radius: 2px;
  513. border: 1px solid #FF3C3F;
  514. margin-left: 20rpx;
  515. font-size: 20rpx;
  516. color: #FF3C3F;
  517. padding: 0 10rpx;
  518. }
  519. }
  520. .integral{
  521. .num{
  522. font-size: 30rpx;
  523. color: #02AB35;
  524. font-weight: 600;
  525. margin-left: 30rpx;
  526. margin-right: 16rpx;
  527. }
  528. .tip{
  529. font-size: 24rpx;
  530. color: #999;
  531. }
  532. .price{
  533. margin-right: 10rpx;
  534. }
  535. }
  536. }
  537. .total{
  538. .total-item{
  539. padding-bottom: 30rpx;
  540. &:not(:last-child){
  541. margin-bottom: 30rpx;
  542. }
  543. .right{
  544. font-weight: 600;
  545. }
  546. }
  547. .gray{
  548. font-size: 24rpx;
  549. margin-left: 15rpx;
  550. }
  551. }
  552. .cart-bottom{
  553. height: 98rpx;
  554. .inner{
  555. position: fixed;
  556. background-color: #fff;
  557. height: 98rpx;
  558. left: 0;
  559. right: 0;
  560. bottom: 0;
  561. padding: 0 20rpx;
  562. .total-price{
  563. font-size: 30rpx;
  564. color: #333;
  565. font-weight: 600;
  566. margin-left: 30rpx;
  567. }
  568. .btn{
  569. height: 80rpx;
  570. line-height: 80rpx;
  571. border-radius: 50rpx;
  572. padding: 0 50rpx;
  573. background-color: #FF3C3F;
  574. color: #fff;
  575. text-align: center;
  576. &.gray{
  577. background-color: #ddd;
  578. color: #999;
  579. }
  580. }
  581. }
  582. }
  583. .product{
  584. .text{
  585. .name{
  586. height: auto;
  587. }
  588. .info{
  589. font-size: 24rpx;
  590. font-weight: 400;
  591. color: #666666;
  592. }
  593. }
  594. }
  595. .receive-way{
  596. margin-top: 20rpx;
  597. font-size: 30rpx;
  598. font-weight: 400;
  599. color: #333333;
  600. .til{
  601. }
  602. .way-item{
  603. margin-left: 50rpx;
  604. .icon{
  605. width: 30rpx;
  606. height: 30rpx;
  607. border-radius: 50%;
  608. box-sizing: border-box;
  609. border: 2px solid #ccc;
  610. margin-right: 10rpx;
  611. }
  612. &.select{
  613. .icon{
  614. background-color: #00A447;
  615. border-color: #00A447;
  616. }
  617. }
  618. }
  619. }
  620. </style>