submitorder.vue 9.4 KB

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