yangfeng
2023-11-29 d7c06cca16d12ecf5d0f233395dcf6062261b39b
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<template>
  <div class="sales-opportunity">
    <div v-if="isDetail" class="detail-top">
      <DetailListCommonBtn :query-class-options="queryClassOptions" />
    </div>
 
    <div class="filter" v-else>
      <div class="filter-card">
        <CommonSearch
            :show-add="false"
            :show-download="false"
            :amount-view="false"
            placeholder="请输入机会名称"
            @searchClick="onFilterSearch"
        >
          <template slot="leftButton">
            <el-button size="small" type="primary"  @click="addBtnClick">新建</el-button>
<!--            <el-button size="small"  @click="delClick">删除</el-button>-->
          </template>
        </CommonSearch>
      </div>
    </div>
 
    <div class="body">
      <div class="body-card">
        <div class="list-view">
          <TableCommonView
              ref="tableListRef"
              :table-list="tableList"
              :select-box="false"
              @selClientClick="selClientClick"
              @selContactsClick="selContactsClick"
              @selCommonClick="selCommonClick"
              @getSelectArray="getSelectArray"
              @selTableCol="selTableCol"
          >
            <template slot="tableButton">
              <el-table-column label="操作" width="120">
                <template slot-scope="scope">
                  <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
                  <el-button @click="followupClick(scope.row)" type="text" size="small">跟进</el-button>
                   <el-button @click="deleteItem(scope.row.id)" type="text" size="small">删除</el-button>
                </template>
              </el-table-column>
            </template>
          </TableCommonView>
        </div>
        <div class="btn-pager">
          <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
        </div>
      </div>
    </div>
    <!-- 新建/编辑 -->
    <AddSalesOpportunityDialog v-if="editConfig.visible" :edit-common-config="editConfig" />
    <!-- 机会详情 -->
    <DetailOpportunity v-if="opportunityDeail.visible" :opportunity-detail="opportunityDeail" />
    <!-- 客户详情 -->
    <DetailClientManage v-if="clientDeail.visible" :client-manage-detail="clientDeail" />
    <!-- 联系人详情 -->
    <DetailContacts v-if="contactsDeail.visible" :contacts-detail="contactsDeail" />
    <!-- 新建/编辑跟进记录 -->
    <AddFollowupRecordsDialog v-if="editFollowupConfig.visible" :edit-contacts-config="editFollowupConfig" />
  </div>
</template>
 
<script>
import AddSalesOpportunityDialog from "@/views/sales/salesOpportunity/AddSalesOpportunityDialog"
import { getSaleChanceList, getDelSaleChance } from "@/api/sales/salesOpportunity"
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import DetailOpportunity from "@/views/sales/salesOpportunity/DetailOpportunity"
import AddFollowupRecordsDialog from "@/views/client/followupRecords/AddFollowupRecordsDialog"
 
