Blame view

src/views/lpb/lpbContent/ch.vue 10.7 KB
1 2 3 4
<!--
 * @Author: yangwei
 * @Date: 2023-02-28 15:47:12
 * @LastEditors: yangwei
5
 * @LastEditTime: 2023-09-20 17:14:39
6
 * @FilePath: \bdcdj-web\src\views\lpb\lpbContent\ch.vue
yuanbo committed
7 8 9
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
10 11 12 13 14 15 16 17 18
-->
<template>
  <div class="ch-wrap">
    <table
      class="chTable"
      ref="ch"
      border="1"
      cellspacing="0"
      cellpadding="0"
19
      v-show="ch.length">
20 21 22 23 24 25
      <tr v-for="(cs, csIndex) in ch" :key="csIndex">
        <!-- 显示层数 -->
        <td
          class="floor"
          ref="cBsm"
          @contextmenu.prevent="openMenu($event, cs, 'c')"
26
          @click="handleClickC($event, cs)">
27 28 29 30 31 32 33 34 35 36 37
          {{ cs.sjc }}
        </td>
        <!-- 显示户 -->
        <td
          v-for="(hs, hsIndex) in cs.hs"
          :rowspan="hs.sjcs"
          :colspan="hs.sjhs"
          :data-bsm="hs.bsm"
          :data-qszt="hs.qszt"
          ref="hBsm"
          :key="hsIndex"
yangwei committed
38
          :style="{'border-color': borderColor}"
39 40 41
          :class="hs.select ? 'tdSelect' : ''"
          @click="handleClickH($event.target, hs.bsm, hs)"
          @dblclick="dbclick(hs.bsm)"
42
          @contextmenu.prevent="openMenu($event, hs, 'h')">
43
          {{ hs.shbw }}
44 45 46
          <span @click.stop="" class="hqszt lin" v-show="hs.qszt == '0'"></span>
          <span @click.stop="" class="hqszt zheng" v-show="hs.qszt == '1'"></span>
          <span @click.stop="" class="hqszt xian" v-show="hs.qszt == '2'"></span>
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
          <ul @click.stop="hDyztClick($event, hs.bsm, hs)" class="dyzt">
            <li style="background-color: #6edee1" v-show="hs.qqzt == '1'">

            </li>
            <li style="background-color: #8adc88" v-show="hs.bazt == '1'">

            </li>
            <li style="background-color: #ff8282" v-show="hs.dyzt == '1'">

            </li>
            <li style="background-color: #d7cecf" v-show="hs.cfzt == '1'">

            </li>
            <li style="background-color: #d4a3eb" v-show="hs.yyzt == '1'">

            </li>
            <li style="background-color: #a5a3fb" v-show="hs.xzzt == '1'">

            </li>
          </ul>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "BdcdjWebCh",
yangwei committed
76 77 78 79
  inject: {
    openMenu:{value:'openMenu',default:null},
    selectAll:{value:'selectAll',default:null},
    changeChoosedObj:{value:'changeChoosedObj',default:null},
yangwei committed
80 81
    clearChangeChoosedObj:{value:'clearChangeChoosedObj',default:null},
    getBsmList:{value:'getBsmList',default:null}
yangwei committed
82
  },
83 84 85 86 87 88 89
  props: {
    ch: {
      type: Array,
      default: function () {
        return [];
      },
    },
90 91 92 93
    onlyShow:{
      type: Boolean,
      default: true,
    }
94 95 96 97 98 99 100 101 102
  },
  data() {
    return {
      //选中户bsm合集
      hbsmList: [],
      //选中层bsm合集
      cbsmList: [],
      //区分单双击事件的定时器
      time: null,
yangwei committed
103
      // 边框颜色
yangwei committed
104 105
      borderColor:'rgb(230, 230, 230)',
      // 申请单元列表数据
yangwei committed
106 107 108
      unitIdList:[],
      // 组件标识
      compFlag:Math.random()
109 110
    };
  },
yangwei committed
111 112
  mounted() {
    // 根据申请单元列表数据处理选中户
113
    console.log("window.unitData",window.unitData);
yangwei committed
114
    if(window.unitData && window.unitData.length){
yangwei committed
115
      window.unitData.forEach(e => {
116
        this.unitIdList.push(e.bdcdyid)
yangwei committed
117 118 119
      })
      this.ch.forEach((c) => {
        c.hs.forEach((h) => {
120
          if (h.dyhbsm.indexOf(this.unitIdList) > -1) {
yangwei committed
121 122 123 124 125 126 127 128
            h.select = true;
            // 使用hbsmList时,需要去重
            this.hbsmList.push(h.bsm)
          }
        });
      });
    }
  },
