index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.productName"
  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. productName: '',
  66. pageNum: 1,
  67. pageSize: 10,
  68. },
  69. list: [],
  70. total: 0,
  71. }
  72. },
  73. computed: {
  74. ...mapGetters(['supplierInfo', 'authUserId', 'authUserId']),
  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. } catch (error) {
  93. console.log(error)
  94. } finally {
  95. this.isRequest = false
  96. this.isLoadingMore = false
  97. }
  98. }, 400),
  99. // 设备详情
  100. toDetail(item) {
  101. this.$router.push(
  102. `/${this.authUserId}/app/approve/device/list?id=${item.productTypeId}`
  103. )
  104. },
  105. // 搜索
  106. onSearch() {
  107. this.listQuery.pageNum = 1
  108. this.list = []
  109. this.fetchList()
  110. },
  111. // 页码变化
  112. onPagiantionChange(index) {
  113. this.listQuery.pageNum = index
  114. this.fetchList()
  115. },
  116. // 加载更多
  117. onLoadMore() {
  118. this.listQuery.pageNum += 1
  119. this.fetchList()
  120. },
  121. },
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. // pc 端
  126. @media screen and (min-width: 768px) {
  127. .page {
  128. position: relative;
  129. min-height: calc(100vh - 80px - 80px);
  130. background-color: #fff;
  131. }
  132. .page-top {
  133. height: 420px;
  134. background: url(https://static.caimei365.com/www/authentic/pc/bg-device.png);
  135. background-size: auto 420px;
  136. .logo {
  137. display: block;
  138. width: 120px;
  139. height: 120px;
  140. border-radius: 50%;
  141. }
  142. .name {
  143. font-size: 30px;
  144. color: #fff;
  145. }
  146. .logo,
  147. .name {
  148. transform: translateY(-30px);
  149. }
  150. }
  151. .page-content {
  152. width: 1200px;
  153. margin: 0 auto;
  154. .search {
  155. position: absolute;
  156. left: 50%;
  157. top: 300px;
  158. transform: translateX(-50%);
  159. }
  160. .title {
  161. font-size: 16px;
  162. color: #404040;
  163. span {
  164. color: #bc1724;
  165. }
  166. }
  167. .list {
  168. display: flex;
  169. align-items: center;
  170. flex-wrap: wrap;
  171. justify-content: space-between;
  172. .empty {
  173. width: 390px;
  174. }
  175. .section {
  176. width: 390px;
  177. height: 108px;
  178. background-color: #f3f5f6;
  179. border-radius: 4px;
  180. box-sizing: border-box;
  181. padding: 16px;
  182. cursor: pointer;
  183. transition: all 0.4s;
  184. &:hover {
  185. box-shadow: 0 0 24px rgba(0, 0, 0, 0.2);
  186. }
  187. .cover {
  188. display: block;
  189. width: 84px;
  190. height: 84px;
  191. }
  192. .name {
  193. width: 260px;
  194. font-size: 16px;
  195. color: #101010;
  196. text-overflow: ellipsis;
  197. white-space: nowrap;
  198. overflow: hidden;
  199. margin-left: 16px;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. // 移动 端
  206. @media screen and (max-width: 768px) {
  207. .page-top {
  208. height: 46vw;
  209. background: url(https://static.caimei365.com/www/authentic/h5/bg-device.png);
  210. background-size: auto 46vw;
  211. .logo {
  212. display: block;
  213. width: 14.8vw;
  214. height: 14.8vw;
  215. border-radius: 50%;
  216. }
  217. .name {
  218. font-size: 4vw;
  219. color: #fff;
  220. }
  221. }
  222. .page-content {
  223. position: relative;
  224. .search {
  225. position: absolute;
  226. left: 50%;
  227. top: 0;
  228. transform: translate(-50%, -50%);
  229. }
  230. .title {
  231. font-size: 3.4vw;
  232. color: #404040;
  233. span {
  234. color: #bc1724;
  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>