list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="list search-list">
  3. <!-- 分类筛选 -->
  4. <CategroySidebar ref="categroySidebar"/>
  5. <!-- /分类筛选 -->
  6. <div class="content">
  7. <div class="crumbs" v-if="categoryId">
  8. <nuxt-link to="/" class="item-a">{{$t('commonHead.home')}}</nuxt-link>
  9. <span class="arrow" v-if="categoryId">></span>
  10. <template v-for="cate in parentCategoryList">
  11. <span @click="changeCategory(0, cate.categoryId)" class="item-a" v-if="categoryParentId === cate.categoryId">{{
  12. cate.categoryName
  13. }}</span>
  14. </template>
  15. <!-- <span class="arrow" v-if="categoryId">></span> -->
  16. <template v-for="cate in categoryList">
  17. <span class="item-span" v-if="categoryId === cate.categoryId">
  18. <span class="arrow">></span>
  19. {{ cate.categoryName }}
  20. </span>
  21. </template>
  22. <span class="arrow" v-if="keyword">></span>
  23. <template>
  24. <span class="item-span" v-if="keyword">{{ keyword }}</span>
  25. <span class="item-span" v-if="keyword">{{ keyword }}</span>
  26. </template>
  27. </div>
  28. <div class="crumbs" v-else>
  29. <nuxt-link to="/" class="item-a">{{$t('commonHead.home')}}</nuxt-link>
  30. <span class="arrow">></span>
  31. <span class="item-span center" v-if="keyword">{{ keyword }}</span>
  32. <span class="item-span" v-if="st == 0">{{$t('commonHead.productList')}}</span>
  33. <span class="item-span" v-if="st == 1">{{$t('commonHead.newProducts')}}</span>
  34. <span class="item-span" v-if="st == 4">{{$t('commonHead.couponPooling')}}</span>
  35. </div>
  36. <div class="goods-sort" v-if="!st">
  37. <div class="sort-con categorys">
  38. <div class="name">{{$t('classification')}}:</div>
  39. <div class="group">
  40. <span
  41. class="item"
  42. :class="[{ active: !categoryParentId }]"
  43. @click="changeCategory(-1, 0)"
  44. >{{$t('all')}}</span
  45. >
  46. <!-- <span class="item">热卖推荐</span> -->
  47. <span
  48. v-for="cate in parentCategoryList"
  49. :key="cate.categoryId"
  50. :class="[
  51. 'item',
  52. categoryParentId == cate.categoryId ? 'active' : ''
  53. ]"
  54. @click="changeCategory(0, cate.categoryId)"
  55. >{{ cate.categoryName }}</span
  56. >
  57. </div>
  58. </div>
  59. <div
  60. class="sort-con categorys"
  61. v-show="categoryList.length && categoryParentId"
  62. >
  63. <div class="name">
  64. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  65. </div>
  66. <div class="group">
  67. <span
  68. v-for="subCate in categoryList"
  69. :key="subCate.categoryId"
  70. :class="[
  71. 'item',
  72. categoryId == subCate.categoryId ? 'active' : ''
  73. ]"
  74. @click="changeCategory(1, subCate.categoryId)"
  75. >{{ subCate.categoryName }}</span
  76. >
  77. </div>
  78. </div>
  79. <div
  80. class="sort-con categorys"
  81. v-show="thCategoryList.length && categoryId"
  82. >
  83. <div class="name">
  84. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  85. </div>
  86. <div class="group">
  87. <span
  88. v-for="threeCate in thCategoryList"
  89. :key="threeCate.categoryId"
  90. :class="[
  91. 'item',
  92. thCategoryId == threeCate.categoryId ? 'active' : ''
  93. ]"
  94. @click="changeCategory(2, threeCate.categoryId)"
  95. >{{ threeCate.categoryName }}</span
  96. >
  97. </div>
  98. </div>
  99. <!-- <div class="sort-con distribution">
  100. <div class="name">配送:</div>
  101. <div class="group">
  102. <span class="item active">全部</span>
  103. <span class="item">包邮</span>
  104. <span class="item">货到付款</span>
  105. </div>
  106. </div>-->
  107. <div class="sort-con sorts">
  108. <div class="name">{{$t('sort')}}:</div>
  109. <div class="group">
  110. <span
  111. :class="['item', sortType == '' ? 'active' : '']"
  112. @click="onStsTap('')"
  113. >{{$t('default')}}</span
  114. >
  115. <span
  116. :class="['item', sortType == 'sales' ? 'active' : '']"
  117. @click="onStsTap('sales')"
  118. >
  119. {{$t('sales')}}
  120. <i class="arrow-up" v-if="sort == 3 && sortType == 'sales'"></i>
  121. <i class="arrow-down" v-if="sort == 2 && sortType == 'sales'"></i>
  122. </span>
  123. <span
  124. :class="['item', sortType == 'price' ? 'active' : '']"
  125. @click="onStsTap('price')"
  126. >
  127. {{$t('price')}}
  128. <i class="arrow-up" v-if="sort == 5 && sortType == 'price'"></i>
  129. <i class="arrow-down" v-if="sort == 4 && sortType == 'price'"></i>
  130. </span>
  131. <!-- <span :class="['item',sts==3?'active':'']" @click="onStsTap(3)">收藏</span> -->
  132. </div>
  133. </div>
  134. </div>
  135. <div class="goods-list">
  136. <!-- 全部 -->
  137. <ProdItem :pale-list="dataList" :list-type="1" :page-type="1" />
  138. <!-- 页码 -->
  139. <pagination
  140. v-model="current"
  141. :pages="pages"
  142. @changePage="getSearchProdPage"
  143. ></pagination>
  144. <!-- /页码 -->
  145. </div>
  146. </div>
  147. </div>
  148. </template>
  149. <script>
  150. import ProdItem from '~/components/prod-item'
  151. import CategroySidebar from '~/components/categroy-sidebar'
  152. import Pagination from '~/components/pagination'
  153. export default {
  154. components: {
  155. ProdItem,
  156. CategroySidebar,
  157. Pagination
  158. },
  159. watchQuery: ['pn', 'cpid', 'cid', 'thCid', 'sort', 'ob', 'c', 'st', 'lang'],
  160. data () {
  161. return {
  162. st: 0,
  163. categoryParentId: null,
  164. thCategoryId: null,
  165. categoryId: null,
  166. goCurrent: this.$route.query.current,
  167. dataList: [],
  168. pages: 1, // 总页数
  169. current: this.$route.query.current || 1, // 当前页数
  170. keyword: '', // 搜索关键字
  171. discountId: this.$route.query.discountId, // 限时特惠id
  172. couponId: this.$route.query.couponId, // 优惠券id
  173. sort: 0,
  174. lang: this.$route.query.lang,
  175. sortType: (!this.$route.query.sort || this.$route.query.sort==0) ? '' : (this.$route.query.sort == 4 || this.$route.query.sort == 5) ? 'price' : 'sales'
  176. }
  177. },
  178. computed: {
  179. parentCategoryList () {
  180. return this.$store.state.categoryHorizontal.parentCategoryList
  181. },
  182. categoryList () {
  183. return this.$store.state.categoryHorizontal.categoryList
  184. },
  185. thCategoryList () {
  186. return this.$store.state.categoryHorizontal.thCategoryList
  187. }
  188. },
  189. /**
  190. * st: 搜索方式 空为默认 1新品推荐 2
  191. * pn: 商品名称
  192. * cpid: 上级分类id
  193. * cid: 分类id
  194. * sort: 根据默认(0)/销量(1)/价格(2)排序
  195. * ob: 0正序 1倒序
  196. * c: 当前第几页
  197. * @param query
  198. */
  199. async asyncData ({ app, query }) {
  200. var param = {
  201. st: parseInt(query.st) || 0,
  202. current: parseInt(query.c) || 1,
  203. size: 12, // 每页显示多少条
  204. }
  205. var data = {}
  206. var url = ''
  207. if (param.st === 1) {
  208. url = '/prod/lastedProdPage'
  209. param = Object.assign({
  210. prodName: query.pn || '',
  211. categoryParentId: '',
  212. categoryId: '',
  213. thCategoryId: '',
  214. sort: 0, // 这里的sort并不是排序 是 状态
  215. orderBy: 0, // 这里的orderby 才是状态
  216. current: 1, // 这里是页码
  217. }, param)
  218. data = Object.assign({}, param)
  219. } else if (param.st === 4) {
  220. url = '/coupon/prodListByCouponId'
  221. param = Object.assign({
  222. couponId: query.couponId,
  223. prodName: query.pn || '',
  224. categoryId: parseInt(query.thCid) || '',
  225. sort: parseInt(query.sort) || 0, // 这里的sort并不是排序 是 状态
  226. orderBy: parseInt(query.ob) || 0, // 这里的orderby 才是状态
  227. current: parseInt(query.c) || 1, // 这里是页码
  228. isAllProdType: true
  229. }, param)
  230. data = Object.assign({}, param)
  231. data.categoryParentId = parseInt(query.cpid) || ''
  232. data.categoryId = parseInt(query.cid) || ''
  233. data.thCategoryId = parseInt(query.thCid) || ''
  234. } else if (query.cpid && !query.cid && !query.thCid) {
  235. // url = '/search/searchProdPage'
  236. url = '/search/page'
  237. param = Object.assign({
  238. keyword: query.pn || '',
  239. categoryId: parseInt(query.thCid) || '',
  240. primaryCategoryId: query.cpid,
  241. sort: parseInt(query.sort) || null, // 这里的sort并不是排序 是 状态
  242. orderBy: parseInt(query.ob) || 0, // 这里的orderby 才是状态
  243. current: parseInt(query.c) || 1, // 这里是页码
  244. isAllProdType: true,
  245. isActive: 1 // 过滤掉活动商品
  246. }, param)
  247. data = Object.assign({}, param)
  248. data.categoryParentId = parseInt(query.cpid) || ''
  249. } else if (query.cpid && query.cid && !query.thCid) {
  250. // url = '/search/searchProdPage'
  251. url = '/search/page'
  252. param = Object.assign({
  253. keyword: query.pn || '',
  254. categoryId: parseInt(query.thCid) || '',
  255. secondaryCategoryId: query.cid,
  256. sort: parseInt(query.sort) || null, // 这里的sort并不是排序 是 状态
  257. orderBy: parseInt(query.ob) || 0, // 这里的orderby 才是状态
  258. current: parseInt(query.c) || 1, // 这里是页码
  259. isAllProdType: true,
  260. isActive: 1 // 过滤掉活动商品
  261. }, param)
  262. data = Object.assign({}, param)
  263. data.categoryParentId = parseInt(query.cpid) || ''
  264. data.categoryId = parseInt(query.cid) || ''
  265. } else {
  266. // url = '/search/searchProdPage'
  267. url = '/search/page'
  268. param = Object.assign({
  269. keyword: query.pn || '',
  270. categoryId: parseInt(query.thCid) || '',
  271. sort: parseInt(query.sort) || null, // 这里的sort并不是排序 是 状态
  272. orderBy: parseInt(query.ob) || 0, // 这里的orderby 才是状态
  273. current: parseInt(query.c) || 1, // 这里是页码
  274. isAllProdType: true,
  275. isActive: 1 // 过滤掉活动商品
  276. }, param)
  277. data = Object.assign({}, param)
  278. data.categoryParentId = parseInt(query.cpid) || ''
  279. data.categoryId = parseInt(query.cid) || ''
  280. data.thCategoryId = parseInt(query.thCid) || ''
  281. }
  282. return await app.$axios.get(url, {
  283. params: param
  284. }).then((result) => {
  285. data.pages = result.data.pages
  286. data.dataList = result.data.records
  287. data.dataList = (query.st == 1 || query.st == 4) ? result.data.records : result.data.records[0].products
  288. return data
  289. })
  290. },
  291. watch: {
  292. categoryParentId () {
  293. this.getCategory(1)
  294. },
  295. categoryId () {
  296. this.getCategory(2)
  297. },
  298. $route (to, from) {
  299. if(this.$route.query.st==1){
  300. document.title = this.$t('commonHead.newProducts')
  301. }
  302. if(this.$route.query.st==0){
  303. document.title = this.$t('commonHead.productList')
  304. }
  305. },
  306. lang () {
  307. this.$refs.categroySidebar.getCategoryList()
  308. }
  309. },
  310. mounted () {
  311. if (this.st === 1) {
  312. document.title = this.$t('commonHead.newProducts')
  313. } else {
  314. document.title = this.$t('commonHead.productList')
  315. }
  316. if (!this.thCategoryId) {
  317. this.getCategory(0)
  318. } else {
  319. this.getCategory(0)
  320. this.getCategory(1)
  321. this.getCategory(2)
  322. }
  323. // if (this.categoryParentId && this.categoryId) {
  324. // this.getCategory(1)
  325. // this.getCategory(2)
  326. // }
  327. // this.getCategory(0)
  328. // // if (this.discountId) {
  329. // // document.title = this.$t('commonHead.productList')
  330. // // }
  331. },
  332. methods: {
  333. /**
  334. * 获取分类
  335. * @param level 0 一级分类 1 二级分类
  336. * @param needSearch 是否需要搜索
  337. */
  338. getCategory (level) {
  339. var categoryParentId = 0
  340. if (level === 1) {
  341. categoryParentId = this.categoryParentId
  342. } else if (level === 2) {
  343. categoryParentId = this.categoryId
  344. }
  345. this.$axios.get('/category/categoryInfo?parentId=' + categoryParentId).then(({ data }) => {
  346. if (level === 1) {
  347. this.$store.commit('categoryHorizontal/initCategoryList', data)
  348. } else if (level == 2) { // 三级分类
  349. this.$store.commit('categoryHorizontal/initThCategoryList', data)
  350. } else {
  351. this.$store.commit('categoryHorizontal/initParentCategoryList', data)
  352. }
  353. })
  354. },
  355. /**
  356. * 改变分类
  357. * @param level 0 一级分类 1 二级分类 2三级分类
  358. * @param categoryId 分类id
  359. */
  360. changeCategory (level, categoryId) {
  361. if (level === -1) {
  362. this.categoryParentId = ''
  363. this.categoryId = ''
  364. this.$store.commit('categoryHorizontal/reomveCategoryList')
  365. } else if (level === 0) {
  366. this.categoryParentId = categoryId
  367. this.prodName = ''
  368. this.$store.commit('categoryHorizontal/reomveThCategoryList')
  369. this.getCategory(1)
  370. } else if (level === 1) {
  371. this.categoryId = categoryId
  372. this.getCategory(2)
  373. } else if (level === 2) {
  374. // this.categoryParentId = this.categoryId
  375. this.thCategoryId = categoryId
  376. }
  377. // if (level === -1 || level === 2) {
  378. // this.getSearchProdPage(1)
  379. // }
  380. if (level === -1) {
  381. this.getSearchProdPage()
  382. }
  383. if (level === 0) {
  384. this.getSearchProdPage(1)
  385. }
  386. if (level === 1) {
  387. this.getSearchProdPage(1,2)
  388. }
  389. if (level === 2) {
  390. this.getSearchProdPage(1,2,3)
  391. }
  392. },
  393. /**
  394. * 请求商品列表
  395. */
  396. getSearchProdPage (current, cid, thcid) {
  397. if (current == undefined) {
  398. this.$router.push({
  399. path: '/list',
  400. query: {
  401. st: this.st,
  402. }
  403. })
  404. } else {
  405. this.$router.push({
  406. path: '/list',
  407. query: {
  408. st: this.st,
  409. couponId: this.couponId || '',
  410. cpid: this.categoryParentId || '',
  411. c: current,
  412. pn: this.prodName || this.keyword || '',
  413. cid: cid?this.categoryId:'',
  414. thCid: (cid && thcid)?this.thCategoryId:'',
  415. sort: this.sort || 0,
  416. ob: this.orderBy || 0
  417. }
  418. })
  419. }
  420. },
  421. /**
  422. * 切换排序
  423. * @param {Number/String} sortType 排序类型
  424. */
  425. onStsTap (sortType) {
  426. this.sortType = sortType
  427. if (!sortType) {
  428. this.sort = 0
  429. } else if (sortType=='sales') {
  430. this.sort = this.sort == 3 ? 2 : 3
  431. } else if (sortType=='price') {
  432. this.sort = this.sort == 5 ? 4 : 5
  433. }
  434. this.current = 1;
  435. this.getSearchProdPage(this.current)
  436. if (this.categoryParentId && this.categoryId && this.thCategoryId ) {
  437. this.getSearchProdPage(1,2,3)
  438. }
  439. else if (this.categoryParentId && this.categoryId) {
  440. this.getSearchProdPage(1,2)
  441. }
  442. else {
  443. this.getSearchProdPage(1)
  444. }
  445. }
  446. },
  447. }
  448. </script>
  449. <style scoped src='~/assets/css/list.css'></style>
  450. <style scoped>
  451. .center{
  452. vertical-align: top ;
  453. text-overflow: ellipsis;
  454. overflow: hidden;
  455. display: inline-block;
  456. max-width: 1000px;
  457. }
  458. .el-pagination {
  459. text-align: right;
  460. padding: 0 30px;
  461. padding-top: 20px;
  462. }
  463. .pagination .el-pagination button,
  464. .el-pagination span:not([class*='suffix']) {
  465. padding: 0 8px !important;
  466. }
  467. .pagination .el-pagination.is-background .btn-next,
  468. .el-pagination.is-background .btn-prev,
  469. .el-pagination.is-background .el-pager li {
  470. background-color: #fff !important;
  471. }
  472. .pagination .el-pagination__editor.el-input .el-input__inner {
  473. width: 30px !important;
  474. }
  475. </style>