青蛙卖大米小程序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.

287 lines
5.3 KiB

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