index.vue 9.4 KB

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