item.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. //公司id
  82. params.enterpriseId=this.$cache.get('enterpriseId')
  83. }else if (loginType==this.$loginType.AGENCY) {
  84. //园区tenantId
  85. // params.tenantId=this.$cache.get('agencyTenantId')
  86. }
  87. if (this.fireType==0) {
  88. //烟感报警
  89. params.prefix=this.$device_prefix.SMOKE
  90. }else if (this.fireType==1) {
  91. //燃气告警
  92. params.prefix=this.$device_prefix.GAS
  93. }else if (this.fireType==2) {
  94. //消防水压
  95. params.deviceType=this.$device_type.FIRE_HYDRANT
  96. }else if (this.fireType==3) {
  97. //电表记录
  98. params.deviceType=this.$device_type.ELECTRIC_METER
  99. }
  100. if (!this.$isEmpty(this.item.value)) {
  101. params.deviceStatus=this.item.value //设备状态
  102. }
  103. try{
  104. let res=null;
  105. if (loginType==this.$loginType.ENTERPRISE) {
  106. //企业设备接口
  107. res=await this.$api.fireDevice.page(params)
  108. }else if (loginType==this.$loginType.AGENCY) {
  109. //园区设备接口
  110. res=await this.$api.fireDevice.agencyPage(params)
  111. }
  112. let data=res.data.records
  113. let length=data.length
  114. let total=res.data.total
  115. mescroll.endBySize(length, total);
  116. if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
  117. that.list=that.list.concat(data); //追加新数据
  118. }catch(e){
  119. mescroll.endErr();
  120. }
  121. },
  122. /**
  123. * 下拉回调
  124. * */
  125. downFn(mescroll) {
  126. setTimeout(()=>{
  127. this.mescroll.resetUpScroll()
  128. },1000)
  129. },
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. view{
  135. box-sizing: border-box;
  136. }
  137. </style>