index1.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="page">
  3. <van-list
  4. v-model="isLoadingMore"
  5. :finished="finished"
  6. :immediate-check="false"
  7. :finished-text="total ? '没有更多了' : ''"
  8. @load="onLoadMore"
  9. >
  10. <div class="page-top flex flex-col justify-center items-center">
  11. <!-- <img class="logo" :src="supplierInfo.logo" /> -->
  12. <div class="mt-2 name">
  13. <span v-text="supplierInfo.shopName"></span>
  14. <span>官方授权设备</span>
  15. </div>
  16. </div>
  17. <div class="page-content">
  18. <!-- 搜索区域 -->
  19. <div class="search">
  20. <SimpleSearch
  21. v-model="listQuery.name"
  22. @search="onSearch"
  23. placeholder="搜索设备"
  24. />
  25. </div>
  26. <!-- 标题 -->
  27. <div class="title px-4 pt-12 pb-6">
  28. 共<span v-text="total"></span>种设备
  29. </div>
  30. <!-- 列表 -->
  31. <div class="list">
  32. <div
  33. class="section flex items-center mb-4"
  34. v-for="item in list"
  35. :key="item.productTypeId"
  36. @click="toDetail(item)"
  37. >
  38. <img class="cover" :src="item.image" />
  39. <div class="name" v-text="item.name"></div>
  40. </div>
  41. <div class="empty" v-for="i in emptyList" :key="'empty-' + i"></div>
  42. </div>
  43. <!-- 列表为空 -->
  44. <SimpleEmpty
  45. v-if="!total && !isRequest"
  46. name="icon-empty-device.png"
  47. description="敬请期待~"
  48. ></SimpleEmpty>
  49. </div>
  50. </van-list>
  51. </div>
  52. </template>
  53. <script>
  54. import { mapGetters } from 'vuex'
  55. import { debounce } from '@/utils'
  56. export default {
  57. layout: 'app',
  58. data() {
  59. return {
  60. isLoadingMore: true,
  61. finished: false,
  62. isRequest: true,
  63. listQuery: {
  64. authUserId: '',
  65. name: '',
  66. pageNum: 1,
  67. pageSize: 9,
  68. },
  69. list: [],
  70. total: 0,
  71. }
  72. },
  73. computed: {
  74. ...mapGetters(['supplierInfo', 'authUserId', 'routePrefix']),
  75. emptyList() {
  76. return 3 - (this.list.length % 3)
  77. },
  78. },
  79. mounted() {
  80. this.fetchList()
  81. },
  82. methods: {
  83. // 获取设备分类
  84. fetchList: debounce(async function () {
  85. try {
  86. this.isLoadingMore = true
  87. this.listQuery.authUserId = this.authUserId
  88. const res = await this.$http.api.getAuthProductCateList(this.listQuery)
  89. this.list = [...this.list, ...res.data.list]
  90. this.finished = !res.data.hasNextPage
  91. this.total = res.data.total
  92. this.isLoadingMore = false
  93. this.listQuery.pageNum += 1
  94. } catch (error) {
  95. console.log(error)
  96. } finally {
  97. this.isRequest = false
  98. }
  99. }, 400),
  100. // 设备详情
  101. toDetail(item) {
  102. const url = `${this.routePrefix}/approve/device/list?id=${item.productTypeId}`
  103. this.$router.push(url)
  104. },
  105. // 搜索
  106. onSearch() {
  107. this.listQuery.pageNum = 1
  108. this.list = []
  109. this.fetchList()
  110. },
  111. // 加载更多
  112. onLoadMore() {
  113. this.fetchList()
  114. },
  115. },
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. // pc 端
  120. @media screen and (min-width: 768px) {
  121. .page {
  122. position: relative;
  123. min-height: calc(100vh - 80px - 80px);
  124. background-color: #fff;
  125. }
  126. .page-top {
  127. height: 420px;
  128. @include themify($themes) {
  129. background: themed('pc-banner-device');
  130. }
  131. background-size: auto 420px;
  132. .logo {
  133. display: block;
  134. width: 120px;
  135. height: 120px;
  136. border-radius: 50%;
  137. background: #fff;
  138. }
  139. .name {
  140. font-size: 30px;
  141. color: #fff;
  142. }
  143. .logo,
  144. .name {
  145. transform: translateY(-30px);
  146. }
  147. }
  148. .page-content {
  149. width: 1200px;
  150. margin: 0 auto;
  151. .search {
  152. position: absolute;
  153. left: 50%;
  154. top: 300px;
  155. transform: translateX(-50%);
  156. }
  157. .title {
  158. font-size: 16px;
  159. color: #404040;
  160. span {
  161. @include themify($themes) {
  162. color: themed('color');
  163. }
  164. }
  165. }
  166. .list {
  167. display: flex;
  168. align-items: center;
  169. flex-wrap: wrap;
  170. justify-content: space-between;
  171. .empty {
  172. width: 390px;
  173. }
  174. .section {
  175. width: 390px;
  176. height: 108px;
  177. background-color: #f3f5f6;
  178. border-radius: 4px;
  179. box-sizing: border-box;
  180. padding: 16px;
  181. cursor: pointer;
  182. transition: all 0.4s;
  183. &:hover {
  184. box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  185. }
  186. .cover {
  187. display: block;
  188. width: 84px;
  189. height: 84px;
  190. }
  191. .name {
  192. width: 260px;
  193. font-size: 16px;
  194. color: #101010;
  195. text-overflow: ellipsis;
  196. white-space: nowrap;
  197. overflow: hidden;
  198. margin-left: 16px;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. // 移动 端
  205. @media screen and (max-width: 768px) {
  206. .page-top {
  207. height: 46vw;
  208. @include themify($themes) {
  209. background: themed('h5-banner-device');
  210. }
  211. background-size: auto 46vw;
  212. .logo {
  213. display: block;
  214. width: 14.8vw;
  215. height: 14.8vw;
  216. border-radius: 50%;
  217. background: #fff;
  218. }
  219. .name {
  220. font-size: 4vw;
  221. color: #fff;
  222. }
  223. }
  224. .page-content {
  225. position: relative;
  226. .search {
  227. position: absolute;
  228. left: 50%;
  229. top: 0;
  230. transform: translate(-50%, -50%);
  231. }
  232. .title {
  233. font-size: 3.4vw;
  234. color: #404040;
  235. span {
  236. @include themify($themes) {
  237. color: themed('color');
  238. }
  239. }
  240. }
  241. .list {
  242. display: flex;
  243. align-items: center;
  244. flex-direction: column;
  245. .section {
  246. width: 93.6vw;
  247. height: 26vw;
  248. background-color: #f3f5f6;
  249. border-radius: 4px;
  250. box-sizing: border-box;
  251. padding: 3.2vw;
  252. .cover {
  253. display: block;
  254. width: 19.6vw;
  255. height: 19.6vw;
  256. }
  257. .name {
  258. width: 66vw;
  259. font-size: 4vw;
  260. color: #101010;
  261. text-overflow: ellipsis;
  262. white-space: nowrap;
  263. overflow: hidden;
  264. margin-left: 3.2vw;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </style>