detail.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. },
  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. res.data.allorderinvoamount = CNY(res.data.allorderinvoamount)
  140. res.data.allorderoutamount = CNY(res.data.allorderoutamount)
  141. res.data.data = res.data.data.filter(v => v.billnum).map(v => {
  142. v.orderoutamount = CNY(v.orderoutamount)
  143. v.orderinvoamount = CNY(v.orderinvoamount)
  144. return v
  145. })
  146. this.setData({
  147. rests: res.data
  148. })
  149. })
  150. },
  151. getDetail() {
  152. _Http.basic({
  153. "id": 20230705144704,
  154. "content": {
  155. "sa_salesforecastbillid": this.data.sa_salesforecastbillid
  156. }
  157. }).then(res => {
  158. console.log("预测详情", res)
  159. if (res.msg != '成功') wx.showToast({
  160. title: res.msg,
  161. icon: "none"
  162. });
  163. res.data.orderoutamount = CNY(res.data.orderoutamount)
  164. res.data.orderinvoamount = CNY(res.data.orderinvoamount)
  165. this.setData({
  166. detail: res.data,
  167. 'content.title': res.data.title,
  168. isLeader: res.data.userid == wx.getStorageSync('userMsg').userid
  169. });
  170. if (!this.data.isLeader) getApp().agentOrNot("sa_salesforecastbill", this.data.sa_salesforecastbillid).then(s => {
  171. console.log("代理人数据", s)
  172. this.setData({
  173. isLeader: s.data.editable == 1 || this.selectComponent("#Group").data.editable == 1
  174. })
  175. })
  176. if (this.data.admin) this.getRests();
  177. })
  178. },
  179. //tabs 切换
  180. tabsChange({
  181. detail
  182. }) {
  183. this.setData({
  184. tabsActive: detail
  185. });
  186. this.partialRenewal();
  187. },
  188. //更新标签
  189. getTags() {
  190. this.selectComponent("#Tags").getTags();
  191. },
  192. //更新团队成员
  193. getGroup() {
  194. this.selectComponent("#Group").getList().then(res => {
  195. if (!this.data.isLeader) this.setData({
  196. isLeader: this.selectComponent("#Group").data.editable == 1
  197. })
  198. });
  199. },
  200. //局部数据更新 tabs
  201. partialRenewal(init = false) {
  202. let model = this.data.tabsList[this.data.tabsActive].model;
  203. if (model) {
  204. let Component = this.selectComponent(model),
  205. {
  206. total,
  207. pageNumber,
  208. pageTotal
  209. } = Component.data.content,
  210. id = this.data.sa_salesforecastbillid;
  211. if (total == null || init) {
  212. Component.getList(id, init);
  213. } else if (pageNumber <= pageTotal) {
  214. Component.getList(id, false);
  215. }
  216. }
  217. },
  218. onReachBottom() {
  219. this.partialRenewal();
  220. },
  221. onUnload() {
  222. let page = getCurrentPages()[getCurrentPages().length - 2];
  223. if (page.getRests) return page.getRests();
  224. let content = JSON.parse(JSON.stringify(page.data.content));
  225. content.pageSize = ((content.pageNumber - 1) * content.pageSize) || 20;
  226. content.pageNumber = 1;
  227. _Http.basic({
  228. id: page.data.admin ? 20230705144604 : 20230706092304,
  229. content
  230. }).then(res => {
  231. console.log("更新预测", res);
  232. res.data = res.data.map(v => {
  233. v.orderoutamount = CNY(v.orderoutamount)
  234. v.orderinvoamount = CNY(v.orderinvoamount)
  235. return v
  236. })
  237. if (res.msg == '成功') page.setData({
  238. list: res.data,
  239. "content.total": res.total
  240. })
  241. })
  242. }
  243. })