two-rate-analysis.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. var reqList = []; //记录请求的参数和url,用于后退时使用
  2. Vue.use(Vuedals.default);
  3. new Vue({
  4. el: "#main",
  5. data: {
  6. appname: "两率分析",
  7. isback: true,
  8. isrefresh: true,
  9. isfilter: false,
  10. isopen: false,
  11. //请求页面所需参数
  12. level: '',
  13. area: '',
  14. areaTitle: '',
  15. index: '18',
  16. endDate: '',
  17. lowLevel: '',
  18. userRole: '',
  19. //数据结果
  20. topDatas: {
  21. sanShiData: 0,
  22. sanShiRate: '0.00%',
  23. gaoWeiData: 0,
  24. gaoWeiRate: '0.00%'
  25. }
  26. },
  27. components: {
  28. vuedals: Vuedals.Component
  29. },
  30. methods: {
  31. changeTag: function(val) {
  32. this.index = val;
  33. loadData([1], this);
  34. //存储请求所带的参数
  35. reqList.push({
  36. level: this.level,
  37. area: this.area,
  38. areaTitle: this.areaTitle,
  39. index: this.index,
  40. date: this.endDate,
  41. endDate: this.endDate,
  42. lowLevel: this.lowLevel
  43. })
  44. },
  45. getAreaData: function(arg) {
  46. //如果level改变,则需要重新加载整个页面的数据,否则只需加载底部区域数据
  47. if(arg.level == this.level) {
  48. this.lowLevel = arg.lowLevel;
  49. loadData([1], this);
  50. } else {
  51. this.level = arg.level;
  52. this.lowLevel = arg.lowLevel;
  53. this.area = arg.area;
  54. this.areaTitle = arg.areaTitle;
  55. loadData([0, 1], this);
  56. }
  57. EventBus.$emit('update-area-name', {
  58. areaName: this.areaTitle
  59. });
  60. //存储请求所带的参数
  61. reqList.push({
  62. level: this.level,
  63. area: this.area,
  64. areaTitle: this.areaTitle,
  65. index: this.index,
  66. endDate: this.endDate,
  67. lowLevel: this.lowLevel,
  68. })
  69. }
  70. },
  71. mounted: function() {
  72. //初始化数据
  73. initData(this);
  74. //获得顶部各tab的值
  75. loadData([0, 1], this); //参数组数表示请求的区域为上中下
  76. //存储请求所带的参数
  77. reqList.push({
  78. level: this.level,
  79. area: this.area,
  80. areaTitle: this.areaTitle,
  81. index: this.index,
  82. endDate: this.endDate,
  83. lowLevel: this.lowLevel
  84. });
  85. //设置监听器, 监听折线图日期变化
  86. var vm = this;
  87. //监听后退按钮的操作
  88. EventBus.$on("back-click", function(arg) {
  89. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  90. if(reqList.length == 1) {
  91. history.go(-1);
  92. } else {
  93. var preInfo = reqList.pop();
  94. var info = reqList[reqList.length - 1];
  95. vm.level = info.level;
  96. vm.area = info.area;
  97. vm.areaTitle = info.areaTitle;
  98. vm.lowLevel = info.lowLevel;
  99. vm.index = info.index;
  100. loadData([0, 1], vm);
  101. EventBus.$emit('update-area-name', {areaName: vm.areaTitle});
  102. }
  103. });
  104. //监听页面刷新
  105. EventBus.$on("refresh-click", function(arg) {
  106. EventBus.$emit('update-statistics-time', {}); //更新统计时间
  107. loadData([0, 1], vm);
  108. });
  109. $("#main").removeClass("c-hide");
  110. }
  111. })
  112. function initData(vm) {
  113. //获得缓存中缓存的角色权限
  114. var userRole = window.sessionStorage.getItem("selectedRole");
  115. if(!userRole) {
  116. return false;
  117. }
  118. vm.userRole = JSON.parse(userRole);
  119. vm.level = vm.userRole.code == '350200' ? 4 : vm.userRole.code.length == 6 ? 3 : 2;
  120. vm.area = vm.userRole.code;
  121. vm.areaTitle = vm.userRole.name;
  122. vm.endDate = getDateBefore(1);
  123. //更新头部信息
  124. EventBus.$emit('update-all-prompt-info', {
  125. areaName: vm.areaTitle,
  126. selectDate: "",
  127. dimensionVal: ""
  128. });
  129. }
  130. function getTopTagDatas(vm) {
  131. var reqs = [],
  132. url = "/statistics/sszq_qwrq_info",
  133. data = {
  134. level: vm.level,
  135. area: vm.area,
  136. endDate: vm.endDate
  137. };
  138. reqs.push(httpRequest.get(url, {
  139. data: data
  140. }));
  141. Promise.all(reqs).then(function(ress) {
  142. for(i = 0; i < ress.length; i++) {
  143. var res = ress[i];
  144. if(res.status == 200) {
  145. var sszq = res.data.sszq;
  146. var gwrq = res.data.gwrq;
  147. vm.topDatas.sanShiData = sszq.amount + "/" + sszq.num;
  148. vm.topDatas.sanShiRate = sszq.rate == 0 ? '0.00%' : sszq.rate.toString().substring(0, sszq.rate.length - 2) + "%";
  149. vm.topDatas.gaoWeiData = gwrq.amount + "/" + gwrq.num;
  150. vm.topDatas.gaoWeiRate = gwrq.rate == 0 ? '0.00%' : gwrq.rate.toString().substring(0, gwrq.rate.length - 2) + "%";
  151. $('#sszql_canvas').waterbubble({
  152. //txt: res.signRate.rate.substring(0,res.signRate.rate.length-2) + "%",res.signRate.rate/100
  153. data: sszq.rate / 100,
  154. waterColor: '#12b7f5',
  155. lineWidth: 0,
  156. textColor: 'rgba(0, 0, 0, 0.8)',
  157. font: 'bold 25px arial'
  158. });
  159. $('#gaowei_canvas').waterbubble({
  160. //txt: res.signRate.rate.substring(0,res.signRate.rate.length-2) + "%",res.signRate.rate/100
  161. data: gwrq.rate / 100,
  162. waterColor: '#12b7f5',
  163. lineWidth: 0,
  164. radius: 75,
  165. textColor: 'rgba(0, 0, 0, 0.8)',
  166. font: 'bold 25px arial'
  167. });
  168. } else {
  169. console.log(res.msg);
  170. }
  171. }
  172. })
  173. }
  174. function initReqParams(vm) {
  175. reqParam = [{
  176. url: "/statistics/lowlevel_all",
  177. reqType: 'get',
  178. data: {
  179. sort: 1,
  180. date: vm.endDate,
  181. level: vm.level,
  182. index: vm.index,
  183. area: vm.area
  184. }
  185. }];
  186. if(vm.lowLevel) {
  187. reqParam[0].data.lowLevel = vm.lowLevel;
  188. }
  189. return reqParam;
  190. }
  191. function loadData(loadArr, vm) {
  192. if(loadArr.indexOf(0) > -1) {
  193. getTopTagDatas(vm);
  194. }
  195. if(vm.level == 2) { //社区管理员不显示团队信息
  196. return false;
  197. }
  198. //获取其他请求的参数
  199. var reqParams = initReqParams(vm),
  200. reqPromise = [],
  201. newArr = []; //记录非顶部请求的请求数组
  202. for(i = 0; i < loadArr.length; i++) {
  203. if(loadArr[i] == 0) {
  204. // do nothing
  205. } else {
  206. var j = loadArr[i] - 1;
  207. var param = reqParams[j];
  208. reqPromise.push(httpRequest.get(param.url, {
  209. data: param.data
  210. }));
  211. newArr.push(loadArr[i]);
  212. }
  213. }
  214. if(reqPromise.length > 0) {
  215. Promise.all(reqPromise).then(function(ress) {
  216. var res = ress[0] || [];
  217. if(res && res.status == 200) {
  218. listHandle(res.data, vm);
  219. }
  220. })
  221. }
  222. }
  223. function listHandle(data, vm) {
  224. for(i in data) {
  225. var list = data[i];
  226. var topArr = [];
  227. var resultData = soreQLY(list);
  228. topArr = soreRank(getKeyValueArr(resultData, 'rate'));
  229. var arr = _.map(resultData, function(o, index) {
  230. var cols = [o.name];
  231. var rate = o.rate ? parseFloat(o.rate).toFixed(2) + "%" : '0.00%';
  232. cols.push(rate);
  233. return {
  234. rank: topArr[index],
  235. code: o.code,
  236. name: o.name,
  237. cols: cols
  238. }
  239. });
  240. var headers = {
  241. '18': ["排名", "三师转签率"],
  242. '19': ["排名", "高危人数签约率"]
  243. };
  244. EventBus.$emit("render-area-data", {
  245. level: vm.level,
  246. area: vm.area,
  247. lowLevel: vm.lowLevel,
  248. headers: headers[vm.index],
  249. rows: arr
  250. });
  251. }
  252. }
  253. //签约率排序
  254. function soreQLY(arr) {
  255. var resArr = [];
  256. for(var i=0;i<arr.length;i++){
  257. var item = arr[i];
  258. item.rate = parseFloat(item.rate);
  259. resArr.push(item)
  260. }
  261. var eventData = _.chain(resArr)
  262. // 根据date日期字段排序
  263. .sortBy("rate").reverse()
  264. // 对集合中每一对象进行处理,返回新的集合
  265. .map(function (item) {
  266. return {
  267. amount: item.amount,
  268. code: item.code,
  269. rate: item.rate,
  270. name: item.name,
  271. num: item.num
  272. }
  273. }).value();
  274. return eventData;
  275. }