listSen.vue 7.6 KB

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