index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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(https://static.caimei365.com/www/authentic/pc/bg-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. color: #bc1724;
  160. }
  161. }
  162. .list {
  163. display: flex;
  164. align-items: center;
  165. flex-wrap: wrap;
  166. justify-content: space-between;
  167. .empty {
  168. width: 390px;
  169. }
  170. .section {
  171. width: 390px;
  172. height: 108px;
  173. background-color: #f3f5f6;
  174. border-radius: 4px;
  175. box-sizing: border-box;
  176. padding: 16px;
  177. cursor: pointer;
  178. transition: all 0.4s;
  179. &:hover {
  180. box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  181. }
  182. .cover {
  183. display: block;
  184. width: 84px;
  185. height: 84px;
  186. }
  187. .name {
  188. width: 260px;
  189. font-size: 16px;
  190. color: #101010;
  191. text-overflow: ellipsis;
  192. white-space: nowrap;
  193. overflow: hidden;
  194. margin-left: 16px;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. // 移动 端
  201. @media screen and (max-width: 768px) {
  202. .page-top {
  203. height: 46vw;
  204. background: url(https://static.caimei365.com/www/authentic/h5/bg-device.png);
  205. background-size: auto 46vw;
  206. .logo {
  207. display: block;
  208. width: 14.8vw;
  209. height: 14.8vw;
  210. border-radius: 50%;
  211. background: #fff;
  212. }
  213. .name {
  214. font-size: 4vw;
  215. color: #fff;
  216. }
  217. }
  218. .page-content {
  219. position: relative;
  220. .search {
  221. position: absolute;
  222. left: 50%;
  223. top: 0;
  224. transform: translate(-50%, -50%);
  225. }
  226. .title {
  227. font-size: 3.4vw;
  228. color: #404040;
  229. span {
  230. color: #bc1724;
  231. }
  232. }
  233. .list {
  234. display: flex;
  235. align-items: center;
  236. flex-direction: column;
  237. .section {
  238. width: 93.6vw;
  239. height: 26vw;
  240. background-color: #f3f5f6;
  241. border-radius: 4px;
  242. box-sizing: border-box;
  243. padding: 3.2vw;
  244. .cover {
  245. display: block;
  246. width: 19.6vw;
  247. height: 19.6vw;
  248. }
  249. .name {
  250. width: 66vw;
  251. font-size: 4vw;
  252. color: #101010;
  253. text-overflow: ellipsis;
  254. white-space: nowrap;
  255. overflow: hidden;
  256. margin-left: 3.2vw;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. </style>