listOne.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="container">
  3. <view class="top-img"><image :src="img" mode='widthFix'></image></view>
  4. <view class="preferred_centent">
  5. <view class="flex_item preferred_item" v-for="ls in list" @click="navToDetailPage(ls)">
  6. <view class="tlist-img">
  7. <view class="goods_image"><image :src="ls.image"></image></view>
  8. <view class="stock flex_item" v-if="ls.stock > 0">
  9. <image class="img" src="/static/img/img56.png" mode="scaleToFill"></image>
  10. <view class="stock-num clamp">库存剩{{ ls.percent * 100 }}%</view>
  11. </view>
  12. </view>
  13. <view class="goods_name">
  14. <view class="goods_title clamp">{{ ls.store_name }}</view>
  15. <view class="guess-list">
  16. <view class="goods_num clamp">{{ ls.store_info }}</view>
  17. <view class="tipBox">
  18. <view class="tipsl" v-if="ls.keyword != ''">
  19. <text v-for="lss in ls.keyword">{{ lss }}</text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="price flex">
  24. <view class="price_list">
  25. <view class="price-red">
  26. ¥{{ ls.price }}<text>/份</text>
  27. <text class="tip">¥{{ ls.ot_price }}</text>
  28. </view>
  29. </view>
  30. <view class="img position-relative" @click.stop="Addcar(ls)">
  31. <image src="/static/img/img21.png"></image>
  32. <view class="corner" v-if="ls.cart_num > 0">
  33. <text>{{ ls.cart_num }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { getProducts } from '@/api/product.js';
  44. import { category_layer } from '@/api/category.js';
  45. import { cartAdd } from '@/api/product.js';
  46. import { saveUrl } from '@/utils/loginUtils.js';
  47. export default {
  48. data() {
  49. return {
  50. list: '',//三级分类商品
  51. cid:'',//二级分类id
  52. img:'',//二级封面图
  53. };
  54. },
  55. onLoad(option) {
  56. this.cid = option.type;
  57. // 判断有无邀请人
  58. if (option.spread) {
  59. uni.setStorageSync('spread', option.spread);
  60. }
  61. saveUrl();
  62. this.GetDate();
  63. },
  64. onshow(){
  65. this.loadData();
  66. },
  67. //下拉刷新
  68. onPullDownRefresh() {
  69. let obj = this;
  70. //监听下拉刷新动作的执行方法,每次手动下拉刷新都会执行一次
  71. setTimeout(function() {
  72. obj.loadData();
  73. uni.stopPullDownRefresh(); //停止下拉刷新动画
  74. }, 1000);
  75. },
  76. methods: {
  77. // 载入二级分类数据
  78. async GetDate() {
  79. let obj = this;
  80. obj.loading = true;
  81. category_layer({
  82. pid: 102
  83. })
  84. .then(({ data }) => {
  85. for (let i = 0; i < data.list.length; i++) {
  86. if(obj.cid == data.list[i].id){
  87. obj.img = data.list[i].pic;
  88. }
  89. }
  90. this.loadData();
  91. })
  92. .catch(err => {
  93. console.log(err);
  94. });
  95. },
  96. // 请求商品列表
  97. loadData() {
  98. let obj = this;
  99. getProducts({
  100. sid:obj.cid,
  101. type:1
  102. })
  103. .then(({ data }) => {
  104. this.list = data;
  105. })
  106. .catch(e => {});
  107. },
  108. //分享
  109. // #ifdef MP
  110. onShareAppMessage: function(res) {
  111. let userInfo = uni.getStorageSync('userInfo');
  112. let GetInfo = uni.getStorageSync('GetInfo');
  113. // 来自页面内分享按钮
  114. let pages = getCurrentPages();
  115. // 获取当前页面
  116. let page = pages[pages.length - 1];
  117. let path = '/pages/activity/listOne?type=103&';
  118. // 保存邀请人
  119. path += 'spread=' + userInfo.uid;
  120. let data = {
  121. path: path,
  122. imageUrl: GetInfo.img,
  123. title: GetInfo.title
  124. };
  125. console.log(data)
  126. return data;
  127. },
  128. // #endif
  129. //加入购物车
  130. Addcar(item) {
  131. let obj = this;
  132. cartAdd({
  133. cartNum: '1', //商品数量
  134. uniqueId: '', //商品标签
  135. new: 0, //商品是否新增加到购物车1为不加入0为加入
  136. mer_id: '',
  137. productId: item.id //商品编号
  138. })
  139. .then(function(e) {
  140. uni.showToast({
  141. title: '成功加入购物车',
  142. type: 'top',
  143. duration: 500,
  144. icon: 'none'
  145. });
  146. obj.loadData();
  147. })
  148. .catch(e => {
  149. console.log(e);
  150. });
  151. },
  152. //跳转商品详情页
  153. navToDetailPage(ls) {
  154. let id = ls.id;
  155. uni.navigateTo({
  156. url: '/pages/product/product?id=' + id
  157. });
  158. }
  159. }
  160. };
  161. </script>
  162. <style lang="scss">
  163. page {
  164. min-height: 100%;
  165. background-color: #FFFFFF;
  166. width: 100%;
  167. }
  168. .container {
  169. background: #ffffff;
  170. // height: 100%;
  171. }
  172. image{
  173. width: 100%;
  174. height: auto;
  175. /* min-height: 2900px; */
  176. }
  177. .top-img {
  178. width: 100%;
  179. image{
  180. width: 100%;
  181. height: auto;
  182. /* min-height: 2900px; */
  183. }
  184. }
  185. .preferred_centent {
  186. width: 100%;
  187. padding: 0rpx 25rpx;
  188. .preferred_item {
  189. width: 100%;
  190. height: 100%;
  191. border-top: 1px solid #f0f0f0;
  192. padding: 25rpx 0rpx;
  193. position: relative;
  194. .tlist-img {
  195. width:180rpx;
  196. height:200rpx ;
  197. position: relative;
  198. .goods_image {
  199. width: 180rpx;
  200. height: 180rpx;
  201. image {
  202. width: 180rpx;
  203. height: 180rpx;
  204. }
  205. }
  206. .stock {
  207. margin-top: 13rpx;
  208. font-size: 26rpx;
  209. background:linear-gradient(90deg,rgba(255,3,95,1),rgba(255,153,14,1));
  210. width: 100%;
  211. color: #FFFFFF;
  212. border-radius: 10rpx;
  213. justify-content: center;
  214. align-items: center;
  215. position: absolute;
  216. left: 0;
  217. bottom: 0;
  218. .img {
  219. width: 20rpx;
  220. height: 20rpx;
  221. flex-shrink: 0;
  222. }
  223. .stock-num {
  224. padding-left: 7rpx;
  225. font-size: 22rpx;
  226. border-radius: 5rpx;
  227. height: 26rpx;
  228. line-height: 26rpx;
  229. }
  230. }
  231. }
  232. .goods_name {
  233. padding-left: 25rpx;
  234. width: 65%;
  235. padding-right: 30rpx;
  236. .goods_title {
  237. white-space: nowrap;
  238. overflow: hidden;
  239. text-overflow: ellipsis;
  240. font-size: 32rpx;
  241. color: $font-color-dark;
  242. }
  243. .guess-list{
  244. height: 70rpx;
  245. .goods_num {
  246. font-size: 24rpx;
  247. color: #8f8f97;
  248. }
  249. .tipBox{
  250. // padding-bottom: 8rpx;
  251. .tipsl {
  252. text {
  253. border: 2rpx solid #ff1a27;
  254. color: #ff1a27;
  255. border-radius: 5rpx;
  256. font-size: 18rpx;
  257. padding: 2rpx 5rpx;
  258. margin-right: 15rpx;
  259. }
  260. }
  261. }
  262. }
  263. .price {
  264. font-size: 28rpx;
  265. padding-top: 40rpx;
  266. .price_list {
  267. .price-red {
  268. color: #ff1a27;
  269. font-weight: bold;
  270. font-size: 34rpx !important;
  271. text {
  272. color: #9699a0;
  273. font-size: 24rpx !important;
  274. font-weight: normal;
  275. padding: 0rpx 10rpx;
  276. }
  277. .tip{
  278. text-decoration: line-through;
  279. }
  280. }
  281. .price-green {
  282. color: #2dbd59;
  283. font-size: 28rpx !important;
  284. text {
  285. background: #2dbd59;
  286. color: #ffffff;
  287. padding: 0rpx 10rpx;
  288. border-radius: 5rpx;
  289. font-size: 22rpx !important;
  290. margin-left: 15rpx;
  291. }
  292. }
  293. }
  294. .img {
  295. width: 50rpx;
  296. height: 50rpx;
  297. image {
  298. width: 100%;
  299. height: 100%;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. </style>