index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. background: url('~assets/theme-images/common/pc-banner-device.png');
  129. background-size: auto 420px;
  130. .logo {
  131. display: block;
  132. width: 120px;
  133. height: 120px;
  134. border-radius: 50%;
  135. background: #fff;
  136. }
  137. .name {
  138. font-size: 30px;
  139. color: #fff;
  140. }
  141. .logo,
  142. .name {
  143. transform: translateY(-30px);
  144. }
  145. }
  146. .page-content {
  147. width: 1200px;
  148. margin: 0 auto;
  149. .search {
  150. position: absolute;
  151. left: 50%;
  152. top: 300px;
  153. transform: translateX(-50%);
  154. }
  155. .title {
  156. font-size: 16px;
  157. color: #404040;
  158. span {
  159. @include themify($themes) {
  160. color: themed('color');
  161. }
  162. }
  163. }
  164. .list {
  165. display: flex;
  166. align-items: center;
  167. flex-wrap: wrap;
  168. justify-content: space-between;
  169. .empty {
  170. width: 390px;
  171. }
  172. .section {
  173. width: 390px;
  174. height: 108px;
  175. background-color: #f3f5f6;
  176. border-radius: 4px;
  177. box-sizing: border-box;
  178. padding: 16px;
  179. cursor: pointer;
  180. transition: all 0.4s;
  181. &:hover {
  182. box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  183. }
  184. .cover {
  185. display: block;
  186. width: 84px;
  187. height: 84px;
  188. }
  189. .name {
  190. width: 260px;
  191. font-size: 16px;
  192. color: #101010;
  193. text-overflow: ellipsis;
  194. white-space: nowrap;
  195. overflow: hidden;
  196. margin-left: 16px;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. // 移动 端
  203. @media screen and (max-width: 768px) {
  204. .page-top {
  205. height: 46vw;
  206. background: url('~assets/theme-images/common/h5-banner-device.png');
  207. background-size: auto 46vw;
  208. .logo {
  209. display: block;
  210. width: 14.8vw;
  211. height: 14.8vw;
  212. border-radius: 50%;
  213. background: #fff;
  214. }
  215. .name {
  216. font-size: 4vw;
  217. color: #fff;
  218. }
  219. }
  220. .page-content {
  221. position: relative;
  222. .search {
  223. position: absolute;
  224. left: 50%;
  225. top: 0;
  226. transform: translate(-50%, -50%);
  227. }
  228. .title {
  229. font-size: 3.4vw;
  230. color: #404040;
  231. span {
  232. @include themify($themes) {
  233. color: themed('color');
  234. }
  235. }
  236. }
  237. .list {
  238. display: flex;
  239. align-items: center;
  240. flex-direction: column;
  241. .section {
  242. width: 93.6vw;
  243. height: 26vw;
  244. background-color: #f3f5f6;
  245. border-radius: 4px;
  246. box-sizing: border-box;
  247. padding: 3.2vw;
  248. .cover {
  249. display: block;
  250. width: 19.6vw;
  251. height: 19.6vw;
  252. }
  253. .name {
  254. width: 66vw;
  255. font-size: 4vw;
  256. color: #101010;
  257. text-overflow: ellipsis;
  258. white-space: nowrap;
  259. overflow: hidden;
  260. margin-left: 3.2vw;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. </style>