index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import { Popup, Col, Row, Icon, Tag, Sticky } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import TabList from '../components/tab-list'
  4. import styles from './index.module.less'
  5. import iconFilter from '@/common/images/icon_filter.png'
  6. import GoodsFilterList from '../modal/goods-filter-list'
  7. import ColSearch from '@/components/col-search'
  8. export default defineComponent({
  9. name: 'goods-list',
  10. data() {
  11. const query = this.$route.query
  12. return {
  13. typeId: 0,
  14. filterActive: 0,
  15. filterListShow: false,
  16. productCategory: {
  17. name: query.tag || '',
  18. id: Number(query.id) || 0
  19. },
  20. productAttributeCategory: {
  21. name: '',
  22. id: 0
  23. },
  24. brand: {
  25. name: '',
  26. id: 0
  27. },
  28. keyword: '' as any,
  29. autofocus: false
  30. }
  31. },
  32. mounted() {
  33. this.$nextTick(() => {
  34. if (this.$route.query.input === 'focus') {
  35. let input: HTMLInputElement = document.querySelector(
  36. '.van-field__control'
  37. ) as HTMLInputElement
  38. input.focus()
  39. }
  40. })
  41. },
  42. methods: {
  43. onFilter(n: number) {
  44. if (this.filterActive === 3 && n === 3) n = 4
  45. if (this.filterActive === 4 && n === 3) n = 3
  46. if (this.filterActive === n) return
  47. this.filterActive = n
  48. this.onSearch()
  49. },
  50. setFilter({ productCategory, productAttributeCategory, brand }) {
  51. this.productCategory = productCategory
  52. ? productCategory
  53. : { id: 0, name: '' }
  54. this.productAttributeCategory = productAttributeCategory
  55. ? productAttributeCategory
  56. : { id: 0, name: '' }
  57. this.brand = brand ? brand : { id: 0, name: '' }
  58. // console.log(
  59. // this.productCategory,
  60. // this.productAttributeCategory,
  61. // this.brand
  62. // )
  63. this.onSearch()
  64. this.filterListShow = false
  65. },
  66. onClearTag(key: string) {
  67. this[key] = { id: 0, name: '' }
  68. let goodsFilter = this.$refs.goodsFilter as any
  69. if (goodsFilter) {
  70. if (key === 'productCategory') {
  71. goodsFilter.setParams('productCategorySmallVoList')
  72. } else if (key === 'productAttributeCategory') {
  73. goodsFilter.setParams('productAttributeCategoryList')
  74. } else {
  75. goodsFilter.setParams('brandList')
  76. }
  77. }
  78. this.$nextTick(() => {
  79. this.onSearch()
  80. })
  81. },
  82. onSearch() {
  83. let tabList = this.$refs.tabList as any
  84. tabList.onSearch()
  85. },
  86. searchBtn(keyword?: string) {
  87. this.keyword = keyword
  88. this.$nextTick(() => {
  89. this.onSearch()
  90. })
  91. }
  92. },
  93. render() {
  94. return (
  95. <div>
  96. <Sticky>
  97. <ColSearch modelValue={this.keyword} onSearch={this.searchBtn} />
  98. <Row class={styles['filter-top']} align="center">
  99. <Col
  100. span={6}
  101. class={this.filterActive === 0 ? styles.active : ''}
  102. onClick={() => this.onFilter(0)}
  103. >
  104. 综合排序
  105. </Col>
  106. <Col
  107. span={6}
  108. class={
  109. this.filterActive === 3 || this.filterActive === 4
  110. ? styles.active
  111. : ''
  112. }
  113. onClick={() => this.onFilter(3)}
  114. >
  115. 价格
  116. <div class={styles.filterSort}>
  117. <Icon
  118. class={this.filterActive === 3 ? styles['icon-active'] : ''}
  119. style={{ transform: 'rotate(-90deg)' }}
  120. name="play"
  121. size={12}
  122. />
  123. <Icon
  124. class={[
  125. styles.iconSort,
  126. this.filterActive === 4 ? [styles['icon-active']] : ''
  127. ]}
  128. style={{ transform: 'rotate(90deg)' }}
  129. name="play"
  130. size={12}
  131. />
  132. </div>
  133. </Col>
  134. <Col
  135. span={6}
  136. class={this.filterActive === 2 ? styles.active : ''}
  137. onClick={() => this.onFilter(2)}
  138. >
  139. 销量
  140. </Col>
  141. <Col
  142. span={6}
  143. class={styles.filterBtn}
  144. onClick={() => (this.filterListShow = true)}
  145. >
  146. 筛选
  147. <Icon name={iconFilter} size={18} />
  148. </Col>
  149. </Row>
  150. </Sticky>
  151. <div class={styles.filterTagWrap}>
  152. {this.productCategory.id ? (
  153. <Tag
  154. class={styles.filterTag}
  155. closeable={true}
  156. onClose={() => this.onClearTag('productCategory')}
  157. >
  158. {this.productCategory.name}
  159. </Tag>
  160. ) : (
  161. ''
  162. )}
  163. {this.productAttributeCategory.id ? (
  164. <Tag
  165. class={styles.filterTag}
  166. closeable={true}
  167. onClose={() => this.onClearTag('productAttributeCategory')}
  168. >
  169. {this.productAttributeCategory.name}
  170. </Tag>
  171. ) : (
  172. ''
  173. )}
  174. {this.brand.id ? (
  175. <Tag
  176. class={styles.filterTag}
  177. closeable={true}
  178. onClose={() => this.onClearTag('brand')}
  179. >
  180. {this.brand.name}
  181. </Tag>
  182. ) : (
  183. ''
  184. )}
  185. </div>
  186. <TabList
  187. ref="tabList"
  188. typeId={Number(this.productCategory.id)}
  189. productAttributeCategoryId={this.productAttributeCategory.id}
  190. brandId={this.brand.id}
  191. sort={this.filterActive}
  192. keyword={this.keyword}
  193. />
  194. <Popup
  195. show={this.filterListShow}
  196. closeable
  197. position="bottom"
  198. round
  199. onClose={() => {
  200. this.filterListShow = false
  201. }}
  202. >
  203. <GoodsFilterList
  204. cateGoryId={this.productCategory.id}
  205. ref="goodsFilter"
  206. setFilter={this.setFilter}
  207. />
  208. </Popup>
  209. </div>
  210. )
  211. }
  212. })