blueHorBarChartOne.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <view class="top-Section">
  5. <view class="title" v-if="type=='default'">{{title}}</view>
  6. <view class="leftBtn" v-if="type=='type1'" @click='leftBtnAction'>
  7. <view class="btnName">
  8. {{title}}
  9. </view>
  10. <image class="btnIcon" src="../../static/icons/icon_drop_black@2x.png" mode=""></image>
  11. </view>
  12. <view class="explainBtn" @click="explainAction" v-if="title!='识别类别'&&title!='项目排名'&&title!='到访类别'&&title!='认证方式' && title!='成交业态' && title!='活动统计'">
  13. <image class="explainImg" src="../../static/icons/icon_introduce@2x.png" mode=""></image>
  14. </view>
  15. <view class="rightBtn" @click="rightBtnAction" v-if="rightTitle.length > 0">
  16. <view class="btnName">
  17. {{rightTitle}}
  18. </view>
  19. <image class="btnIcon" v-if="rightType == 'default'" src="../../static/icons/icon_dropDown@2x.png" mode=""></image>
  20. <view class="btnIcon" v-else></view>
  21. </view>
  22. </view>
  23. <view style="position: relative;">
  24. <view style="width: 100%; height: 260rpx; min-height: 260rpx;display: flex;flex-direction: column;align-items: center; margin-top: 0;margin-left: 0;"
  25. v-if="dataList.length==0">
  26. <image src="../../static/icons/empty_bb.png" mode="" style="width: 283rpx;height: 227rpx;"></image>
  27. <text style="opacity: 0.35;font-size: 28rpx;font-family: PingFang SC, PingFang SC-Medium;font-weight: 500;text-align: center;color: #202638;">暂时没有{{emptyDesc}}</text>
  28. </view>
  29. <view>
  30. <view v-if="dataList.length>0" class="lineView" :style="`background-color: ${isThemeColor ? themeColor: fuzhuColor}; height: ${(nameList.length * 60 - 40) + 'rpx'} `"></view>
  31. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId"
  32. class="echarts" v-if="fuzhuColor50!=null" :style="`height: ${(nameList.length * 60) + 'rpx'}`"></view>
  33. <view class="clickDiv">
  34. <view class="clickDiv-item" v-for="(item, index) in nameList" :key="index" style="height: 70px" @click="showAllName(item)"></view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="goMoreData" @click="getMoreDataAction" v-if="isShowMore">查看更多></view>
  39. <!-- #endif -->
  40. <view class="toastDiv" v-show="isShowToast">
  41. <view class="toast">{{toastStr}}</view>
  42. </view>
  43. <dm-explain-picker :title="explainTitle" :chartId="chartId" :isJiTuanCeng="isJiTuanCeng" :brandSelected="brandSelected" ref="dmExplainPicker"></dm-explain-picker>
  44. </view>
  45. </template>
  46. <script>
  47. import echarts from '../../static/echarts.js'
  48. import dmExplainPicker from '../subComponents/dmExplainPicker.vue'
  49. export default {
  50. props: {
  51. themeColor: null,
  52. fuzhuColor: null,
  53. themeColor50: null,
  54. themeColor25: null,
  55. fuzhuColor50: null,
  56. chartId: String,
  57. title: String,
  58. rightTitle: String,
  59. isThemeColor: {
  60. type: Boolean,
  61. default: true
  62. },
  63. unit: {
  64. type: String,
  65. default: '%'
  66. },
  67. dataList: Array,
  68. yDataList: Array,
  69. isShowMore: {
  70. type: Boolean,
  71. default: false
  72. },
  73. dataCount: {
  74. type: Number,
  75. default: 6
  76. },
  77. emptyDesc: {
  78. type: String,
  79. default: "数据"
  80. },
  81. type: {
  82. type: String,
  83. default: 'default'
  84. },
  85. rightType: {
  86. type: String,
  87. default: 'default'
  88. },
  89. isJiTuanCeng:{
  90. type: Boolean,
  91. default: false
  92. },
  93. brandSelected: {
  94. type: Boolean,
  95. default: false
  96. }
  97. },
  98. data() {
  99. return {
  100. y2DataList: [],
  101. explainTitle: '',
  102. nameList: [],
  103. option: {
  104. // tooltip: {
  105. // formatter: '{b}',
  106. // // trigger: 'item',
  107. // // align: 'auto',
  108. // extraCssText: 'z-index:50',
  109. // // hideDelay: 2000,
  110. // // formatter: function(e) {
  111. // // // // console.log('tooltip打印:', e)
  112. // // return e.name
  113. // // }
  114. // },
  115. grid: {
  116. left: '36%',
  117. right: '20%',
  118. top: '0%',
  119. bottom: '0%',
  120. containLabel: false
  121. },
  122. xAxis: {
  123. type: 'value',
  124. show: false
  125. },
  126. yAxis: [{
  127. type: 'category',
  128. data: [],
  129. triggerEvent: true,
  130. inverse: true,
  131. axisLabel: { //坐标轴刻度标签的相关设置。
  132. margin: 115,
  133. align: 'left',
  134. // backgroundColor: '#FEE1A7',
  135. interval: 0,
  136. textStyle: {
  137. color: '#393939',
  138. fontFamily: 'Verdana',
  139. fontSize: 14,
  140. // lineHeight: 7,
  141. }
  142. },
  143. axisTick: { //坐标轴刻度相关设置。
  144. show: false,
  145. },
  146. axisLine: { //坐标轴轴线相关设置
  147. show: false
  148. },
  149. },
  150. {
  151. type: 'category',
  152. data: [],
  153. inverse: true,
  154. axisLabel: { //坐标轴刻度标签的相关设置。
  155. margin: 60,
  156. align: 'right',
  157. textStyle: {
  158. color: '',
  159. fontFamily: 'Verdana',
  160. fontSize: 14,
  161. },
  162. // formatter: (a) => {
  163. // return a + '%'
  164. // },
  165. },
  166. axisTick: { //坐标轴刻度相关设置。
  167. show: false,
  168. },
  169. axisLine: { //坐标轴轴线相关设置
  170. show: false
  171. }
  172. },
  173. ],
  174. series: {
  175. name: '',
  176. type: 'bar',
  177. barWidth: 6,
  178. data: [],
  179. itemStyle: { //图形样式
  180. normal: {
  181. barBorderRadius: 3,
  182. color: ''
  183. },
  184. }
  185. }
  186. },
  187. isShowToast: false,
  188. toastStr: ''
  189. }
  190. },
  191. mounted() {},
  192. methods: {
  193. getDataAction() {
  194. this.option.series.data = []
  195. this.option.yAxis[0].data = []
  196. this.option.yAxis[1].data
  197. this.option.series.data = this.dataList
  198. // // console.log("getDataAction -> this.dataList", this.chartId, this.dataList)
  199. var yTempDataList = JSON.parse(JSON.stringify(this.yDataList.length > 6 ? this.yDataList.slice(0, 6) : this.yDataList))
  200. this.nameList = JSON.parse(JSON.stringify(this.yDataList.length > 6 ? this.yDataList.slice(0, 6) : this.yDataList))
  201. for (var i = 0; i < yTempDataList.length; i++) {
  202. let item = yTempDataList[i]
  203. if (item.length > 7) {
  204. yTempDataList[i] = item.slice(0, 7) + "..."
  205. }
  206. }
  207. // for (var i = 0; i < yTempDataList.length; i++) {
  208. // let item = yTempDataList[i]
  209. // // if (item.length > 5) {
  210. // // yTempDataList[i] = item.slice(0, 5) + "..."
  211. // // // yTempDataList[i] = item.join()
  212. // // // yTempDataList[i] = this.insertStr()
  213. // // }
  214. // var newParamsName = ""; // 最终拼接成的字符串
  215. // var paramsNameNumber = item.length; // 实际标签的个数
  216. // var provideNumber = 6; // 每行能显示的字的个数
  217. // var rowNumber = Math.ceil(paramsNameNumber / provideNumber); // 换行的话,需要显示几行,向上取整
  218. // /**
  219. // * 判断标签的个数是否大于规定的个数, 如果大于,则进行换行处理 如果不大于,即等于或小于,就返回原标签
  220. // */
  221. // // 条件等同于rowNumber>1
  222. // if (paramsNameNumber > provideNumber) {
  223. // /** 循环每一行,p表示行 */
  224. // for (var p = 0; p < rowNumber; p++) {
  225. // var tempStr = ""; // 表示每一次截取的字符串
  226. // var start = p * provideNumber; // 开始截取的位置
  227. // var end = start + provideNumber; // 结束截取的位置
  228. // // 此处特殊处理最后一行的索引值
  229. // if (p == rowNumber - 1) {
  230. // // 最后一次不换行
  231. // tempStr = item.substring(start, paramsNameNumber);
  232. // } else {
  233. // // 每一次拼接字符串并换行
  234. // tempStr = item.substring(start, end) + "\n";
  235. // }
  236. // newParamsName += tempStr; // 最终拼成的字符串
  237. // }
  238. // } else {
  239. // // 将旧标签的值赋给新标签
  240. // newParamsName = item;
  241. // }
  242. // //将最终的字符串返回
  243. // yTempDataList[i] = newParamsName
  244. // if (yTempDataList[i].length > 12) {
  245. // yTempDataList[i] = yTempDataList[i].slice(0, 12) + '...'
  246. // }
  247. // }
  248. // console.log("当前数,--+pp", yTempDataList)
  249. this.option.yAxis[0].data = yTempDataList
  250. this.y2DataList = []
  251. var self = this
  252. this.dataList.forEach((item, index) => {
  253. self.y2DataList.push((item + self.unit))
  254. })
  255. var y2TempDataList = this.y2DataList.length > 6 ? this.y2DataList.slice(0, 6) : this.y2DataList
  256. this.option.yAxis[1].data = y2TempDataList
  257. // this.reloadColor()
  258. // console.log('柱状图A数据刷新', this.option)
  259. uni.$emit('onchanged')
  260. },
  261. // insertStr(soure, start, newStr){
  262. // return soure.slice(0, start) + newStr + soure.slice(start);
  263. // }
  264. reloadColor() {
  265. this.option.series.itemStyle.normal.color = new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  266. offset: 0,
  267. color: this.isThemeColor ? this.themeColor : this.fuzhuColor
  268. }, {
  269. offset: 1,
  270. color: this.isThemeColor ? this.themeColor50 : this.fuzhuColor50
  271. }])
  272. this.option.yAxis[1].axisLabel.textStyle.color = this.isThemeColor ? this.themeColor : this.fuzhuColor
  273. },
  274. onViewClick(options) {
  275. // console.log(options)
  276. if (options && options.test) {
  277. uni.showToast({
  278. icon: 'none',
  279. title: options.test
  280. })
  281. }
  282. },
  283. rightBtnAction() {
  284. this.$emit('chartRightBtnAction', this.chartId)
  285. },
  286. leftBtnAction() {
  287. this.$emit('chartLeftBtnAction', this.chartId)
  288. },
  289. getMoreDataAction() {
  290. this.$emit('chartGetMoreDataAction', this.chartId)
  291. },
  292. explainAction() {
  293. this.$refs.dmExplainPicker.show()
  294. },
  295. showAllName(e) {
  296. // console.log('名字打印:', e)
  297. // uni.showToast({
  298. // icon: 'none',
  299. // title: e,
  300. // duration: 1000
  301. // })
  302. this.toastStr = e
  303. this.isShowToast = true
  304. var self = this
  305. var timer = setTimeout(function() {
  306. self.isShowToast = false
  307. clearTimeout(timer)
  308. }, 2000);
  309. }
  310. },
  311. components: {
  312. dmExplainPicker
  313. },
  314. watch: {
  315. // chartId: {
  316. // handler(e) {
  317. // this.getDataAction()
  318. // },
  319. // immediate: true
  320. // },
  321. dataList: {
  322. handler(e) {
  323. this.getDataAction()
  324. },
  325. immediate: true
  326. },
  327. yDataList: {
  328. handler(e) {
  329. this.getDataAction()
  330. },
  331. immediate: true
  332. },
  333. themeColor: {
  334. handler(e) {
  335. this.reloadColor()
  336. },
  337. immediate: true
  338. },
  339. title: {
  340. handler(e) {
  341. this.explainTitle = e
  342. },
  343. immediate: true
  344. }
  345. }
  346. }
  347. </script>
  348. <script module="echarts" lang="renderjs">
  349. let myChart
  350. export default {
  351. mounted() {
  352. this.initAction();
  353. },
  354. methods: {
  355. initAction() {
  356. if (typeof window.echarts === 'function') {
  357. this.initEcharts();
  358. } else {
  359. // 动态引入较大类库避免影响页面展示
  360. const script = document.createElement('script')
  361. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  362. script.src = 'static/echarts.js'
  363. script.onload = this.initEcharts.bind(this)
  364. document.head.appendChild(script)
  365. }
  366. },
  367. initEcharts() {
  368. // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
  369. myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
  370. // 观测更新的数据在 view 层可以直接访问到
  371. if (myChart) {
  372. myChart.setOption(this.option)
  373. myChart.resize();
  374. var self = this
  375. myChart.on('mousemove', function(params) {
  376. // console.log('parmas mouseover 打印:', params)
  377. if (params.componentType == "yAxis") {
  378. // alert(params.value)
  379. // var offsetX = params.event.offsetX + 10;
  380. // var offsetY = params.event.offsetY + 10;
  381. // myChart.dispatchAction({
  382. // type: 'showTip',
  383. // // seriesIndex: params.seriesIndex,
  384. // // dataIndex: params.dataIndex,
  385. // position: [offsetX, offsetY]
  386. // });
  387. } else {
  388. // alert(params.name)
  389. // var offsetX = params.event.offsetX + 10;
  390. // var offsetY = params.event.offsetY + 10;
  391. // myChart.dispatchAction({
  392. // type: 'showTip',
  393. // // seriesIndex: params.seriesIndex,
  394. // // dataIndex: params.dataIndex,
  395. // position: [offsetX, offsetY]
  396. // });
  397. }
  398. });
  399. }
  400. },
  401. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  402. // 监听 service 层数据变更
  403. if (myChart) {
  404. myChart.setOption(newValue)
  405. myChart.resize();
  406. }
  407. },
  408. onClick(event, ownerInstance) {
  409. // 调用 service 层的方法
  410. // // console.log('onClick交互:', event, ownerInstance)
  411. // ownerInstance.callMethod('onViewClick', {
  412. // test: 'test'
  413. // })
  414. }
  415. }
  416. }
  417. </script>
  418. <style scoped lang="scss">
  419. .content {
  420. width: 100%;
  421. height: 100%;
  422. // background-color: #FFFFFF;
  423. position: relative;
  424. // padding: 20rpx;
  425. padding-bottom: 20rpx;
  426. margin-bottom: 40rpx;
  427. .top-Section {
  428. padding: 0 20rpx;
  429. display: flex;
  430. flex-direction: row;
  431. justify-content: flex-start;
  432. font-family: Verdana;
  433. position: relative;
  434. margin-bottom: 20rpx;
  435. .title {
  436. font-size: 32rpx;
  437. font-weight: bold;
  438. color: #383838;
  439. display: block;
  440. }
  441. .leftBtn {
  442. display: flex;
  443. .btnName {
  444. font-size: 32rpx;
  445. font-weight: bold;
  446. color: #383838;
  447. }
  448. .btnIcon {
  449. color: #000000;
  450. margin-left: 10rpx;
  451. margin-top: 7rpx;
  452. width: 30rpx;
  453. height: 30rpx;
  454. }
  455. }
  456. .explainBtn {
  457. width: 30rpx;
  458. height: 30rpx;
  459. margin-left: 10rpx;
  460. .explainImg {
  461. width: 30rpx;
  462. height: 30rpx;
  463. }
  464. }
  465. .rightBtn {
  466. font-size: 24rpx;
  467. margin-top: 5rpx;
  468. display: flex;
  469. flex-direction: row;
  470. position: absolute;
  471. right: 20rpx;
  472. .btnName {
  473. color: #546074;
  474. }
  475. .btnIcon {
  476. color: #000000;
  477. margin-left: 10rpx;
  478. margin-top: 2rpx;
  479. width: 30rpx;
  480. height: 30rpx;
  481. }
  482. }
  483. }
  484. .echarts {
  485. width: 100%;
  486. margin-top: 0;
  487. }
  488. .goMoreData {
  489. font-family: Verdana;
  490. color: #546074;
  491. font-size: 24rpx;
  492. text-align: center;
  493. margin-top: 30rpx;
  494. }
  495. .lineView {
  496. position: absolute;
  497. left: 26rpx;
  498. width: 4rpx;
  499. border-radius: 2rpx;
  500. top: 18rpx;
  501. }
  502. .clickDiv {
  503. width: 100%;
  504. height: 90%;
  505. // background-color: #4CD964;
  506. // opacity: 0.5;
  507. z-index: 100;
  508. top: 10%;
  509. left: 0;
  510. position: absolute;
  511. display: flex;
  512. flex-direction: column;
  513. .clickDiv-item {
  514. width: 100%;
  515. margin-left: 0;
  516. // background-color: #007AFF;
  517. // opacity: 0.5;
  518. margin-bottom: 5px;
  519. }
  520. }
  521. .toastDiv {
  522. position: absolute;
  523. top: 0;
  524. left: 0;
  525. width: 100%;
  526. height: 100%;
  527. display: flex;
  528. align-items: center;
  529. justify-content: center;
  530. .toast {
  531. border-radius: 10rpx;
  532. background-color: rgba($color: #333, $alpha: 0.42);
  533. font-size: 28rpx;
  534. text-align: center;
  535. padding: 20rpx;
  536. max-width: 90%;
  537. line-height: 60rpx;
  538. color: #FFFFFF;
  539. font-family: Verdana;
  540. }
  541. }
  542. }
  543. </style>