index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view>
  3. <u-tabs :list="types" :activeStyle="{ fontWeight: 'bold', color: '#C30D23' }" lineColor="#C30D23"
  4. keyName="classname" @change="tabsChange">
  5. <view slot="right" class="nav-search" hover-class="navigator-hover" @click="changeSearchShow(searchShow)">
  6. <view class="iconfont icon-sousuo" :style="{ color: searchShow ? '#C30D23' : '#999999' }" />
  7. </view>
  8. </u-tabs>
  9. <u-transition :show="searchShow">
  10. <view class="My_search-box">
  11. <My_search :value="content.where.condition" @onSearch="onSearch">
  12. <view class="cancel" v-if="content.where.condition" hover-class="navigator-hover" @click="onSearch('')">
  13. 取消
  14. </view>
  15. <view v-else style="width: 5px;" />
  16. </My_search>
  17. </view>
  18. </u-transition>
  19. <view class="scroll-view-box" v-if="tabs.length">
  20. <scroll-view class="scroll-view" :scroll-left="scrollLeft" scroll-x scroll-with-animation>
  21. <view class="tab-box">
  22. <view class="tab-item tabitem" :id="item.classname + item.sa_fadclassid"
  23. :class="item.sa_fadclassid == sa_fadclassid ? 'tab-item-active' : ''" v-for="(item, index) in tabs"
  24. :key="item.sa_fadclassid" @click="changeActive(item.sa_fadclassid, index)">
  25. {{ item.classname }}
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. <view style="height: 10px;" />
  31. <view class="list">
  32. <view class="head">
  33. <view class="crumbs u-line-1">
  34. <text class="crumb" v-for="item in crumbs" :key="item.classname">{{ item.classname }}</text>
  35. </view>
  36. <view class="total">共{{ total }}件</view>
  37. </view>
  38. <My_listbox ref="List" @getlist="getList">
  39. <view class="list-box">
  40. <navigator class="item" :url="'/packageCase/product/detail?id=' + item.sa_fadid" v-for="item in list"
  41. :key="item.sa_fadid" hover-class="navigator-hover">
  42. <image class="image" :src="item.cover" mode="aspectFill" lazy-load="true" />
  43. <view class="title u-line-1">
  44. {{ item.name }}
  45. </view>
  46. </navigator>
  47. </view>
  48. </My_listbox>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. searchShow: true,
  57. crumbs: [],
  58. types: [],
  59. tabs: [],
  60. condition: "",
  61. scrollLeft: 0,
  62. "content": {
  63. "where": {
  64. "condition": "",
  65. "isonsale": 1,
  66. "begindate_create": "",
  67. "enddate_create": "",
  68. "begindate_onsale": "",
  69. "enddate_onsale": "",
  70. }
  71. },
  72. sa_fadclassid: '',
  73. total: 0,
  74. searchShowAntiShake: null,
  75. list: [],
  76. widths: [0],
  77. }
  78. },
  79. created() {
  80. uni.setNavigationBarTitle({
  81. title: '电器系统',
  82. })
  83. this.$Http.basic({
  84. "id": "20240418112002",
  85. "content": {
  86. "parentid": 0,
  87. "where": { "isenable": 1 }
  88. }
  89. }).then(res => {
  90. let 电器系统 = res.data.find(v => v.classname == '电器系统')
  91. this.types = [{
  92. classname: "全部",
  93. children: "",
  94. sa_fadclassid: 电器系统.sa_fadclassid,
  95. }].concat(电器系统.children);
  96. this.crumbs = [{
  97. classname: "电器"
  98. }, {
  99. classname: '全部',
  100. sa_fadclassid: 电器系统.sa_fadclassid
  101. }]
  102. this.sa_fadclassid = 电器系统.sa_fadclassid;
  103. this.getList(true)
  104. })
  105. },
  106. methods: {
  107. getList(init = false) {
  108. if (this.paging(this.content, init)) return;
  109. this.content.where.sa_fadclassids = [[this.sa_fadclassid]];
  110. this.$Http.basic({
  111. "id": "20240418141302",
  112. content: this.content
  113. }).then(res => {
  114. this.$refs.List.RefreshToComplete()
  115. console.log("获取电器列表", res)
  116. if (this.cutoff(res.msg)) return;
  117. res.data = res.data.map(v => {
  118. v.cover = v.attinfos.length ? this.getSpecifiedImage(v.attinfos.find(s => s.usetype == "sa_fad") || v.attinfos[0]) : ''
  119. return v
  120. })
  121. this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
  122. this.content = this.$refs.List.paging(this.content, res)
  123. this.total = res.total;
  124. })
  125. },
  126. onSearch(condition) {
  127. if (condition == this.content.where.condition) return;
  128. this.content.where.condition = condition;
  129. this.getList(true);
  130. },
  131. tabsChange(e) {
  132. let all = {
  133. classname: "全部",
  134. sa_fadclassid: e.sa_fadclassid
  135. }
  136. this.sa_fadclassid = e.sa_fadclassid;
  137. e.classname == '全部' ? this.crumbs = this.crumbs.splice(1) : this.crumbs.splice(2, 1, all)
  138. this.crumbs[1] = e;
  139. if (e.children.length && e.children[0].classname != '全部') e.children.unshift(all)
  140. this.tabs = e.children;
  141. this.active = '全部'
  142. this.widths = [0];
  143. this.scrollLeft = 0;
  144. setTimeout(() => {
  145. uni.createSelectorQuery().in(this).selectAll(`.tabitem`).boundingClientRect(list => {
  146. let count = 0;
  147. list.forEach((v, i) => {
  148. if (i) this.widths.push(count)
  149. count += v.right;
  150. })
  151. }).exec();
  152. }, 100);
  153. this.$refs.List.setHeight();
  154. this.getList(true)
  155. },
  156. changeActive(sa_fadclassid, index) {
  157. this.scrollLeft = this.widths[index]
  158. if (this.sa_fadclassid == sa_fadclassid) return;
  159. this.sa_fadclassid = sa_fadclassid
  160. this.getList(true)
  161. },
  162. changeSearchShow(searchShow) {
  163. this.searchShow = !searchShow;
  164. clearTimeout(this.searchShowAntiShake)
  165. this.searchShowAntiShake = setTimeout(() => {
  166. this.$refs.List.setHeight();
  167. }, 350)
  168. }
  169. },
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .nav-search {
  174. display: flex;
  175. align-items: center;
  176. padding: 0 15px;
  177. height: 44px;
  178. border-radius: 8px;
  179. margin-right: 5px;
  180. }
  181. .My_search-box {
  182. background: #fff;
  183. width: 100vw;
  184. padding: 5px;
  185. padding-left: 10px;
  186. box-sizing: border-box;
  187. .cancel {
  188. line-height: 30px;
  189. margin-left: 10px;
  190. padding: 0 10px;
  191. font-family: Source Han Sans SC, Source Han Sans SC;
  192. font-size: 14px;
  193. color: #666666;
  194. border-radius: 4px;
  195. }
  196. }
  197. .scroll-view-box {
  198. width: 100vw;
  199. padding: 10px;
  200. padding-top: 5px;
  201. background: #fff;
  202. height: 44px;
  203. box-sizing: border-box;
  204. .scroll-view {
  205. .tab-box {
  206. flex: 1;
  207. display: flex;
  208. }
  209. .tab-item {
  210. flex-shrink: 0;
  211. height: 24px;
  212. line-height: 24px;
  213. padding: 0 5px;
  214. background: #F2F2F2;
  215. border-radius: 12px;
  216. margin-right: 5px;
  217. font-size: 12px;
  218. }
  219. .tab-item-active {
  220. background: #C30D23;
  221. color: #FFFFFF;
  222. }
  223. }
  224. }
  225. .list-box {
  226. display: flex;
  227. flex-wrap: wrap;
  228. justify-content: space-between;
  229. .item {
  230. width: 173px;
  231. height: 207px;
  232. margin-top: 10px;
  233. border-radius: 5px;
  234. overflow: hidden;
  235. flex-shrink: 0;
  236. .image {
  237. width: 173px;
  238. height: 172px;
  239. background: #F5F5F5;
  240. border-radius: 5px;
  241. }
  242. .title {
  243. width: 100%;
  244. height: 25px;
  245. line-height: 20px;
  246. font-family: PingFang SC, PingFang SC;
  247. font-size: 14px;
  248. color: #333333;
  249. margin-top: 10px;
  250. text-align: center;
  251. }
  252. }
  253. }
  254. .list {
  255. width: 100vw;
  256. padding: 10px;
  257. box-sizing: border-box;
  258. background: #fff;
  259. .head {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. height: 17px;
  264. line-height: 17px;
  265. .crumbs {
  266. flex: 1;
  267. width: 0;
  268. .crumb {
  269. flex-shrink: 0;
  270. font-size: 12px;
  271. font-family: PingFang SC, PingFang SC;
  272. }
  273. .crumb::after {
  274. content: ">";
  275. padding: 0 2px;
  276. }
  277. .crumb:last-child {
  278. font-weight: bold;
  279. }
  280. .crumb:last-child::after {
  281. content: "";
  282. }
  283. }
  284. .total {
  285. flex-shrink: 0;
  286. font-family: Source Han Sans SC, Source Han Sans SC;
  287. font-size: 12px;
  288. color: #999999;
  289. margin-left: 20px;
  290. }
  291. }
  292. }
  293. </style>