GoodsList.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class="productList" ref="container">
  3. <form @submit.prevent="submitForm">
  4. <div class="search bg-color-red acea-row row-between-wrapper">
  5. <div
  6. class="iconfont icon-xiangzuo"
  7. style="color: #ffffff; font-size: 20px; padding-right: 10px; padding-left: 5px;"
  8. @click="returns"
  9. ></div>
  10. <div class="input acea-row row-between-wrapper">
  11. <span class="iconfont icon-sousuo"></span>
  12. <input placeholder="搜索商品信息" v-model="where.keyword" />
  13. </div>
  14. <div
  15. class="iconfont"
  16. :class="Switch === true ? 'icon-pailie' : 'icon-tupianpailie'"
  17. @click="switchTap"
  18. ></div>
  19. </div>
  20. </form>
  21. <div class="nav acea-row row-middle">
  22. <div
  23. class="item"
  24. :class="title ? 'font-color-red' : ''"
  25. @click="set_where(0)"
  26. >
  27. {{ title ? title : "默认" }}
  28. </div>
  29. <div class="item" @click="set_where(1)">
  30. 价格
  31. <img src="@assets/images/horn.png" v-if="price === 0" />
  32. <img src="@assets/images/up.png" v-if="price === 1" />
  33. <img src="@assets/images/down.png" v-if="price === 2" />
  34. </div>
  35. <div class="item" @click="set_where(2)">
  36. 销量
  37. <img src="@assets/images/horn.png" v-if="stock === 0" />
  38. <img src="@assets/images/up.png" v-if="stock === 1" />
  39. <img src="@assets/images/down.png" v-if="stock === 2" />
  40. </div>
  41. <!-- down -->
  42. <div
  43. class="item"
  44. :class="nows ? 'font-color-red' : ''"
  45. @click="set_where(3)"
  46. >
  47. 新品
  48. </div>
  49. </div>
  50. <div
  51. class="list acea-row row-between-wrapper"
  52. :class="Switch === true ? '' : 'on'"
  53. ref="container"
  54. >
  55. <div
  56. @click="goDetail(item)"
  57. class="item"
  58. :class="Switch === true ? '' : 'on'"
  59. v-for="(item, index) in productList"
  60. :key="index"
  61. :title="item.store_name"
  62. >
  63. <div class="pictrue" :class="Switch === true ? '' : 'on'">
  64. <img :src="item.image" :class="Switch === true ? '' : 'on'" />
  65. <span
  66. class="pictrue_log_class"
  67. :class="Switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  68. v-if="item.activity && item.activity.type === '1'"
  69. >秒杀</span
  70. >
  71. <span
  72. class="pictrue_log_class"
  73. :class="Switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  74. v-if="item.activity && item.activity.type === '2'"
  75. >砍价</span
  76. >
  77. <span
  78. class="pictrue_log_class"
  79. :class="Switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  80. v-if="item.activity && item.activity.type === '3'"
  81. >拼团</span
  82. >
  83. </div>
  84. <div class="text" :class="Switch === true ? '' : 'on'">
  85. <div class="name line1">{{ item.store_name }}</div>
  86. <div
  87. class="money font-color-red"
  88. :class="Switch === true ? '' : 'on'"
  89. >
  90. ¥<span class="num">{{ isVip ? item.vip_price : item.price }}</span>
  91. </div>
  92. <div
  93. class="vip acea-row row-between-wrapper"
  94. :class="Switch === true ? '' : 'on'"
  95. >
  96. <div class="vip-money" v-if="item.vip_price && item.vip_price > 0">
  97. ¥{{ item.vip_price }}<img src="@assets/images/vip.png" />
  98. </div>
  99. <div>已售{{ item.sales }}件</div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. <Loading :loaded="loadend" :loading="loading"></Loading>
  105. <div
  106. class="noCommodity"
  107. v-cloak
  108. style="background-color: #fff;"
  109. v-if="productList.length === 0 && where.page > 1"
  110. >
  111. <div class="noPictrue">
  112. <img src="@assets/images/noGood.png" class="image" />
  113. </div>
  114. </div>
  115. <Recommend v-if="productList.length === 0 && where.page > 1"></Recommend>
  116. </div>
  117. </template>
  118. <script>
  119. import { getUserInfo } from "@api/user";
  120. import Recommend from "@components/Recommend";
  121. import { getProducts } from "@api/store";
  122. import debounce from "lodash.debounce";
  123. import Loading from "@components/Loading";
  124. import { goShopDetail } from "@libs/order";
  125. export default {
  126. name: "GoodsList",
  127. components: {
  128. Recommend,
  129. Loading
  130. },
  131. props: {},
  132. data: function() {
  133. const { s = "", id = 0, title = "" } = this.$route.query;
  134. return {
  135. hostProduct: [],
  136. productList: [],
  137. Switch: true,
  138. where: {
  139. page: 1,
  140. limit: 8,
  141. keyword: s,
  142. sid: id, //二级分类id
  143. news: 0,
  144. priceOrder: "",
  145. salesOrder: ""
  146. },
  147. title: title && id ? title : "",
  148. loadTitle: "",
  149. loading: false,
  150. loadend: false,
  151. price: 0,
  152. stock: 0,
  153. nows: false,
  154. isVip: false
  155. };
  156. },
  157. watch: {
  158. title() {
  159. this.updateTitle();
  160. },
  161. $route(to) {
  162. if (to.name !== "GoodsList") return;
  163. const { s = "", id = 0, title = "" } = to.query;
  164. if (s !== this.where.keyword || id !== this.where.sid) {
  165. this.where.keyword = s;
  166. this.loadend = false;
  167. this.loading = false;
  168. this.where.page = 1;
  169. this.where.sid = id;
  170. this.title = title && id ? title : "";
  171. this.nows = false;
  172. this.$set(this, "productList", []);
  173. this.price = 0;
  174. this.stock = 0;
  175. this.get_product_list();
  176. }
  177. this.updateVIP();
  178. }
  179. },
  180. mounted: function() {
  181. this.updateVIP();
  182. this.updateTitle();
  183. this.get_product_list();
  184. this.$scroll(this.$refs.container, () => {
  185. !this.loading && this.get_product_list();
  186. });
  187. },
  188. methods: {
  189. updateVIP() {
  190. var userinfo = this.$store.state.app.userInfo;
  191. if (this.$store.state.app.token) {
  192. getUserInfo().then(res => {
  193. userinfo = res.data;
  194. this.isVip = userinfo.vip_level > 0;
  195. console.log("Current VIP:", userinfo.vip_level);
  196. });
  197. return;
  198. }
  199. this.isVip = false;
  200. console.log("Current is not Login");
  201. },
  202. // 商品详情跳转
  203. goDetail(item) {
  204. goShopDetail(item).then(() => {
  205. this.$router.push({ path: "/detail/" + item.id });
  206. });
  207. },
  208. updateTitle() {
  209. document.title = this.title || this.$route.meta.title;
  210. },
  211. get_product_list: debounce(function() {
  212. var that = this;
  213. if (that.loading) return; //阻止下次请求(false可以进行请求);
  214. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  215. that.loading = true;
  216. this.setWhere();
  217. let q = that.where;
  218. getProducts(q).then(res => {
  219. that.loading = false;
  220. that.productList.push.apply(that.productList, res.data);
  221. that.loadend = res.data.length < that.where.limit; //判断所有数据是否加载完成;
  222. that.where.page = that.where.page + 1;
  223. });
  224. }, 300),
  225. submitForm: function() {
  226. this.$set(this, "productList", []);
  227. this.where.page = 1;
  228. this.loadend = false;
  229. this.loading = false;
  230. this.get_product_list();
  231. },
  232. //点击事件处理
  233. set_where: function(index) {
  234. let that = this;
  235. switch (index) {
  236. case 0:
  237. return;
  238. // return that.$router.back();
  239. case 1:
  240. if (that.price === 0) that.price = 1;
  241. else if (that.price === 1) that.price = 2;
  242. else if (that.price === 2) that.price = 0;
  243. that.stock = 0;
  244. break;
  245. case 2:
  246. if (that.stock === 0) that.stock = 1;
  247. else if (that.stock === 1) that.stock = 2;
  248. else if (that.stock === 2) that.stock = 0;
  249. that.price = 0;
  250. break;
  251. case 3:
  252. that.nows = !that.nows;
  253. break;
  254. default:
  255. break;
  256. }
  257. that.$set(that, "productList", []);
  258. that.where.page = 1;
  259. that.loadend = false;
  260. that.get_product_list();
  261. },
  262. //设置where条件
  263. setWhere: function() {
  264. let that = this;
  265. if (that.price === 0) {
  266. that.where.priceOrder = "";
  267. } else if (that.price === 1) {
  268. that.where.priceOrder = "asc";
  269. } else if (that.price === 2) {
  270. that.where.priceOrder = "desc";
  271. }
  272. if (that.stock === 0) {
  273. that.where.salesOrder = "";
  274. } else if (that.stock === 1) {
  275. that.where.salesOrder = "asc";
  276. } else if (that.stock === 2) {
  277. that.where.salesOrder = "desc";
  278. }
  279. that.where.news = that.nows ? "1" : "0";
  280. },
  281. switchTap: function() {
  282. let that = this;
  283. that.Switch = !that.Switch;
  284. },
  285. returns() {
  286. this.$router.push({ path: "/" });
  287. }
  288. }
  289. };
  290. </script>
  291. <style scoped>
  292. .noCommodity {
  293. border-top: 3px solid #f5f5f5;
  294. padding-bottom: 1px;
  295. }
  296. </style>