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
  <template>
    <a-modal :title="title" :visible="visible" :width="700" @cancel="handleCloseModal" @ok="handleOpenCompareModal"
             :maskClosable="false">
      <a-table :dataSource="dataSource" :columns="columns" :pagination="false" bordered :scroll="{y:364}"
               :customRow="customRow"
               :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" rowKey="fileId">
        <template slot="fileName" slot-scope="text,record,index">
        <span :style="{color:setCurrentVersionColor(record.publishFlag)}">
          {{ text }}.{{ record.fileSuffix }}
          <span v-if="record.publishFlag">[当前版本]</span>
        </span>
        </template>
      </a-table>
 
      <FileCompareModal ref="fileCompareModalRef" :fileDiffObject="fileDiffObject" :fileVersionArray="fileVersionArray"/>
    </a-modal>
  </template>
 
  <script>
  import dncApi from '@/api/dnc'
  import FileCompareModal from './FileCompareModal'
 
  export default {
    name: 'SelectFileCompareModal',
    components: { FileCompareModal },
    props: {
      dataSource: {
        type: Array
      },
      setCurrentVersionColor: {
        type: Function
      }
    },
    data() {
      return {
        visible: false,
        title: '',
        selectedRowKeys: [],
        fileDiffObject: {},
        fileVersionArray: [],
        selectedFileInfo: {},
        columns: [
          {
            title: '序号',
            dataIndex: 'rowIndex',
            width: 65,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          { title: '文件名称', dataIndex: 'fileName', align: 'center', scopedSlots: { customRender: 'fileName' } },
          { title: '版本号', dataIndex: 'docVersion', align: 'center' }
        ]
      }
    },
    watch: {
      visible: {
        handler(value) {
          this.$nextTick(() => {
            const selectAllCheckboxNode = document.querySelector('.ant-table-selection-column .ant-table-selection')
            if (value) {
              if (this.dataSource.length > 2) selectAllCheckboxNode.style.display = 'none'
              else selectAllCheckboxNode.style.display = 'block'
            }
          })
        }
      }
    },
    methods: {
      /**
       * 定制表格行样式
       * @param record 表格行信息
       * @returns {{style: {color: *}}} 样式
       */
      customRow(record) {
        return {
          style: {
            color: this.setCurrentVersionColor(record.publishFlag)
          }
        }
      },
 
      /**
       * 当表格多选框改变时触发
       * @param selectedRowKeys 选中的每一行的key集合
       */
      onSelectChange(selectedRowKeys) {
        if (selectedRowKeys.length < 3) this.selectedRowKeys = selectedRowKeys
        else this.selectedRowKeys = selectedRowKeys.slice(-2)
      },
 
      // 打开对比窗口
      handleOpenCompareModal() {
        const { $confirm, $notification, selectedRowKeys, title, dataSource } = this
        if (selectedRowKeys.length < 2) {
          $notification.warning({
            message: '消息',
            description: '请勾选两个版本比对'
          })
          return
        }
        const that = this
        $confirm({
          title: '提示',
          content: '确认提交吗?',
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            that.fileVersionArray = []
            dncApi.fileCompareApi(selectedRowKeys)
              .then(res => {
                if (res.success) {
                  $notification.success({
                    message: '消息',
                    description: res.message
                  })
                  that.fileDiffObject = res.data
                  // 传递给子组件当前选中的文件版本号
                  selectedRowKeys.forEach(fileId => {
                    const selectedFileVersion = dataSource.find(item => item.fileId === fileId).docVersion
                    that.fileVersionArray.push(selectedFileVersion)
                  })
                  that.handleCloseModal()
                  if (!that.$refs.fileCompareModalRef) return
                  that.$refs.fileCompareModalRef.visible = true
                  that.$refs.fileCompareModalRef.title = title
                } else {
                  $notification.error({
                    message: '消息',
                    description: res.message
                  })
                }
              })
              .catch(err => {
                $notification.error({
                  message: '消息',
                  description: err.message
                })
              })
          }
        })
      },
 
      // 关闭窗口
      handleCloseModal() {
        this.visible = false
        this.selectedRowKeys = []
      }
    }
  }
  </script>
 
  <style scoped>
 
  </style>