zjf
2023-03-08 51468f93275c2bcfcc7ad25bf05f3d6a079ff764
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
<template>
  <el-dialog
    v-loading="loading"
    :visible.sync="visible"
    :append-to-body="true"
    title="批量转移"
    width="400px"
    @close="handleCancel">
    <div class="handle-box">
      <flexbox class="handle-item">
        <div class="handle-item-name">变更负责人为:</div>
        <xh-user-cell
          class="handle-item-content"
          placeholder="点击选择"
          @value-change="userChage"/>
      </flexbox>
      <flexbox
        v-if="showRemoveType"
        class="handle-item">
        <div class="handle-item-name">将原负责人:</div>
        <el-radio-group v-model="removeType">
          <el-radio :label="1">移出</el-radio>
          <el-radio :label="2">转为团队成员</el-radio>
        </el-radio-group>
      </flexbox>
      <flexbox
        v-if="removeType === 2"
        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>
      <!-- 仅客户下可进行同时变成负责人 -->
      <flexbox
        v-if="crmType === 'customer'"
        class="handle-item">
        <div class="handle-item-name">同时变更负责人至:</div>
        <el-checkbox-group v-model="addsTypes">
          <el-checkbox label="1" checked>联系人</el-checkbox>
          <el-checkbox label="2">商机</el-checkbox>
          <el-checkbox label="3">合同</el-checkbox>
        </el-checkbox-group>
      </flexbox>
    </div>
    <span
      slot="footer"
      class="dialog-footer">
      <el-button @click.native="handleCancel">取消</el-button>
      <el-button
        type="primary"
        @click.native="handleConfirm">保存</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import { XhUserCell } from '@/components/CreateCom'
// import { crmCustomerTransfer } from '@/api/customermanagement/customerManage'
// import { crmContactsTransfer } from '@/api/clients/contacts'
// import { crmBusinessTransfer } from '@/api/clients/business'
// import { crmContractTransfer } from '@/api/clients/contract'
// import { crmLeadsTransfer } from '@/api/clients/clue'
 
export default {
  /** 客户管理 的 勾选后的 转移 操作 */
  name: 'TransferHandle',
  components: {
    XhUserCell
  },
  mixins: [],
  props: {
    dialogVisible: {
      type: Boolean,
      required: true,
      default: false
    },
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    },
    /** 转移数据 */
    selectionList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      loading: false, // 加载动画
      visible: false,
 
      usersList: [], // 变更负责人
      removeType: 1, // 移动类型
      handleType: 1, // 操作类型
      addsTypes: [] // 添加至
    }
  },
  computed: {
    // 是否展示移除操作类型
    showRemoveType () {
      if (this.crmType === 'leads' || this.crmType === 'contacts') {
        return false
      }
      return true
    }
  },
  watch: {
    dialogVisible: {
      handler (val) {
        this.visible = val
      },
      deep: true,
      immediate: true
    }
  },
  mounted () {
    this.visible = this.dialogVisible
  },
  methods: {
    /**
     * 取消选择
     */
    handleCancel () {
      this.visible = false
      this.$emit('update:dialogVisible', false)
    },
    /** 负责人更改 */
    userChage (data) {
      this.usersList = data.value
    },
    handleConfirm () {
      if (this.usersList.length === 0) {
        this.$message.error('请选择变更负责人')
      } else {
        this.loading = true
        this.getRequest()(this.getParams())
          .then(res => {
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.loading = false
            this.handleCancel()
            this.$emit('handle', { type: 'transfer' })
          })
          .catch(() => {
            this.loading = false
          })
      }
    },
    getRequest () {
      // if (this.crmType === 'leads') {
      //   return crmLeadsTransfer
      // } else if (this.crmType === 'customer') {
      //   return crmCustomerTransfer
      // } else if (this.crmType === 'contacts') {
      //   return crmContactsTransfer
      // } else if (this.crmType === 'business') {
      //   return crmBusinessTransfer
      // } else if (this.crmType === 'contract') {
      //   return crmContractTransfer
      // }
    },
    getParams () {
      var ownerUserId = this.usersList[0].userId
      var params = {
        newOwnerUserId: ownerUserId,
        transferType: this.removeType
      }
      if (this.removeType === 2) {
        // 1移出,2转为团队成员
        params.power = this.handleType
      }
 
      var self = this
      var actionId = this.selectionList.map(function (item, index, array) {
        return item[self.crmType + 'Id']
      })
      params[this.crmType + 'Ids'] = actionId.join(',')
      if (this.crmType === 'customer') {
        // 只有客户下面有同时变更
        params.changeType = this.addsTypes.join(',')
      }
      return params
    }
  }
}
</script>
 
<style lang="less" scoped>
.handle-box {
  color: #333;
  font-size: 12px;
}
.handle-item {
  padding-bottom: 15px;
  .handle-item-name {
    flex-shrink: 0;
    width: 110px;
  }
  .handle-item-content {
    flex: 1;
  }
}
.handle-bar {
  position: relative;
  margin-top: 10px;
  height: 30px;
  button {
    float: right;
    margin-right: 10px;
  }
}
</style>