index.js 9.6 KB

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