敢为人鲜小程序前端代码仓库
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.

357 lines
7.5 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
3 months ago
4 months ago
3 months ago
3 months ago
3 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
4 months ago
3 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
5 months ago
4 months ago
3 months ago
5 months ago
  1. <template>
  2. <view class="item" @click="$emit('click')">
  3. <!-- 商品图片 -->
  4. <view class="item-image">
  5. <!-- <image :src="item.image &&
  6. item.image.split(',')[0]" mode="aspectFill">
  7. </image> -->
  8. <image :src="item.image" mode="aspectFill" class="item-image-img">
  9. </image>
  10. </view>
  11. <!-- 商品信息 -->
  12. <view class="info">
  13. <!-- 商品标题 -->
  14. <view class="title">
  15. {{ item.title }}
  16. </view>
  17. <!-- 价格 -->
  18. <!-- <view class="price">
  19. <view class="money">
  20. <text>{{ getPriceByRole(item) }}</text>
  21. <text class="unit">/元每件</text>
  22. </view>
  23. <view class="price-imgs">
  24. <image v-if="userInfo.role == 1" :src="configList.vip_money_one" mode="aspectFill" class="price-img">
  25. </image>
  26. <image v-if="userInfo.role == 2" :src="configList.vip_money_two" mode="aspectFill" class="price-img">
  27. </image>
  28. <image v-if="userInfo.role == 3" :src="configList.vip_money_three" mode="aspectFill"
  29. class="price-img"></image>
  30. </view>
  31. </view> -->
  32. <!-- 价格区 -->
  33. <!-- <view class="price-section">
  34. <view class="price">
  35. <view class="money">
  36. <text>{{ item.price }}</text>
  37. <text class="unit">/元每件</text>
  38. </view>
  39. <view class="oldPrice">
  40. <text>{{ item.oldPrice }}</text>
  41. <text class="unit">/</text>
  42. </view>
  43. </view>
  44. <view class="oldPrice">
  45. <view class="money">
  46. <text>{{ item.oldPrice }}</text>
  47. <text class="unit">/元每件</text>
  48. </view>
  49. <view class="price-imgs">
  50. </view>
  51. </view>
  52. <view class="member-price">
  53. <view class="price">
  54. <view class="money">
  55. <text>{{ item.silverPrice }}</text>
  56. <text class="unit">/元每件</text>
  57. </view>
  58. <view class="price-imgs">
  59. <image :src="configList.vip_money_one" mode="aspectFill" class="price-img">
  60. </image>
  61. </view>
  62. </view>
  63. <view class="price">
  64. <view class="money">
  65. <text>{{ item.goldPrice }}</text>
  66. <text class="unit">/元每件</text>
  67. </view>
  68. <view class="price-imgs">
  69. <image :src="configList.vip_money_two" mode="aspectFill"
  70. class="price-img"></image>
  71. </view>
  72. </view>
  73. <view class="price">
  74. <view class="money">
  75. <text>{{ item.diamondPrice }}</text>
  76. <text class="unit">/元每件</text>
  77. </view>
  78. <view class="price-imgs">
  79. <image :src="configList.vip_money_three" mode="aspectFill" class="price-img">
  80. </image>
  81. </view>
  82. </view>
  83. </view>
  84. </view> -->
  85. <!-- 销量 -->
  86. <view class="sales-volume">
  87. <view class="sales-volume-imgbox">
  88. <image src="@/static/image/category/sales-volume-icon.png" mode="widthFix" class="sales-volume-img">
  89. </image>
  90. </view>
  91. <view class="sales-volume-number">
  92. 已售出{{ item.sales }}
  93. </view>
  94. </view>
  95. <!-- 价格 -->
  96. <view :style="{ color: '#FF2A2A'}">
  97. <text style="font-size: 18rpx;"></text><text style="font-size: 30rpx;">{{ item.price }}</text>
  98. </view>
  99. <!-- 购买按钮 -->
  100. <view class="" style="display: flex;justify-content: space-between;">
  101. <view @click.stop="purchase(item.id)" class="buy-btn buy-order">
  102. 立即下单
  103. </view>
  104. <view @click.stop="addCart(item)" class="buy-btn">
  105. <uv-badge type="error" max="9" :value="1" absolute :offset="[-10, 1]" bg-color="#FF2A2A"></uv-badge>
  106. 加购物车
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. import {
  114. mapState
  115. } from 'vuex'
  116. export default {
  117. props: {
  118. item: {
  119. default: {}
  120. }
  121. },
  122. computed: {
  123. ...mapState(['userInfo'])
  124. },
  125. data() {
  126. return {
  127. }
  128. },
  129. mounted() {
  130. console.log('商品项数据:', this.item);
  131. },
  132. methods: {
  133. // 购买商品(创建订单)
  134. purchase(id) {
  135. this.$api('getRiceProductDetail', {
  136. id
  137. }, res => {
  138. if (res.code == 200) {
  139. res.result.num = 1
  140. this.$store.commit('setPayOrderProduct', [
  141. res.result
  142. ])
  143. this.$utils.navigateTo('/pages_order/order/createOrder')
  144. }
  145. })
  146. },
  147. // 加入购物车
  148. addCart(item){
  149. uni.showLoading({
  150. title: '加载中...'
  151. })
  152. this.$api('addShopcar', {
  153. goodsId : item.id,
  154. num : 1,
  155. }, res => {
  156. uni.hideLoading()
  157. if(res.code == 200){
  158. uni.showToast({
  159. title: '加入购物车成功',
  160. icon: 'none',
  161. duration: 1000
  162. })
  163. }
  164. })
  165. },
  166. //根据角色获取对应价格
  167. getPriceByRole(item) {
  168. let priceFiledList = ['goldPrice','silverPrice','diamondPrice']
  169. let price = item[priceFiledList[this.userInfo.role - 1]]
  170. return price >= 0 ? price : item.price
  171. }
  172. },
  173. onload() {
  174. console.log(props.item);
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .item {
  180. width: 92%;
  181. margin: 20rpx auto;
  182. padding: 20rpx 10rpx;
  183. align-items: center;
  184. display: flex;
  185. box-sizing: border-box;
  186. border-bottom: 1rpx solid #00000012;
  187. background: white;
  188. border-radius: 10rpx;
  189. // margin-bottom: 20rpx;
  190. // box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
  191. // 商品图片
  192. .item-image {
  193. width: 200rpx;
  194. height: 200rpx;
  195. overflow: hidden;
  196. image {
  197. height: 100%;
  198. width: 100%;
  199. }
  200. }
  201. // 商品信息
  202. .info {
  203. // height: 220rpx;
  204. padding: 15rpx 0rpx 15rpx 15rpx;
  205. color: #555;
  206. width: calc(100% - 200rpx);
  207. box-sizing: border-box;
  208. overflow: hidden;
  209. display: flex;
  210. flex-direction: column;
  211. gap: 4rpx;
  212. // 商品标题
  213. .title {
  214. font-size: 30rpx;
  215. font-weight: bold;
  216. overflow: hidden; //超出的文本隐藏
  217. text-overflow: ellipsis; //溢出用省略号显示
  218. white-space: nowrap; //溢出不换行
  219. color: #333;
  220. margin-bottom: 5rpx;
  221. }
  222. .price-section {
  223. display: flex;
  224. flex-direction: column;
  225. gap: 6rpx;
  226. }
  227. // 价格
  228. .price {
  229. display: flex;
  230. align-items: center;
  231. color: #f40;
  232. font-size: 24rpx;
  233. align-items: flex-end;
  234. .money {
  235. font-size: 30rpx;
  236. font-weight: 600;
  237. .unit {
  238. font-size: 18rpx;
  239. font-weight: normal;
  240. margin-left: 2rpx;
  241. }
  242. }
  243. .price-imgs {
  244. display: flex;
  245. flex-wrap: wrap;
  246. align-items: center;
  247. .price-img {
  248. width: 70rpx;
  249. height: 26rpx;
  250. margin-left: 8rpx;
  251. }
  252. }
  253. }
  254. .oldPrice{
  255. color: #999;
  256. font-size: 20rpx;
  257. text-decoration: line-through;
  258. margin-left: 8rpx;
  259. }
  260. .member-price {
  261. display: flex;
  262. flex-direction: column;
  263. gap: 4rpx;
  264. margin-top: 4rpx;
  265. padding-top: 6rpx;
  266. border-top: 1rpx dashed #eee;
  267. .money {
  268. font-size: 26rpx;
  269. .unit {
  270. font-size: 18rpx;
  271. }
  272. }
  273. .price-imgs {
  274. display: flex;
  275. flex-wrap: wrap;
  276. .price-img {
  277. width: 70rpx;
  278. height: 26rpx;
  279. margin-left: 8rpx;
  280. }
  281. }
  282. }
  283. // 销量
  284. .sales-volume {
  285. display: flex;
  286. align-items: center;
  287. flex-wrap: wrap;
  288. margin-top: 2rpx;
  289. .sales-volume-imgbox {
  290. width: 18rpx;
  291. .sales-volume-img {
  292. width: 100%;
  293. }
  294. }
  295. .sales-volume-number {
  296. color: #999;
  297. font-size: 24rpx;
  298. padding-left: 8rpx;
  299. }
  300. }
  301. // 购买按钮
  302. .buy-btn {
  303. background: $uni-color;
  304. color: white;
  305. display: inline-block;
  306. padding: 10rpx 24rpx;
  307. border-radius: 10rpx;
  308. width: fit-content;
  309. font-size: 23rpx;
  310. font-weight: 500;
  311. box-shadow: 0 2rpx 6rpx rgba(255,68,0,0.2);
  312. transition: all 0.3s;
  313. margin-top: 4rpx;
  314. position: relative;
  315. }
  316. .buy-order{
  317. background: inherit;
  318. border: 3rpx solid $uni-color;
  319. color: $uni-color;
  320. }
  321. }
  322. }
  323. </style>