detail.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. "content": {
  15. "type": 1,
  16. "dataid": 0,
  17. "baseonproject": 0,
  18. "title": ""
  19. },
  20. isonlydep: false
  21. },
  22. onLoad(options) {
  23. this.setData({
  24. sa_salesforecastbillid: options.id
  25. })
  26. if (options.admin == 'true') this.setData({
  27. admin: true
  28. })
  29. let tabsList = [{
  30. label: "订单",
  31. icon: "icon-E-dingdan",
  32. model: "#OrderForm"
  33. }, {
  34. label: "项目",
  35. icon: "icon-tabxiangmu",
  36. model: "#Project"
  37. }, {
  38. label: "客户",
  39. icon: "icon-tabkehu",
  40. model: "#Client"
  41. }, {
  42. label: "附件",
  43. icon: "icon-tabfujian1",
  44. model: "#Files"
  45. }, {
  46. label: "操作记录",
  47. icon: "icon-tabcaozuojilu1",
  48. model: "#Record"
  49. }];
  50. const {
  51. isdatafollowup,
  52. istask,
  53. isdatatag,
  54. isdatateam
  55. } = wx.getStorageSync('auth')[options.admin == 'true' ? 'invoiceforecastadmin' : 'invoiceforecast'];
  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. getApp().globalData.Language.getLanguagePackage(this, '预测填报');
  76. },
  77. switchOnChange({
  78. detail
  79. }) {
  80. this.setData({
  81. isonlydep: detail
  82. });
  83. if (detail) this.setData({
  84. active: null,
  85. "content.type": 1,
  86. "content.dataid": 0,
  87. });
  88. this.selectComponent("#organization").initDepAndUser();
  89. this.getRests();
  90. },
  91. /* 切换 */
  92. onChange(e) {
  93. this.setData({
  94. pageIndex: e.detail.index
  95. })
  96. },
  97. openFiltrate() {
  98. this.setData({
  99. showFiltrate: true
  100. })
  101. },
  102. onReady() {
  103. if (this.data.admin) this.selectComponent("#organization").initDepAndUser();
  104. },
  105. handleFilter({
  106. detail
  107. }) {
  108. if (detail.name == 'reset') {
  109. this.selectComponent("#organization").initDepAndUser()
  110. this.setData({
  111. active: null,
  112. 'content.dataid': 0,
  113. 'content.type': 1,
  114. isonlydep: false
  115. })
  116. } else {
  117. let active = this.selectComponent("#organization").data.result;
  118. let type = active.userid ? 0 : 1,
  119. dataid = type == 0 ? active.userid : active.departmentid
  120. this.setData({
  121. active,
  122. 'content.dataid': dataid,
  123. 'content.type': type
  124. })
  125. }
  126. this.getRests();
  127. },
  128. getRests() {
  129. let content = this.data.content;
  130. content.isonlydep = this.data.isonlydep ? 1 : 0
  131. _Http.basic({
  132. "id": 20230705144804,
  133. content
  134. }).then(res => {
  135. console.log("其他预测单", res)
  136. if (res.code != '1') wx.showToast({
  137. title: res.msg,
  138. icon: "none"
  139. });
  140. res.data.allorderinvoamount = CNY(res.data.allorderinvoamount)
  141. res.data.allorderoutamount = CNY(res.data.allorderoutamount)
  142. res.data.data = res.data.data.filter(v => v.billnum).map(v => {
  143. v.orderoutamount = CNY(v.orderoutamount)
  144. v.orderinvoamount = CNY(v.orderinvoamount)
  145. return v
  146. })
  147. this.setData({
  148. rests: res.data
  149. })
  150. })
  151. },
  152. getDetail() {
  153. _Http.basic({
  154. "id": 20230705144704,
  155. "content": {
  156. "sa_salesforecastbillid": this.data.sa_salesforecastbillid
  157. }
  158. }).then(res => {
  159. console.log("预测详情", res)
  160. if (res.code != '1') wx.showToast({
  161. title: res.msg,
  162. icon: "none"
  163. });
  164. res.data.orderoutamount = CNY(res.data.orderoutamount)
  165. res.data.orderinvoamount = CNY(res.data.orderinvoamount)
  166. this.setData({
  167. detail: res.data,
  168. 'content.title': res.data.title,
  169. isLeader: res.data.userid == wx.getStorageSync('userMsg').userid
  170. });
  171. if (!this.data.isLeader) getApp().agentOrNot("sa_salesforecastbill", this.data.sa_salesforecastbillid).then(s => {
  172. console.log("代理人数据", s)
  173. this.setData({
  174. isLeader: s.data.editable == 1 || this.selectComponent("#Group").data.editable == 1
  175. })
  176. })
  177. if (this.data.admin) this.getRests();
  178. })
  179. },
  180. //tabs 切换
  181. tabsChange({
  182. detail
  183. }) {
  184. this.setData({
  185. tabsActive: detail
  186. });
  187. this.partialRenewal();
  188. },
  189. //更新标签
  190. getTags() {
  191. this.selectComponent("#Tags").getTags();
  192. },
  193. //更新团队成员
  194. getGroup() {
  195. this.selectComponent("#Group").getList().then(res => {
  196. if (!this.data.isLeader) this.setData({
  197. isLeader: this.selectComponent("#Group").data.editable == 1
  198. })
  199. });
  200. },
  201. //局部数据更新 tabs
  202. partialRenewal(init = false) {
  203. let model = this.data.tabsList[this.data.tabsActive].model;
  204. if (model) {
  205. let Component = this.selectComponent(model),
  206. {
  207. total,
  208. pageNumber,
  209. pageTotal
  210. } = Component.data.content,
  211. id = this.data.sa_salesforecastbillid;
  212. if (total == null || init) {
  213. Component.getList(id, init);
  214. } else if (pageNumber <= pageTotal) {
  215. Component.getList(id, false);
  216. }
  217. }
  218. },
  219. onReachBottom() {
  220. this.partialRenewal();
  221. },
  222. onUnload() {
  223. let page = getCurrentPages()[getCurrentPages().length - 2];
  224. if (page.getRests) return page.getRests();
  225. let content = JSON.parse(JSON.stringify(page.data.content));
  226. content.pageSize = ((content.pageNumber - 1) * content.pageSize) || 20;
  227. content.pageNumber = 1;
  228. _Http.basic({
  229. id: page.data.admin ? 20230705144604 : 20230706092304,
  230. content
  231. }).then(res => {
  232. console.log("更新预测", res);
  233. res.data = res.data.map(v => {
  234. v.orderoutamount = CNY(v.orderoutamount)
  235. v.orderinvoamount = CNY(v.orderinvoamount)
  236. return v
  237. })
  238. if (res.code == '1') page.setData({
  239. list: res.data,
  240. "content.total": res.total
  241. })
  242. })
  243. }
  244. })