青蛙卖大米小程序2024-11-24
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
5.6 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="下单支付" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="box">
  5. <!-- 地址 -->
  6. <view class="address" @click="openAddress">
  7. <image src="../static/address/icon1.png" mode=""></image>
  8. <view class="">
  9. {{ address.name }}
  10. </view>
  11. <view class="">
  12. {{ address.address }}
  13. </view>
  14. <view class="icon">
  15. <uv-icon size="30rpx" name="arrow-right"></uv-icon>
  16. </view>
  17. </view>
  18. <view class="productList">
  19. <view class="item"
  20. :key="index"
  21. v-for="(item, index) in productList">
  22. <view class="item-image">
  23. <image :src="item.image &&
  24. item.image.split(',')[0]"
  25. mode="aspectFill"></image>
  26. </view>
  27. <view class="info">
  28. <view class="title">
  29. {{ item.title }}
  30. </view>
  31. <view class="desc">
  32. {{ item.sku }}
  33. </view>
  34. <view class="price">
  35. <view class="">
  36. <uv-number-box
  37. v-model="item.num"
  38. ></uv-number-box>
  39. </view>
  40. <view class="">
  41. {{ item.price }}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="submit-box">
  48. <view class="peis">
  49. <view class="">
  50. 配送方式
  51. </view>
  52. <view class="">
  53. 商家自行配送
  54. </view>
  55. </view>
  56. <view class="priceInfo">
  57. <view class="">
  58. 付款金额
  59. </view>
  60. <view class="totalPrice">
  61. {{ totalPrice }}
  62. </view>
  63. </view>
  64. <view class="remark">
  65. <input type="text"
  66. placeholder="请输入备注"
  67. v-model="remark"/>
  68. </view>
  69. </view>
  70. <view class="uni-color-btn"
  71. @click="submit">
  72. 确认下单
  73. </view>
  74. </view>
  75. <!-- 地址选择 -->
  76. <uv-popup ref="addressPopup" :round="30">
  77. <addressList ref="addressList" height="60vh" @select="selectAddress" />
  78. </uv-popup>
  79. </view>
  80. </template>
  81. <script>
  82. import addressList from '../components/address/addressList.vue'
  83. import { mapState } from 'vuex'
  84. export default {
  85. components: {
  86. addressList,
  87. },
  88. data() {
  89. return {
  90. productList: [],
  91. address: {
  92. name: '请选择地址',
  93. address: '',
  94. },
  95. addressTotal: 0,
  96. remark : '',
  97. num : 1,
  98. }
  99. },
  100. computed : {
  101. totalPrice(){
  102. let price = 0
  103. this.productList.forEach(n => {
  104. price += n.price * n.num
  105. })
  106. return Number(price).toFixed(2)
  107. },
  108. ...mapState(['payOrderProduct']),
  109. },
  110. onLoad() {
  111. this.getRiceProductDetail()
  112. },
  113. onShow() {
  114. this.getAddressList()
  115. },
  116. methods: {
  117. // 获取商品
  118. getRiceProductDetail() {
  119. this.productList = JSON.parse(JSON.stringify(this.payOrderProduct))
  120. },
  121. // 打开
  122. getAddressList() {
  123. // 获取地址列表
  124. this.$refs.addressList.getAddressList().then(res => {
  125. this.addressTotal = res.total
  126. if (this.addressTotal != 0) {
  127. this.address = res.records[0]
  128. }
  129. })
  130. },
  131. // 打开选择地址
  132. openAddress() {
  133. if (this.addressTotal == 0) {
  134. return uni.navigateTo({
  135. url: '/pages_order/mine/address?type=back'
  136. })
  137. }
  138. this.$refs.addressPopup.open('bottom')
  139. },
  140. // 选择地址
  141. selectAddress(e) {
  142. this.address = e
  143. this.$refs.addressPopup.close()
  144. },
  145. // 确认下单
  146. submit(){
  147. this.$api('createOrder', {
  148. productId : this.productList[0].id,
  149. num : 1,
  150. }, res => {
  151. if(res.code == 200){
  152. uni.showToast({
  153. title: '购买成功',
  154. icon: 'none'
  155. })
  156. setInterval(uni.navigateTo, 1000, {
  157. url : '/pages/index/order'
  158. })
  159. }
  160. })
  161. },
  162. }
  163. }
  164. </script>
  165. <style scoped lang="scss">
  166. .page {
  167. .box {
  168. padding: 20rpx;
  169. .address {
  170. display: flex;
  171. padding: 20rpx;
  172. background-color: #fff;
  173. align-items: center;
  174. border-radius: 20rpx;
  175. image {
  176. width: 40rpx;
  177. height: 40rpx;
  178. margin: 20rpx;
  179. }
  180. view {
  181. margin: 20rpx;
  182. overflow: hidden; //超出的文本隐藏
  183. text-overflow: ellipsis; //溢出用省略号显示
  184. white-space: nowrap; //溢出不换行
  185. }
  186. .icon {
  187. margin-left: auto;
  188. }
  189. }
  190. .productList {
  191. margin-top: 20rpx;
  192. background-color: #fff;
  193. border-radius: 20rpx;
  194. .item {
  195. padding: 10rpx 20rpx;
  196. align-items: center;
  197. margin-bottom: 20rpx;
  198. display: flex;
  199. width: 100%;
  200. box-sizing: border-box;
  201. .item-image {
  202. width: 140rpx;
  203. height: 140rpx;
  204. flex-shrink: 0;
  205. image {
  206. height: 100%;
  207. width: 100%;
  208. border-radius: 20rpx;
  209. }
  210. }
  211. .info {
  212. padding: 20rpx;
  213. color: #555;
  214. flex: 1;
  215. .title {
  216. font-size: 28rpx;
  217. font-weight: 900;
  218. }
  219. .desc {
  220. font-size: 22rpx;
  221. color: #777;
  222. margin-top: 10rpx;
  223. }
  224. .price {
  225. display: flex;
  226. justify-content: space-between;
  227. color: #f40;
  228. font-size: 30rpx;
  229. font-weight: 900;
  230. }
  231. }
  232. }
  233. }
  234. .submit-box{
  235. background-color: #fff;
  236. padding: 20rpx;
  237. border-radius: 20rpx;
  238. &>view:nth-child(2){
  239. margin-top: 20rpx;
  240. }
  241. &>view{
  242. display: flex;
  243. justify-content: space-between;
  244. align-items: center;
  245. font-size: 28rpx;
  246. &>view:nth-child(1){
  247. font-weight: 900;
  248. }
  249. &>view:nth-child(2){
  250. color: #999;
  251. font-size: 24rpx;
  252. }
  253. .totalPrice{
  254. color: #f40 !important;
  255. font-size: 34rpx !important;
  256. font-weight: 900;
  257. }
  258. }
  259. .remark{
  260. margin-top: 30rpx;
  261. input{
  262. background-color: #f3f3f3;
  263. padding: 14rpx 20rpx;
  264. border-radius: 20rpx;
  265. flex: 1;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>