deviceList.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. provinceId: '',
  24. cityId: '',
  25. townId: '',
  26. authParty: '',
  27. pageNum: 1,
  28. pageSize: 10,
  29. },
  30. list: [],
  31. total: 0,
  32. productSelectList: [],
  33. searchFlag: false,
  34. }
  35. },
  36. computed: {
  37. ...mapGetters(['routePrefix', 'supplierInfo', 'authUserId']),
  38. },
  39. mounted() {
  40. this.fetchProductSelectList()
  41. },
  42. methods: {
  43. // 获取设备列表
  44. fetchList: debounce(async function () {
  45. try {
  46. this.isRequest = true
  47. this.loadingMore = true
  48. const res = await this.$http.api.getAuthProductList(this.listQuery)
  49. this.list = [...this.list, ...res.data.list]
  50. this.finished = !res.data.hasNextPage
  51. this.total = res.data.total
  52. this.loadingMore = false
  53. this.listQuery.pageNum += 1
  54. this.searchFlag = true
  55. } catch (error) {
  56. console.log(error)
  57. } finally {
  58. this.isRequest = false
  59. this.searchFlag = true
  60. }
  61. }, 400),
  62. // 搜索
  63. onSearch() {
  64. const { productTypeId } = this.listQuery
  65. const { type, keyword } = this.searchQuery
  66. if (!productTypeId) {
  67. return this.$toast('请选择设备分类')
  68. }
  69. if (!type) {
  70. return this.$toast('请选择搜索条件')
  71. }
  72. if (!keyword) {
  73. return this.$toast('搜索内容不能为空')
  74. }
  75. if (type === 1) {
  76. this.listQuery.snCode = keyword
  77. this.listQuery.authParty = ''
  78. } else {
  79. this.listQuery.snCode = ''
  80. this.listQuery.authParty = keyword
  81. }
  82. this.list = []
  83. this.listQuery.pageNum = 1
  84. this.fetchList()
  85. },
  86. // 获取设备种类
  87. async fetchProductSelectList() {
  88. try {
  89. const res = await this.$http.api.fetchProductSelectList({
  90. authUserId: this.authUserId,
  91. })
  92. this.productSelectList = res.data
  93. } catch (error) {
  94. console.log(error)
  95. }
  96. },
  97. // 设备详情
  98. toDetail(item) {
  99. const url = `${this.routePrefix}/approve/device/detail?id=${item.productId}`
  100. this.$router.push(url)
  101. },
  102. // 机构详情
  103. toClubDetail(item) {
  104. const url = `${this.routePrefix}/approve/club/detail?id=${item.authId}`
  105. this.$router.push(url)
  106. },
  107. // 加载更多
  108. onLoadMore() {
  109. if (!this.searchFlag) return
  110. this.fetchList()
  111. },
  112. // 城市变化
  113. onCityChange(valueMap) {
  114. const { provinceId, cityId, townId } = valueMap
  115. this.listQuery.provinceId = provinceId
  116. this.listQuery.cityId = cityId
  117. this.listQuery.townId = townId
  118. },
  119. },
  120. }