submitorder.vue 17 KB

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