index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = (value, symbol = "", precision = 2) => currency(value, {
  4. symbol,
  5. precision
  6. }).format();
  7. Page({
  8. data: {
  9. dropdownItem: 0,
  10. dropdown: [{
  11. text: '作业看板',
  12. value: 0
  13. },
  14. {
  15. text: '线索',
  16. value: 1
  17. },
  18. {
  19. text: '客户',
  20. value: 2
  21. },
  22. {
  23. text: '项目商机',
  24. value: 3
  25. },
  26. {
  27. text: '作业单据',
  28. value: 4
  29. }
  30. ],
  31. filtratelist: [],
  32. showFiltrate: false,
  33. active: {
  34. name: wx.getStorageSync('userMsg').name,
  35. userid: wx.getStorageSync('userMsg').userid,
  36. isleave: 1
  37. }
  38. },
  39. onLoad(options) {
  40. this.refreshData();
  41. },
  42. openFiltrate() {
  43. this.setData({
  44. showFiltrate: true
  45. })
  46. },
  47. handleFilter({
  48. detail
  49. }) {
  50. if (detail.name == 'reset') {
  51. this.selectComponent("#organization").setData({
  52. isleave: 1
  53. })
  54. this.selectComponent("#organization").initDepAndUser().then(active => {
  55. console.log("active", active)
  56. active.isleave = 1;
  57. this.setData({
  58. active
  59. })
  60. this.refreshData();
  61. this.refreshModel();
  62. });
  63. } else {
  64. this.setData({
  65. active: this.selectComponent("#organization").data.result
  66. })
  67. this.refreshData();
  68. this.refreshModel();
  69. }
  70. },
  71. refreshData() {
  72. const conversion = (n) => {
  73. const integer = (n + '').split(".")[0] + '',
  74. length = integer.length,
  75. regexp = /(?:\.0*|(\.\d+?)0+)$/
  76. if (length <= 4) {
  77. const index = 4 - length;
  78. return { //元
  79. show: CNY(n, "", index).replace(regexp, '$1'),
  80. value: CNY(n, '¥')
  81. }
  82. } else if (length <= 8) {
  83. return { //万-千万
  84. show: CNY(currency(n).divide(10000)).replace(regexp, '$1') + '万',
  85. value: CNY(n)
  86. }
  87. } else {
  88. return { //亿
  89. show: CNY(currency(n).divide(100000000)).replace(regexp, '$1') + '亿',
  90. value: CNY(n)
  91. }
  92. }
  93. };
  94. const sortOut = (obj, data, isConversion = false) => {
  95. for (const key in obj) {
  96. if (key == 'tab') continue;
  97. for (const k in obj[key]) {
  98. obj[key][k] = isConversion ? conversion(data[key + k]) : data[key + k]
  99. }
  100. }
  101. return obj
  102. };
  103. const getData = (dataType) => {
  104. let active = this.data.active;
  105. let type = active.userid ? 0 : 1,
  106. dataid = type == 0 ? active.userid : active.departmentid,
  107. where = {
  108. isleave: active.isleave
  109. };
  110. return _Http.basic({
  111. "id": 20230616131404,
  112. "content": {
  113. nocache: true,
  114. dataType, // 1 作业数据 2 销售数据 3业绩数据
  115. type,
  116. dataid,
  117. where
  118. }
  119. }).then(res => {
  120. let data = {};
  121. switch (dataType) {
  122. case 1:
  123. data = {
  124. tab: {
  125. active: "by",
  126. list: [{
  127. name: "本周",
  128. id: "bz"
  129. }, {
  130. name: "本月",
  131. id: "by"
  132. }, {
  133. name: "本年",
  134. id: "bn"
  135. }]
  136. },
  137. bz: {
  138. khgj: 0,
  139. khxz: 0,
  140. xmgj: 0,
  141. xmxz: 0,
  142. xsxz: 0,
  143. xsgj: 0,
  144. },
  145. by: {
  146. khgj: 0,
  147. khxz: 0,
  148. xmgj: 0,
  149. xmxz: 0,
  150. xsxz: 0,
  151. xsgj: 0,
  152. },
  153. bn: {
  154. khgj: 0,
  155. khxz: 0,
  156. xmgj: 0,
  157. xmxz: 0,
  158. xsxz: 0,
  159. xsgj: 0,
  160. }
  161. }
  162. break;
  163. case 2:
  164. data = {
  165. tab: {
  166. active: "by",
  167. list: [{
  168. name: "本周",
  169. id: "bz"
  170. }, {
  171. name: "本月",
  172. id: "by"
  173. }, {
  174. name: "本年",
  175. id: "bn"
  176. }]
  177. },
  178. bz: {
  179. chje: 0,
  180. kpje: 0,
  181. skje: 0,
  182. xsje: 0
  183. },
  184. by: {
  185. chje: 0,
  186. kpje: 0,
  187. skje: 0,
  188. xsje: 0
  189. },
  190. bn: {
  191. chje: 0,
  192. kpje: 0,
  193. skje: 0,
  194. xsje: 0
  195. }
  196. }
  197. break;
  198. default:
  199. data = res.data
  200. data.tab = {
  201. active: "by",
  202. list: [{
  203. name: "本月",
  204. id: "by"
  205. }, {
  206. name: "本季",
  207. id: "bj"
  208. }, {
  209. name: "本年",
  210. id: "bn"
  211. }]
  212. }
  213. break;
  214. }
  215. return dataType == 3 ? data : sortOut(data, res.data, dataType == 2)
  216. })
  217. };
  218. wx.showLoading({
  219. title: '加载中...',
  220. mask: true
  221. })
  222. Promise.all([getData(1), getData(2), getData(3)]).then(res => {
  223. wx.hideLoading()
  224. for (const key in res[2]) {
  225. if (key == 'tab') continue;
  226. res[2][key].target_l = conversion(res[2][key].target_l);
  227. //实际
  228. res[2][key].amount = conversion(res[2][key].amount);
  229. res[2][key].outamount = conversion(res[2][key].outamount);
  230. res[2][key].invoiceamount = conversion(res[2][key].invoiceamount);
  231. //差额
  232. res[2][key].unamount = CNY(res[2][key].unamount / 10000, '');
  233. res[2][key].unamountcolor = res[2][key].unamount >= 0 ? '#5AB73F' : '#EB4B5C';
  234. res[2][key].unoutamount = CNY(res[2][key].unoutamount / 10000, '');
  235. res[2][key].unoutamountcolor = res[2][key].unoutamount >= 0 ? '#5AB73F' : '#EB4B5C';
  236. res[2][key].uninvoiceamount = CNY(res[2][key].uninvoiceamount / 10000, '');
  237. res[2][key].uninvoiceamountcolor = res[2][key].uninvoiceamount >= 0 ? '#5AB73F' : '#EB4B5C';
  238. //达成率
  239. res[2][key].wcamount = currency(res[2][key].wcamount).multiply(100) + '%';
  240. res[2][key].wcoutamount = currency(res[2][key].wcoutamount).multiply(100) + '%';
  241. res[2][key].wcinvoiceamount = currency(res[2][key].wcinvoiceamount).multiply(100) + '%';
  242. }
  243. this.setData({
  244. zysj: res[0],
  245. xssj: res[1],
  246. yjsj: res[2],
  247. })
  248. })
  249. },
  250. dropdownItemChange({
  251. detail
  252. }) {
  253. this.setData({
  254. dropdownItem: detail
  255. })
  256. this.refreshModel();
  257. },
  258. changeId(e) {
  259. const {
  260. id,
  261. name
  262. } = e.currentTarget.dataset;
  263. if (this.data[name].tab.active == id) return;
  264. this.setData({
  265. [`${name}.tab.active`]: id
  266. })
  267. },
  268. refreshModel() {
  269. const dropdownItem = this.data.dropdownItem;
  270. if (dropdownItem == 0) return;
  271. const model = this.selectComponent("#model" + dropdownItem);
  272. if (!model) return;
  273. const active = this.data.active;
  274. model.init(active.departmentid ? '1' : '0', active.departmentid || active.userid);
  275. },
  276. onReady() {
  277. this.selectComponent("#ListBox").setHeight(".head", this);
  278. this.selectComponent("#organization").setData({
  279. isleave: 1
  280. })
  281. this.selectComponent("#organization").initDepAndUser().then(active => {
  282. this.setData({
  283. active
  284. })
  285. this.refreshModel();
  286. });
  287. }
  288. })