common.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. var indexName = { 'index_128': '预约总量', 'index_129': '居民预约量', 'index_130': '代预约量' }
  2. function getSignDate() {
  3. //获取初始化签约年
  4. var nowdate = new Date()
  5. var year = nowdate.getFullYear()
  6. var month = nowdate.getMonth() + 1
  7. if (year >= 2023) {
  8. year = year
  9. } else if (month <= 6) {
  10. year = year - 1
  11. }
  12. return year
  13. }
  14. function getStartDate(chooseYear) {
  15. // 按年度来计算的时候,开始时间是该年度7月1号还是到下一个年的6月30号结束
  16. // 2022年及以前开始时间07-01
  17. // 2023及以后开始时间01-01
  18. if (chooseYear == 2016) {
  19. return chooseYear + '-08-01'
  20. } else if (chooseYear <= 2022) {
  21. return chooseYear + '-07-01'
  22. } else if (chooseYear >= 2023) {
  23. return chooseYear + '-01-01'
  24. }
  25. }
  26. //获取结束时间
  27. function getEndDate(chooseYear) {
  28. var nowdate = new Date()
  29. var year = nowdate.getFullYear()
  30. var month = nowdate.getMonth() + 1
  31. var day = nowdate.getDate()
  32. var endDate = ''
  33. if (chooseYear < '2022') {
  34. endDate = new Date(parseInt(chooseYear) + 1 + '-06-30')
  35. } else {
  36. endDate = new Date(parseInt(chooseYear) + '-12-31')
  37. }
  38. var now = new Date()
  39. if (now <= endDate) {
  40. return now.format('yyyy-MM-dd')
  41. } else {
  42. if (chooseYear < '2022') {
  43. return parseInt(chooseYear) + 1 + '-06-30'
  44. } else {
  45. return parseInt(chooseYear) + '-12-31'
  46. }
  47. }
  48. }
  49. //获取结束时间29
  50. function getEndDate29(chooseYear) {
  51. chooseYear = parseInt(chooseYear)
  52. var endDate = new Date(chooseYear + 1 + '-06-29'),
  53. now = new Date()
  54. if (now <= endDate) {
  55. return now.format('yyyy-MM-dd')
  56. } else {
  57. return chooseYear + 1 + '-06-29'
  58. }
  59. }
  60. /**
  61. * 获取多少天前的日期
  62. */
  63. function getDateBefore(days) {
  64. var now = new Date()
  65. var date = new Date(now.getTime() - days * 24 * 3600 * 1000)
  66. var year = date.getFullYear()
  67. var month = date.getMonth() + 1
  68. var day = date.getDate()
  69. var hour = date.getHours()
  70. var minute = date.getMinutes()
  71. var second = date.getSeconds()
  72. return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day)
  73. }
  74. /*
  75. * 获取用来排序的字段值,返回数组
  76. * 参数: list - 列表, key - 字段的名称
  77. */
  78. function getKeyValueArr(list, key) {
  79. var arr = []
  80. for (var k in list) {
  81. arr.push(list[k][key])
  82. }
  83. return arr
  84. }
  85. /*
  86. * 排名
  87. */
  88. function soreRank(arr) {
  89. var temp = []
  90. var lis = []
  91. for (var i = 0; i < arr.length; i++) {
  92. lis.push(arr[i])
  93. }
  94. lis = _.uniq(lis)
  95. for (var i = 0; i < arr.length; i++) {
  96. temp[i] = lis.indexOf(arr[i]) + 1
  97. }
  98. return temp
  99. }
  100. /*
  101. * 绘制饼图数据处理 // elId, arry, title, hasNum,colors,radius,noLedend,param
  102. */
  103. function handlePieData(arg) {
  104. var legend = {
  105. orient: 'vertical',
  106. right: arg.legendRight || '15%',
  107. y: 'center'
  108. }
  109. var colorList = []
  110. legendNames = []
  111. var arr1 = _.map(arg.arry, function (o, i) {
  112. var count = 0
  113. if (arg.param) {
  114. count = parseFloat(o[arg.param])
  115. } else {
  116. count = parseFloat(o.amount)
  117. }
  118. var obj = {
  119. name: o[arg.nameparam] || o.name,
  120. count: count
  121. }
  122. legendNames.push(obj)
  123. if (o.code) {
  124. colorList.push(arg.colors[o.code])
  125. } else {
  126. colorList.push(arg.colors[i])
  127. }
  128. return {
  129. value: count,
  130. name: o[arg.nameparam] || o.name
  131. }
  132. })
  133. legend.formatter = function (name) {
  134. if (arg.hasNum) {
  135. var target
  136. for (var i = 0, l = legendNames.length; i < l; i++) {
  137. if (legendNames[i].name == name) {
  138. target = parseInt(legendNames[i].count)
  139. }
  140. }
  141. return name + ': ' + target
  142. } else {
  143. return name
  144. }
  145. }
  146. if (arg.noLedend) {
  147. //true时无注释
  148. drawPie(arg.elId, arr1, colorList, null, arg.position || ['50%', '51%'], arg.radius || ['70%', '90%'], arg.title)
  149. } else {
  150. drawPie(arg.elId, arr1, colorList, legend, arg.position || ['30%', '51%'], arg.radius || ['70%', '90%'], arg.title)
  151. }
  152. }
  153. /*
  154. * 绘制饼图
  155. */
  156. function drawPie(elId, arry, color, legend, center, radius, title) {
  157. var pieChart = echarts.init(document.getElementById(elId))
  158. var options = {
  159. tooltip: {
  160. trigger: 'item',
  161. formatter: '{b} : {c} ({d}%)'
  162. // position: ['50%', '50%']
  163. },
  164. color: color,
  165. series: [
  166. {
  167. type: 'pie',
  168. radius: ['80%', '99%'],
  169. startAngle: 270,
  170. legendHoverLink: false,
  171. hoverAnimation: false,
  172. avoidLabelOverlap: false,
  173. label: {
  174. normal: {
  175. show: false,
  176. textStyle: {
  177. color: '#000'
  178. }
  179. }
  180. },
  181. labelLine: {
  182. normal: {
  183. show: false
  184. }
  185. },
  186. data: arry
  187. }
  188. ]
  189. }
  190. if (legend) {
  191. options.legend = legend
  192. }
  193. if (center) {
  194. options.series[0].center = center
  195. }
  196. if (radius) {
  197. options.series[0].radius = radius
  198. }
  199. if (title) {
  200. options.title = title
  201. }
  202. pieChart.clear()
  203. pieChart.setOption(options)
  204. }
  205. /*
  206. * 绘制饼图
  207. * arry [{name: '', value: ''}]
  208. * color ['#ffc800', '#17b3ec']
  209. * silent 图形是否不响应和触发鼠标事件,默认为 false,即响应和触发鼠标事件
  210. */
  211. function drawPieChart(elId, arry, color, silent) {
  212. var myChart = echarts.init(document.getElementById(elId))
  213. var option = {
  214. tooltip: {
  215. trigger: 'item',
  216. formatter: '{b} : {c} ({d}%)',
  217. position: ['50%', '50%']
  218. },
  219. color: color,
  220. series: [
  221. {
  222. type: 'pie',
  223. radius: ['80%', '99%'],
  224. startAngle: 270,
  225. legendHoverLink: false,
  226. hoverAnimation: false,
  227. avoidLabelOverlap: false,
  228. silent: silent,
  229. label: {
  230. normal: {
  231. show: false,
  232. textStyle: {
  233. color: '#000'
  234. }
  235. }
  236. },
  237. labelLine: {
  238. normal: {
  239. show: false
  240. }
  241. },
  242. data: arry
  243. }
  244. ]
  245. }
  246. $('#' + elId).removeAttr('_echarts_instance_')
  247. myChart.setOption(option)
  248. return myChart
  249. }
  250. /**
  251. * 绘制柱状图
  252. */
  253. function drawBarChart(el, xData, yData, color, name) {
  254. var myChart = echarts.init(document.getElementById(el))
  255. // 指定图表的配置项和数据
  256. var option = {
  257. tooltip: {
  258. trigger: 'item'
  259. },
  260. toolbox: {
  261. dataZoom: true,
  262. show: true,
  263. orient: 'vertical',
  264. x: 'right',
  265. y: 'center'
  266. },
  267. grid: {
  268. left: '20px',
  269. right: '20px',
  270. bottom: '20px',
  271. top: '20px',
  272. containLabel: true
  273. },
  274. xAxis: [
  275. {
  276. type: 'category',
  277. data: xData,
  278. axisLabel: {
  279. interval: 0 //横轴信息全部显示
  280. },
  281. splitLine: {
  282. show: false
  283. }
  284. }
  285. ],
  286. yAxis: [
  287. {
  288. type: 'value',
  289. splitLine: { show: false }
  290. }
  291. ],
  292. series: [
  293. {
  294. clickable: true,
  295. name: name,
  296. itemStyle: {
  297. normal: {
  298. label: {
  299. show: true,
  300. position: 'top'
  301. },
  302. color: color
  303. }
  304. },
  305. barWidth: 20,
  306. type: 'bar',
  307. data: yData
  308. }
  309. ]
  310. }
  311. // 使用刚指定的配置项和数据显示图表。
  312. myChart.setOption(option)
  313. return myChart
  314. }
  315. /**
  316. * 绘制折线图数据处理
  317. * @param {Object} elId div的id值
  318. * @param {Object} data 数据值
  319. * @param {Object} selectedDateType true的时候x轴值年-月-日 1-日,2-周, 3-月
  320. */
  321. function getChartData(elId, data, selectedDateType, hasLegend, title, unit) {
  322. var dataZoom_end,
  323. xDatas = [],
  324. yDatas = [],
  325. names = [],
  326. colors = ['#12b7f5', '#cd67fd', '#FF9526']
  327. for (var p in data) {
  328. if (hasLegend) {
  329. names.push(indexName[p])
  330. }
  331. var xData = _.map(data[p], function (o) {
  332. return o.range
  333. })
  334. var yData = _.map(data[p], function (o) {
  335. return o.amount
  336. })
  337. xDatas.push(xData)
  338. yDatas.push(yData)
  339. var lastIndex = yData.length % 10
  340. if (yData.length > 10) {
  341. dataZoom_end = 100 - (9 / yData.length) * 100
  342. } else {
  343. dataZoom_end = 0
  344. }
  345. }
  346. setTimeout(function () {
  347. EventBus.$emit('draw-line-chart', {
  348. panelName: title,
  349. quotaNames: names,
  350. xData: xDatas[0],
  351. yDatas: yDatas,
  352. colors: colors,
  353. selectedDateType: selectedDateType,
  354. nowlineid: elId,
  355. unit: unit
  356. })
  357. }, 10)
  358. }
  359. /**
  360. * 绘制柱状图数据处理
  361. * @param {Object} elId div的id值
  362. * @param {Object} data 数据值
  363. */
  364. function getBarData(arg) {
  365. var dataZoom_end,
  366. xDatas = [],
  367. yDatas = [],
  368. names = [],
  369. colors = ['#12b7f5', '#cd67fd', '#FF9526']
  370. if (arg.colors) {
  371. colors = arg.colors
  372. }
  373. for (var p in arg.data) {
  374. if (arg.hasLegend) {
  375. names.push(arg.indexNames[p])
  376. }
  377. var xData = _.map(arg.data[p].data || arg.data[p], function (o) {
  378. return o[arg.rangeParams] || o.range
  379. })
  380. var yData = _.map(arg.data[p].data || arg.data[p], function (o) {
  381. return o[arg.amountParams] || o.amount
  382. })
  383. xDatas.push(xData)
  384. yDatas.push(yData)
  385. var lastIndex = yData.length % 10
  386. if (yData.length > 10) {
  387. dataZoom_end = 100 - (9 / yData.length) * 100
  388. } else {
  389. dataZoom_end = 0
  390. }
  391. }
  392. if (arg.typeV) {
  393. drawBarV({ elId: arg.elId, name: names, dataZoom_end: dataZoom_end, xData: xDatas[0], yDatas: yDatas, colors: colors, barCategoryGap: arg.barCategoryGap, argInit: arg })
  394. } else {
  395. drawBarH({ elId: arg.elId, name: names, dataZoom_end: dataZoom_end, xData: xDatas[0], yDatas: yDatas, colors: colors, barCategoryGap: arg.barCategoryGap, argInit: arg })
  396. }
  397. }
  398. function drawBarH(arg) {
  399. var barCharts = echarts.init(document.getElementById(arg.elId))
  400. var options = {
  401. tooltip: {
  402. trigger: 'axis',
  403. axisPointer: {
  404. // 坐标轴指示器,坐标轴触发有效
  405. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  406. },
  407. textStyle: {
  408. align: 'left'
  409. },
  410. formatter: function (datas) {
  411. var res = datas[0].name + '<br/>'
  412. for (var i = 0, length = datas.length; i < length; i++) {
  413. var unit = ''
  414. if (arg.argInit.units) {
  415. unit = arg.argInit.units[datas[i].seriesName]
  416. }
  417. res += datas[i].seriesName + ':' + datas[i].value + unit + '<br/>'
  418. }
  419. return res
  420. }
  421. },
  422. calculable: false,
  423. grid: {
  424. borderWidth: 0,
  425. top: '20px',
  426. left: '20px',
  427. right: '20px',
  428. bottom: '20px',
  429. containLabel: true
  430. },
  431. xAxis: [
  432. {
  433. type: 'category',
  434. axisLine: {
  435. lineStyle: {
  436. type: 'solid',
  437. color: '#333333', //左边线的颜色
  438. width: '1' //坐标线的宽度
  439. }
  440. },
  441. axisTick: {
  442. show: false
  443. },
  444. splitArea: {
  445. show: false
  446. },
  447. splitLine: {
  448. show: false
  449. },
  450. data: arg.xData
  451. }
  452. ],
  453. yAxis: [
  454. {
  455. type: 'value',
  456. axisTick: {
  457. show: false
  458. },
  459. splitArea: {
  460. show: false
  461. },
  462. splitLine: {
  463. show: false
  464. },
  465. axisLine: {
  466. lineStyle: {
  467. type: 'solid',
  468. color: '#333333', //左边线的颜色
  469. width: '1' //坐标线的宽度
  470. }
  471. }
  472. }
  473. ]
  474. }
  475. var series = []
  476. for (var i = 0; i < arg.yDatas.length; i++) {
  477. var obj = {
  478. name: arg.name[i],
  479. data: arg.yDatas[i],
  480. type: 'bar',
  481. barGap: 0,
  482. barWidth: 30, //柱图宽度
  483. itemStyle: {
  484. normal: {
  485. barBorderRadius: [50, 50, 0, 0],
  486. color: arg.colors[i],
  487. label: {
  488. show: true,
  489. position: 'top',
  490. textStyle: {
  491. color: '#333333',
  492. fontSize: 12
  493. }
  494. }
  495. }
  496. }
  497. }
  498. series.push(obj)
  499. }
  500. options.series = series
  501. $('#' + arg.elId).removeAttr('_echarts_instance_')
  502. barCharts.setOption(options)
  503. }
  504. function drawBarV(arg) {
  505. var barCharts = echarts.init(document.getElementById(arg.elId))
  506. var options = {
  507. tooltip: {
  508. trigger: 'axis',
  509. axisPointer: {
  510. // 坐标轴指示器,坐标轴触发有效
  511. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  512. },
  513. textStyle: {
  514. align: 'left'
  515. },
  516. formatter: function (datas) {
  517. var res = datas[0].name + '<br/>'
  518. for (var i = 0, length = datas.length; i < length; i++) {
  519. var unit = ''
  520. if (arg.argInit.units) {
  521. unit = arg.argInit.units[datas[i].seriesName]
  522. }
  523. res += datas[i].seriesName + ':' + datas[i].value + unit + '<br/>'
  524. }
  525. return res
  526. }
  527. },
  528. calculable: false,
  529. grid: {
  530. borderWidth: 0,
  531. top: '5%',
  532. left: '3%',
  533. right: '10%',
  534. bottom: '5%',
  535. containLabel: true
  536. },
  537. yAxis: [
  538. {
  539. type: 'category',
  540. axisLine: {
  541. lineStyle: {
  542. type: 'solid',
  543. color: '#333333', //左边线的颜色
  544. width: '1' //坐标线的宽度
  545. }
  546. },
  547. axisTick: {
  548. show: false
  549. },
  550. splitArea: {
  551. show: false
  552. },
  553. splitLine: {
  554. show: false
  555. },
  556. data: arg.xData
  557. }
  558. ],
  559. xAxis: [
  560. {
  561. type: 'value',
  562. axisTick: {
  563. show: false
  564. },
  565. splitArea: {
  566. show: false
  567. },
  568. splitLine: {
  569. show: false
  570. },
  571. axisLine: {
  572. lineStyle: {
  573. type: 'solid',
  574. color: '#333333', //左边线的颜色
  575. width: '1' //坐标线的宽度
  576. }
  577. }
  578. }
  579. ]
  580. }
  581. var series = []
  582. for (var i = 0; i < arg.yDatas.length; i++) {
  583. var obj = {
  584. name: arg.name[i],
  585. data: arg.yDatas[i],
  586. type: 'bar',
  587. barGap: 0,
  588. barWidth: 12, //柱图宽度
  589. itemStyle: {
  590. normal: {
  591. barBorderRadius: [0, 50, 50, 0],
  592. color: arg.colors[i],
  593. label: {
  594. show: true,
  595. position: 'right',
  596. textStyle: {
  597. color: '#333333',
  598. fontSize: 12
  599. }
  600. }
  601. }
  602. }
  603. }
  604. series.push(obj)
  605. }
  606. options = newline(options, 4, 'yAxis')
  607. options.series = series
  608. $('#' + arg.elId).removeAttr('_echarts_instance_')
  609. barCharts.setOption(options)
  610. }
  611. function newline(option, number, axis) {
  612. /* 此处注意你的json是数组还是对象 */
  613. option[axis][0]['axisLabel'] = {
  614. interval: 0,
  615. formatter: function (params) {
  616. var newParamsName = ''
  617. var paramsNameNumber = params.length
  618. var provideNumber = number
  619. var rowNumber = Math.ceil(paramsNameNumber / provideNumber)
  620. if (paramsNameNumber > provideNumber) {
  621. for (var p = 0; p < rowNumber; p++) {
  622. var tempStr = ''
  623. var start = p * provideNumber
  624. var end = start + provideNumber
  625. if (p == rowNumber - 1) {
  626. tempStr = params.substring(start, paramsNameNumber)
  627. } else {
  628. tempStr = params.substring(start, end) + '\n'
  629. }
  630. newParamsName += tempStr
  631. }
  632. } else {
  633. newParamsName = params
  634. }
  635. return newParamsName
  636. }
  637. }
  638. return option
  639. }
  640. function getSecondClassifyList(val) {
  641. switch (val) {
  642. case '':
  643. return [
  644. { label: '全部', value: '' },
  645. { label: '健康竞走', value: '健康竞走' },
  646. { label: '健康问答', value: '健康问答' },
  647. { label: '健康咨询', value: '健康咨询' }
  648. ]
  649. case '健康运动类':
  650. return [
  651. { label: '全部', value: '' },
  652. { label: '健康竞走', value: '健康竞走' }
  653. ]
  654. case '健康教育类':
  655. return [
  656. { label: '全部', value: '' },
  657. { label: '健康问答', value: '健康问答' }
  658. ]
  659. case '促进业务类':
  660. return [
  661. { label: '全部', value: '' },
  662. { label: '健康咨询', value: '健康咨询' }
  663. ]
  664. }
  665. }