submitorder.vue 10 KB

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