detail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. let _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. showFiltrate: false,
  10. pageIndex: 0,
  11. admin: false,
  12. tabsActive: 0,
  13. active: null,
  14. tabbarList: [{
  15. icon: "icon-guanlian-bianji",
  16. label: "添加项目"
  17. }, {
  18. icon: "icon-guanlian-fuzhi",
  19. label: "移除项目"
  20. }],
  21. "content": {
  22. "type": 1,
  23. "dataid": 0,
  24. "baseonproject": 1,
  25. "title": ""
  26. },
  27. isonlydep: false
  28. },
  29. onLoad(options) {
  30. this.setData({
  31. sa_salesforecastbillid: options.id
  32. })
  33. if (options.admin == 'true') this.setData({
  34. admin: true
  35. })
  36. let tabsList = [{
  37. label: "项目产品清单",
  38. icon: "icon-tabchanpin",
  39. model: "#Project"
  40. }, {
  41. label: "附件",
  42. icon: "icon-tabfujian1",
  43. model: "#Files"
  44. }, {
  45. label: "操作记录",
  46. icon: "icon-tabcaozuojilu1",
  47. model: "#Record"
  48. }];
  49. const {
  50. isdatafollowup,
  51. istask,
  52. isdatatag,
  53. isdatateam
  54. } = wx.getStorageSync('auth')[options.admin == 'true' ? 'finishforecastadmin' : 'finishforecast'];
  55. console.log(wx.getStorageSync('auth')[options.admin == 'true' ? 'finishforecastadmin' : 'finishforecast'])
  56. if (isdatafollowup) tabsList.push({
  57. label: "跟进动态",
  58. icon: "icon-tabgenjinjilu",
  59. model: "#Trace"
  60. })
  61. if (istask) tabsList.push({
  62. label: "任务",
  63. icon: "icon-tabrenwu",
  64. model: "#Work"
  65. })
  66. this.setData({
  67. tabsList,
  68. isdatatag,
  69. isdatateam
  70. })
  71. this.getDetail();
  72. if (isdatatag) this.getTags();
  73. if (isdatateam) this.getGroup()
  74. this.partialRenewal();
  75. },
  76. switchOnChange({
  77. detail
  78. }) {
  79. this.setData({
  80. isonlydep: detail
  81. });
  82. if (detail) this.setData({
  83. active: null,
  84. "content.type": 1,
  85. "content.dataid": 0,
  86. });
  87. this.selectComponent("#organization").initDepAndUser();
  88. this.getRests();
  89. },
  90. /* 切换 */
  91. onChange(e) {
  92. this.setData({
  93. pageIndex: e.detail.index
  94. })
  95. },
  96. openFiltrate() {
  97. this.setData({
  98. showFiltrate: true
  99. })
  100. },
  101. onReady() {
  102. if (this.data.admin) this.selectComponent("#organization").initDepAndUser();
  103. },
  104. handleFilter({
  105. detail
  106. }) {
  107. if (detail.name == 'reset') {
  108. this.selectComponent("#organization").initDepAndUser()
  109. this.setData({
  110. active: null,
  111. 'content.dataid': 0,
  112. 'content.type': 1,
  113. isonlydep: false
  114. })
  115. } else {
  116. let active = this.selectComponent("#organization").data.result;
  117. let type = active.userid ? 0 : 1,
  118. dataid = type == 0 ? active.userid : active.departmentid
  119. this.setData({
  120. active,
  121. 'content.dataid': dataid,
  122. 'content.type': type
  123. })
  124. }
  125. this.getRests();
  126. },
  127. getRests() {
  128. let content = this.data.content;
  129. content.isonlydep = this.data.isonlydep ? 1 : 0
  130. _Http.basic({
  131. "id": 20230705144804,
  132. content
  133. }).then(res => {
  134. console.log("其他预测单", res)
  135. if (res.msg != '成功') wx.showToast({
  136. title: res.msg,
  137. icon: "none"
  138. });
  139. if (res.data.allprojectamount) res.data.allprojectamount = CNY(res.data.allprojectamount)
  140. res.data.data = res.data.data.filter(v => v.sa_salesforecastbillid).map(v => {
  141. v.showAmount = CNY(v.projectamount)
  142. return v
  143. })
  144. this.setData({
  145. rests: res.data
  146. })
  147. })
  148. },
  149. getDetail() {
  150. _Http.basic({
  151. "id": 20230705144704,
  152. "content": {
  153. "sa_salesforecastbillid": this.data.sa_salesforecastbillid
  154. }
  155. }).then(res => {
  156. console.log("预测详情", res)
  157. if (res.msg != '成功') wx.showToast({
  158. title: res.msg,
  159. icon: "none"
  160. });
  161. res.data.projectamount = CNY(res.data.projectamount)
  162. this.setData({
  163. detail: res.data,
  164. 'content.title': res.data.title,
  165. isLeader: res.data.userid == wx.getStorageSync('userMsg').userid
  166. });
  167. if (!this.data.isLeader) getApp().agentOrNot("sa_salesforecastbill", this.data.sa_salesforecastbillid).then(s => {
  168. console.log("代理人数据", s)
  169. this.setData({
  170. isLeader: s.data.editable == 1 || this.selectComponent("#Group").data.editable == 1
  171. })
  172. })
  173. if (this.data.admin) this.getRests();
  174. })
  175. },
  176. tabbarOnClick({
  177. detail
  178. }) {
  179. switch (detail.label) {
  180. case "添加项目":
  181. this.toAddProject();
  182. break;
  183. case "移除项目":
  184. wx.navigateTo({
  185. url: `/packageA/select/project/select2?params=${JSON.stringify({
  186. "id": "20230705144904",
  187. "content": {
  188. nocache: true,
  189. sa_salesforecastbillid:this.data.sa_salesforecastbillid,
  190. pageSize: 20,
  191. "where":{
  192. "condition":""
  193. }
  194. }
  195. })}&radio=true`,
  196. })
  197. getApp().globalData.handleSelect = this.deteleProject.bind(this);
  198. break;
  199. }
  200. },
  201. //tabs 切换
  202. tabsChange({
  203. detail
  204. }) {
  205. this.setData({
  206. tabsActive: detail
  207. });
  208. this.partialRenewal();
  209. },
  210. toAddProject() {
  211. wx.navigateTo({
  212. url: `/packageA/select/project/select2?params=${JSON.stringify({
  213. "id": 20230705145604,
  214. "content": {
  215. nocache:true,
  216. sa_salesforecastbillid:this.data.sa_salesforecastbillid,
  217. "where":{
  218. "condition":""
  219. }
  220. }
  221. })}`,
  222. });
  223. getApp().globalData.handleSelect = this.addProject.bind(this);
  224. },
  225. /* 添加项目 */
  226. addProject({
  227. list
  228. }) {
  229. let that = this;
  230. wx.showModal({
  231. title: '提示',
  232. content: `是否确认添加${list.length}个项目`,
  233. complete: ({
  234. confirm
  235. }) => {
  236. if (confirm) _Http.basic({
  237. id: 20230705145104,
  238. content: {
  239. sa_salesforecastbillid: that.data.sa_salesforecastbillid,
  240. "ownertable": "sa_project",
  241. salesforecastproject: list.map(v => {
  242. return {
  243. ownerid: v.sa_projectid,
  244. ownertable: "sa_project",
  245. discountrate: v.discountrate,
  246. sa_salesforecastprojectid: 0
  247. }
  248. })
  249. }
  250. }).then(res => {
  251. console.log("添加项目", res)
  252. wx.showToast({
  253. title: res.msg == '成功' ? '添加成功' : res.msg,
  254. icon: "none"
  255. });
  256. if (res.msg == '成功') {
  257. that.setData({
  258. tabsActive: that.data.tabsList.findIndex(v => v.label == '项目产品清单')
  259. });
  260. setTimeout(() => {
  261. wx.navigateBack();
  262. setTimeout(() => {
  263. that.selectComponent('#Project').getList(that.data.sa_salesforecastbillid, false);
  264. }, 300)
  265. }, 300)
  266. }
  267. })
  268. }
  269. })
  270. },
  271. /* 删除项目 */
  272. deteleProject({
  273. item
  274. }) {
  275. let that = this;
  276. wx.showModal({
  277. title: '提示',
  278. content: `是否确认移除“${item.projectname}”`,
  279. complete: ({
  280. confirm
  281. }) => {
  282. if (confirm) _Http.basic({
  283. "id": 20230705145304,
  284. "content": {
  285. "sa_salesforecastbillid": that.data.sa_salesforecastbillid,
  286. "sa_salesforecastprojectids": [item.sa_salesforecastprojectid]
  287. }
  288. }).then(res => {
  289. console.log("移除项目", res)
  290. if (res.msg != '成功') return wx.showToast({
  291. title: res.msg,
  292. icon: "none"
  293. });
  294. that.selectComponent("#Project").getList(that.data.sa_salesforecastbillid);
  295. setTimeout(() => {
  296. wx.showToast({
  297. title: `已移除“${item.projectname}”`,
  298. icon: "none"
  299. })
  300. let page = getCurrentPages().find(v => v.__route__ == 'packageA/select/project/select2');
  301. if (page) page.deteleItem(item.sa_projectid);
  302. that.getDetail();
  303. }, 500)
  304. })
  305. }
  306. })
  307. },
  308. //更新标签
  309. getTags() {
  310. this.selectComponent("#Tags").getTags();
  311. },
  312. //局部数据更新 tabs
  313. partialRenewal(init = false) {
  314. let model = this.data.tabsList[this.data.tabsActive].model;
  315. if (model) {
  316. let Component = this.selectComponent(model),
  317. {
  318. total,
  319. pageNumber,
  320. pageTotal
  321. } = Component.data.content,
  322. id = this.data.sa_salesforecastbillid;
  323. if (total == null || init) {
  324. Component.getList(id, init);
  325. } else if (pageNumber <= pageTotal) {
  326. Component.getList(id, false);
  327. }
  328. }
  329. },
  330. onReachBottom() {
  331. this.partialRenewal();
  332. },
  333. //更新团队成员
  334. getGroup() {
  335. this.selectComponent("#Group").getList().then(res => {
  336. if (!this.data.isLeader) this.setData({
  337. isLeader: this.selectComponent("#Group").data.editable == 1
  338. })
  339. });
  340. },
  341. onUnload() {
  342. let page = getCurrentPages()[getCurrentPages().length - 2];
  343. if (page.getRests) return page.getRests();
  344. let content = JSON.parse(JSON.stringify(page.data.content));
  345. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  346. content.pageNumber = 1;
  347. _Http.basic({
  348. id: page.data.admin ? 20230705144604 : 20230706092304,
  349. content
  350. }).then(res => {
  351. console.log("更新预测", res);
  352. res.data = res.data.map(v => {
  353. v.showAmount = CNY(v.projectamount)
  354. return v
  355. })
  356. if (res.msg == '成功') page.setData({
  357. list: res.data,
  358. "content.total": res.total
  359. })
  360. })
  361. }
  362. })