submitorder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. title="提交订单"
  5. @leftClick="leftClick"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <view class="addr page-wrap u-flex u-row-between">
  11. <view class="left">
  12. <view class="top">
  13. <text class="label" v-if="orderInfo.receive.ifDefault">默认</text>{{receive.address}}
  14. </view>
  15. <view class="center">{{receive.receiveAdress}}</view>
  16. <view class="bottom">{{receive.receiveName}} {{receive.receivePhone}}</view>
  17. </view>
  18. <u-icon name="arrow-right" color="#676767" size="20" @click="selectAddr"></u-icon>
  19. </view>
  20. <!-- <view class="payway page-wrap u-flex u-row-between">
  21. <view class="left">支付方式</view>
  22. <view class="u-flex">
  23. 微信支付
  24. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  25. </view>
  26. </view> -->
  27. <view class="order-product page-wrap">
  28. <view class="product u-flex" v-for="(item,index) in orderInfo.goodsList" :key="item.id">
  29. <u--image :showLoading="true" :src="item.mainImg" width="180rpx" height="180rpx"></u--image>
  30. <view class="text">
  31. <view class="up">
  32. <view class="name ellipsis-2">{{item.goodsName}}</view>
  33. <view class="info">
  34. {{item.specification}}
  35. {{item.unit}}
  36. </view>
  37. </view>
  38. <view class="down u-flex u-row-between">
  39. <view class="left">
  40. <view class="" v-if="vuex_member_info.priceType>1">
  41. <text class="price">¥ <text class="price-num">{{item.vipPrice}}</text></text>
  42. <text class="vip-icon">VIP</text>
  43. <text class="original-price gray line-through">¥ {{item.salePrice}}</text>
  44. </view>
  45. <view class="" v-else>
  46. <text class="price">¥ <text class="price-num">{{item.salePrice}}</text></text>
  47. </view>
  48. </view>
  49. <u-number-box v-if="fromPage!='creditOrder'" v-model="item.quantity" @change="changeQuantity(index, $event)" integer></u-number-box>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="page-wrap order-reduced">
  55. <!-- <view class="reduced-item u-flex u-row-between u-border-bottom">
  56. <view class="left">
  57. <text>优惠券</text>
  58. <text class="label">已选一张</text>
  59. </view>
  60. <view class="right u-flex">
  61. <text class="price red">-¥ <text class="price-num">1000</text></text>
  62. <u-icon name="arrow-right" color="#676767" size="20"></u-icon>
  63. </view>
  64. </view> -->
  65. <view class="reduced-item integral u-flex u-row-between" v-if="orderTotalCredit">
  66. <view class="left">
  67. <text>积分</text>
  68. <!-- <text class="num">3676</text> -->
  69. <!-- <text class="tip">满1000可用</text> -->
  70. </view>
  71. <view class="right u-flex">
  72. <text class="price red" >- <text class="price-num">{{orderTotalCredit}}</text></text>
  73. <!-- <u-checkbox-group @change="integralCheckboxChange">
  74. <u-checkbox shape="circle" activeColor="#02AB35" name="integral" ></u-checkbox>
  75. </u-checkbox-group> -->
  76. </view>
  77. </view>
  78. </view>
  79. <view class="page-wrap total">
  80. <view class="total-item u-flex u-row-between u-border-bottom">
  81. <view class="left">
  82. 商品金额
  83. </view>
  84. <view class="right red">
  85. ¥ {{totalAmount}}
  86. </view>
  87. </view>
  88. <view class="total-item u-flex u-row-between">
  89. <view class="left">
  90. 运费
  91. <text class="gray">总重:{{totalWeight}}</text>
  92. </view>
  93. <view class="right red">
  94. <text v-if="distribution.distributionPrice">+ ¥ {{distribution.distributionPrice}}</text>
  95. <text v-else>免运费</text>
  96. </view>
  97. </view>
  98. </view>
  99. <view class="cart-bottom">
  100. <view class="inner u-flex u-row-between">
  101. <view class="left u-flex">
  102. <view class="total-price">
  103. 待支付:<text class="red">¥ {{payAmount + distribution.distributionPrice}}</text>
  104. </view>
  105. </view>
  106. <view class="btn gray" v-if="orderTotalCredit&&userTotalCredit<orderTotalCredit">积分不够</view>
  107. <view class="" v-else>
  108. <view class="btn" v-if="cansubmit" @click="submitOrder">去结算</view>
  109. <view class="btn gray" v-else>去结算</view>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. export default {
  117. data() {
  118. return {
  119. cansubmit:true,
  120. fromPage:'',
  121. useIntegral:false,
  122. dataList:[],
  123. receiveId:'',
  124. receive:{},
  125. isDefaultAddr:false,
  126. orderInfo:{goodsList:[]},
  127. distribution:{},//物流信息
  128. totalAmount:null,//订单总金额
  129. payAmount:null,//订单支付金额
  130. userTotalBalance:null,//用户总余额
  131. userTotalCredit:null,//用户总积分
  132. orderTotalCredit:null,//订单需要的总积分
  133. }
  134. },
  135. onLoad(page) {
  136. // console.log('page',page);
  137. // console.log('this.creditGoods',this.creditGoods);
  138. this.fromPage = page.fromPage;
  139. // if(this.cartGoods>0&&this.fromPage!='cart'){
  140. // console.log('fromPagecart',this.fromPage);
  141. // this.orderInfo.goodsList = this.cartGoods;
  142. // }
  143. // if(this.creditGoods.length>0&&this.fromPage=='creditOrder'){
  144. // console.log('fromPagecreditOrder',this.fromPage);
  145. // this.orderInfo.goodsList = this.creditGoods;
  146. // }
  147. this.orderInfo.goodsList = this.cartGoods;
  148. this.settlement();
  149. },
  150. onShow() {
  151. if(this.fromPage=='addrlist'){
  152. this.settlement()
  153. }
  154. console.log('cartGoods===',this.cartGoods);
  155. },
  156. computed: {
  157. totalWeight() {
  158. let that = this;
  159. return this.orderInfo.goodsList.reduce((total, item) => {
  160. let weight = null;
  161. weight = item.weight
  162. total += weight * item.quantity;
  163. return total;
  164. }, 0);
  165. }
  166. },
  167. methods: {
  168. leftClick(e){
  169. console.log('leftClick',e);
  170. },
  171. integralCheckboxChange(e){
  172. this.useIntegral = e[0] && e[0] === 'integral' ? true : false;
  173. },
  174. selectAddr(){
  175. uni.$u.route('/center/addrlist', {
  176. from: 'settlement'
  177. });
  178. },
  179. // getAddrList(){
  180. // this.$u.api.addrList().then(res=>{
  181. // this.theAddr = res.data.rows;
  182. // let defaultAddress;
  183. // let firstAddress = res.data.rows[0];
  184. // res.data.rows.forEach(address => {
  185. // if (address.ifDefault) { // 如果有默认地址标识
  186. // defaultAddress = address;
  187. // this.isDefaultAddr = true;
  188. // }
  189. // });
  190. // if (!defaultAddress) { // 如果没有默认地址标识
  191. // defaultAddress = firstAddress;
  192. // }
  193. // this.theAddr = defaultAddress;
  194. // }).catch(err=>{
  195. // console.log('getAddrList',err.data);
  196. // })
  197. // },
  198. // 改变商品数量
  199. changeQuantity(index, value) {
  200. console.log('goodsList',this.orderInfo.goodsList);
  201. this.$nextTick(()=>{
  202. this.settlement();
  203. })
  204. },
  205. settlement(){
  206. let orderType = 1;
  207. // console.log('settlement',this.selectGoods);
  208. let param = {
  209. receiveId:this.receive.id
  210. };
  211. if(this.fromPage == 'creditOrder'){
  212. orderType = 2
  213. }
  214. param.orderType = orderType;
  215. param.goodsList = this.orderInfo.goodsList.map(item=>{
  216. return {goodsId:item.id||item.goodsId,quantity:item.quantity}
  217. });
  218. console.log('param',param);
  219. this.$u.api.getSettlement(param).then(res=>{
  220. console.log('res',res.data);
  221. this.setData(res.data)
  222. }).catch(err=>{
  223. console.log('getSettlement',err);
  224. })
  225. },
  226. setData(originData){
  227. console.log('originData',originData);
  228. let dataType = typeof originData;
  229. let jsonData;
  230. if(dataType=='string'){
  231. jsonData = JSON.parse(originData);
  232. }else{
  233. jsonData = originData
  234. }
  235. let {
  236. receive,
  237. distribution,
  238. totalAmount,
  239. payAmount,
  240. userTotalBalance,
  241. userTotalCredit,
  242. orderTotalCredit } = jsonData || {};
  243. console.log('orderTotalCredit',orderTotalCredit);
  244. this.orderInfo = jsonData;
  245. this.receive = receive;
  246. this.distribution = distribution;//物流信息
  247. this.totalAmount = totalAmount;//订单总金额
  248. this.payAmount = payAmount;// 订单支付金额
  249. this.userTotalBalance = userTotalBalance;// 用户总余额
  250. this.userTotalCredit = userTotalCredit;// 用户总积分
  251. this.orderTotalCredit = orderTotalCredit;//订单需要的总积分
  252. },
  253. submitOrder(){
  254. let that = this;
  255. this.cansubmit = false;
  256. let orderType = 1;
  257. let param = {
  258. receiveId:this.receive.id,
  259. distribution:this.distribution,
  260. };
  261. if(this.fromPage == 'creditOrder'){
  262. orderType = 2
  263. }
  264. param.orderType = orderType;
  265. param.goodsList = this.orderInfo.goodsList.map(item=>{
  266. return {goodsId:item.id,quantity:item.quantity}
  267. })
  268. //获取经纬度
  269. uni.getLocation({
  270. type: 'gcj02',
  271. success: (res) => {
  272. param.latitude = res.latitude;
  273. param.longitude = res.longitude;
  274. that.$u.api.submitOrder(param).then(res=>{
  275. console.log('res',res.data);
  276. that.cansubmit = true;
  277. uni.$u.route('/shopping/pay', {
  278. orderId: res.data.orderId,
  279. fromPage:this.fromPage,
  280. payAmount:res.data.payAmount
  281. });
  282. }).catch(err=>{
  283. that.cansubmit = true;
  284. console.log('submitOrder',err);
  285. })
  286. },
  287. });
  288. }
  289. }
  290. }
  291. </script>
  292. <style>
  293. page{
  294. background-color: #F5F5F5;
  295. /* padding-top: 50px; */
  296. }
  297. </style>
  298. <style lang="scss" scoped>
  299. .page-wrap{
  300. background-color: #fff;
  301. margin-bottom: 20rpx;
  302. }
  303. .addr{
  304. .top{
  305. margin-bottom: 16rpx;
  306. font-size: 26rpx;
  307. color: #999;
  308. .label{
  309. background-color: #FFEBEB;
  310. border: 1px solid #FF5F62;
  311. color: #FF5F62;
  312. padding: 5rpx 20rpx;
  313. border-radius: 30rpx;
  314. margin-right: 10rpx;
  315. }
  316. }
  317. .center{
  318. margin-bottom: 10rpx;
  319. font-size: 30rpx;
  320. color: #333;
  321. line-height: 50rpx;
  322. font-weight: 600;
  323. }
  324. .bottom{
  325. font-size: 30rpx;
  326. color: #666;
  327. }
  328. }
  329. .order-reduced{
  330. .reduced-item{
  331. &:not(:last-child){
  332. margin-bottom: 30rpx;
  333. padding-bottom: 30rpx;
  334. }
  335. .label{
  336. border-radius: 2px;
  337. border: 1px solid #FF3C3F;
  338. margin-left: 20rpx;
  339. font-size: 20rpx;
  340. color: #FF3C3F;
  341. padding: 0 10rpx;
  342. }
  343. }
  344. .integral{
  345. .num{
  346. font-size: 30rpx;
  347. color: #02AB35;
  348. font-weight: 600;
  349. margin-left: 30rpx;
  350. margin-right: 16rpx;
  351. }
  352. .tip{
  353. font-size: 24rpx;
  354. color: #999;
  355. }
  356. .price{
  357. margin-right: 10rpx;
  358. }
  359. }
  360. }
  361. .total{
  362. .total-item{
  363. &:not(:last-child){
  364. margin-bottom: 30rpx;
  365. padding-bottom: 30rpx;
  366. }
  367. .right{
  368. font-weight: 600;
  369. }
  370. }
  371. .gray{
  372. font-size: 24rpx;
  373. margin-left: 15rpx;
  374. }
  375. }
  376. .cart-bottom{
  377. height: 98rpx;
  378. .inner{
  379. position: fixed;
  380. background-color: #fff;
  381. height: 98rpx;
  382. left: 0;
  383. right: 0;
  384. bottom: 0;
  385. padding: 0 20rpx;
  386. .total-price{
  387. font-size: 30rpx;
  388. color: #333;
  389. font-weight: 600;
  390. margin-left: 30rpx;
  391. }
  392. .btn{
  393. height: 80rpx;
  394. line-height: 80rpx;
  395. border-radius: 50rpx;
  396. padding: 0 50rpx;
  397. background-color: #FF3C3F;
  398. color: #fff;
  399. text-align: center;
  400. &.gray{
  401. background-color: #ddd;
  402. color: #999;
  403. }
  404. }
  405. }
  406. }
  407. .product{
  408. .text{
  409. .name{
  410. height: auto;
  411. }
  412. .info{
  413. font-size: 24rpx;
  414. font-weight: 400;
  415. color: #666666;
  416. }
  417. }
  418. }
  419. </style>