index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view>
  3. <!-- 二级分类 tabs -->
  4. <view class="tabs2-box" v-if="secondLevelTabs.length">
  5. <u-tabs :list="secondLevelTabs" :activeStyle="{ fontWeight: 'bold', color: '#C30D23' }" lineColor="#C30D23"
  6. keyName="classname" @change="changeSecondLevel">
  7. <template #right>
  8. <view class="nav-search" hover-class="navigator-hover" @click="changeSearchShow">
  9. <view class="iconfont icon-sousuo" :style="{ color: searchShow ? '#C30D23' : '#999999' }" />
  10. </view>
  11. </template>
  12. </u-tabs>
  13. </view>
  14. <u-transition :show="searchShow">
  15. <view class="My_search-box">
  16. <My_search :focus="searchShow" :value="content.where.condition" @onSearch="onSearch">
  17. <view class="cancel" v-if="content.where.condition" hover-class="navigator-hover"
  18. @click="onSearch('')">
  19. 取消
  20. </view>
  21. <view v-else style="width: 5px;" />
  22. </My_search>
  23. </view>
  24. </u-transition>
  25. <!-- 三级分类 tabs -->
  26. <view class="tabs3-box" v-if="thirdLevelTabs.length">
  27. <u-tabs ref="tabs3" :list="thirdLevelTabs" :current="thirdLevelActive"
  28. :activeStyle="{ color: '#C30D23', backgroundColor: '#fff', borderRadius: '14px', padding: '8rpx 10px' }"
  29. :inactiveStyle="{ color: '#fff' }" lineColor="#202E42" keyName="classname" :is-scroll="true"
  30. @click="changeThirdLevel" />
  31. </view>
  32. <view class="list">
  33. <view class="head">
  34. <view class="crumbs u-line-1">
  35. <text class="crumb" v-for="item in crumbs" :key="item.classname">{{ item.classname }}</text>
  36. </view>
  37. <view class="total">共{{ total }}个资源</view>
  38. </view>
  39. <My_listbox ref="List" @getlist="getList" boxBackground="#fff">
  40. <view class="waterfalls" v-if="list.length">
  41. <custom-waterfalls-flow
  42. ref="waterfallsFlowRef"
  43. :value="list"
  44. :column="2"
  45. :columnSpace="1.5"
  46. :seat="2"
  47. @wapperClick="wapperClick"
  48. @imageClick="wapperClick"
  49. >
  50. <!-- #ifdef MP-WEIXIN -->
  51. <view
  52. class="waterfalls-item"
  53. v-for="(item, index) in list"
  54. :key="index"
  55. slot="slot{{index}}"
  56. >
  57. <view class="waterfalls-item-title u-line-2">{{ item.title }}</view>
  58. </view>
  59. <!-- #endif -->
  60. <!-- #ifndef MP-WEIXIN -->
  61. <template v-slot:default="item">
  62. <view class="waterfalls-item">
  63. <view class="waterfalls-item-title u-line-2">{{
  64. item.title
  65. }}</view>
  66. </view>
  67. </template>
  68. <!-- #endif -->
  69. </custom-waterfalls-flow>
  70. </view>
  71. </My_listbox>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. export default {
  77. data() {
  78. return {
  79. list: [],
  80. content: {
  81. isDataAuth: true, //小程序默认传true
  82. where: {
  83. condition: "",
  84. status: "发布",
  85. type: "", //1:图片,2:视频,3:图文
  86. sat_sharematerial_classids: [[]],
  87. begindate_create: "", //创建时间
  88. enddate_create: "", //创建时间
  89. begindate: "", //发布时间
  90. enddate: "", //发布时间
  91. },
  92. },
  93. secondLevelList: [],
  94. secondLevelTabs: [],
  95. thirdLevelTabs: [],
  96. thirdLevelActive: 0,
  97. parentid: '',
  98. searchShow: false,
  99. searchShowAntiShake: null,
  100. sat_sharematerial_classid: '',
  101. crumbs: [],
  102. total: 0
  103. };
  104. },
  105. onLoad(options) {
  106. console.log(options)
  107. this.parentid = options.id
  108. this.crumbs = [{
  109. classname: options.name,
  110. sat_sharematerial_classid: options.id
  111. }]
  112. this.sat_sharematerial_classid = options.id
  113. this.getType()
  114. this.getList(true)
  115. uni.setNavigationBarTitle({
  116. title: options.name
  117. });
  118. },
  119. onShow() {
  120. this.updateList();
  121. },
  122. methods: {
  123. getType() {
  124. this.$Http.basic({
  125. "id": "20221102143202",
  126. content: {
  127. pageSize: 9999,
  128. parentid: this.parentid,
  129. "where": {
  130. "isenable": 1
  131. }
  132. }
  133. }).then(res => {
  134. console.log("获取二级列表", res)
  135. if (this.cutoff(res.msg)) return;
  136. this.secondLevelList = res.data
  137. // 添加"全部"选项
  138. if (res.data.length && res.data[0].classname != '全部') {
  139. res.data.unshift({
  140. classname: "全部",
  141. sat_sharematerial_classid: this.parentid,
  142. children: []
  143. })
  144. }
  145. this.secondLevelTabs = res.data
  146. // 初始化选中第一个
  147. this.changeSecondLevel(res.data[0])
  148. })
  149. },
  150. changeSecondLevel(item) {
  151. if (this.sat_sharematerial_classid == item.sat_sharematerial_classid) return;
  152. this.sat_sharematerial_classid = item.sat_sharematerial_classid;
  153. // 更新面包屑
  154. this.crumbs = [this.crumbs[0], item];
  155. // 处理三级分类
  156. let children = item.children || []
  157. if (children.length && children[0].classname != '全部') {
  158. children.unshift({
  159. classname: "全部",
  160. sat_sharematerial_classid: item.sat_sharematerial_classid
  161. })
  162. }
  163. this.thirdLevelTabs = children
  164. this.thirdLevelActive = 0
  165. try {
  166. if (this.thirdLevelTabs.length) {
  167. setTimeout(() => {
  168. this.$refs.tabs3?.update()
  169. }, 100)
  170. }
  171. } catch (error) {
  172. }
  173. this.$refs.List.setHeight();
  174. this.getList(true)
  175. },
  176. changeThirdLevel(e) {
  177. const { index } = e;
  178. let item = this.thirdLevelTabs[index];
  179. if (this.sat_sharematerial_classid == item.sat_sharematerial_classid) return;
  180. this.sat_sharematerial_classid = item.sat_sharematerial_classid;
  181. this.thirdLevelActive = index;
  182. // 更新面包屑
  183. this.crumbs = [this.crumbs[0], this.crumbs[1], item];
  184. this.$refs.List.setHeight();
  185. this.getList(true);
  186. },
  187. getList(init = false) {
  188. if (this.paging(this.content, init)) return;
  189. // 使用当前选中的分类ID
  190. this.content.where.sat_sharematerial_classids = this.sat_sharematerial_classid ? [[this.sat_sharematerial_classid]] : []
  191. if (init) this.list = JSON.parse(JSON.stringify([]));
  192. this.$Http
  193. .basic({
  194. id: 20240407094702,
  195. content: this.content,
  196. })
  197. .then((res) => {
  198. this.$refs.List.RefreshToComplete();
  199. console.log("获取装备资源库列表", res);
  200. if (this.cutoff(res.msg)) return;
  201. res.data = res.data.map((v) => {
  202. v.image = v.attinfos.length
  203. ? this.getSpecifiedImage(
  204. v.attinfos.find((s) => s.usetype == "avatar") || v.attinfos[0]
  205. )
  206. : "";
  207. return v;
  208. });
  209. this.list =
  210. res.firstPage ? res.data : this.list.concat(res.data);
  211. this.content = this.$refs.List.paging(this.content, res);
  212. this.total = res.total || 0
  213. });
  214. },
  215. updateList() {
  216. if (this.content.pageNumber && this.content.pageNumber >= 2) {
  217. let content = this.paging(this.content, true, true);
  218. this.$Http
  219. .basic({
  220. id: "20240407094702",
  221. content,
  222. })
  223. .then((res) => {
  224. console.log("更新装备资源库列表", res);
  225. if (this.cutoff(res.msg)) return;
  226. this.list = res.data;
  227. this.$refs.List.paging(content, res, true);
  228. this.total = res.total || 0
  229. });
  230. }
  231. },
  232. wapperClick(e) {
  233. let url = e.ispicture
  234. ? "/packageA/resourceLibrary/picture?id="
  235. : "/packageA/resourceLibrary/detail?id=";
  236. uni.navigateTo({ url: url + e.sat_sharematerialid });
  237. },
  238. onSearch(condition) {
  239. if (condition == this.content.where.condition) return;
  240. this.content.where.condition = condition;
  241. this.getList(true);
  242. },
  243. changeSearchShow() {
  244. this.searchShow = !this.searchShow;
  245. clearTimeout(this.searchShowAntiShake);
  246. this.searchShowAntiShake = setTimeout(() => {
  247. if (this.$refs.List) {
  248. this.$refs.List.setHeight();
  249. }
  250. }, 350);
  251. }
  252. },
  253. };
  254. </script>
  255. <style lang="scss" scoped >
  256. .nav-search {
  257. display: flex;
  258. align-items: center;
  259. padding: 0 15px;
  260. height: 44px;
  261. border-radius: 8px;
  262. margin-right: 5px;
  263. }
  264. .tabs2-box {
  265. background: #fff;
  266. }
  267. .tabs3-box {
  268. /deep/ .u-tabs {
  269. height: 44px;
  270. background: #202E42;
  271. }
  272. }
  273. .My_search-box {
  274. background: #fff;
  275. width: 100vw;
  276. padding: 5px;
  277. padding-left: 10px;
  278. box-sizing: border-box;
  279. .cancel {
  280. line-height: 30px;
  281. margin-left: 10px;
  282. padding: 0 10px;
  283. font-family: Source Han Sans SC, Source Han Sans SC;
  284. font-size: 14px;
  285. color: #666666;
  286. border-radius: 4px;
  287. }
  288. }
  289. .list {
  290. padding: 10px;
  291. box-sizing: border-box;
  292. background: #fff;
  293. .head {
  294. display: flex;
  295. align-items: center;
  296. justify-content: space-between;
  297. height: 17px;
  298. line-height: 17px;
  299. .crumbs {
  300. flex: 1;
  301. width: 0;
  302. .crumb {
  303. flex-shrink: 0;
  304. font-size: 12px;
  305. font-family: PingFang SC, PingFang SC;
  306. }
  307. .crumb::after {
  308. content: ">";
  309. padding: 0 2px;
  310. }
  311. .crumb:last-child {
  312. font-weight: bold;
  313. }
  314. .crumb:last-child::after {
  315. content: "";
  316. }
  317. }
  318. .total {
  319. flex-shrink: 0;
  320. font-family: Source Han Sans SC, Source Han Sans SC;
  321. font-size: 12px;
  322. color: #999999;
  323. margin-left: 20px;
  324. }
  325. }
  326. }
  327. .waterfalls {
  328. padding: 10px;
  329. box-sizing: border-box;
  330. &-item {
  331. border-radius: 0 !important;
  332. &-title {
  333. text-align: center;
  334. line-height: 18.5px;
  335. width: 100%;
  336. background: #ffffff;
  337. font-family: PingFang SC, PingFang SC;
  338. font-size: 12px;
  339. color: #333333;
  340. }
  341. }
  342. }
  343. </style>