CzCard.vue 6.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
<!--
 * @Author: your name
 * @Date: 2022-03-25 17:15:31
 * @LastEditTime: 2022-03-29 10:09:52
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /gassafety-progress/gassafetyprogress-web/src/views/operationMonitor/monitorData/component/charsData/CzCard.vue
-->

<template>
  <div class="czcard">
    <my-collapse
      title="场站"
      ref="myCollapse"
      :listNum="czList.filter((item) => item.show).length"
    >
      <template v-slot:chackbox>
        <FilterVue
          :filterList="filterList"
          @fliterTypeChange="fliterTypeChange"
        />
      </template>
      <template #container>
        <div class="container" :class="{ start: getShowNum }">
          <div
            v-for="(item, index) in czList"
            :key="item.deviceName + index"
            v-show="item.show"
          >
            <CzItem ref="czItem" :list="item" v-if="item.show" />
          </div>
        </div>
      </template>
    </my-collapse>
  </div>
</template>

<script>
import MyCollapse from "./MyCollapse";
import CzItem from "./CzItem";
import FilterVue from "./FilterVue";

export default {
  // 场站
  components: {
    MyCollapse,
    CzItem,
    FilterVue,
  },
  data() {
    return {
      carHide: true,
      addStartNum: 3,
      filterList: [
        { value: "全部", count: 6, type: "all" },
        { value: "加气站", count: 2, type: 1 },
        { value: "门站", count: 0, type: 2 },
        { value: "调压站", count: 0, type: 3 },
        { value: "储备站", count: 0, type: 4 },
        { value: "气化站", count: 4, type: 5 },
      ],
      deviceTypeArr: [1, 2, 3, 4],
      czList: [
        {
          deviceName: "中诚燃气门站",
          state: 1,
          a: 12,
          b: 57.7,
          c: 0.46,
          d: 54.2,
          // e: 56,
          image: "",
          show: true,
          type: 1,
        },
        {
          deviceName: "平山中燃气站",
          state: 1,
          a: 13.1,
          b: 64.3,
          c: 0.51,
          d: 48.2,
          // e: 56,
          image: "",
          show: true,
          type: 1,
        },
        // {
        //   deviceName: "门站",
        //   state: 2,
        //   a: 25,
        //   b: 56,
        //   c: 54,
        //   d: 15,
        //   e: 56,
        //   image: "",
        //   show: true,
        //   type: 2,
        // },
        // {
        //   deviceName: "调压站",
        //   state: 1,
        //   a: 25,
        //   b: 56,
        //   c: 54,
        //   d: 15,
        //   e: 56,
        //   image: "",
        //   show: true,
        //   type: 3,
        // },
        // {
        //   deviceName: "储备站",
        //   state: 1,
        //   a: 25,
        //   b: 56,
        //   c: 54,
        //   d: 15,
        //   e: 56,
        //   image: "",
        //   show: true,
        //   type: 4,
        // },
        {
          deviceName: "隆和气化站",
          state: 1,
          a: 15.2,
          b: 52.9,
          c: 0.49,
          d: 54,
          // e: 56,
          image: "",
          show: true,
          type: 5,
        },
        {
          deviceName: "温塘气化站",
          state: 1,
          a: 12.6,
          b: 61.8,
          c: 0.47,
          d: 49,
          // e: 56,
          image: "",
          show: true,
          type: 5,
        },
        {
          deviceName: "93701部队气化站",
          state: 1,
          a: 14.6,
          b: 56.5,
          c: 0.58,
          d: 47.6,
          // e: 56,
          image: "",
          show: true,
          type: 5,
        },
        {
          deviceName: "隆城绿都气化站",
          state: 1,
          a: 12.5,
          b: 54,
          c: 0.52,
          d: 50,
          // e: 56,
          image: "",
          show: true,
          type: 5,
        },
        // {
        //   deviceName: "储备站",
        //   state: 1,
        //   a: 25,
        //   b: 56,
        //   c: 54,
        //   d: 15,
        //   e: 56,
        //   image: "",
        //   show: true,
        //   type: 4,
        // },
      ],
    };
  },
  computed: {
    // 计算有多少个展示的对象,如果小于3个,就把justify-content: space-between;取消
    getShowNum() {
      return this.czList.filter((item) => item.show).length < this.addStartNum;
    },
  },
  mounted() {
    this.changeAddStartNum();
  },
  methods: {
    hide() {
      this.carHide = !this.carHide;
      // this.myCollapse();
    },
    // 根据父子元素自动计算是否需要添加值start
    changeAddStartNum() {
      const czItem = this.$refs.czItem;
      let czItemWidth;
      // 组件有可能是一个数组,所以要这样判断
      if (Array.isArray(czItem)) {
        const { width } = czItem[0].$el.getBoundingClientRect();
        czItemWidth = width;
      } else {
        const { width } = czItem.$el.getBoundingClientRect();
        czItemWidth = width;
      }
      // 取出collap的宽
      const { width: CollapseWidth } =
        this.$refs.myCollapse.$el.getBoundingClientRect();
      // 得到最小的承载数量
      this.addStartNum = Math.floor(CollapseWidth / czItemWidth);
    },
    //过滤选择
    fliterTypeChange(data) {
      this.filter([...data]);
      // 改变大小,因为动画原因加个延迟
      // this.$nextTick(() => {
      //   setTimeout(()=>{
      //     this.myCollapse()
      //   }, 300);
      // });
    },
    myCollapse() {
      // this.$refs.myCollapse.getHeight();
    },
    // 过滤对象
    filter(arr) {
      this.czList.forEach((item) => {
        const { type } = item;
        if (arr.includes(type)) {
          item.show = true;
        } else {
          item.show = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>

.container {
  width: 100%;
  flex-wrap: wrap;
  display: flex;
  &.start {
    justify-content: flex-start;
    & > div {
      // margin-right: 50px;
    }
  }
  & > div {
    margin-bottom: 20px;
    margin-left: 1%;
    width: 24%;
    min-width: 295px;
    border: 1px solid #e6ebf5;
    border-radius: 4px;

    box-sizing: border-box;
  }
}
.flex {
  display: flex;
  justify-content: space-between;
}
</style>