index.vue 12 KB

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