Blame view

src/views/djbworkflow/components/clxx/index.vue 11.8 KB
1 2 3
<!--
 * @Description:
 * @Autor: renchao
4
 * @LastEditTime: 2023-10-24 17:17:46
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
-->
<template>
  <div class="clxx">
    <div class="right">
      <!-- 材料预览 -->
      <div class="clyl-box">
        <div class="menu-tree">
          <el-button
            type="primary"
            native-type="submit"
            @click="viewDetail"
            style="width: 100%; margin-top: 10px" v-if="tableData.length > 0">申请材料目录</el-button>
          <div class="item">
            材料目录({{ tableData.length }})
            <div style="margin-top: 10px">
              <div
                style="
                  text-align: center;
                  line-height: 20px;
                  color: black;
                  font-size: 14px;
                "
                v-if="tableData.length == 0">
                暂无数据
              </div>
              <div
                v-for="(item, index) in tableData"
32 33
                :key="item.bsmSj"
                :class="['child', treeCheckId == item.bsmSj ? 'checked' : '']"
34
                @click="treeClick(item, index)">
35 36 37
                <span v-if="item.isrequired == 1" class="required">必选</span>
                {{ item.sjmc }}
                <span class="cl_number" :key="key">({{ item.ys ? item.ys : 0 }})</span>
38 39 40 41 42 43 44 45 46 47 48
              </div>
            </div>
          </div>
          <el-button
            type="primary"
            native-type="submit"
            style="width: 100%"
            @click="handleAdd()">新增</el-button>
        </div>
        <image-preview
          ref="imageRef"
49
          :key="imgKey"
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
          v-if="tableData.length > 0"
          :previewImg="previewImg"
          @updateList="updateList"
          @nextPriview="nextPriview"
          @prevPriview="prevPriview" />
      </div>
    </div>
    <clxxAddDialog v-model="isDialog" />
  </div>
</template>
<script>
  import store from '@/store/index.js'
  import { ywPopupDialog } from "@/utils/popup.js";
  import imagePreview from "./dialog/imagePreview.vue";
  import clxxAddDialog from "./dialog/clxxAddDialog.vue";
  import clxxDetailDialog from "./dialog/clxxDetailDialog.vue";
66
  import { repairInitClml, saveClml, getClmxList } from "@/api/clxx.js";
