submitorder.vue 9.7 KB

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