item.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <MeScroll :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
  3. <card :list="list" ></card>
  4. </MeScroll>
  5. </template>
  6. <script>
  7. import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
  8. import card from './card.vue'
  9. var app=getApp()
  10. export default {
  11. components:{
  12. MeScroll,card
  13. },
  14. props: {
  15. refresh:Boolean,
  16. type: Number,
  17. i: Number,
  18. fireType: Number,
  19. item:Object
  20. },
  21. data() {
  22. return {
  23. isInit: false, // 是否初始化
  24. list: [], // 列表数据
  25. mescroll: null, // mescroll 对象
  26. // 上拉配置参数
  27. up: {
  28. noMoreSize: 2,
  29. auto: false,
  30. page: {
  31. page: 0,
  32. size: 10
  33. }
  34. },
  35. // 下拉配置参数
  36. down: {
  37. use: true,
  38. auto: false
  39. }
  40. }
  41. },
  42. watch:{
  43. refresh() {
  44. console.log("我要刷新了");
  45. this.mescroll.resetUpScroll()
  46. },
  47. type(val) {
  48. if(!this.isInit && val === this.i) {
  49. this.mescroll.resetUpScroll()
  50. }
  51. }
  52. },
  53. mounted() {
  54. if(!this.isInit && this.i === 0) {
  55. this.mescroll.resetUpScroll()
  56. }
  57. },
  58. methods: {
  59. /**
  60. * @param {Object} mescroll 初始化组件
  61. */
  62. initMeScroll(mescroll) {
  63. this.mescroll = mescroll
  64. },
  65. /**
  66. * 企业通过 page接口查询,园区通过agencyPage接口查询
  67. * 烟感和燃气通过设备前缀查询
  68. * 消防栓通过设备类型查询
  69. * @param {Object} mescroll 上拉回调
  70. */
  71. async upFn(mescroll) {
  72. let that=this
  73. let loginType=this.$cache.get('loginType')
  74. let params={
  75. current:mescroll.num,
  76. size:mescroll.size,
  77. }
  78. if (loginType==this.$loginType.ENTERPRISE) {
  79. //公司统一信用代码
  80. params.creditCode=this.$cache.get('creditCode')
  81. }else if (loginType==this.$loginType.AGENCY) {
  82. //园区tenantId
  83. params.tenantId=this.$cache.get('agencyTenantId')
  84. }
  85. if (this.fireType==0) {
  86. //烟感报警
  87. params.prefix=this.$device_prefix.SMOKE
  88. }else if (this.fireType==1) {
  89. //燃气告警
  90. params.prefix=this.$device_prefix.GAS
  91. }else if (this.fireType==2) {
  92. //消防水压
  93. params.deviceType=this.$device_type.FIRE_HYDRANT
  94. }else if (this.fireType==3) {
  95. //电表记录
  96. params.deviceType=this.$device_type.ELECTRIC_METER
  97. }
  98. if (!this.$isEmpty(this.item.value)) {
  99. params.deviceStatus=this.item.value //设备状态
  100. }
  101. try{
  102. let res=null;
  103. if (loginType==this.$loginType.ENTERPRISE) {
  104. //企业设备接口
  105. res=await this.$api.fireDevice.page(params)
  106. }else if (loginType==this.$loginType.AGENCY) {
  107. //园区设备接口
  108. res=await this.$api.fireDevice.agencyPage(params)
  109. }
  110. let data=res.data.records
  111. let length=data.length
  112. let total=res.data.total
  113. mescroll.endBySize(length, total);
  114. if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
  115. that.list=that.list.concat(data); //追加新数据
  116. }catch(e){
  117. mescroll.endErr();
  118. }
  119. },
  120. /**
  121. * 下拉回调
  122. * */
  123. downFn(mescroll) {
  124. setTimeout(()=>{
  125. this.mescroll.resetUpScroll()
  126. },1000)
  127. },
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. view{
  133. box-sizing: border-box;
  134. }
  135. </style>