index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="cart-pages">
  3. <view class="cart-bar">
  4. <view>
  5. <u-image height="40rpx" width="40rpx" src="/static/position.png"></u-image>
  6. </view>
  7. <view class="position">
  8. <view class="address">陕西省西安市未央区华帝金座A座6楼</view>
  9. <view>王明 1456465455</view>
  10. </view>
  11. <view @click="editAddress">
  12. <u-image height="50rpx" width="50rpx" src="/static/edit.png"></u-image>
  13. </view>
  14. </view>
  15. <view class="goods-list">
  16. <!-- 商品列表 -->
  17. <view class="goods-item" v-for="(item,index) in goodsList" :key="item.id">
  18. <view class="goods-imgs">
  19. <u-image border-radius="12" width="158rpx" height="140rpx" :src="item.goods.homeImage"></u-image>
  20. </view>
  21. <view class="goods-info">
  22. <view class="good-name">{{item.goods.name}}</view>
  23. <view class="goods-price">
  24. <view>
  25. <text>{{item.goods.sellGold}}</text>
  26. <u-image mode="scaleToFill" width="30rpx" height="30rpx" src="/static/ledou.png"></u-image>
  27. </view>
  28. <view>×{{item.buyQty}}</view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 总计 -->
  33. <view class="goods-heji">
  34. <view>
  35. <view>商品合计:</view>
  36. <view class="heji">
  37. <text>{{totalPrice}}</text>
  38. <u-image mode="scaleToFill" width="35rpx" height="35rpx" src="/static/ledou.png"></u-image>
  39. </view>
  40. </view>
  41. <view>
  42. <view>运费:</view>
  43. <view>免运费</view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="cart-submit">
  48. <view>
  49. <view>总计:<text>{{totalPrice}}</text></view>
  50. <u-image mode="scaleToFill" width="40rpx" height="40rpx" src="/static/ledou.png"></u-image>
  51. </view>
  52. <view>
  53. <u-button size="mini" :loading="btnLoading" :custom-style="toOrderButton" type="error" @click="toSave">确认支付</u-button>
  54. </view>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import { saveOrder, signPay} from '@/api/order.js'
  60. import {
  61. findAddressBycustomerNo
  62. } from '@/api/receiveAddress.js'
  63. export default {
  64. data() {
  65. return {
  66. toOrderButton: {
  67. borderRadius:'100rpx',
  68. fontSize:'30rpx',
  69. width: '180rpx',
  70. height: '60rpx'
  71. },
  72. goodsList: [],
  73. userInfo: {
  74. receiveAddress: '陕西省西安市未央区华帝金座',
  75. receiverName: '王明',
  76. receiverPhone: '14564654551',
  77. },
  78. btnLoading: false // 提交按钮加载圈
  79. };
  80. },
  81. onLoad() {
  82. this.goodsList = this.$store.state.vuex_toOrderList
  83. this.getLocation()
  84. },
  85. computed: {
  86. totalPrice() {
  87. let total = 0
  88. this.goodsList.map(item => {
  89. total = total + item.buyQty * item.goods.sellGold
  90. })
  91. return total
  92. }
  93. },
  94. methods: {
  95. // 获取用户位置
  96. getLocation() {
  97. findAddressBycustomerNo({customerNo:'12313'}).then(res => {
  98. console.log(res)
  99. })
  100. },
  101. //修改收货地址信息
  102. editAddress(){
  103. uni.navigateTo({
  104. url:"/pages/toOrder/editAddress"
  105. })
  106. },
  107. // 支付 保存订单
  108. toSave(){
  109. let orderGoodsList = []
  110. this.goodsList.map((item,index)=>{
  111. orderGoodsList[index] = {
  112. goodsNo: item.goodsNo,
  113. buyQty: item.buyQty
  114. }
  115. })
  116. this.btnLoading = true
  117. let params = Object.assign(this.userInfo,{orderGoodsList:orderGoodsList})
  118. console.log(orderGoodsList,params,'orderGoodsList')
  119. saveOrder(params).then(res=>{
  120. console.log(res,'rrrrrrr')
  121. if(res.status==200) {
  122. let id = res.data.id
  123. this.toPay(id)
  124. } else {
  125. this.btnLoading = false
  126. uni.showToast({
  127. title: res.message,
  128. icon: 'none'
  129. })
  130. }
  131. })
  132. },
  133. // 支付
  134. toPay(id) {
  135. signPay({id:id}).then(res=>{
  136. this.btnLoading = false
  137. if(res.status == 200) {
  138. uni.showToast({
  139. title: res.message,
  140. icon: 'none'
  141. })
  142. // 跳转到支付完成界面
  143. uni.navigateTo({
  144. url:""
  145. })
  146. } else{
  147. uni.showToast({
  148. title: res.message,
  149. icon: 'none'
  150. })
  151. }
  152. })
  153. }
  154. },
  155. }
  156. </script>
  157. <style lang="scss">
  158. page{
  159. height: 100%;
  160. }
  161. .cart-pages{
  162. width: 100%;
  163. height: 100%;
  164. display: flex;
  165. flex-direction: column;
  166. .cart-bar{
  167. background: #FFFFFF;
  168. border-bottom: 1px solid #F8F8F8;
  169. border-top: 10upx solid #F8F8F8;
  170. display: flex;
  171. align-items: center;
  172. padding:15upx 20upx;
  173. .position{
  174. flex-grow: 1;
  175. }
  176. > view{
  177. padding: 10upx;
  178. .address{
  179. padding: 5upx 0;
  180. }
  181. &:last-child{
  182. padding: 0 20upx;
  183. }
  184. }
  185. }
  186. .goods-list{
  187. padding: 20upx 0;
  188. flex-grow: 1;
  189. overflow: auto;
  190. .goods-class-box{
  191. background: #FFFFFF;
  192. box-shadow: 1px 1px 3px #eee;
  193. margin-bottom: 20upx;
  194. }
  195. .goods-item{
  196. padding: 20upx 40upx;
  197. display: flex;
  198. align-items: center;
  199. border-bottom: 1px solid #F8F8F8;
  200. background: #fff;
  201. &:last-child{
  202. border: 0;
  203. }
  204. .goods-imgs{
  205. position: relative;
  206. }
  207. .goods-info{
  208. flex-grow: 1;
  209. padding-left: 20upx;
  210. .good-name{
  211. font-weight: bold;
  212. word-break: break-all;
  213. }
  214. }
  215. .goods-price{
  216. display: flex;
  217. align-items: center;
  218. justify-content: space-between;
  219. padding-top: 20upx;
  220. >view{
  221. &:first-child{
  222. display: flex;
  223. align-items: center;
  224. text{
  225. color: red;
  226. font-size: 35upx;
  227. margin-right: 6upx;
  228. font-weight: bold;
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. .goods-heji{
  236. padding: 20upx 40upx;
  237. background: #FFFFFF;
  238. box-shadow: 1px 1px 3px #eee;
  239. margin-top: 20upx;
  240. >view{
  241. display: flex;
  242. align-items: center;
  243. justify-content: space-between;
  244. padding: 10upx 0;
  245. .heji{
  246. display: flex;
  247. align-items: center;
  248. text{
  249. color: red;
  250. margin-right: 6upx;
  251. font-size: 35upx;
  252. font-weight: bold;
  253. }
  254. }
  255. }
  256. }
  257. .cart-submit{
  258. padding: 20upx 30upx;
  259. background: #FFFFFF;
  260. box-shadow: 1px 1px 3px #eee;
  261. border-top: 1px solid #eee;
  262. display: flex;
  263. align-items: center;
  264. justify-content: space-between;
  265. > view{
  266. &:first-child{
  267. display: flex;
  268. align-items: center;
  269. text{
  270. color: red;
  271. font-size: 40upx;
  272. margin-right: 6upx;
  273. font-weight: bold;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. </style>