export default {
  name: "SalesOpportunity",
  props: {
    isDetail: {
      type: Boolean,
      default: false
    },
    addConfig: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  mixins: [pageMixin],
  components: {
    AddSalesOpportunityDialog,
    DetailOpportunity,
    DetailContacts: () => import("@/views/client/contacts/DetailContacts"),
    DetailClientManage: () => import("@/views/client/client/DetailClientManage"),
    AddFollowupRecordsDialog
  },
  computed: {},
  data() {
    return {
      tableList: {},
      queryClassOptions: [
        { value: "1", label: "全部" },
        { value: "2", label: "初期沟通" },
        { value: "3", label: "商务谈判" },
        { value: "4", label: "成功结案" },
        { value: "5", label: "失败结案" },
        { value: "6", label: "本周创建" },
        { value: "7", label: "本月创建" },
        { value: "8", label: "本周预计成交" },
        { value: "9", label: "本月预计成交" },
        { value: "10", label: "在谈商机" },
        { value: "11", label: "项目暂停" },
        { value: "12", label: "15天未联系商机" },
        { value: "13", label: "预计金额1W以上" }
      ],
      searchOptions: [],
      operatesList: [
        { id: "1", name: "共享" },
        { id: "2", name: "批量编辑" },
        { id: "3", name: "导出" },
        { id: "4", name: "下载全部附件" },
        { id: "5", name: "更改创建人" },
        { id: "6", name: "树结构设置" },
        { id: "7", name: "审批设置" },
        { id: "8", name: "恢复预设列宽" }
      ],
      editConfig: {
        visible: false,
        title: "新建",
        infomation: {}
      },
      opportunityDeail: {
        visible: false,
        infomation: {}
      },
      contactsDeail: {
        visible: false,
        infomation: {}
      },
      clientDeail: {
        visible: false,
        infomation: {}
      },
      search_map: {},
      selValueList: [],
      editFollowupConfig: {
        visible: false,
        title: "新建",
        infomation: {}
      },
      tableColumn: [
        { label: "机会名称", prop: "name", min: 120, isCommonClick: true ,default:true}, // 机会名称
        { label: "客户名称", prop: "client_name", min: 90, isClientClick: true }, // 客户名称
        { label: "销售机会编号", prop: "number" }, // 销售机会编号
        { label: "联系人姓名", prop: "contact_name", min: 100, isContactClick: true }, // 联系人姓名
        { label: "销售阶段", prop: "sale_stage_name" }, // 销售阶段
        { label: "可能性(%)", prop: "possibility_name" }, // 可能性
        { label: "预计成交日期", prop: "expected_time", min: 130 }, // 预计成交日期
        { label: "预计合同金额", prop: "projected_amount" }, // 预计合同金额
        { label: "预算绝对值", prop: "budget" }, // 预算绝对值
        { label: "销售负责人", prop: "member_name" } // 销售负责人
      ],
      showCol:["机会名称", "客户名称", "销售机会编号", "联系人姓名", "销售阶段", "可能性(%)", "预计成交日期", "预计合同金额", "预算绝对值", "销售负责人"]
    }
  },
  created() {
    this.setTable()
    if (!this.isDetail) {
      this.search_map = {}
    } else {
      this.search_map = {
        [this.addConfig.id_name]: this.addConfig.client_name
      }
    }
    this.getData(this.search_map)
  },
  methods: {
    setTable() {
      this.tableList = {
        selectIndex:true,
        tableInfomation: [],
        allcol: [],
        showcol: this.showCol,
        tableColumn:this.setColumnVisible(this.showCol)
      }
      this.tableList.allcol = this.tableList.tableColumn.filter(ele=>!ele.default).map(ele=>ele.label);
      this.searchOptions = []
      for (let i = 0; i < this.tableList.tableColumn.length; i++) {
        const label = this.tableList.tableColumn[i].label
        const value = this.tableList.tableColumn[i].prop
        this.searchOptions.push({ value: value, label: label })
      }
    },
    setColumnVisible(showCol){
      return  this.tableColumn.map(ele=>{
        return {
          ...ele,
          isShowColumn:showCol.includes(ele.label)
        }
      })
    },
    selTableCol(val) {
      this.showcol = val;
      this.tableList.tableColumn = this.setColumnVisible(val);
    },
    // 请求数据
    async getData() {
      this.loading = true
      await getSaleChanceList({
        search_map: this.search_map,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      })
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            if (res.data.list && res.data.list.length > 0) {
              const list = res.data.list.map((item) => {
                return {
                  ...item,
                  client_name: item.client.name,
                  contact_name: item.contact.name,
                  sale_stage_name: item.sale_stage.name,
                  member_name: item.member.username,
                  possibility_name: item.possibility.name
                }
              })
              this.tableList.tableInfomation = list || []
              this.pagerOptions.totalCount = res.data.count
            } else {
              this.tableList.tableInfomation = []
            }
          } else {
            this.tableList.tableInfomation = []
          }
          this.loading = false
        })
        .catch((err) => {
          console.log(err)
          this.tableList.tableInfomation = []
          this.loading = false
        })
    },
    // 搜索
    onFilterSearch(searchText){
      this.search_map.name = searchText ?? ''
      this.pagerOptions.currPage = 1
      this.getData()
    },
    // 新建
    addBtnClick() {
      this.editConfig.visible = true
      this.editConfig.title = "新建"
      this.editConfig.infomation = { city_id: 0, ...this.addConfig }
    },
    // 编辑
    handleClick(row) {
      console.log(row)
      this.editConfig.visible = true
      this.editConfig.title = "编辑"
      this.editConfig.infomation = { ...row }
    },
    // 批量删除
    delClick() {
      if (this.selValueList && this.selValueList.length > 0) {
        this.$confirm("是否确认删除?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            console.log("dddd")
            getDelSaleChance({ ids: this.selValueList }).then((response) => {
              if (response.code === 200) {
                this.$message.success("删除成功")
                this.getData()
              } else {
                this.$message.warning("删除失败")
              }
            })
          })
          .catch(() => {})
      } else {
        this.$message.warning("请至少选择一条记录")
      }
    },
    /**
     * 单个删除
     * @param id 销售机会id
     */
    deleteItem(id) {
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
          .then(() => {
            getDelSaleChance({ids: [id]}).then((response) => {
              if (response.code === 200) {
                this.$message.success("删除成功")
                this.getData()
              } else {
                this.$message.warning("删除失败")
              }
            })
          })
          .catch((err) => {
            if (err!== 'cancel'){
              console.error(err)
              this.$message.warning("删除失败")
            }
          })
    },
    getSelectArray(val) {
      console.log(val)
      this.selValueList = []
      const list = val.map((item) => {
        return item.id
      })
      this.selValueList = list
    },
    // 客户名称详情
    selClientClick(row) {
      console.log(row)
      this.clientDeail.visible = true
      this.clientDeail.infomation = {
        ...row.client,
        client_name: row.client.name,
        client_level: row.client.client_level.name,
        client_status: row.client.client_status.name
      }
    },
    // 联系人详情
    selContactsClick(row) {
      console.log(row)
      this.contactsDeail.visible = true
      this.contactsDeail.infomation = {
        ...row.contact,
        sale_chance_name: row.name,
        sale_chance_id: row.id,
        Client: { name: row.client.name, client_status_id: row.client.client_status_id },
        client_name: row.name
      }
    },
    // 机会名称详情
    selCommonClick(row) {
      console.log(row)
      this.opportunityDeail.visible = true
      this.opportunityDeail.infomation = { ...row }
    },
    // 跟进
    followupClick(row) {
      console.log(row)
      this.editFollowupConfig.title = "新建"
      this.editFollowupConfig.infomation = {
        ...row,
        number: "",
        sale_chance_name: row.name,
        sale_chance_id: row.id
      }
      this.editFollowupConfig.infomation.codeStandID=''
      this.editFollowupConfig.visible = true
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.sales-opportunity{
  height: 100%;
  overflow: hidden;
  .filter{
    height: 80px;
    display: flex;
    align-items: center;
    padding: 12px 20px 0 20px;
    &-card{
      height: 80px;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 10px 20px;
      flex: 1;
      border-radius: 12px;
      background-color: #fff;
    }
  }
  .body{
    box-sizing: border-box;
    padding: 10px 20px;
    border-radius: 12px;
    height: calc(100% - 92px);
    .body-card {
      background-color: #fff;
      border-radius: 12px;
      height: 100%;
      overflow: hidden;
    }
    .list-view {
      height: calc(100% - 60px);
      overflow: hidden;
    }
    .btn-pager {
      display: flex;
      margin-top: 10px;
      .page {
        margin-left: auto;
      }
    }
  }
}
</style>