zjf
2023-02-24 2126cd24b8a0174ac0597340917c0a4595f72254
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<template>
  <div class="rc-cont">
    <flexbox
      v-if="!isSeas"
      class="rc-head"
      direction="row-reverse">
      <!--<el-button
        class="rc-head-item"
        type="primary"
        @click.native="addFile">上传附件</el-button>-->
      <input
        id="file"
        type="file"
        class="rc-head-file"
        accept="*/*"
        multiple
        @change="uploadFile">
    </flexbox>
    <el-table
      :data="list"
      :height="tableHeight"
      :header-cell-style="headerRowStyle"
      :cell-style="cellStyle"
      align="center"
      header-align="center"
      style="width: 100%;border: 1px solid #E6E6E6;"
      @row-click="handleRowClick">
      <el-table-column
        v-for="(item, index) in fieldList"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        :formatter="fieldFormatter"
        show-overflow-tooltip/>
      <!--<el-table-column
        label="操作"
        width="150">
        <template slot-scope="scope">
          <flexbox justify="center">
            <el-button
              type="text"
              @click.native="handleFile('preview', scope)">预览</el-button>
            <el-button
              type="text"
              @click.native="handleFile('edit', scope)">重命名</el-button>
            <el-button
              type="text"
              @click.native="handleFile('delete', scope)">删除</el-button>
          </flexbox>
        </template>
      </el-table-column> -->
    </el-table>
    <div class="p-contianer" v-show='total>0'>
      <el-pagination
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size.sync="pageSize"
        :total="total"
        class="p-bar"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
    <el-dialog
      :append-to-body="true"
      :visible.sync="editDialog"
      title="编辑"
      width="30%">
      <el-form :model="editForm">
        <el-form-item
          label="新名称"
          label-width="100">
          <el-input
            v-model="editForm.name"
            autocomplete="off"/>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer">
        <el-button @click="editDialog = false">取 消</el-button>
        <el-button
          type="primary"
          @click="confirmEdit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script type="text/javascript">
import loading from '../mixins/loading'
import { GetCustomerDocumentFileList } from '@/api/customermanagement/customerManage'
import { GetSalesDocumentFileList } from '@/api/customermanagement/business'
import { GetContacterDocumentFileList } from '@/api/customermanagement/contacts'
// import {
//   crmFileSave,
//   crmFileIndex,
//   crmFileDelete,
//   crmFileUpdate
// } from '@/api/common'
 
export default {
  name: 'RelativeFiles', // 相关附件  可能再很多地方展示 放到客户管理目录下
  components: {},
  mixins: [loading],
  props: {
    /** 模块ID */
    id: [String, Number],
    /** 联系人人下 新建商机 需要联系人里的客户信息  合同下需要客户和商机信息 */
    detail: {
      type: Object,
      default: () => {
        return {}
      }
    },
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    },
    /** 是公海 默认是客户 */
    isSeas: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      list: [],
      fieldList: [],
      tableHeight: '400px',
      /** 重命名 弹窗 */
      editDialog: false,
      /** 编辑信息 */
      editForm: { name: '', data: {} },
      total: 0,
      currentPage: 1,
      pageSize: 10,
      pageSizes: [10, 30, 60, 100]
    }
  },
  computed: {},
  watch: {
    id: function (val) {
      this.list = []
      this.getDetail()
    }
  },
  mounted () {
    this.fieldList.push(
      { prop: 'DocumentName', label: '附件名称', width: '300' },
      { prop: 'Comment', label: '备注', width: '400' },
      { prop: 'DocumentFileName', label: '文档文件名', width: '400' },
      { prop: 'FileExtensionName', label: '扩展名', width: '200' },
      // { prop: 'DocumentType', label: '文档所属业务类型', width: '200' },
      { prop: 'FileType', label: '文档附件类型', width: '100' },
      { prop: 'CreateTime', label: '创建时间', width: '200' }
    )
 
    this.getDetail()
  },
  activated: function () {},
  deactivated: function () {},
  methods: {
    handleSizeChange (newSize) {
      this.pageSize = newSize
      this.getDetail()
    },
    handleCurrentChange (newPage) {
      this.currentPage = newPage
      this.getDetail()
    },
    getDetail () {
      this.loading = true
      const request = {
        customer: GetCustomerDocumentFileList,
        business: GetSalesDocumentFileList,
        contacts: GetContacterDocumentFileList
      }[this.crmType]
      const params = {}
      params['Id'] = this.id
      params['PageSize'] = this.pageSize
      params['PageIndex'] = this.currentPage
      request(params)
        .then(res => {
          this.loading = false
          this.list = res.data.Result
          this.total = res.data.Result.length
        })
        .catch(() => {
          this.loading = false
        })
    },
    /** 格式化字段 */
    fieldFormatter (row, column) {
      // 如果需要格式化
      if (column.property === 'FileType') {
        return this.getStatusName(row.FileType)
      }
      return row[column.property] || '--'
    },
    getStatusName (status) {
      if (status === 1) {
        return '附件'
      } else if (status === 2) {
        return '图片'
      }
      return '暂无'
    },
    addFile () {
      document.getElementById('file').click()
    },
    /** 图片选择出发 */
    uploadFile (event) {
      var files = event.target.files
      for (let index = 0; index < files.length; index++) {
        const file = files[index]
        // if (file.type.indexOf('image') !== -1) {
        var params = {}
        params.batchId = this.detail.batchId
        params.file = file
        // crmFileSave(params)
        //   .then(res => {
        //     this.getDetail()
        //   })
        //   .catch(() => {})
        // }
      }
 
      event.target.value = ''
    },
    // 当某一行被点击时会触发该事件
    handleRowClick (row, column, event) {},
    /** 编辑删除cell */
    handleFile (type, item) {
      if (type === 'preview') {
        var previewList = this.list.map(element => {
          element.url = element.DocumentFileName
          return element
        })
        this.$bus.emit('preview-image-bus', {
          index: item.$index,
          data: previewList
        })
      } else if (type === 'delete') {
        this.$confirm('您确定要删除该文件吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            // crmFileDelete({
            //   id: item.row.fileId
            // })
            //   .then(res => {
            //     this.list.splice(item.$index, 1)
            //     this.$message.success('操作成功')
            //   })
            //   .catch(() => {})
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            })
          })
      } else {
        this.editForm.data = item
        this.editForm.name = item.row.name
        this.editDialog = true
      }
    },
    confirmEdit () {
      if (this.editForm.name) {
        // crmFileUpdate({
        //   fileId: this.editForm.data.row.fileId,
        //   name: this.editForm.name
        // })
        //   .then(res => {
        //     this.$message.success('编辑成功')
        //     this.editDialog = false
        //     var item = this.list[this.editForm.data.$index]
        //     item.name = this.editForm.name
        //   })
        //   .catch(() => {})
      }
    },
    /** 通过回调控制表头style */
    headerRowStyle ({ row, column, rowIndex, columnIndex }) {
      return { textAlign: 'left' }
    },
    /** 通过回调控制style */
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      return { textAlign: 'left' }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../styles/relativecrm.scss';
.h-item {
  font-size: 13px;
  color: #409eff;
  margin: 0 5px;
  cursor: pointer;
}
 
.rc-head-file {
  position: absolute;
  top: 0;
  right: 0;
  height: 98px;
  width: 98px;
  opacity: 0;
  z-index: -1;
  cursor: pointer;
}
</style>