ImageList.vue 2.92 KB
<template>
  <div class="image_list_page">
    <template v-if="imgList && imgList.length">
      <template v-for="(item, index) in imgList">
        <div class="image_cell" :key="`img_upload_${index}`" v-if="index < 20">
          <image-upload
            :value="item"
            :status="status"
            :limit="1"
            :list="workOrderDocs"
            @change="onChange('imgList')"
          ></image-upload>
          <div class="image_name" :title="item.originName">
            {{ item.originName || item.name }}
          </div>
        </div>
      </template>
    </template>
    <ImageOtherUpload
      v-model="otherList"
      :list="workOrderDocs"
      :limit="20-imgList.length"
      :status="status"
      :nameIndex="otherList.length"
      @change="onChange('otherList')"
    ></ImageOtherUpload>
  </div>
</template>
<script>
import ImageUpload from "./image.vue";
import ImageOtherUpload from "./otherImage.vue";
import {deepClone} from '@/utils/util';
export default {
  name: "ImageList",
  components: {
    ImageUpload,
    ImageOtherUpload,
  },
  props: {
    value: {
      type: Array,
      default: function () {
        return [];
      },
    },
    type: {
      type: [String, Number],
      default: 1, //
    },
    status: {
      //1:查看工单,不可编辑   2:编辑工单   3:激活工单    4:审核工单   5: 单独编辑图片
      type: [String, Number],
      default: "",
    },
  },
  watch: {
    value: {
      handler: function (n, o) {
        let m = [];
        let _other = [];
        n.map((k) => {
          // 固定位置
          if (k.source == "bhg") {
            m.push(k);
          } else {
            _other.push(k);
          }
        });

        // let len = m.length;
        // if (len <= 20) {
        //   this.limit = 20 - len - _other.length;
        // } else {
        //   this.limit = 1;
        // }
        // let _num = 20 - len - Number(_other.length);
        // this.limit = _num > 0 ? _num : 0;
        // console.log(this.limit);
        this.imgList = m;
        this.otherList = _other;
        this.workOrderDocs = n
      },
      immediate: true,
    },
  },
  data() {
    return {
      imgList: [], // 固定位置
      otherList: [], // 其他
      limit: 1,
      workOrderDocs:[], // 所有图片
    };
  },
  methods: {
    // 监听图片组件删除、上传更新
    onChange(id) {
      let m = deepClone(this.imgList);
      let _list = m.concat(this.otherList);
      console.log(_list);
      this.$emit("input", _list);
    },
  },
};
</script>

<style lang="scss" scoped>
.image_list_page {
  // display: flex;
  // flex-wrap: wrap;
  overflow: hidden;
  .image_cell {
    width: 120px;
    margin: 0 10px 10px 0;
    float: left;
  }
  .image_name {
    height: 30px;
    width: 100%;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    word-break: break-all;
    text-overflow: ellipsis;
    line-height: 30px;
  }
}
</style>