deviceList.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { debounce } from '@/utils'
  2. import { mapGetters } from 'vuex'
  3. export default {
  4. filters: {
  5. formatSnCode(code) {
  6. if (!code) return ''
  7. return code.replace(/^(\w{2})\w+(\w{4})$/, '$1******$2')
  8. },
  9. },
  10. data() {
  11. return {
  12. loadingMore: false,
  13. finished: true,
  14. isRequest: false,
  15. searchQuery: {
  16. type: 2,
  17. keyword: '',
  18. },
  19. listQuery: {
  20. listType: 1,
  21. productTypeId: '',
  22. snCode: '',
  23. authParty: '',
  24. pageNum: 1,
  25. pageSize: 10,
  26. },
  27. list: [],
  28. total: 0,
  29. productSelectList: [],
  30. searchFlag: false,
  31. }
  32. },
  33. computed: {
  34. ...mapGetters(['routePrefix', 'supplierInfo', 'authUserId']),
  35. },
  36. mounted() {
  37. this.fetchProductSelectList()
  38. },
  39. methods: {
  40. // 获取设备列表
  41. fetchList: debounce(async function () {
  42. try {
  43. this.isRequest = true
  44. this.loadingMore = true
  45. const res = await this.$http.api.getAuthProductList(this.listQuery)
  46. this.list = [...this.list, ...res.data.list]
  47. this.finished = !res.data.hasNextPage
  48. this.total = res.data.total
  49. this.loadingMore = false
  50. this.listQuery.pageNum += 1
  51. this.searchFlag = true
  52. } catch (error) {
  53. console.log(error)
  54. } finally {
  55. this.isRequest = false
  56. this.searchFlag = true
  57. }
  58. }, 400),
  59. // 搜索
  60. onSearch() {
  61. const { productTypeId } = this.listQuery
  62. const { type, keyword } = this.searchQuery
  63. if (!productTypeId) {
  64. return this.$toast('请选择设备分类')
  65. }
  66. if (!type) {
  67. return this.$toast('请选择搜索条件')
  68. }
  69. if (!keyword) {
  70. return this.$toast('搜索内容不能为空')
  71. }
  72. if (type === 1) {
  73. this.listQuery.snCode = keyword
  74. this.listQuery.authParty = ''
  75. } else {
  76. this.listQuery.snCode = ''
  77. this.listQuery.authParty = keyword
  78. }
  79. this.list = []
  80. this.listQuery.pageNum = 1
  81. this.fetchList()
  82. },
  83. // 获取设备种类
  84. async fetchProductSelectList() {
  85. try {
  86. const res = await this.$http.api.fetchProductSelectList({
  87. authUserId: this.authUserId,
  88. })
  89. this.productSelectList = res.data
  90. } catch (error) {
  91. console.log(error)
  92. }
  93. },
  94. // 设备详情
  95. toDetail(item) {
  96. const url = `${this.routePrefix}/approve/device/detail?id=${item.productId}`
  97. this.$router.push(url)
  98. },
  99. // 机构详情
  100. toClubDetail(item) {
  101. const url = `${this.routePrefix}/approve/club/detail?id=${item.authId}`
  102. this.$router.push(url)
  103. },
  104. // 加载更多
  105. onLoadMore() {
  106. if (!this.searchFlag) return
  107. this.fetchList()
  108. },
  109. },
  110. }