detail.js 17 KB

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