<!--
    上传图片的弹窗
-->

<template>
  <el-dialog title="上传图片" :visible.sync="dialog.uploadImgs" width="500px">
    <div style="max-height: 500px; overflow-y: auto;">
        <upload-imgs :readOnly="read" :keysArr="deepcopy(keysArr)" @change="changeItem" max="2"></upload-imgs>
    </div>
  </el-dialog>
</template>
<script>
  import uploadImgs from "@/components/ledger/lib/uploadImgs";

  export default {
    components: {
      uploadImgs
    },
    props: {
      dialog: {
        type: Object,
        default: function () {
          return {
            uploadImgs: true
          };
                }
            },
            keysArr: {
                type: Array,
                default: function () {
                    return []
                }
            },
            read: {
                type: Boolean,
                default: false
            },
            firmDataType: {
                type: String
            },
            information: {
                type: Object
            },
            infoType: {
                type: String
            }
        },
        data() {
            return {};
        },
        created() {
        },
        mounted() {
        },
        methods: {
    deepcopy(obj) {
      return JSON.parse(JSON.stringify(obj));
    },
    changeItem(file) {
        if (this.firmDataType === 'dialog') {
            let info = this.infoType
            switch (info) {
                case 'installPic':
                    this.information.installPic.InstallPic = file
                    this.$emit('changeFile', this.information, this.firmDataType)
                    break
                case 'installDrawing':
                    this.information.installDrawing.InstallDrawing = file
                  this.$emit('changeFile', this.information, this.firmDataType)
                  break
              case 'nameplate':
                this.information.nameplate.Nameplate = file
                this.$emit('changeFile', this.information, this.firmDataType)
                break
              case 'drawing':
                this.information.drawing.Drawing = file
                this.$emit('changeFile', this.information, this.firmDataType)
                break
              case 'infos.installPic':
                this.$emit("changeFile", info, this.firmDataType, file)
                break
              case 'infos.nameplate':
                this.$emit("changeFile", info, this.firmDataType, file)
                break
            }
        } else {
            this.$emit("changeFile", file)
        }

    }
  },
};
</script>
<style>
</style>
