liuxiaolong
2019-05-06 d380e76ec9783bcd80eb42e495d6f8e1af0827b4
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
<template>
  <b-modal
    :title="title"
    size="lg"
    ref="uploadModal"
    ok-title="保存"
    @ok="handleOk"
    @cancel="clearName"
    cancel-title="取消"
    :hide-header="!title"
    :hide-footer="isShowFooter"
  >
    <div class="flex-center">
      <upload-common
        :isShowProgress="false"
        uploadBtntext="上传图片"
        :isList="false"
        limitTypes=".png,.jpg.jpeg.gif"
        title
        :isShowHr="false"
        :isMultiple="true"
        fileName="files"
        @addFilesBaBackFN="addFiles"
      />
    </div>
    <div class="upload-list row py-4" v-if="fileList && fileList.length">
      <ul
        v-for="attachment in fileList"
        :key="attachment.id"
        class="col-sm-6 col-md-4 col-lg-6 col-xl-3"
      >
        <li class="ui-bordered p-2 mr-3 mb-3 flex-center" :title="attachment.name">
          <b-form-checkbox
            class="attachment-check flex-center"
            v-model="attachment.iscChecked"
            :value="true"
            :unchecked-value="false"
          >
            <div
              :style="{'background-image': `url(/httpImage/${attachment.path})`}"
              class="message-attachment-img"
            ></div>
          </b-form-checkbox>
        </li>
      </ul>
    </div>
  </b-modal>
</template>
<script>
import uploadCommon from './uploadCommon'
export default {
  props: {
    title: String,
    item: Object,
    isShowFooter: {
      default: false
    }
  },
  data: () => ({
    fileList: []
  }),
  methods: {
    // * 打开modal
    showModel() {
      this.$refs.uploadModal.show()
      this.$nextTick(() => {
        this.fileList = []
        this.reView(this.item)
      })
    },
    hideModel() {
      this.$refs.uploadModal.hide()
    },
    /* 上传组件回调 */
    addFiles({ fileIds, fileList }) {
      this.fileList = [...this.fileList, ...fileList]
    },
    // 回显
    reView(item) {
      console.log(item, 'item----')
    },
    // * 提交表单
    handleOk(e) {
      e.preventDefault()
      const checkList = this.fileList.filter(item => item.iscChecked)
      const checkListkeys = checkList.map(item => item.id)
      if (!checkListkeys.length) {
        this.$toast({
          type: 'error',
          message: '您还没有选择图片'
        })
        return
      }
      this.$emit('submit', {
        checkList,
        checkListkeys
      })
    },
    // * 取消
    clearName() {}
  },
  components: {
    uploadCommon
  }
}
</script>
<style>
.attachment-check {
  width: 100%;
}
.attachment-check .custom-control-label::before {
  top: 1.5rem;
}
.upload-list ul li:hover {
  background: #f8f8f8;
}
</style>