zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
<template>
  <a-modal
    :title='title'
    :width='1200'
    :visible='visible'
    :confirmLoading='confirmLoading'
    @ok='handleOk'
    @cancel='handleCancel'
  >
    <a-spin :spinning='confirmLoading'>
      <div>
        <a-transfer
          :data-source='dataSource'
          :target-keys='targetKeys'
          :disabled='disabled'
          :show-search='showSearch'
          :filter-option='(inputValue, item) => item.title.indexOf(inputValue) !== -1'
          :show-select-all='false'
          @change='onChange'
        >
          <template
            slot='children'
            slot-scope='{
          props: { direction, filteredItems, selectedKeys, disabled: listDisabled },
          on: { itemSelectAll, itemSelect },
        }'
          >
            <a-table
              :row-selection='
            getRowSelection({ disabled: listDisabled, selectedKeys, itemSelectAll, itemSelect })
          '
              :columns="direction === 'left' ? leftColumns : rightColumns"
              :data-source='filteredItems'
              size='small'
              :style="{ pointerEvents: listDisabled ? 'none' : null }"
              :custom-row='
            ({ key, disabled: itemDisabled }) => ({
              on: {
                click: () => {
                  if (itemDisabled || listDisabled) return;
                  itemSelect(key, !selectedKeys.includes(key));
                },
              },
            })
          '
            />
          </template>
        </a-transfer>
 
      </div>
 
    </a-spin>
 
    <!--   选择用户  -->
  </a-modal>
</template>
 
<script>
import JSelectUserByDepModal from '@/components/jeecgbiz/modal/JSelectUserByDepModal'
import { getAction, putAction } from '@/api/manage'
 
import difference from 'lodash/difference'
 
 
const leftTableColumns = [
  {
    dataIndex: 'title',
    title: '项目名称'
  },
  {
    dataIndex: 'description',
    title: '项目编号'
  }
]
const rightTableColumns = [
  {
    dataIndex: 'title',
    title: '项目名称'
  }
]
 
 
export default {
  name: 'ProGroupSelectModal',
  components: {
    JSelectUserByDepModal
  },
  data() {
    return {
      title: '选择项目',
      visible: false,
      model: {},
 
      confirmLoading: false,
      validatorRules: {},
 
      dataSource: [],
      targetKeys: [],
      disabled: false,
      showSearch: true,
      leftColumns: leftTableColumns,
      rightColumns: rightTableColumns,
      url: {
        list: '/pro/project/list',
        editBatch: '/pro/project/editBatch',
      }
    }
  },
  watch: {},
  methods: {
    edit(record) {
      this.visible = true
      this.model = Object.assign({}, record)
      this.loadData()
    },
 
    handleCancel() {
      this.close()
    },
    onChange(nextTargetKeys) {
      this.targetKeys = nextTargetKeys
    },
 
 
    getRowSelection({ disabled, selectedKeys, itemSelectAll, itemSelect }) {
      return {
        getCheckboxProps: item => ({ props: { disabled: disabled || item.disabled } }),
        onSelectAll(selected, selectedRows) {
          const treeSelectedKeys = selectedRows
            .filter(item => !item.disabled)
            .map(({ key }) => key)
          const diffKeys = selected
            ? difference(treeSelectedKeys, selectedKeys)
            : difference(selectedKeys, treeSelectedKeys)
          itemSelectAll(diffKeys, selected)
        },
        onSelect({ key }, selected) {
          itemSelect(key, selected)
        },
        selectedRowKeys: selectedKeys
      }
    },
    handleOk() {
      let  params = {id:this.targetKeys.join(","),groupCode:this.model.groupCode }
      this.confirmLoading = true
      putAction(this.url.editBatch,params).then(res=>{
       if(res.success){
         this.$message.success(res.message)
         this.$emit('ok')
         this.close()
 
       }
      }).finally(() => {
        this.confirmLoading = false
      })
 
    },
    loadData() {
      let params = { pageNo: 1, pageSize: 100000 }
      this.confirmLoading = true
      //拉取所有项目
      getAction(this.url.list, params).then((res) => {
        this.confirmLoading = false
        if (res.success) {
          let data = res.result.records
          //筛选未分配的项目和 当前项目集(groupCode)的项目
          this.dataSource = data.filter(item => item.id && (item.groupCode == null ||  item.groupCode == this.model.groupCode)).map(item => {
            return { key: item.id, title: item.xmmc, description: item.xmbh}
          })
          //当前项目集已分配项目
         this.targetKeys = data.filter(item => item.id && item.groupCode == this.model.groupCode).map(item=>item.id);
        }
      }).finally(() => {
        this.confirmLoading = false
      })
    },
 
    /*handleOk() {
      let that = this
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          //add
 
          putAction(this.url.edit, that.model)
            .then((res) => {
              that.confirmLoading = false
              if (res.success) {
                that.close()
                that.$message.success(res.message)
                that.$emit('ok', res.result)
                that.close()
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },*/
    close() {
      this.$emit('close')
      this.visible = false
    },
 
    handleChangeUserCommon(v) {
    }
  }
}
</script>
 
<style scoped>
</style>