detail.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: true,
  10. isLeader: false, //是否为负责人
  11. tabsActive: 1, //tabs 选中项
  12. sa_customersid: 0,
  13. modeList: [{
  14. name: '潜在',
  15. },
  16. {
  17. name: '合作中'
  18. },
  19. {
  20. name: '已终止'
  21. }
  22. ],
  23. changeMode: false
  24. },
  25. onLoad(options) {
  26. const appAuth = wx.getStorageSync('auth').wCustomer;
  27. console.log("appAuth", appAuth)
  28. let tabsList = [{
  29. label: "详细信息",
  30. icon: "icon-tabxiangxixinxi1"
  31. }, {
  32. label: "联系人",
  33. icon: "icon-tablianxiren",
  34. model: "#Contacts"
  35. }, {
  36. label: "客户地址",
  37. icon: "icon-tabdizhi",
  38. model: "#Address"
  39. }, {
  40. label: "开票信息",
  41. icon: "icon-tabbaojiadan",
  42. model: "#Financing"
  43. }, {
  44. label: "项目商机",
  45. icon: "icon-tabxiangmu",
  46. model: "#Project"
  47. }, {
  48. label: "报价单",
  49. icon: "icon-tabbaojiadan",
  50. model: "#Offers"
  51. }, {
  52. label: "合同",
  53. icon: "icon-tabhetong",
  54. model: "#Contract"
  55. }, {
  56. label: "账户余额",
  57. icon: "icon-tabkaipiaoxinxi",
  58. model: "#Account"
  59. }, {
  60. label: "银行卡信息",
  61. icon: "icon-tabchanpin",
  62. model: "#Bankcard"
  63. }, {
  64. label: "关联线索",
  65. icon: "icon-tabxiansuo",
  66. model: "#Clue"
  67. }];
  68. if (appAuth.isdatafollowup) tabsList.unshift({
  69. label: "跟进动态",
  70. icon: "icon-tabgenjinjilu",
  71. model: "#Trace"
  72. })
  73. if (appAuth.istask) tabsList.push({
  74. label: "任务",
  75. icon: "icon-tabrenwu",
  76. model: "#Work"
  77. })
  78. tabsList = tabsList.concat([{
  79. label: "附件",
  80. icon: "icon-tabfujian1",
  81. model: "#Files"
  82. }, {
  83. label: "操作",
  84. icon: "icon-tabcaozuojilu1",
  85. model: "#Record"
  86. }])
  87. this.setData({
  88. sa_customersid: options.id,
  89. isAdmin: appAuth.options.some(v => v == "admin"), //是否具有管理权限
  90. options: appAuth.options, //权限列表
  91. tabsList,
  92. appAuth
  93. })
  94. this.getDetail();
  95. },
  96. modeSelect(e) {
  97. console.log(e)
  98. let {
  99. sa_customersid,
  100. status
  101. } = this.data.detail,
  102. that = this;
  103. wx.showModal({
  104. title: '提示',
  105. content: `是否确定将合作模式更改为:“${e.detail.name}”`,
  106. complete: (res) => {
  107. if (res.cancel) that.modeCancel()
  108. if (res.confirm) _Http.basic({
  109. "id": 20221010164602,
  110. "content": {
  111. "sa_customersids": [sa_customersid],
  112. "status": e.detail.name
  113. }
  114. }).then(res => {
  115. console.log("更改合作状态", res)
  116. wx.showToast({
  117. title: res.msg == '成功' ? '修改成功' : res.msg,
  118. icon: "none"
  119. })
  120. if (res.msg == '成功') that.getDetail()
  121. that.modeCancel()
  122. })
  123. }
  124. })
  125. },
  126. modeCancel() {
  127. this.setData({
  128. changeMode: false
  129. })
  130. },
  131. //详情按钮回调
  132. tabbarOnClick({
  133. detail
  134. }) {
  135. let data = this.data.detail,
  136. that = this;
  137. switch (detail.label) {
  138. case "更改合作状态":
  139. this.setData({
  140. changeMode: true
  141. })
  142. break;
  143. case "退回":
  144. wx.showModal({
  145. title: '提示',
  146. content: `是否确定将${data.enterprisename}退回到公海客户`,
  147. complete: (res) => {
  148. console.log(data)
  149. if (res.confirm) _Http.basic({
  150. "id": 20221014102602,
  151. "content": {
  152. "sa_customerpoolid": data.sa_customerpoolid_source,
  153. "sa_customersid": data.sa_customersid
  154. }
  155. }).then(res => {
  156. console.log("公海线索退回", res)
  157. wx.showToast({
  158. title: res.msg == '成功' ? '退回成功' : res.msg,
  159. icon: "none"
  160. });
  161. if (res.msg == '成功') setTimeout(() => {
  162. let page = getCurrentPages().find(v => v.__route__ == 'packageA/setclient/index');
  163. if (page) page.setData({
  164. list: page.data.list.filter(v => v.sa_customersid != data.sa_customersid)
  165. });
  166. wx.redirectTo({
  167. url: '/packageA/publicCustomer/detail?id' + data.sa_customersid,
  168. })
  169. }, 300)
  170. })
  171. }
  172. });
  173. break;
  174. case "回收":
  175. wx.navigateTo({
  176. url: `/packageA/publicCustomer/pond/index?params=${JSON.stringify({
  177. "id": 20221206195102,
  178.                 "content": {
  179. nocache:true,
  180.                     "where": {
  181.                         "condition": ""
  182.                     }
  183.                 }
  184. })}`,
  185. })
  186. getApp().globalData.handleSelect = this.handleTransfer.bind(this);
  187. break;
  188. case "跟进":
  189. this.selectComponent("#Trace").insetr();
  190. break;
  191. case "编辑":
  192. data.parentid = data.superiorenterprisename ? [data.superiorenterprisename, [data.parentid]] : "";
  193. wx.navigateTo({
  194. url: `/packageA/setclient/addAndEditor?data=${JSON.stringify(data)}`,
  195. })
  196. break;
  197. case "作废":
  198. wx.navigateTo({
  199. url: `/packageA/setclient/delete?item=${JSON.stringify({
  200. "sa_customersids": [this.data.detail.sa_customersid],
  201. datastatus: 1, //(0:正常;1:作废;2:锁定)
  202. })}`,
  203. })
  204. break;
  205. case "更换负责人":
  206. wx.navigateTo({
  207. url: `/pages/group/select?data=${JSON.stringify({
  208. ownertable:"sa_customers",
  209. ownerid:this.data.sa_customersid,
  210. })}&radio=true&principal=true`,
  211. })
  212. break;
  213. case "查看重复":
  214. _Http.basic({
  215. "id": 20221208172002,
  216. "content": {
  217. ...data,
  218. pageSize: 999
  219. }
  220. }).then(res => {
  221. console.log("查看重复", res)
  222. if (res.msg != '成功') return wx.showToast({
  223. title: res.msg,
  224. icon: "none"
  225. });
  226. if (res.data.length == 0) return wx.showToast({
  227. title: '未查询到重复数据',
  228. icon: "none"
  229. });
  230. this.setData({
  231. repetitionList: res.data,
  232. repetitionShow: true
  233. })
  234. })
  235. break;
  236. default:
  237. console.log(detail)
  238. break;
  239. }
  240. },
  241. /* 前去重复项详情 */
  242. toRepDetail(e) {
  243. const {
  244. item
  245. } = e.currentTarget.dataset;
  246. wx.navigateTo({
  247. url: '/packageA/setclient/detail?id=' + item.sa_customersid,
  248. })
  249. this.repClose()
  250. },
  251. /* 关闭查重 */
  252. repClose() {
  253. this.setData({
  254. repetitionShow: false
  255. })
  256. },
  257. /* 处理回收客户 */
  258. handleTransfer({
  259. value
  260. }) {
  261. wx.showModal({
  262. title: '提示',
  263. content: `是否确定将客户回收至${value[0]}?`,
  264. complete: (res) => {
  265. if (res.confirm) _Http.basic({
  266. "id": 20221014165602,
  267. "content": {
  268. "sa_customerpoolid": value[1][0], //公海池id
  269. "sa_customersids": [this.data.detail.sa_customersid],
  270. "sa_customersid": this.data.detail.sa_customersid
  271. },
  272. }).then(res => {
  273. console.log("回收客户", res)
  274. wx.showToast({
  275. title: res.data == '成功' ? `回收成功` : res.msg,
  276. icon: "none"
  277. });
  278. if (res.data == '成功') setTimeout(() => {
  279. wx.navigateBack()
  280. let page = getCurrentPages().find(v => v.__route__ == 'packageA/setclient/index');
  281. if (page) page.setData({
  282. list: page.data.list.filter(v => v.sa_customersid != this.data.detail.sa_customersid)
  283. });
  284. wx.redirectTo({
  285. url: '/packageA/publicCustomer/detail?id=' + this.data.detail.sa_customersid,
  286. })
  287. }, 300)
  288. })
  289. }
  290. })
  291. },
  292. /* 更换负责人 */
  293. handelSubmit(arr) {
  294. const that = this;
  295. wx.showModal({
  296. title: '提示',
  297. content: '是否确认更换负责人',
  298. complete: ({
  299. confirm
  300. }) => {
  301. if (confirm) wx.showModal({
  302. title: '提示',
  303. content: '是否参与该数据的后续工作',
  304. confirmText: "参与",
  305. cancelText: "不参与",
  306. complete: (s) => {
  307. _Http.basic({
  308. "id": 20220930103701,
  309. "content": {
  310. ownertable: "sa_customers",
  311. ownerid: that.data.sa_customersid,
  312. userid: arr[0],
  313. isaddoldleader: s.confirm ? 1 : 0
  314. }
  315. }).then(res => {
  316. console.log("更换负责人", res)
  317. if (res.msg != '成功') return wx.showToast({
  318. title: res.data,
  319. icon: "none"
  320. });
  321. wx.showToast({
  322. title: '更换成功!',
  323. icon: "none",
  324. mask: true
  325. });
  326. getCurrentPages().forEach(v => {
  327. if (['packageA/setclient/index'].includes(v.__route__)) v.getList(true)
  328. })
  329. setTimeout(() => {
  330. wx.navigateBack({
  331. delta: 2
  332. });
  333. }, 300)
  334. })
  335. }
  336. })
  337. }
  338. })
  339. },
  340. /* 获取详情 */
  341. getDetail() {
  342. /* 基本信息 */
  343. _Http.basic({
  344. "id": 20221012164302,
  345. "content": {
  346. sa_customersid: this.data.sa_customersid
  347. },
  348. }).then(res => {
  349. console.log("详情", res)
  350. if (res.msg != '成功') return wx.showToast({
  351. title: res.data,
  352. icon: "none"
  353. })
  354. this.setPreview(res);
  355. this.setData({
  356. loading: false,
  357. detail: res.data,
  358. })
  359. //获取标签
  360. if (this.data.appAuth.isdatatag) this.getTags();
  361. if (this.data.appAuth.isdatateam) this.getGroup()
  362. this.setTabbar();
  363. this.partialRenewal();
  364. });
  365. },
  366. async setTabbar() {
  367. /* 底部功能 */
  368. let detail = this.data.detail,
  369. isAdmin = this.data.isAdmin,
  370. isLeader = detail.leader.some(some => some.userid == wx.getStorageSync('userMsg').userid),
  371. editdataleader = isLeader ? 1 : 0,
  372. tabbarList = [];
  373. if (this.data.appAuth.isdatafollowup) tabbarList.push({
  374. icon: "icon-genjin",
  375. label: "跟进"
  376. });
  377. if (!isLeader) {
  378. let res = await getApp().agentOrNot("sa_customers", this.data.sa_customersid),
  379. data = res.msg == '成功' ? res.data : {
  380. editable: 0,
  381. editdataleader: 0
  382. }
  383. if (this.data.appAuth.isdatateam) isLeader = this.selectComponent("#Group").data.editable == 1;
  384. if (!isLeader) isLeader = data.editable == 1;
  385. editdataleader = data.editdataleader;
  386. }
  387. //负责人或管理员基础功能
  388. if (isLeader || isAdmin) {
  389. tabbarList.push({
  390. icon: "icon-bianji",
  391. label: "编辑"
  392. })
  393. if (editdataleader) tabbarList.push({
  394. icon: "icon-zhuanyi",
  395. label: "更换负责人"
  396. })
  397. /* if (isLeader) tabbarList.push({
  398. icon: "icon-dibu-biangengchengjiaozhuangtai",
  399. label: "更改合作状态"
  400. }) */
  401. tabbarList.push({
  402. icon: "icon-shanchu",
  403. label: "作废"
  404. })
  405. }
  406. //来自公海
  407. if (detail.ispublic == 1) {
  408. //查询到回收公海客户权限
  409. if (this.data.options.some(v => v == 'recycle')) tabbarList.push({
  410. icon: "icon-dibu-chehui",
  411. label: "回收"
  412. })
  413. //负责人
  414. if (isLeader) tabbarList.push({
  415. icon: "icon-dibu-chehui",
  416. label: "退回"
  417. })
  418. }
  419. if (this.data.options.find(v => v == 'viewRepetition')) tabbarList.push({
  420. icon: "icon-a-shouyejingangquhehuoren",
  421. label: "查看重复"
  422. });
  423. this.setData({
  424. tabbarList,
  425. isLeader
  426. })
  427. },
  428. setPreview(res) {
  429. /* 摘要信息 */
  430. let briefs = [{
  431. label: "客户类型",
  432. value: res.data.type
  433. }, {
  434. label: "企业等级",
  435. value: res.data.grade
  436. }, {
  437. label: "上级企业",
  438. value: res.data.superiorenterprisename
  439. }, {
  440. label: "负责人",
  441. value: res.data.leader.map(v => v.name) || ""
  442. }, {
  443. label: "归属经销商",
  444. value: res.data.agentname
  445. }, {
  446. label: '营销费用',
  447. value: CNY(res.data.salesfeesamount || '0')
  448. }];
  449. /* 基本信息 */
  450. let list1 = [{
  451. label: "客户名称",
  452. value: res.data.enterprisename
  453. }, {
  454. label: "客户编号",
  455. value: res.data.sa_customersid
  456. }, {
  457. label: "erp编号",
  458. value: res.data.erpagentnum
  459. }, {
  460. label: "企业简称",
  461. value: res.data.abbreviation
  462. }, {
  463. label: "客户类型",
  464. value: res.data.type
  465. }, {
  466. label: "企业等级",
  467. value: res.data.grade
  468. }, {
  469. label: "客户分类",
  470. value: res.data.customergrade
  471. }, {
  472. label: "客户行业",
  473. value: res.data.industry
  474. }, {
  475. label: "税号",
  476. value: res.data.taxno
  477. }, {
  478. label: "法人",
  479. value: res.data.contact
  480. }, {
  481. label: "电话",
  482. value: res.data.telephone
  483. }, {
  484. label: "省市县",
  485. value: res.data.province ? [res.data.province, res.data.city, res.data.county] : ""
  486. }, {
  487. label: "详细地址",
  488. value: res.data.address
  489. }, {
  490. label: "上级企业",
  491. value: res.data.superiorenterprisename
  492. }, {
  493. label: "客户来源",
  494. value: res.data.source
  495. }, {
  496. label: "来源公海",
  497. value: res.data.sourcepoolname
  498. }, {
  499. label: "成交状态",
  500. value: res.data.tradingstatus
  501. }, {
  502. label: "成交次数",
  503. value: res.data.contact_signnum
  504. }, {
  505. label: "合作状态",
  506. value: res.data.status
  507. }, {
  508. label: "负责人",
  509. value: res.data.leader.map(v => v.name) || ""
  510. }, {
  511. label: "部门",
  512. value: res.data.leader.length ? res.data.leader[0].depname : ""
  513. }, {
  514. label: "归属经销商",
  515. value: res.data.agentname
  516. }];
  517. /* 系统信息 */
  518. let list2 = [{
  519. label: "创建人",
  520. value: res.data.createby
  521. }, {
  522. label: "创建时间",
  523. value: res.data.createdate
  524. }, {
  525. label: "最近编辑人",
  526. value: res.data.changeby
  527. }, {
  528. label: "最近编辑时间",
  529. value: res.data.changedate
  530. }, {
  531. label: "作废原因",
  532. value: res.data.deletereason
  533. }, {
  534. label: "转手次数",
  535. value: res.data.leader[0] ? res.data.leader[0].leadernum : 0
  536. }];
  537. this.setData({
  538. briefs,
  539. list1,
  540. list2
  541. });
  542. },
  543. //tabs 切换
  544. tabsChange({
  545. detail
  546. }) {
  547. this.setData({
  548. tabsActive: detail
  549. });
  550. this.partialRenewal();
  551. },
  552. //局部数据更新 tabs
  553. partialRenewal(init = false) {
  554. let model = this.data.tabsList[this.data.tabsActive].model;
  555. if (model) {
  556. let Component = this.selectComponent(model),
  557. {
  558. total,
  559. pageNumber,
  560. pageTotal
  561. } = Component.data.content,
  562. id = model == "#Clue" ? this.data.detail.sa_customersid : this.data.detail.sys_enterpriseid;
  563. if (total == null || init) {
  564. Component.getList(id, init);
  565. } else if (pageNumber <= pageTotal) {
  566. Component.getList(id, false);
  567. }
  568. }
  569. },
  570. //更新标签
  571. getTags() {
  572. this.selectComponent("#Tags").getTags();
  573. },
  574. //更新团队成员
  575. getGroup() {
  576. this.selectComponent("#Group").getList().then(this.setTabbarList)
  577. },
  578. onReachBottom() {
  579. this.partialRenewal();
  580. },
  581. onUnload() {
  582. const page = getCurrentPages().find(v => v.__route__ == 'packageA/setclient/index');
  583. if (!page) return;
  584. let content = JSON.parse(JSON.stringify(page.data.content));
  585. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  586. content.pageNumber = 1;
  587. _Http.basic({
  588. id: '20221012164402',
  589. content
  590. }).then(res => {
  591. console.log("更新客户列表", res);
  592. if (res.msg == '成功') {
  593. page.setData({
  594. list: res.data,
  595. "content.total": res.total
  596. })
  597. page.getTags()
  598. }
  599. })
  600. }
  601. })