detail.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. tabsActive: 0, //tabs 选中项
  5. sys_taskid: "",
  6. detail: '',
  7. tabsList: [{
  8. label: "详细信息",
  9. icon: "icon-tabxiangxixinxi1"
  10. }, {
  11. label: "跟进动态",
  12. icon: "icon-tabgenjinjilu"
  13. }, {
  14. label: "操作",
  15. icon: "icon-tabcaozuojilu1"
  16. }, {
  17. label: "附件",
  18. icon: "icon-tabfujian1"
  19. }],
  20. tabbarList: [],
  21. confirmShow: false,
  22. finishnotes: "", //完成说明
  23. },
  24. /* 完成情况说明输入 */
  25. areaInput(e) {
  26. this.setData({
  27. finishnotes: e.detail.value
  28. })
  29. },
  30. onConfirm(e) {
  31. _Http.basic({
  32. "id": 20221211112501,
  33. "content": {
  34. "sys_taskid": this.data.sys_taskid,
  35. "finishnotes": this.data.finishnotes
  36. }
  37. }).then(res => {
  38. console.log("完成情况说明", res)
  39. wx.showToast({
  40. title: res.msg == '成功' ? "提交成功" : res.msg,
  41. icon: "none"
  42. })
  43. if (res.msg == '成功') setTimeout(this.getDetail, 500)
  44. })
  45. },
  46. /* 取消提交说明 */
  47. onCancel(e) {
  48. this.setData({
  49. confirmShow: false
  50. })
  51. },
  52. onLoad(options) {
  53. this.setData({
  54. sys_taskid: options.id
  55. });
  56. this.getDetail();
  57. getApp().globalData.previewClick = this.previewClick.bind(this);
  58. },
  59. previewClick({
  60. label,
  61. value
  62. }) {
  63. if (label == '关联应用数据') {
  64. const detail = this.data.detail;
  65. if (detail.ownerid) {
  66. const authComparison = wx.getStorageSync('authComparison');
  67. //判断具体消息归属
  68. switch (detail.ownertable) {
  69. case "sa_customers":
  70. this.saCustomer(detail.ownerid);
  71. break;
  72. case "sat_orderclue":
  73. this.satOrderclue(detail.ownerid);
  74. break;
  75. case "sa_order":
  76. this.saOrder(detail.ownerid)
  77. break;
  78. case "sa_salesforecastbill":
  79. let url = detail.baseonproject == 1 ? '/packageA/finishforecast/detail' : '/packageA/invoiceforecast/detail';
  80. wx.navigateTo({
  81. url: url + "?id=" + detail.ownerid,
  82. })
  83. break;
  84. case "sys_phonebook":
  85. wx.navigateTo({
  86. url: `/packageA/contacts/detail?id=${detail.ownerid}&contactsid=0&sa_project_contactsid=0`,
  87. })
  88. break;
  89. case "sys_enterprise_contacts":
  90. wx.navigateTo({
  91. url: `/packageA/contacts/detail?id=0&contactsid=${detail.ownerid}&sa_project_contactsid=0`,
  92. })
  93. break;
  94. case "sa_project_contacts":
  95. wx.navigateTo({
  96. url: `/packageA/contacts/detail?id=0&contactsid=0&sa_project_contactsid=${detail.ownerid}`,
  97. })
  98. break;
  99. default:
  100. let data = authComparison.find(s => (s.objectname || "") == detail.ownertable);
  101. if (data) wx.navigateTo({
  102. url: data.path.split("/index")[0] + "/detail?id=" + detail.ownerid,
  103. })
  104. break;
  105. }
  106. }
  107. }
  108. },
  109. saOrder(sa_orderid) {
  110. _Http.basic({
  111. "id": 20221108151302,
  112. "content": {
  113. nocache: true,
  114. sa_orderid
  115. }
  116. }).then(res => {
  117. console.log("订单", res)
  118. if (res.msg != '成功') return wx.showToast({
  119. title: res.data,
  120. icon: "none"
  121. });
  122. let path = '';
  123. switch (res.data.type) {
  124. case '工具借用单':
  125. path = '/packageA/borrow/detail'
  126. break;
  127. case '借用归还单':
  128. path = '/packageA/toolBill/detail'
  129. break;
  130. default:
  131. path = '/packageA/orderForm/detail'
  132. break;
  133. }
  134. wx.navigateTo({
  135. url: path + '?id=' + sa_orderid,
  136. })
  137. });
  138. },
  139. satOrderclue(sat_orderclueid) {
  140. _Http.basic({
  141. "classname": "saletool.orderclue.web.orderclue",
  142. "method": "selectDetail",
  143. "version": 1,
  144. "content": {
  145. "nocache": true,
  146. sat_orderclueid
  147. },
  148. }).then(res => {
  149. console.log("线索详情", res)
  150. if (res.msg != '成功') return wx.showToast({
  151. title: res.data,
  152. icon: "none"
  153. });
  154. wx.navigateTo({
  155. url: (res.data.isprivate ? '/packageA/saleClue/detail' : '/packageA/publicClue/detail') + '?id=' + sat_orderclueid,
  156. })
  157. });
  158. },
  159. saCustomer(sa_customersid) {
  160. _Http.basic({
  161. "id": 20221012164302,
  162. "content": {
  163. sa_customersid
  164. },
  165. }).then(res => {
  166. console.log("客户详情", res)
  167. if (res.msg != '成功') return wx.showToast({
  168. title: res.data,
  169. icon: "none"
  170. });
  171. wx.navigateTo({
  172. url: (res.data.ispublic ? '/packageA/publicCustomer/detail' : '/packageA/setclient/detail') + '?id=' + sa_customersid,
  173. })
  174. });
  175. },
  176. getDetail() {
  177. _Http.basic({
  178. "id": 20221211111901,
  179. "content": {
  180. "nocache": true,
  181. "sys_taskid": this.data.sys_taskid
  182. },
  183. }).then(res => {
  184. console.log("任务详情", res)
  185. if (res.msg != '成功') return wx.showToast({
  186. title: res.msg,
  187. icon: "none"
  188. });
  189. let tabbarList = [{
  190. icon: "icon-genjin",
  191. label: "跟进"
  192. }];
  193. if (res.data.status != '已完成') tabbarList.push({
  194. icon: "icon-dibu-chengjiao",
  195. label: "完成"
  196. })
  197. try {
  198. let isLeader = res.data.createuserid == wx.getStorageSync('userMsg').userid;
  199. if (isLeader) {
  200. tabbarList.splice(1, 0, {
  201. icon: "icon-shanchu",
  202. label: "删除"
  203. })
  204. tabbarList.splice(1, 0, {
  205. icon: "icon-guanlian-bianji",
  206. label: "编辑"
  207. })
  208. }
  209. } catch (error) {}
  210. this.setData({
  211. tabbarList,
  212. detail: res.data,
  213. briefs: [{
  214. label: "任务内容",
  215. value: res.data.remarks
  216. }, {
  217. label: "开始日期",
  218. value: res.data.starttime
  219. }, {
  220. label: "结束日期",
  221. value: res.data.endtime
  222. },
  223. {
  224. label: '关联应用数据',
  225. value: res.data.title
  226. }, {
  227. label: '状态',
  228. value: res.data.status
  229. }
  230. ],
  231. list1: [{
  232. label: "任务标题",
  233. value: res.data.title
  234. }, {
  235. label: "任务内容",
  236. value: res.data.remarks
  237. }, {
  238. label: "开始日期",
  239. value: res.data.starttime
  240. }, {
  241. label: "结束日期",
  242. value: res.data.endtime
  243. }, {
  244. label: "执行人",
  245. value: res.data.leader[0].name
  246. }, {
  247. label: "协助人",
  248. value: ""
  249. }, {
  250. label: '关联应用数据',
  251. value: res.data.title,
  252. color: "#085CDF",
  253. slot: 'title'
  254. }, {
  255. label: '状态',
  256. value: res.data.status
  257. }, {
  258. label: '完成说明',
  259. value: res.data.finishnotes
  260. }],
  261. list2: [{
  262. label: "创建人",
  263. value: res.data.createby
  264. }, {
  265. label: "创建时间",
  266. value: res.data.createdate
  267. }, {
  268. label: "最近编辑人",
  269. value: res.data.changeby
  270. }, {
  271. label: "最近编辑时间",
  272. value: res.data.changedate
  273. }, {
  274. label: "完成人",
  275. value: res.data.finishby
  276. }, {
  277. label: "完成时间",
  278. value: res.data.finishdate
  279. }, {
  280. label: "转手次数",
  281. value: res.data.leader.length ? res.data.leader[0].leadernum : 0
  282. }]
  283. });
  284. /* 更新列表中状态 */
  285. let page = getCurrentPages().find(v => v.__route__ == 'packageA/saleClue/index');
  286. if (page) {
  287. let index = page.data.list.findIndex(v => v.sys_taskid == res.data.sys_taskid);
  288. if (index != -1) page.setData({
  289. [`list[${index}].status`]: res.data.status,
  290. [`list[${index}].title`]: res.data.title,
  291. [`list[${index}].remarks`]: res.data.remarks
  292. })
  293. } else {
  294. let pages = getCurrentPages(),
  295. p = pages[pages.length - 2].selectComponent("#Work");
  296. if (p) {
  297. let index = p.data.list.findIndex(v => v.sys_taskid == res.data.sys_taskid);
  298. if (index != -1) p.setData({
  299. [`list[${index}].status`]: res.data.status,
  300. [`list[${index}].title`]: res.data.title,
  301. [`list[${index}].remarks`]: res.data.remarks
  302. })
  303. }
  304. }
  305. this.getTags();
  306. this.getGroup();
  307. this.partialRenewal();
  308. })
  309. },
  310. //tabs 切换
  311. tabsChange({
  312. detail
  313. }) {
  314. this.setData({
  315. tabsActive: detail
  316. });
  317. this.partialRenewal();
  318. },
  319. //更新标签
  320. getTags() {
  321. this.selectComponent("#Tags").getTags();
  322. },
  323. //更新团队成员
  324. getGroup() {
  325. this.selectComponent("#Group").getList().then(res => {
  326. let i = this.data.list1.findIndex(v => v.label == '协助人')
  327. this.setData({
  328. [`list1[${i}].value`]: res.filter(v => !v.isleader).map(v => v.name)
  329. })
  330. });
  331. },
  332. onClose() {
  333. this.setData({
  334. show: false
  335. });
  336. },
  337. //局部数据更新 tabs
  338. partialRenewal(init = false) {
  339. let id = this.data.detail.sys_taskid;
  340. let model = '';
  341. let name = this.data.tabsList[this.data.tabsActive].label;
  342. switch (name) {
  343. case "操作":
  344. model = "#Record"
  345. break;
  346. case "跟进动态":
  347. model = "#Trace"
  348. break;
  349. case "附件":
  350. model = "#Files"
  351. break;
  352. };
  353. if (model) {
  354. // 确定好模块ID total = null 是第一次加载 加载数据
  355. // init是新增或修改需要清数据
  356. let Component = this.selectComponent(model);
  357. const {
  358. total,
  359. pageNumber,
  360. pageTotal
  361. } = Component.data.content;
  362. if (total == null || init) {
  363. Component.getList(id, init);
  364. } else if (pageNumber <= pageTotal) {
  365. Component.getList(id, false);
  366. } else {
  367. //用来判断 在搜索页面修改,与tabs选项不一致 但是切换到该选项 重置数据
  368. }
  369. }
  370. },
  371. onReachBottom() {
  372. this.partialRenewal();
  373. },
  374. //详情按钮回调
  375. tabbarOnClick({
  376. detail
  377. }) {
  378. let that = this;
  379. switch (detail.label) {
  380. case "编辑":
  381. let group = this.selectComponent("#Group").query();
  382. wx.navigateTo({
  383. url: `/packageA/work/add?data=${JSON.stringify(this.data.detail)}&group=${JSON.stringify(group)}`,
  384. })
  385. break;
  386. case "完成":
  387. this.setData({
  388. confirmShow: true
  389. })
  390. break;
  391. case "跟进":
  392. wx.navigateTo({
  393. url: `/packageA/setclient/modules/trace/add/index?ownertable=sys_task&ownerid=${this.data.sys_taskid}`,
  394. })
  395. break;
  396. case "删除":
  397. wx.showModal({
  398. title: '提示',
  399. content: `是否要删除当前任务?`,
  400. complete: (res) => {
  401. if (res.confirm) _Http.basic({
  402. "id": 20221211112601,
  403. "content": {
  404. "sys_taskids": [that.data.detail.sys_taskid]
  405. }
  406. }).then(res => {
  407. console.log("删除任务", res)
  408. wx.showToast({
  409. title: res.msg == '成功' ? '删除成功' : res.msg,
  410. icon: "none",
  411. mask: res.msg == '成功'
  412. })
  413. if (res.msg == '成功') setTimeout(() => {
  414. wx.navigateBack()
  415. }, 800)
  416. })
  417. }
  418. })
  419. break;
  420. }
  421. },
  422. onUnload() {
  423. let page = getCurrentPages()[getCurrentPages().length - 2]
  424. if (page.__route__ == 'packageA/work/index') {
  425. let content = JSON.parse(JSON.stringify(page.data.content));
  426. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  427. content.pageNumber = 1;
  428. _Http.basic({
  429. id: '20220901162901',
  430. content
  431. }).then(res => {
  432. console.log("更新任务列表", res);
  433. if (res.msg == '成功') page.setData({
  434. list: res.data,
  435. "content.total": res.total
  436. })
  437. })
  438. } else {
  439. page.getTags && page.getTags()
  440. page.partialRenewal && page.partialRenewal(true)
  441. }
  442. },
  443. startSynchronization() {
  444. console.log("开始同步")
  445. wx.navigateTo({
  446. url: '/packageA/work/synchronization?data=' + JSON.stringify({
  447. ownertable: this.data.detail.ownertable,
  448. ownerid: this.data.detail.ownerid
  449. }),
  450. });
  451. _Http.selectSync = (item, ownertable) => {
  452. if (["sys_task", "sa_customers", "sa_project"].includes(ownertable)) {
  453. this.setData({
  454. finishnotes: `跟进类型:${item.type}\n跟进对象:${item.contacts ? item.contacts.join(","):""}\n${item.content}`
  455. })
  456. } else if (ownertable == 'sat_orderclue') {
  457. this.setData({
  458. finishnotes: `跟进类型:${item.followupmode}\n跟进内容:${item.content}`
  459. })
  460. } else {
  461. this.setData({
  462. finishnotes: '跟进内容:' + item.content
  463. })
  464. }
  465. wx.navigateBack()
  466. delete(_Http.selectSync)
  467. }
  468. },
  469. })