67 68 69 70 71 72 73 74 75 76 77 78
  export default {
    components: { clxxAddDialog, imagePreview, clxxDetailDialog },
    props: {
      formData: {
        type: Object,
        default: () => {
          return {}
        }
      }
    },
    data () {
      return {
79
        imgKey: 0,
80 81 82 83 84 85 86 87
        isDialog: false,
        iclass: "",
        // 材料目录选中
        treeCheckIndex: 0,
        treeCheckId: "",
        key: 0,
        tableData: [],
        previewImg: {
88
          bsmSj: "",
89 90 91 92 93 94 95 96 97 98 99 100 101 102
          index: 0,
          selectedIndex: 0,
          imgList: []
        }
      }
    },
    computed: {
      workFresh () {
        return store.state.user.workFresh
      }
    },
    watch: {
      workFresh: {
        handler (newValue, oldValue) {
103
          if (newValue) this.clmlInitList(1)
104 105 106 107 108 109
        },
        deep: true,
        immediate: true
      }
    },
    created () {
110
      this.clmlInitList(1)
111 112 113 114 115 116 117 118 119 120
    },
    methods: {
      /**
       * @description: 自动预览
       * @author: renchao
       */
      nextPriview () {
        if (this.treeCheckIndex < this.tableData.length) {
          this.treeCheckIndex++;
          if (this.tableData[this.treeCheckIndex]) {
121
            this.treeCheckId = this.tableData[this.treeCheckIndex].bsmSj;
122 123 124 125 126
            // 判断页数
            let ys = this.tableData[this.treeCheckIndex].ys
            this.previewImg.index = 0;
            // 获取材料明细
            if (ys > 0) {
127
              getClmxList(this.treeCheckId).then(res => {
128 129 130 131 132
                this.previewImg.imgList = res.result ? res.result : []
              })
            } else {
              this.previewImg.imgList = []
            }
133
            this.previewImg.bsmSj = this.tableData[this.treeCheckIndex].bsmSj;
134 135 136 137 138 139 140 141 142 143 144 145
          } else {
            this.$message.error('没有最后一张了');
          }
        }
      },
      /**
       * @description: prevPriview
       * @author: renchao
       */
      prevPriview () {
        if (this.treeCheckIndex >= 1) {
          this.treeCheckIndex--;
146
          this.treeCheckId = this.tableData[this.treeCheckIndex].bsmSj;
147 148 149
          // 判断页数
          let ys = this.tableData[this.treeCheckIndex].ys
          if (ys > 0) {
150
            getClmxList(this.treeCheckId).then(res => {
151 152 153 154 155 156 157
              this.previewImg.imgList = res.result ? res.result : []
              this.previewImg.index = this.previewImg.imgList.length - 1;
            })
          } else {
            this.previewImg.imgList = [];
            this.previewImg.index = 0
          }
158
          this.previewImg.bsmSj = this.tableData[this.treeCheckIndex].bsmSj;
159 160 161 162 163 164 165 166 167 168 169 170
        } else {
          this.$message.error('没有第一张了');
        }
      },
      /**
       * @description: 材料目录明细初始化
       * @param {*} type
       * @author: renchao
       */
      clmlInitList (type) {
        // 1:列表初始化  2:新增材料
        return new Promise((resolve) => {
171
          repairInitClml(this.$parent).then((res) => {
172 173 174 175 176 177
            if (res.code == 200) {
              resolve(res.code);
              if (res.result && res.result.length > 0) {
                this.tableData = res.result;
                if (type == 1) {
                  this.treeClick(this.tableData[0], 0);
178
                } else if (type == 2) {
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
                  //新增材料后刷新列表焦点置于新增的对象上
                  this.treeClick(
                    this.tableData[this.tableData.length - 1],
                    this.tableData.length - 1
                  );
                }
              }
            } else {
              this.$message.error(res.message);
            }
          })
        })
      },
      /**
       * @description: setChecked
       * @param {*} item
       * @author: renchao
       */
      setChecked (item) {
198
        this.treeCheckId = item.bsmSj;
199 200 201 202
        this.title = item.sjmc;
        this.titleYs = 1;
        this.titleNum = item.children.length;
        this.previewImg.imgList = item.children;
203
        this.previewImg.bsmSj = item.bsmSj;
204 205 206 207 208 209 210 211 212 213 214
      },
      /**
       * @description: updateList
       * @param {*} val
       * @author: renchao
       */
      updateList (val) {
        let that = this;
        if (val.children.length != 0) {
          //删除最后一张图片时 val=null
          this.tableData.forEach((item) => {
215
            if (item.bsmSj == val.bsmSj) {
216
              item.ys = val.children.length
217 218 219 220 221 222 223 224 225 226
            }
          });
          this.previewImg.imgList = _.cloneDeep(val.children);
          if (this.previewImg.index == this.previewImg.imgList.length) {
            this.previewImg.index = this.previewImg.index - 1;
          }
          this.key++
        } else {
          this.previewImg.imgList = [];
          this.tableData.forEach((item, index) => {
227
            if (this.treeCheckId == item.bsmSj) {
228
              item.ys = 0;
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
              that.treeCheckIndex = index;
            }
          })
        }
      },
      /**
       * @description: 添加材料目录
       * @author: renchao
       */
      handleAdd () {
        this.isDialog = true;
      },
      /**
       * @description: 新增弹窗保存
       * @param {*} data
       * @author: renchao
       */
      addSave (data) {
247 248 249 250 251 252 253 254 255 256 257 258 259
        let obj = {
          bsmSlsq: this.$parent.bsmSlsq,
          isrequired: "1",
          sjmc: data.clmc,
          sjsl: 0,
          smzt: "",
          ys: 0,
          sjlx: data.cllx,
          sjbm: data.clbm,
          sfxjcl: "1", // 是否必选
          sfggcl: data.sfggcl,
        };
        //是否公共材料
260
        obj["bsmSldy"] = this.$parent.currentSelectProps.bsmRepair;
261
        saveClml(obj).then(async (res) => {
262 263 264 265 266
          if (res.code == 200) {
            let res = await this.clmlInitList(2);
            if (res == 200)
              this.$message({
                message: "新增成功",
267 268
                type: "success",
              });
269
          }
270
        });
271 272 273 274 275 276 277 278 279
      },
      /**
       * @description: 材料目录点击选中
       * @param {*} item
       * @param {*} index
       * @author: renchao
       */
      treeClick (item, index) {
        this.previewImg.index = 0;
280
        this.treeCheckId = item?.bsmSj;
281
        this.treeCheckIndex = index;
282
        getClmxList(item.bsmSj).then(res => {
283 284
          this.previewImg.imgList = res.result ? res.result : []
        })
285
        this.previewImg.bsmSj = item?.bsmSj;
286 287 288
        if (this.$refs.imageRef) {
          this.$refs.imageRef.initialIndex = 0
        }
289
        this.imgKey++
290 291 292 293 294 295 296 297 298 299 300 301
      },
      /**
       * @description: 小图片点击
       * @param {*} item
       * @param {*} index
       * @author: renchao
       */
      imgClick (item, index) {
        this.showImg = item;
        this.titleYs = index + 1;
      },
      //查看明细
302
      async viewDetail () {
303 304 305 306 307 308
        await this.clmlInitList();
        store.dispatch("user/reWorkFresh", false);
        ywPopupDialog("申请材料目录", "djbworkflow/components/clxx/dialog/clxxDetailDialog", {
          data: this.tableData,
          ableOperation: this.$parent.ableOperation
        }, "60%", true, false)
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
      },
      //设置tableData
      setTableData (tableData) {
        this.$nextTick((res) => {
          this.tableData = tableData;
        })
      }
    }
  }
