submitorder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. // if(this.cartGoods>0&&this.fromPage!='cart'){
  147. // console.log('fromPagecart',this.fromPage);
  148. // this.orderInfo.goodsList = this.cartGoods;
  149. // }
  150. // if(this.creditGoods.length>0&&this.fromPage=='creditOrder'){
  151. // console.log('fromPagecreditOrder',this.fromPage);
  152. // this.orderInfo.goodsList = this.creditGoods;
  153. // }
  154. this.orderInfo.goodsList = this.cartGoods;
  155. this.settlement();
  156. },
  157. onShow() {
  158. if(this.fromPage=='addrlist'){
  159. this.settlement()
  160. }
  161. console.log('cartGoods===',this.cartGoods);
  162. },
  163. computed: {
  164. totalWeight() {
  165. let that = this;
  166. return this.orderInfo.goodsList.reduce((total, item) => {
  167. let weight = null;
  168. weight = item.weight
  169. total += weight * item.quantity;
  170. return total;
  171. }, 0);
  172. }
  173. },
  174. methods: {
  175. leftClick(e){
  176. console.log('leftClick',e);
  177. },
  178. integralCheckboxChange(e){
  179. this.useIntegral = e[0] && e[0] === 'integral' ? true : false;
  180. },
  181. selectAddr(){
  182. uni.$u.route('/center/addrlist', {
  183. from: 'settlement'
  184. });
  185. },
  186. // getAddrList(){
  187. // this.$u.api.addrList().then(res=>{
  188. // this.theAddr = res.data.rows;
  189. // let defaultAddress;
  190. // let firstAddress = res.data.rows[0];
  191. // res.data.rows.forEach(address => {
  192. // if (address.ifDefault) { // 如果有默认地址标识
  193. // defaultAddress = address;
  194. // this.isDefaultAddr = true;
  195. // }
  196. // });
  197. // if (!defaultAddress) { // 如果没有默认地址标识
  198. // defaultAddress = firstAddress;
  199. // }
  200. // this.theAddr = defaultAddress;
  201. // }).catch(err=>{
  202. // console.log('getAddrList',err.data);
  203. // })
  204. // },
  205. // 改变商品数量
  206. changeQuantity(index, value) {
  207. // console.log('goodsList',this.orderInfo.goodsList);
  208. // console.log('index',index);
  209. // console.log('value',value);
  210. this.orderInfo.goodsList[index].quantity = value.value;
  211. this.settlement();
  212. },
  213. settlement(){
  214. let orderType = 1;
  215. // console.log('settlement',this.selectGoods);
  216. let param = {
  217. receiveId:this.receive.id
  218. };
  219. if(this.fromPage == 'creditOrder'){
  220. orderType = 2
  221. }
  222. param.orderType = orderType;
  223. param.goodsList = this.orderInfo.goodsList.map(item=>{
  224. return {goodsId:item.id||item.goodsId,quantity:item.quantity}
  225. });
  226. console.log('param',param);
  227. this.$u.api.getSettlement(param).then(res=>{
  228. console.log('res',res.data);
  229. this.setData(res.data)
  230. }).catch(err=>{
  231. console.log('getSettlement',err);
  232. })
  233. },
  234. setData(originData){
  235. console.log('originData',originData);
  236. let dataType = typeof originData;
  237. let jsonData;
  238. if(dataType=='string'){
  239. jsonData = JSON.parse(originData);
  240. }else{
  241. jsonData = originData
  242. }
  243. let {
  244. receive,
  245. distribution,
  246. totalAmount,
  247. payAmount,
  248. userTotalBalance,
  249. userTotalCredit,
  250. orderTotalCredit } = jsonData || {};
  251. console.log('orderTotalCredit',orderTotalCredit);
  252. this.orderInfo = jsonData;
  253. this.receive = receive;
  254. this.distribution = distribution;//物流信息
  255. this.totalAmount = totalAmount;//订单总金额
  256. this.payAmount = payAmount;// 订单支付金额
  257. this.userTotalBalance = userTotalBalance;// 用户总余额
  258. this.userTotalCredit = userTotalCredit;// 用户总积分
  259. this.orderTotalCredit = orderTotalCredit;//订单需要的总积分
  260. },
  261. submitOrder(){
  262. let that = this;
  263. this.cansubmit = false;
  264. let orderType = 1;
  265. let param = {
  266. receiveId:this.receive.id,
  267. distribution:this.distribution,
  268. };
  269. if(this.fromPage == 'creditOrder'){
  270. orderType = 2
  271. }
  272. param.orderType = orderType;
  273. param.goodsList = this.orderInfo.goodsList.map(item=>{
  274. return {goodsId:item.id,quantity:item.quantity}
  275. })
  276. //获取经纬度
  277. uni.getLocation({
  278. type: 'gcj02',
  279. success: (res) => {
  280. param.latitude = res.latitude;
  281. param.longitude = res.longitude;
  282. that.$u.api.submitOrder(param).then(res=>{
  283. console.log('res',res.data);
  284. that.cansubmit = true;
  285. if(res.data.payAmount>0){
  286. uni.$u.route('/shopping/pay', {
  287. orderId: res.data.orderId,
  288. fromPage:that.fromPage,
  289. payAmount:res.data.payAmount
  290. });
  291. }else{
  292. uni.$u.route('/shopping/paysuccess', {
  293. fromPage:'nocash'
  294. });
  295. }
  296. }).catch(err=>{
  297. that.cansubmit = true;
  298. console.log('submitOrder',err);
  299. })
  300. },
  301. });
  302. }
  303. }
  304. }
  305. </script>
  306. <style>
  307. page{
  308. background-color: #F5F5F5;
  309. /* padding-top: 50px; */
  310. }
  311. </style>
  312. <style lang="scss" scoped>
  313. .page-wrap{
  314. background-color: #fff;
  315. margin-bottom: 20rpx;
  316. }
  317. .addr{
  318. .top{
  319. margin-bottom: 16rpx;
  320. font-size: 26rpx;
  321. color: #999;
  322. .label{
  323. background-color: #FFEBEB;
  324. border: 1px solid #FF5F62;
  325. color: #FF5F62;
  326. padding: 5rpx 20rpx;
  327. border-radius: 30rpx;
  328. margin-right: 10rpx;
  329. }
  330. }
  331. .center{
  332. margin-bottom: 10rpx;
  333. font-size: 30rpx;
  334. color: #333;
  335. line-height: 50rpx;
  336. font-weight: 600;
  337. }
  338. .bottom{
  339. font-size: 30rpx;
  340. color: #666;
  341. }
  342. }
  343. .order-reduced{
  344. .reduced-item{
  345. &:not(:last-child){
  346. margin-bottom: 30rpx;
  347. padding-bottom: 30rpx;
  348. }
  349. .label{
  350. border-radius: 2px;
  351. border: 1px solid #FF3C3F;
  352. margin-left: 20rpx;
  353. font-size: 20rpx;
  354. color: #FF3C3F;
  355. padding: 0 10rpx;
  356. }
  357. }
  358. .integral{
  359. .num{
  360. font-size: 30rpx;
  361. color: #02AB35;
  362. font-weight: 600;
  363. margin-left: 30rpx;
  364. margin-right: 16rpx;
  365. }
  366. .tip{
  367. font-size: 24rpx;
  368. color: #999;
  369. }
  370. .price{
  371. margin-right: 10rpx;
  372. }
  373. }
  374. }
  375. .total{
  376. .total-item{
  377. &:not(:last-child){
  378. margin-bottom: 30rpx;
  379. padding-bottom: 30rpx;
  380. }
  381. .right{
  382. font-weight: 600;
  383. }
  384. }
  385. .gray{
  386. font-size: 24rpx;
  387. margin-left: 15rpx;
  388. }
  389. }
  390. .cart-bottom{
  391. height: 98rpx;
  392. .inner{
  393. position: fixed;
  394. background-color: #fff;
  395. height: 98rpx;
  396. left: 0;
  397. right: 0;
  398. bottom: 0;
  399. padding: 0 20rpx;
  400. .total-price{
  401. font-size: 30rpx;
  402. color: #333;
  403. font-weight: 600;
  404. margin-left: 30rpx;
  405. }
  406. .btn{
  407. height: 80rpx;
  408. line-height: 80rpx;
  409. border-radius: 50rpx;
  410. padding: 0 50rpx;
  411. background-color: #FF3C3F;
  412. color: #fff;
  413. text-align: center;
  414. &.gray{
  415. background-color: #ddd;
  416. color: #999;
  417. }
  418. }
  419. }
  420. }
  421. .product{
  422. .text{
  423. .name{
  424. height: auto;
  425. }
  426. .info{
  427. font-size: 24rpx;
  428. font-weight: 400;
  429. color: #666666;
  430. }
  431. }
  432. }
  433. </style>