| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- const _Http = getApp().globalData.http;
- Page({
- data: {
- "id": 20221101094502,
- list: [],
- teamList: [],
- authoptions: [],
- hasAllotPermission: false,
- leader: null,
- showActionSheet: false,
- teamActions: [],
- showAssignConfirm: false,
- showWithdrawConfirm: false,
- selectedTeam: null,
- currentClueId: null,
- content: {
- isAll: false,
- nocache: true,
- pageNumber: 1,
- pageSize: 20,
- pageTotal: 1,
- where: {
- condition: "",
- status: ""
- },
- tableid: 1784
- }
- },
- onLoad() {
- this.getAuth();
- this.getTeamList();
- this.getList();
- },
- // 获取权限信息
- getAuth() {
- let auth = wx.getStorageSync("auth").wcrmlead;
- if (auth) {
- const hasAllotPermission = auth.options.some(v => v == 'allot');
- this.setData({
- authoptions: auth.options,
- hasAllotPermission: hasAllotPermission
- });
- }
- },
- /* 获取线索列表 */
- getList(init = false) {
- if (init.detail != undefined) init = init.detail;
- if (init) {
- this.setData({
- 'content.pageNumber': 1
- });
- }
- if (this.data.content.pageNumber > this.data.content.pageTotal) return;
- this.setListHeight();
- _Http.basic({
- id: this.data.id,
- content: this.data.content
- }).then(res => {
- console.log("线索列表数据", res);
- this.selectComponent('#ListBox').RefreshToComplete();
- this.setData({
- 'content.pageNumber': res.pageNumber + 1,
- 'content.pageTotal': res.pageTotal,
- list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
- total: res.total
- });
- }).catch(err => {
- console.error("获取线索列表失败", err);
- this.selectComponent('#ListBox').RefreshToComplete();
- wx.showToast({
- title: '获取线索列表失败',
- icon: 'none'
- });
- });
- },
- /* 设置页面高度 */
- setListHeight() {
- this.selectComponent("#ListBox").setHeight(".header", this);
- },
- /* 搜索 */
- onSearch({
- detail
- }) {
- this.setData({
- 'content.where.condition': detail
- });
- this.getList(true);
- },
- /* 跳转到详情页 */
- goToDetail(e) {
- const id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: `./detail?id=${id}`
- });
- },
- // 获取经销商团队列表
- getTeamList() {
- _Http.basic({
- classname: "sale.team.team",
- method: "query_teamList",
- content: {
- pageNumber: 1,
- pageSize: 99999,
- where: {
- condition: ""
- }
- },
- }).then(res => {
- if (res.code === 1) {
- const teamList = res.data || [];
- const leader = teamList.find(team => team.isleader === 1);
- // 生成团队成员操作选项(排除负责人自己)
- const teamActions = teamList.map(team => ({
- name: team.name + ' ' + team.phonenumber,
- subname: '在手 待跟进、跟进中 线索数量:' + team.ordercluecount,
- data: team
- }));
- this.setData({
- teamList,
- leader,
- teamActions
- });
- }
- }).catch(err => {
- console.error('获取经销商团队列表失败', err);
- });
- },
- // 转客户
- convertToCustomer(e) {
- const item = e.currentTarget.dataset.item;
- wx.navigateTo({
- url: `/CRM/customer/create?clueId=${item.sat_orderclueid}&clueInfo=${encodeURIComponent(JSON.stringify(item))}`
- });
- },
- // 点击分配按钮 - 弹出选人面板
- onAssignTap(e) {
- const item = e.currentTarget.dataset.item;
- // 禁用当前负责人选项
- const teamActions = this.data.teamList.map(team => ({
- name: team.name + ' ' + team.phonenumber,
- subname: '在手 待跟进、跟进中 线索数量:' + team.ordercluecount,
- disabled: item.leadername === team.name,
- data: team
- }));
- this.setData({
- currentClueId: item.sat_orderclueid,
- teamActions,
- showActionSheet: true
- });
- },
- // 选择团队成员
- onActionSheetSelect(event) {
- const selectedTeam = event.detail.data;
- this.setData({
- selectedTeam,
- showActionSheet: false,
- showAssignConfirm: true
- });
- },
- // 关闭动作面板
- onActionSheetClose() {
- this.setData({
- showActionSheet: false
- });
- },
- // 确认分配
- confirmAssign() {
- const { selectedTeam, currentClueId } = this.data;
- if (selectedTeam && currentClueId) {
- this.doAssignClue(currentClueId, selectedTeam);
- }
- this.setData({
- showAssignConfirm: false,
- selectedTeam: null
- });
- },
- // 取消分配
- cancelAssign() {
- this.setData({
- showAssignConfirm: false,
- selectedTeam: null
- });
- },
- // 点击撤回按钮 - 弹出确认框
- onWithdrawTap(e) {
- const item = e.currentTarget.dataset.item;
- const { leader } = this.data;
- if (!leader) {
- wx.showToast({ title: '未找到团队负责人', icon: 'none' });
- return;
- }
- this.setData({
- currentClueId: item.sat_orderclueid,
- selectedTeam: leader,
- showWithdrawConfirm: true
- });
- },
- // 确认撤回
- confirmWithdraw() {
- const { selectedTeam, currentClueId } = this.data;
- if (selectedTeam && currentClueId) {
- this.doAssignClue(currentClueId, selectedTeam);
- }
- this.setData({
- showWithdrawConfirm: false,
- selectedTeam: null
- });
- },
- // 取消撤回
- cancelWithdraw() {
- this.setData({
- showWithdrawConfirm: false,
- selectedTeam: null
- });
- },
- // 执行分配/撤回接口
- doAssignClue(clueId, team) {
- _Http.basic({
- classname: "crm.agent.orderclue.orderclue",
- method: "changeClue",
- content: {
- sat_orderclueid: [clueId],
- sys_enterprise_hrid: team.sys_enterprise_hrid,
- ordercluecount: "待跟进"
- }
- }).then(res => {
- console.log("线索分配结果", res);
- if (res.code === 1) {
- wx.showToast({ title: '操作成功', icon: 'none' });
- this.getList(true);
- } else {
- wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
- }
- }).catch(err => {
- console.error('线索分配失败', err);
- wx.showToast({ title: '网络错误', icon: 'none' });
- });
- },
- // 打电话
- makeCall(e) {
- const item = e.currentTarget.dataset.item;
- const phoneNumber = item.phonenumber;
- if (!phoneNumber) {
- wx.showToast({
- title: '未找到电话号码',
- icon: 'none'
- });
- return;
- }
- wx.makePhoneCall({
- phoneNumber: phoneNumber,
- success: (res) => {
- // 调用跟进接口
- this.addFollowRecord(item.sat_orderclueid);
- },
- fail: (err) => {
- console.error('拨打电话失败', err);
- }
- });
- },
- // 添加跟进记录
- addFollowRecord(clueId) {
- const content = {
- sat_orderclueid: clueId,
- content: '',
- logtype: "电话沟通",
- followTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
- result: "继续跟进"
- };
- _Http.basic({
- id: "20221208100602",
- content
- }).then(res => {
- console.log('添加跟进记录结果:', res);
- if (res.code === 1) {
- // 刷新列表
- this.getList(true);
- }
- }).catch(err => {
- console.error('添加跟进记录失败:', err);
- });
- }
- });
|