index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. "id": 20221101094502,
  5. list: [],
  6. teamList: [],
  7. authoptions: [],
  8. hasAllotPermission: false,
  9. leader: null,
  10. showActionSheet: false,
  11. teamActions: [],
  12. showAssignConfirm: false,
  13. showWithdrawConfirm: false,
  14. selectedTeam: null,
  15. currentClueId: null,
  16. content: {
  17. isAll: false,
  18. nocache: true,
  19. pageNumber: 1,
  20. pageSize: 20,
  21. pageTotal: 1,
  22. where: {
  23. condition: "",
  24. status: ""
  25. },
  26. tableid: 1784
  27. }
  28. },
  29. onLoad() {
  30. this.getAuth();
  31. this.getTeamList();
  32. this.getList();
  33. },
  34. // 获取权限信息
  35. getAuth() {
  36. let auth = wx.getStorageSync("auth").wcrmlead;
  37. if (auth) {
  38. const hasAllotPermission = auth.options.some(v => v == 'allot');
  39. this.setData({
  40. authoptions: auth.options,
  41. hasAllotPermission: hasAllotPermission
  42. });
  43. }
  44. },
  45. /* 获取线索列表 */
  46. getList(init = false) {
  47. if (init.detail != undefined) init = init.detail;
  48. if (init) {
  49. this.setData({
  50. 'content.pageNumber': 1
  51. });
  52. }
  53. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  54. this.setListHeight();
  55. _Http.basic({
  56. id: this.data.id,
  57. content: this.data.content
  58. }).then(res => {
  59. console.log("线索列表数据", res);
  60. this.selectComponent('#ListBox').RefreshToComplete();
  61. this.setData({
  62. 'content.pageNumber': res.pageNumber + 1,
  63. 'content.pageTotal': res.pageTotal,
  64. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  65. total: res.total
  66. });
  67. }).catch(err => {
  68. console.error("获取线索列表失败", err);
  69. this.selectComponent('#ListBox').RefreshToComplete();
  70. wx.showToast({
  71. title: '获取线索列表失败',
  72. icon: 'none'
  73. });
  74. });
  75. },
  76. /* 设置页面高度 */
  77. setListHeight() {
  78. this.selectComponent("#ListBox").setHeight(".header", this);
  79. },
  80. /* 搜索 */
  81. onSearch({
  82. detail
  83. }) {
  84. this.setData({
  85. 'content.where.condition': detail
  86. });
  87. this.getList(true);
  88. },
  89. /* 跳转到详情页 */
  90. goToDetail(e) {
  91. const id = e.currentTarget.dataset.id;
  92. wx.navigateTo({
  93. url: `./detail?id=${id}`
  94. });
  95. },
  96. // 获取经销商团队列表
  97. getTeamList() {
  98. _Http.basic({
  99. classname: "sale.team.team",
  100. method: "query_teamList",
  101. content: {
  102. pageNumber: 1,
  103. pageSize: 99999,
  104. where: {
  105. condition: ""
  106. }
  107. },
  108. }).then(res => {
  109. if (res.code === 1) {
  110. const teamList = res.data || [];
  111. const leader = teamList.find(team => team.isleader === 1);
  112. // 生成团队成员操作选项(排除负责人自己)
  113. const teamActions = teamList.map(team => ({
  114. name: team.name + ' ' + team.phonenumber,
  115. subname: '在手 待跟进、跟进中 线索数量:' + team.ordercluecount,
  116. data: team
  117. }));
  118. this.setData({
  119. teamList,
  120. leader,
  121. teamActions
  122. });
  123. }
  124. }).catch(err => {
  125. console.error('获取经销商团队列表失败', err);
  126. });
  127. },
  128. // 转客户
  129. convertToCustomer(e) {
  130. const item = e.currentTarget.dataset.item;
  131. wx.navigateTo({
  132. url: `/CRM/customer/create?clueId=${item.sat_orderclueid}&clueInfo=${encodeURIComponent(JSON.stringify(item))}`
  133. });
  134. },
  135. // 点击分配按钮 - 弹出选人面板
  136. onAssignTap(e) {
  137. const item = e.currentTarget.dataset.item;
  138. // 禁用当前负责人选项
  139. const teamActions = this.data.teamList.map(team => ({
  140. name: team.name + ' ' + team.phonenumber,
  141. subname: '在手 待跟进、跟进中 线索数量:' + team.ordercluecount,
  142. disabled: item.leadername === team.name,
  143. data: team
  144. }));
  145. this.setData({
  146. currentClueId: item.sat_orderclueid,
  147. teamActions,
  148. showActionSheet: true
  149. });
  150. },
  151. // 选择团队成员
  152. onActionSheetSelect(event) {
  153. const selectedTeam = event.detail.data;
  154. this.setData({
  155. selectedTeam,
  156. showActionSheet: false,
  157. showAssignConfirm: true
  158. });
  159. },
  160. // 关闭动作面板
  161. onActionSheetClose() {
  162. this.setData({
  163. showActionSheet: false
  164. });
  165. },
  166. // 确认分配
  167. confirmAssign() {
  168. const { selectedTeam, currentClueId } = this.data;
  169. if (selectedTeam && currentClueId) {
  170. this.doAssignClue(currentClueId, selectedTeam);
  171. }
  172. this.setData({
  173. showAssignConfirm: false,
  174. selectedTeam: null
  175. });
  176. },
  177. // 取消分配
  178. cancelAssign() {
  179. this.setData({
  180. showAssignConfirm: false,
  181. selectedTeam: null
  182. });
  183. },
  184. // 点击撤回按钮 - 弹出确认框
  185. onWithdrawTap(e) {
  186. const item = e.currentTarget.dataset.item;
  187. const { leader } = this.data;
  188. if (!leader) {
  189. wx.showToast({ title: '未找到团队负责人', icon: 'none' });
  190. return;
  191. }
  192. this.setData({
  193. currentClueId: item.sat_orderclueid,
  194. selectedTeam: leader,
  195. showWithdrawConfirm: true
  196. });
  197. },
  198. // 确认撤回
  199. confirmWithdraw() {
  200. const { selectedTeam, currentClueId } = this.data;
  201. if (selectedTeam && currentClueId) {
  202. this.doAssignClue(currentClueId, selectedTeam);
  203. }
  204. this.setData({
  205. showWithdrawConfirm: false,
  206. selectedTeam: null
  207. });
  208. },
  209. // 取消撤回
  210. cancelWithdraw() {
  211. this.setData({
  212. showWithdrawConfirm: false,
  213. selectedTeam: null
  214. });
  215. },
  216. // 执行分配/撤回接口
  217. doAssignClue(clueId, team) {
  218. _Http.basic({
  219. classname: "crm.agent.orderclue.orderclue",
  220. method: "changeClue",
  221. content: {
  222. sat_orderclueid: [clueId],
  223. sys_enterprise_hrid: team.sys_enterprise_hrid,
  224. ordercluecount: "待跟进"
  225. }
  226. }).then(res => {
  227. console.log("线索分配结果", res);
  228. if (res.code === 1) {
  229. wx.showToast({ title: '操作成功', icon: 'none' });
  230. this.getList(true);
  231. } else {
  232. wx.showToast({ title: res.msg || '操作失败', icon: 'none' });
  233. }
  234. }).catch(err => {
  235. console.error('线索分配失败', err);
  236. wx.showToast({ title: '网络错误', icon: 'none' });
  237. });
  238. },
  239. // 打电话
  240. makeCall(e) {
  241. const item = e.currentTarget.dataset.item;
  242. const phoneNumber = item.phonenumber;
  243. if (!phoneNumber) {
  244. wx.showToast({
  245. title: '未找到电话号码',
  246. icon: 'none'
  247. });
  248. return;
  249. }
  250. wx.makePhoneCall({
  251. phoneNumber: phoneNumber,
  252. success: (res) => {
  253. // 调用跟进接口
  254. this.addFollowRecord(item.sat_orderclueid);
  255. },
  256. fail: (err) => {
  257. console.error('拨打电话失败', err);
  258. }
  259. });
  260. },
  261. // 添加跟进记录
  262. addFollowRecord(clueId) {
  263. const content = {
  264. sat_orderclueid: clueId,
  265. content: '',
  266. logtype: "电话沟通",
  267. followTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
  268. result: "继续跟进"
  269. };
  270. _Http.basic({
  271. id: "20221208100602",
  272. content
  273. }).then(res => {
  274. console.log('添加跟进记录结果:', res);
  275. if (res.code === 1) {
  276. // 刷新列表
  277. this.getList(true);
  278. }
  279. }).catch(err => {
  280. console.error('添加跟进记录失败:', err);
  281. });
  282. }
  283. });