detail.js 24 KB

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