1. <template>
    2. <div>
    3. <div class="title-left">
    4. 现场照片:
    5. </div>
    6. <div class="peer">
    7. <el-image
    8. style="width: 150px; height: 150px;margin-left: 5px"
    9. v-for="(item,index) in fileList"
    10. :src="item"
    11. ref="previewImage"
    12. :key="index"
    13. @click.capture="handlePreviewImage(index)">
    14. </el-image>
    15. </div>
    16. <el-upload
    17. ref="elUpload"
    18. :action="uploadUrl"
    19. :data="fileData"
    20. list-type="picture-card"
    21. :on-success="handleSuccess"
    22. :on-error="uploadError"
    23. :before-upload="beforeUpload"
    24. style="padding: 0 20px; display: inline"
    25. >
    26. <i class="el-icon-plus"></i>
    27. <div slot="file" slot-scope="{file}">
    28. <el-image id="122" ref="previewImg" :src="file.url" :preview-src-list='file.url' lazy></el-image>
    29. <span class="el-upload-list__item-actions">
    30. <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
    31. <i class="el-icon-zoom-in"/>
    32. </span>
    33. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
    34. <i class="el-icon-download"/>
    35. </span>
    36. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
    37. <i class="el-icon-delete"/>
    38. </span>
    39. </span>
    40. </div>
    41. </el-upload>
    42. <!--图片预览-->
    43. <el-image-viewer :z-index="2002" v-if="showViewer"
    44. :on-close="closeViewer" :initial-index="initialIndex"
    45. :onSwitch="onSwitch"
    46. :url-list="dialogImageUrl"/>
    47. </div>
    48. </template>
    49. <script>
    50. import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
    51. import {getZjdlyFileInfo} from "@/assets/js/zjdsjjg/zd";
    52. export default {
    53. name: "ZjdsjjgZjdzdZjdly",
    54. props: {
    55. parameter: {}
    56. },
    57. created: function () {
    58. this.getZjdlyFileInfo(this.parameter.iid);
    59. },
    60. computed: {
    61. fileData: function () {
    62. return {
    63. iid: this.parameter.iid,
    64. userid: window.getCookie('userId')
    65. // "token": this.token,
    66. // "args": [this.token, this.iid]
    67. }
    68. },
    69. },
    70. components: {
    71. ElImageViewer
    72. },
    73. data() {
    74. return {
    75. uploadUrl: this.$API.uploadSignImg + "?jwt=" + window.getCookie("token"),
    76. dialogImageUrl: [],
    77. disabled: false,
    78. fileList: [],
    79. showViewer: false, // 显示查看器
    80. token: window.getCookie("token"),
    81. initialIndex: 0
    82. }
    83. },
    84. methods: {
    85. ontopfunction: function (data, json) {
    86. this.$emit("ontopfunction", data, json);
    87. },
    88. // 删除
    89. handleRemove(file, fileList) {
    90. let uploadFiles = this.$refs.elUpload.uploadFiles;
    91. uploadFiles.forEach((value, index) => {
    92. if (value.uid === file.uid) {
    93. uploadFiles.splice(index, 1)
    94. this.fileList.splice(index, 1)
    95. }
    96. })
    97. },
    98. // 大图预览
    99. handlePictureCardPreview(file) {
    100. this.dialogImageUrl = file.url || file.response.imgUrl;
    101. this.showViewer = true;
    102. },
    103. // 下载图片
    104. handleDownload(file) {
    105. let a = document.createElement('a');
    106. a.download = file.name;
    107. a.href = (file.url);
    108. a.click();
    109. },
    110. // 上传前检查
    111. beforeUpload(file) {
    112. const fileType = file.type,
    113. isImage = fileType.indexOf('image') !== -1,
    114. isLt2M = file.size / 1024 / 1024 < 2;
    115. if (!isImage) {
    116. this.$message.error('上传图片格式只能是png、jpg、gif!');
    117. }
    118. return isImage;
    119. },
    120. //上传失败
    121. uploadError() {
    122. this.$message.error('上传失败!');
    123. },
    124. //上传成功
    125. handleSuccess(res, file, list) {
    126. let self = this;
    127. let status = res.status;
    128. if (status == -1) {
    129. self.$message.error('上传失败!');
    130. } else {
    131. self.fileList.push(res.data.result);
    132. self.$message.success('上传成功!');
    133. }
    134. },
    135. // 关闭
    136. closeViewer() {
    137. this.showViewer = false;
    138. },
    139. // 获取现场照片
    140. getZjdlyFileInfo(iid) {
    141. let self = this;
    142. getZjdlyFileInfo([self.token, iid]).then(res => {
    143. if (res.data.status == 0) {
    144. let result = eval('(' + res.data.result + ')');
    145. self.fileList = result;
    146. }
    147. });
    148. },
    149. // 预览图查看
    150. handlePreviewImage(index) {
    151. this.dialogImageUrl = this.fileList;
    152. this.initialIndex = index;
    153. this.showViewer = true;
    154. },
    155. // 切换下一张预览图
    156. onSwitch(index){
    157. this.initialIndex = index;
    158. }
    159. }
    160. }
    161. </script>
    162. <style scoped>
    163. .title-left {
    164. font-size: 26px;
    165. height: 40px;
    166. }
    167. .peer {
    168. display: inline-block;
    169. }
    170. </style>