129 130
  methods: {
    // 层选中事件
yuanbo committed
131 132 133 134 135 136
    /**
     * @description: 层选中事件
     * @param {*} e
     * @param {*} item
     * @author: renchao
     */
137
    handleClickC(e, item) {
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
      if (!this.onlyShow) {
        // 判断点击的层是否选中
        if (e.target.className.indexOf("tdSelect") == -1) {
          //未选中→选中
          item.hs.forEach((h) => {
            //加边框
            e.target.className += " tdSelect";
            h.select = true;
            // 使用hbsmList时,需要去重
            this.hbsmList.push(h.bsm)
          });
        } else {
          //选中→未选中
          item.hs.forEach((h) => {
            e.target.className = "floor";
            h.select = false;
            this.hbsmList = this.hbsmList.filter((i) => i != h.bsm);
          });
        }
yangwei committed
157
      }
158 159
    },
    //户单击事件
yuanbo committed
160 161 162 163 164 165 166
    /**
     * @description: 户单击事件
     * @param {*} e
     * @param {*} bsm
     * @param {*} hs
     * @author: renchao
     */
167
    handleClickH(e, bsm, hs) {
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      if (!this.onlyShow) {
        let self = this;
        // 开启延时器,200ms的间隔区分单击和双击,解决双击时执行两次单击事件
        clearTimeout(self.time);
        self.time = setTimeout(() => {
          // this.closeMenu();
          //判断点击的户是否选中
          if (!hs.select) {
            //未选中→选中
            //加边框
            hs.select = true;
            // 将户bsm放进hbsmList
            self.hbsmList.push(bsm);
          } else {
            //选中→未选中
            hs.select = false;
            self.hbsmList = self.hbsmList.filter((i) => i != bsm);
          }
          //更新当前选中户数据
          this.$forceUpdate();
        }, 200);
      }
190 191
    },
    // 户单元状态点击事件
yuanbo committed
192 193 194 195 196 197 198
    /**
     * @description: 户单元状态点击事件
     * @param {*} e
     * @param {*} bsm
     * @param {*} hs
     * @author: renchao
     */
199
    hDyztClick(e, bsm, hs) {
200 201 202
      if (!this.onlyShow) {
        this.handleClickH(e.target.parentNode, bsm, hs);
      }
203 204
    },
    //户双击事件
yuanbo committed
205 206 207 208 209
    /**
     * @description: 户双击事件
     * @param {*} bsm
     * @author: renchao
     */
210
    dbclick(bsm) {
yangwei committed
211
      // clearTimeout(this.time);
212 213
    },
    //幢单元全选/反选
yuanbo committed
214 215 216 217 218 219
    /**
     * @description: 幢单元全选/反选
     * @param {*} val
     * @param {*} flag
     * @author: renchao
     */
yangwei committed
220 221 222
    zdySelectAll(val,flag) {
      // 手动点击全部取消选中
      !flag &&  this.clearChangeChoosedObj()
223 224 225 226 227 228 229 230
      this.ch.forEach((c) => {
        c.hs.forEach((h) => {
          if (val) {
            h.select = true;
            // 使用hbsmList时,需要去重
            this.hbsmList.push(h.bsm)
          } else {
            h.select = false;
yangwei committed
231
            this.borderColor = 'rgb(230, 230, 230)'
232 233 234 235
            this.hbsmList = []
          }
        });
      });
yangwei committed
236 237 238 239 240
      this.$refs.hBsm && this.$refs.hBsm.forEach((item) => {
        // item.style.borderColor = this.borderColor
        item.style.backgroundColor =  '#fff';
        // item.style.border = `1px solid ${this.borderColor}`
      });
241
    },
yangwei committed
242 243 244 245 246 247 248 249 250 251
    //清除选中
    clearChoosed(){
      //清除选中户
      this.zdySelectAll(false)
      //清除选中层
      this.cbsmList = [];
      this.$refs.cBsm && this.$refs.cBsm.forEach((item)=>{
        item.className = 'floor'
      })
    },
252 253 254 255 256
  },
  watch: {
    selectAll: {
      handler(val) {
        this.zdySelectAll(val.selectAll);
yangwei committed
257
        val.cancelChoosed && this.clearChoosed()
258 259 260 261
      },
      immediate: true,
      deep: true,
    },
yangwei committed
262
    hbsmList(val){ 
yangwei committed
263 264 265
      let list = []
      val.length && val.forEach((i)=>{
        this.ch.forEach((c) => {
yangwei committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279
          c.hs.forEach((h) => {
            if (i == h.bsm) {
              list.push(
                {
                  bdcdyh:h.bdcdyh,
                  bsm:h.bsm,
                  dyhbsm:h.dyhbsm,
                  bdcdyid:h.dyhbsm,
                  bdcdylx:'7',
                  flag:this.compFlag
                }
              )
            }
          });
yangwei committed
280 281
        });
      })
yangwei committed
282
      this.getBsmList(list,this.compFlag)
yangwei committed
283
    },
yangwei committed
284 285 286 287
    changeChoosedObj: {
      handler(val) {
        this.borderColor = 'rgb(230, 230, 230)';
        if (val.bsms.length) {
yangwei committed
288 289
          //清除选中户
          this.zdySelectAll(false,true)
yangwei committed
290 291 292 293 294 295 296 297
          this.$refs.hBsm.forEach((item) => {
            val.bsms.forEach((i,ind) => {
              if (item.dataset.bsm == i) {
                if (ind == 0) {
                  //定位到第一个户所在位置
                  window.lpbContent.$refs.lpbContent.scrollTop = item.offsetTop;
                  window.lpbContent.$refs.lpbContent.scrollLeft = item.offsetLeft;
                }
yangwei committed
298 299 300
                // item.style.border = '1px solid '+ val.color;
                // 背景色高亮
                item.style.backgroundColor =  val.color;
yangwei committed
301 302 303 304 305 306 307
              }
            });
          });
        }
      },
      immediate: true,
      deep: true,
yangwei committed
308
    }
309 310 311 312
  },
};
</script>
<style lang="scss" scoped>
313 314 315 316 317 318 319 320 321 322
  .ch-wrap {
    display: flex;
    flex-direction: column-reverse;
    .chTable {
      // margin-left: -1px;
      border-color: #e4ebf4 !important;
      border-collapse: collapse;
      border-spacing: 0;
      // position: relative;
      tr {
yangwei committed
323
        .floor {
324 325 326
          min-width: 56px;
          background: #e8f2ff;
          border: 1px solid #acbae8;
327
        }
328 329 330 331
        &:first-child {
          .floor {
            border-radius: 4px 0px 0px 1px;
          }
332
        }
333 334 335 336 337 338 339 340
        td {
          min-width: 138px;
          height: 64px;
          line-height: 64px;
          text-align: center;
          cursor: pointer;
          position: relative;
          .hqszt {
341
            display: inline-block;
342 343
            width: 16px;
            height: 16px;
344
            font-size: 12px;
345 346 347 348
            line-height: 16px;
            position: absolute;
            left: 6px;
            top: 6px;
349
            border: 1px solid;
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
            border-radius: 3px 0px 3px 0px;
          }
          .lin {
            color: #f7b500;
            border-color: #f7b500;
          }
          .zheng {
            color: #1ad6e1;
            border-color: #1ad6e1;
          }
          .xian {
            color: #45aefd;
            border-color: #45aefd;
          }
          .dyzt {
            user-select: none;
            width: 138px;
            height: 18px;
            position: absolute;
            bottom: 28px;
            box-sizing: border-box;
            padding: 0 6px;
            li {
              display: inline-block;
              width: 18px;
              height: 18px;
              font-size: 12px;
              line-height: 18px;
              color: #ffffff;
              border: 1px solid;
              border-radius: 9px;
            }
382 383
          }
        }
384 385 386 387 388 389 390 391 392 393 394 395
        .tdSelect {
          border: 1px solid;
          border-color: #5a78de !important;
          background-image: url("./images/tdSelect.png");
          background-repeat: no-repeat;
          background-position: right top;
          background-size: 30px;
        }
        .hasBorder {
          border-width: 1px;
          border-style: solid;
        }
396 397 398 399
      }
    }
  }
</style>