</script>
<style scoped lang="scss">
  @import "~@/styles/mixin.scss";
  .active {
    background: $light-blue !important;
    color: #fff;
  }

  .required {
    font-size: 12px;
    color: $pink;
    float: left;
  }

  .cl_number {
    float: right;
  }

  .clxx {
    width: 100%;
    height: 94%;
    display: flex;
    padding-left: 5px;
    .left {
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .item {
        width: 28px;
        height: 49%;
        @include flex-center;
        background-color: #e4e7ed;
        border-bottom-right-radius: 10px;
        padding: 5px;
        cursor: pointer;
        transition: all 0.3s;

        &:hover {
          @extend .active;
        }
      }
    }

    .right {
      width: 100%;
      height: 100%;

      .clmlmx-box {
        margin: 0 auto;

        .title {
          text-align: center;
          height: 60px;
          line-height: 60px;
          border: 1px solid #dfe6ec;
          font-size: 20px;
          background: #81d3f81a;
          margin-bottom: -1px;
        }
      }

      .clyl-box {
        width: 100%;
        height: 100%;
        display: flex;

        .menu-tree {
          width: 20%;
          min-width: 160px;
          height: 100%;
          margin-right: 10px;
          border-right: 1px dotted #d9d9d9;
          padding: 0 15px;

          .item {
            line-height: 30px;
            padding-top: 5px;
            border-bottom: 1px solid #e8e8e8;
            font-size: 16px;
            text-align: center;
            color: $light-blue;

            .itemIcon {
              float: right;
              line-height: 60px;
              cursor: pointer;
            }

            .child {
              line-height: 32px;
              border-bottom: 1px solid #e8e8e8;
              padding-left: 10px;
              color: #6b6b6b;
              cursor: pointer;
              box-sizing: border-box;
              border-radius: 6px;
              line-height: 20px;
              transition: all 0.3s;
              padding: 8px 0;
418
              overflow: hidden;
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
            }

            .child:hover {
              color: $light-blue;
              transform: scale(1.1);
            }

            .checked {
              border: 1px solid $light-blue;
              color: $light-blue;
            }
          }
        }

        .clyl-img {
          width: 75%;
          height: 100%;
          background: #f3f4f7;
          margin: 0 auto;
          position: relative;
        }
      }
    }
  }
</style>