detail.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. },
  21. onLoad(options) {
  22. this.setData({
  23. sa_salesforecastbillid: options.id
  24. })
  25. if (options.admin == 'true') {
  26. this.setData({
  27. admin: true
  28. })
  29. _Http.basic({
  30. "id": 20230620102004,
  31. "content": {}
  32. }).then(res => {
  33. console.log("获取下级部门和下级人员", res)
  34. if (res.msg != '成功') return wx.showToast({
  35. title: res.data,
  36. icon: "none"
  37. })
  38. let data = {
  39. label: "查询范围",
  40. showName: "name", //显示字段
  41. valueKey: "active", //返回Key
  42. value: "id", //选中值
  43. list: res.data.hr.map(v => {
  44. v.id = v.userid;
  45. v.type = '人员'
  46. delete(v.rowindex)
  47. delete(v.userid)
  48. return v
  49. })
  50. };
  51. const mflat = (v, prefix) => {
  52. v.subdep.forEach(s => mflat(s, v.depname));
  53. v.name = v.depname;
  54. v.type = '部门';
  55. v.id = v.departmentid;
  56. delete(v.depname)
  57. delete(v.departmentid)
  58. delete(v.parentid)
  59. delete(v.rowindex)
  60. delete(v.subdep)
  61. data.list.unshift(v)
  62. };
  63. res.data.dep.forEach(v => mflat(v))
  64. this.setData({
  65. "filtratelist[0]": data
  66. });
  67. });
  68. }
  69. const appAuth = wx.getStorageSync('auth')[options.admin == 'true' ? 'invoiceforecastadmin' : 'invoiceforecast'];
  70. let tabsList = [{
  71. label: "订单",
  72. icon: "icon-E-dingdan",
  73. model: "#OrderForm"
  74. }, {
  75. label: "项目",
  76. icon: "icon-tabxiangmu",
  77. model: "#Project"
  78. }, {
  79. label: "客户",
  80. icon: "icon-tabkehu",
  81. model: "#Client"
  82. }, {
  83. label: "附件",
  84. icon: "icon-tabfujian1",
  85. model: "#Files"
  86. }, {
  87. label: "操作记录",
  88. icon: "icon-tabcaozuojilu1",
  89. model: "#Record"
  90. }];
  91. if (appAuth.istask) tabsList.push({
  92. label: "任务",
  93. icon: "icon-tabrenwu",
  94. model: "#Work"
  95. })
  96. this.setData({
  97. tabsList
  98. })
  99. this.getDetail();
  100. this.getTags();
  101. this.partialRenewal();
  102. },
  103. /* 切换 */
  104. onChange(e) {
  105. this.setData({
  106. pageIndex: e.detail.index
  107. })
  108. },
  109. openFiltrate() {
  110. this.setData({
  111. showFiltrate: true
  112. })
  113. },
  114. handleFilter(e) {
  115. let {
  116. active
  117. } = e.detail;
  118. try {
  119. if (active.type) this.setData({
  120. active,
  121. 'content.type': active.type == '人员' ? 0 : 1,
  122. 'content.dataid': active.id || 0,
  123. });
  124. } catch (error) {
  125. this.setData({
  126. active: null,
  127. 'content.type': 1,
  128. 'content.dataid': 0,
  129. })
  130. }
  131. this.getRests();
  132. },
  133. getRests() {
  134. _Http.basic({
  135. "id": 20230705144804,
  136. content: this.data.content
  137. }).then(res => {
  138. console.log("其他预测单", res)
  139. if (res.msg != '成功') wx.showToast({
  140. title: res.msg,
  141. icon: "none"
  142. });
  143. res.data.allorderinvoamount = CNY(res.data.allorderinvoamount)
  144. res.data.allorderoutamount = CNY(res.data.allorderoutamount)
  145. res.data.data = res.data.data.filter(v => v.billnum).map(v => {
  146. v.orderoutamount = CNY(v.orderoutamount)
  147. v.orderinvoamount = CNY(v.orderinvoamount)
  148. return v
  149. })
  150. this.setData({
  151. rests: res.data
  152. })
  153. })
  154. },
  155. getDetail() {
  156. _Http.basic({
  157. "id": 20230705144704,
  158. "content": {
  159. "sa_salesforecastbillid": this.data.sa_salesforecastbillid
  160. }
  161. }).then(res => {
  162. console.log("预测详情", res)
  163. if (res.msg != '成功') wx.showToast({
  164. title: res.msg,
  165. icon: "none"
  166. });
  167. res.data.orderoutamount = CNY(res.data.orderoutamount)
  168. res.data.orderinvoamount = CNY(res.data.orderinvoamount)
  169. this.setData({
  170. detail: res.data,
  171. 'content.title': res.data.title,
  172. isLeader: res.data.userid == wx.getStorageSync('userMsg').userid
  173. });
  174. if (this.data.admin) this.getRests();
  175. })
  176. },
  177. //tabs 切换
  178. tabsChange({
  179. detail
  180. }) {
  181. this.setData({
  182. tabsActive: detail
  183. });
  184. this.partialRenewal();
  185. },
  186. //更新标签
  187. getTags() {
  188. this.selectComponent("#Tags").getTags();
  189. },
  190. //局部数据更新 tabs
  191. partialRenewal(init = false) {
  192. let model = this.data.tabsList[this.data.tabsActive].model;
  193. if (model) {
  194. let Component = this.selectComponent(model),
  195. {
  196. total,
  197. pageNumber,
  198. pageTotal
  199. } = Component.data.content,
  200. id = this.data.sa_salesforecastbillid;
  201. if (total == null || init) {
  202. Component.getList(id, init);
  203. } else if (pageNumber <= pageTotal) {
  204. Component.getList(id, false);
  205. }
  206. }
  207. },
  208. onReachBottom() {
  209. this.partialRenewal();
  210. },
  211. onUnload() {
  212. let page = getCurrentPages()[getCurrentPages().length - 2];
  213. if (page.getRests) return page.getRests();
  214. let content = JSON.parse(JSON.stringify(page.data.content));
  215. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  216. content.pageNumber = 1;
  217. _Http.basic({
  218. id: page.data.admim ? 20230705144604 : 20230706092304,
  219. content
  220. }).then(res => {
  221. console.log("更新预测", res);
  222. res.data = res.data.map(v => {
  223. v.orderoutamount = CNY(v.orderoutamount)
  224. v.orderinvoamount = CNY(v.orderinvoamount)
  225. return v
  226. })
  227. if (res.msg == '成功') page.setData({
  228. list: res.data,
  229. "content.total": res.total
  230. })
  231. })
  232. }
  233. })