index.vue 8.3 KB

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