index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='productList'>
  4. <view class='search bg-color acea-row row-between-wrapper'>
  5. <view class='input acea-row row-between-wrapper'><text class='iconfont icon-sousuo'></text>
  6. <input :placeholder='$t(`搜索商品名称`)' placeholder-class='placeholder' confirm-type='search' name="search"
  7. :value='where.keyword' @confirm="searchSubmit"></input>
  8. </view>
  9. <view class='iconfont' :class='is_switch==true?"icon-pailie":"icon-tupianpailie"' @click='Changswitch'>
  10. </view>
  11. </view>
  12. <view class='nav acea-row row-middle'>
  13. <view class='item line1' :class='title ? "font-num":""' @click='set_where(1)'>{{title ? $t(title) : $t(`默认`)}}
  14. </view>
  15. <view class='item' @click='set_where(2)'>
  16. {{$t(`价格`)}}
  17. <image v-if="price==1" src='../../../static/images/up.png'></image>
  18. <image v-else-if="price==2" src='../../../static/images/down.png'></image>
  19. <image v-else src='../../../static/images/horn.png'></image>
  20. </view>
  21. <view class='item' @click='set_where(3)'>
  22. {{$t(`销量`)}}
  23. <image v-if="stock==1" src='../../../static/images/up.png'></image>
  24. <image v-else-if="stock==2" src='../../../static/images/down.png'></image>
  25. <image v-else src='../../../static/images/horn.png'></image>
  26. </view>
  27. <!-- down -->
  28. <view class='item' :class='nows ? "font-color":""' @click='set_where(4)'>{{$t(`新品`)}}</view>
  29. </view>
  30. <view class='list acea-row row-between-wrapper' :class='is_switch==true?"":"on"'>
  31. <view class='item' :class='is_switch==true?"":"on"' hover-class='none'
  32. v-for="(item,index) in productList" :key="index" @click="godDetail(item)">
  33. <view class='pictrue' :class='is_switch==true?"":"on"'>
  34. <image :src='item.image' :class='is_switch==true?"":"on"'></image>
  35. <span class="pictrue_log_class" :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  36. v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
  37. <span class="pictrue_log_class" :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  38. v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
  39. <span class="pictrue_log_class" :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  40. v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
  41. </view>
  42. <view class='text' :class='is_switch==true?"":"on"'>
  43. <view class='name line1'>{{item.store_name}}</view>
  44. <view class='money font-color' :class='is_switch==true?"":"on"'>{{$t(`¥`)}}<text
  45. class='num'>{{item.price}}</text></view>
  46. <view class='vip acea-row row-between-wrapper' :class='is_switch==true?"":"on"'>
  47. <view class='vip-money' v-if="item.vip_price && item.vip_price > 0">{{$t(`¥`)}}{{item.vip_price}}
  48. <image src='../../../static/images/vip.png'></image>
  49. </view>
  50. <view>{{$t(`已售`)}} {{item.sales}}{{$t(item.unit_name) || $t(`件`)}}</view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class='loadingicon acea-row row-center-wrapper' v-if='productList.length > 0'>
  55. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  56. </view>
  57. </view>
  58. </view>
  59. <view class='noCommodity' v-if="productList.length==0 && where.page > 1">
  60. <view class='emptyBox'>
  61. <image :src="imgHost + '/statics/images/no-thing.png'"></image>
  62. </view>
  63. <recommend :hostProduct="hostProduct"></recommend>
  64. </view>
  65. <!-- #ifndef MP -->
  66. <home></home>
  67. <!-- #endif -->
  68. </view>
  69. </template>
  70. <script>
  71. import home from '@/components/home';
  72. import {
  73. getProductslist,
  74. getProductHot
  75. } from '@/api/store.js';
  76. import recommend from '@/components/recommend';
  77. import {
  78. mapGetters
  79. } from "vuex";
  80. import {
  81. goShopDetail
  82. } from '@/libs/order.js'
  83. import {HTTP_REQUEST_URL} from '@/config/app';
  84. import colors from '@/mixins/color.js';
  85. export default {
  86. computed: mapGetters(['uid']),
  87. components: {
  88. recommend,
  89. home
  90. },
  91. mixins:[colors],
  92. data() {
  93. return {
  94. imgHost:HTTP_REQUEST_URL,
  95. productList: [],
  96. is_switch: true,
  97. where: {
  98. sid: 0,
  99. keyword: '',
  100. priceOrder: '',
  101. salesOrder: '',
  102. news: 0,
  103. page: 1,
  104. limit: 20,
  105. cid: 0,
  106. },
  107. price: 0,
  108. stock: 0,
  109. nows: false,
  110. loadend: false,
  111. loading: false,
  112. loadTitle: this.$t(`加载更多`),
  113. title: '',
  114. hostProduct: [],
  115. hotPage: 1,
  116. hotLimit: 10,
  117. hotScroll: false
  118. };
  119. },
  120. onLoad: function(options) {
  121. this.where.cid = options.cid || 0;
  122. this.$set(this.where, 'sid', options.sid || 0);
  123. this.title = options.title || '';
  124. this.$set(this.where, 'keyword', options.searchValue || '');
  125. this.$set(this.where, 'productId', options.productId || '');
  126. this.get_product_list();
  127. },
  128. methods: {
  129. // 去详情页
  130. godDetail(item) {
  131. goShopDetail(item, this.uid).then(res => {
  132. uni.navigateTo({
  133. url: `/pages/goods_details/index?id=${item.id}`
  134. })
  135. })
  136. },
  137. Changswitch: function() {
  138. let that = this;
  139. that.is_switch = !that.is_switch
  140. },
  141. searchSubmit: function(e) {
  142. let that = this;
  143. that.$set(that.where, 'keyword', e.detail.value);
  144. that.loadend = false;
  145. that.$set(that.where, 'page', 1)
  146. this.get_product_list(true);
  147. },
  148. /**
  149. * 获取我的推荐
  150. */
  151. get_host_product: function() {
  152. let that = this;
  153. if (that.hotScroll) return
  154. getProductHot(
  155. that.hotPage,
  156. that.hotLimit,
  157. ).then(res => {
  158. that.hotPage++
  159. that.hotScroll = res.data.length < that.hotLimit
  160. that.hostProduct = that.hostProduct.concat(res.data)
  161. // that.$set(that, 'hostProduct', res.data)
  162. });
  163. },
  164. //点击事件处理
  165. set_where: function(e) {
  166. switch (e) {
  167. case 1:
  168. // #ifdef H5
  169. return history.back();
  170. // #endif
  171. // #ifndef H5
  172. return uni.navigateBack({
  173. delta: 1,
  174. })
  175. // #endif
  176. break;
  177. case 2:
  178. if (this.price == 0) this.price = 1;
  179. else if (this.price == 1) this.price = 2;
  180. else if (this.price == 2) this.price = 0;
  181. this.stock = 0;
  182. break;
  183. case 3:
  184. if (this.stock == 0) this.stock = 1;
  185. else if (this.stock == 1) this.stock = 2;
  186. else if (this.stock == 2) this.stock = 0;
  187. this.price = 0
  188. break;
  189. case 4:
  190. this.nows = !this.nows;
  191. break;
  192. }
  193. this.loadend = false;
  194. this.$set(this.where, 'page', 1);
  195. this.get_product_list(true);
  196. },
  197. //设置where条件
  198. setWhere: function() {
  199. if (this.price == 0) this.where.priceOrder = '';
  200. else if (this.price == 1) this.where.priceOrder = 'asc';
  201. else if (this.price == 2) this.where.priceOrder = 'desc';
  202. if (this.stock == 0) this.where.salesOrder = '';
  203. else if (this.stock == 1) this.where.salesOrder = 'asc';
  204. else if (this.stock == 2) this.where.salesOrder = 'desc';
  205. this.where.news = this.nows ? 1 : 0;
  206. },
  207. //查找产品
  208. get_product_list: function(isPage) {
  209. let that = this;
  210. that.setWhere();
  211. if (that.loadend) return;
  212. if (that.loading) return;
  213. if (isPage === true) that.$set(that, 'productList', []);
  214. that.loading = true;
  215. that.loadTitle = '';
  216. uni.request({
  217. url:'api/mock/Productslist',
  218. success:res=>{
  219. let list = res.data;
  220. let productList = that.$util.SplitArray(list, that.productList);
  221. let loadend = list.length < that.where.limit;
  222. that.loadend = loadend;
  223. that.loading = false;
  224. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  225. that.$set(that, 'productList', productList);
  226. that.$set(that.where, 'page', that.where.page + 1);
  227. if (!that.productList.length) this.get_host_product();
  228. }
  229. })
  230. // getProductslist(that.where).then(res => {
  231. // let list = res.data;
  232. // let productList = that.$util.SplitArray(list, that.productList);
  233. // let loadend = list.length < that.where.limit;
  234. // that.loadend = loadend;
  235. // that.loading = false;
  236. // that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  237. // that.$set(that, 'productList', productList);
  238. // that.$set(that.where, 'page', that.where.page + 1);
  239. // if (!that.productList.length) this.get_host_product();
  240. // }).catch(err => {
  241. // that.loading = false;
  242. // that.loadTitle = that.$t(`加载更多`);
  243. // });
  244. },
  245. },
  246. onPullDownRefresh() {
  247. },
  248. onReachBottom() {
  249. if (this.productList.length > 0) {
  250. this.get_product_list();
  251. } else {
  252. this.get_host_product();
  253. }
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. .productList .search {
  259. width: 100%;
  260. height: 86rpx;
  261. padding-left: 23rpx;
  262. box-sizing: border-box;
  263. position: fixed;
  264. left: 0;
  265. top: 0;
  266. z-index: 9;
  267. }
  268. .productList .search .input {
  269. width: 640rpx;
  270. height: 60rpx;
  271. background-color: #fff;
  272. border-radius: 50rpx;
  273. padding: 0 20rpx;
  274. box-sizing: border-box;
  275. }
  276. .productList .search .input input {
  277. width: 548rpx;
  278. height: 100%;
  279. font-size: 26rpx;
  280. }
  281. .productList .search .input .placeholder {
  282. color: #999;
  283. }
  284. .productList .search .input .iconfont {
  285. font-size: 35rpx;
  286. color: #555;
  287. }
  288. .productList .search .icon-pailie,
  289. .productList .search .icon-tupianpailie {
  290. color: #fff;
  291. width: 62rpx;
  292. font-size: 40rpx;
  293. height: 86rpx;
  294. line-height: 86rpx;
  295. }
  296. .productList .nav {
  297. height: 86rpx;
  298. color: #454545;
  299. position: fixed;
  300. left: 0;
  301. width: 100%;
  302. font-size: 28rpx;
  303. background-color: #fff;
  304. margin-top: 86rpx;
  305. top: 0;
  306. z-index: 9;
  307. }
  308. .productList .nav .item {
  309. width: 25%;
  310. text-align: center;
  311. }
  312. .productList .nav .item.font-color {
  313. font-weight: bold;
  314. }
  315. .productList .nav .item image {
  316. width: 15rpx;
  317. height: 19rpx;
  318. margin-left: 10rpx;
  319. }
  320. .productList .list {
  321. padding: 0 20rpx;
  322. margin-top: 172rpx;
  323. }
  324. .productList .list.on {
  325. background-color: #fff;
  326. border-top: 1px solid #f6f6f6;
  327. }
  328. .productList .list .item {
  329. width: 345rpx;
  330. margin-top: 20rpx;
  331. background-color: #fff;
  332. border-radius: 20rpx;
  333. }
  334. .productList .list .item.on {
  335. width: 100%;
  336. display: flex;
  337. border-bottom: 1rpx solid #f6f6f6;
  338. padding: 30rpx 0;
  339. margin: 0;
  340. }
  341. .productList .list .item .pictrue {
  342. position: relative;
  343. width: 100%;
  344. height: 345rpx;
  345. }
  346. .productList .list .item .pictrue.on {
  347. width: 180rpx;
  348. height: 180rpx;
  349. }
  350. .productList .list .item .pictrue image {
  351. width: 100%;
  352. height: 100%;
  353. border-radius: 20rpx 20rpx 0 0;
  354. }
  355. .productList .list .item .pictrue image.on {
  356. border-radius: 6rpx;
  357. }
  358. .productList .list .item .text {
  359. padding: 20rpx 17rpx 26rpx 17rpx;
  360. font-size: 30rpx;
  361. color: #222;
  362. }
  363. .productList .list .item .text.on {
  364. width: 508rpx;
  365. padding: 0 0 0 22rpx;
  366. }
  367. .productList .list .item .text .money {
  368. font-size: 26rpx;
  369. font-weight: bold;
  370. margin-top: 8rpx;
  371. }
  372. .productList .list .item .text .money.on {
  373. margin-top: 50rpx;
  374. }
  375. .productList .list .item .text .money .num {
  376. font-size: 34rpx;
  377. }
  378. .productList .list .item .text .vip {
  379. font-size: 22rpx;
  380. color: #aaa;
  381. margin-top: 7rpx;
  382. }
  383. .productList .list .item .text .vip.on {
  384. margin-top: 12rpx;
  385. }
  386. .productList .list .item .text .vip .vip-money {
  387. font-size: 24rpx;
  388. color: #282828;
  389. font-weight: bold;
  390. }
  391. .productList .list .item .text .vip .vip-money image {
  392. width: 46rpx;
  393. height: 21rpx;
  394. margin-left: 4rpx;
  395. }
  396. .noCommodity {
  397. background-color: #fff;
  398. padding-bottom: 30rpx;
  399. .emptyBox{
  400. text-align: center;
  401. padding-top: 20rpx;
  402. .tips{
  403. color: #aaa;
  404. font-size: 26rpx;
  405. }
  406. image {
  407. width: 414rpx;
  408. height: 304rpx;
  409. }
  410. }
  411. }
  412. </style>