gjj
2023-02-07 08690e2fd123a710406a101a2a5bd98fa0992502
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
<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="handleClick('remove')">移除</el-button>
      <el-button
        class="rc-head-item"
        type="primary"
        @click.native="handleClick('edit')">编辑</el-button>
      <el-button
        class="rc-head-item"
        type="primary"
        @click.native="handleClick('add')">添加团队成员</el-button>
    </flexbox>
    <el-table
      :data="list"
      :height="tableHeight"
      :header-cell-style="headerRowStyle"
      :cell-style="cellStyle"
      style="width: 100%;border: 1px solid #E6E6E6;"
      @row-click="handleRowClick"
      @selection-change="handleSelectionChange">
      <el-table-column
        :selectable="handleSelectable"
        show-overflow-tooltip
        type="selection"
        align="center"
        width="55"/>
      <el-table-column
        v-for="(item, index) in fieldList"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        show-overflow-tooltip/>
    </el-table>
    <teams-handle
      :crm-type="crmType"
      :selection-list="[detail]"
      :dialog-visible.sync="teamsDialogShow"
      title="添加团队成员"
      @handle="handleCallBack"/>
 
    <el-dialog
      v-loading="loading"
      :visible.sync="editPermissionShow"
      :append-to-body="true"
      title="编辑权限"
      width="400px">
      <div class="handle-box">
        <flexbox class="handle-item">
          <div class="handle-item-name">权限:</div>
          <el-radio-group v-model="handleType">
            <el-radio :label="1">只读</el-radio>
            <el-radio :label="2">读写</el-radio>
          </el-radio-group>
        </flexbox>
      </div>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button @click.native="editPermissionShow=false">取消</el-button>
        <el-button
          type="primary"
          @click.native="handleEditConfirm">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script type="text/javascript">
import loading from '../mixins/loading'
import TeamsHandle from './selectionHandle/TeamsHandle' // 操作团队成员
// import {
//   crmCustomerTeamMembers,
//   crmCustomerUpdateMembers,
//   crmCustomerSettingTeamDelete
// } from '@/api/customermanagement/customerManage'
// import {
//   crmBusinessTeamMembers,
//   crmBusinessUpdateMembers,
//   crmBusinessSettingTeamDelete
// } from '@/api/clients/business'
// import {
//   crmContractTeamMembers,
//   crmContractUpdateMembers,
//   crmContractSettingTeamDelete
// } from '@/api/clients/contract'
 
export default {
  name: 'RelativeTeam', // 相关团队  可能再很多地方展示 放到客户管理目录下
  components: {
    TeamsHandle
  },
  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',
      teamsDialogShow: false, // 是否展示添加团队成员窗口
      handleType: 1, // 权限类型
      editPermissionShow: false, // 编辑权限接口展示
      selectionList: [] // 勾选的数据
    }
  },
  computed: {},
  watch: {
    id: function (val) {
      this.list = []
      this.getDetail()
    }
  },
  mounted () {
    this.fieldList.push({ prop: 'realname', width: '200', label: '姓名' })
    this.fieldList.push({ prop: 'name', width: '200', label: '职位' })
    this.fieldList.push({ prop: 'groupRole', width: '200', label: '团队角色' })
    this.fieldList.push({ prop: 'power', width: '200', label: '权限' })
 
    this.getDetail()
  },
  activated: function () {},
  deactivated: function () {},
  methods: {
    getDetail () {
      this.loading = true
      const request = {
        // customer: crmCustomerTeamMembers,
        // business: crmBusinessTeamMembers,
        // contract: crmContractTeamMembers
      }[this.crmType]
      const params = {}
      params[this.crmType + 'Id'] = this.id
      request(params)
        .then(res => {
          this.loading = false
          this.list = res.data
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 当选择项发生变化时会触发该事件
    handleSelectionChange (val) {
      this.selectionList = val
    },
    handleClick (type) {
      if (type === 'add') {
        this.teamsDialogShow = true
      } else {
        if (this.selectionList.length === 0) {
          this.$message.error('请勾选需要操作的团队成员')
        } else {
          if (type === 'edit') {
            this.editPermissionShow = true
          } else if (type === 'remove') {
            this.$confirm('此操作将移除这些团队成员是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            })
              .then(() => {
                var userIds = this.selectionList.map(function (
                  item,
                  index,
                  array
                ) {
                  return item.id
                })
 
                const request = {
                  // customer: crmCustomerSettingTeamDelete,
                  // contract: crmContractSettingTeamDelete,
                  // business: crmBusinessSettingTeamDelete
                }[this.crmType]
 
                var params = {
                  ids: this.id,
                  memberIds: userIds.join(',')
                }
 
                this.loading = true
                request(params)
                  .then(res => {
                    this.$message({
                      type: 'success',
                      message: '操作成功'
                    })
                    this.loading = false
                    this.getDetail()
                  })
                  .catch(() => {
                    this.loading = false
                  })
              })
              .catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
              })
          }
        }
      }
    },
    /** 添加操作 */
    handleCallBack (data) {
      this.getDetail()
    },
    /** 编辑操作确定 */
    handleEditConfirm () {
      var userIds = this.selectionList.map(function (item, index, array) {
        return item.id
      })
      this.loading = true
      const request = {
        // customer: crmCustomerUpdateMembers,
        // business: crmBusinessUpdateMembers,
        // contract: crmContractUpdateMembers
      }[this.crmType]
      request({
        ids: this.id,
        memberIds: userIds.join(','),
        power: this.handleType
      })
        .then(res => {
          this.editPermissionShow = false
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.loading = false
          this.getDetail()
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 返回值用来决定这一行的 CheckBox 是否可以勾选
    handleSelectable (row, index) {
      if (row.power === '负责人权限') {
        return false
      }
      return true
    },
    // 当某一行被点击时会触发该事件
    handleRowClick (row, column, event) {},
    /** 通过回调控制表头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';
</style>