mianji.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view style="width: 100%;display: flex;align-items: center;">
  3. <view class="content">
  4. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId" class="echarts"></view>
  5. </view>
  6. <view>
  7. <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left;color: #5f636f;">意向面积</text>
  8. <view style="display: flex;justify-content: space-between;margin-top: 10rpx;">
  9. <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left;" :style="{'color':fuzhuColor}" v-if="dataList.length > 0">{{dataList[0]}}m²</text>
  10. <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left; margin-left: 82rpx;" v-if="dataList.length > 1">{{dataList[1]}}m²</text>
  11. <text style="font-size: 28rpx;font-family: Verdana, Verdana-Regular;font-weight: 400;text-align: left; margin-left: 82rpx;" v-if="dataList.length > 2">{{dataList[2]}}m²</text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import echarts from '../../static/echarts.js'
  18. var colorList = ['#FDD56A','#73ACFF','#73DDFF' ];
  19. export default {
  20. props: {
  21. chartId: String,
  22. title: {
  23. type: String,
  24. default: '面积'
  25. },
  26. dataList: {
  27. type: Array,
  28. default:() => {
  29. return []
  30. }
  31. }
  32. },
  33. data() {
  34. return {
  35. themeColor: "",
  36. fuzhuColor: "",
  37. themeColor25: "",
  38. option: {
  39. title: {
  40. text: '面积',
  41. x: 'center',
  42. y: 'center',
  43. textStyle: {
  44. fontSize: 10
  45. }
  46. },
  47. color: colorList,
  48. series: [{
  49. name: '访问来源',
  50. type: 'pie',
  51. radius: ['50%', '70%'],
  52. avoidLabelOverlap: false,
  53. hoverAnimation: false,
  54. label: {
  55. show: false,
  56. position: 'center'
  57. },
  58. itemStyle: {
  59. normal: {
  60. // color: function(params) {
  61. // return colorList[params.dataIndex]
  62. // }
  63. }
  64. },
  65. emphasis: {
  66. label: {
  67. show: false,
  68. fontSize: '30',
  69. fontWeight: 'bold'
  70. }
  71. },
  72. labelLine: {
  73. show: false
  74. },
  75. data: []
  76. // data: [{
  77. // value: 335,
  78. // name: '直接访问'
  79. // },
  80. // {
  81. // value: 310,
  82. // name: '邮件营销'
  83. // },
  84. // {
  85. // value: 234,
  86. // name: '联盟广告'
  87. // }
  88. // ]
  89. }]
  90. }
  91. }
  92. },
  93. methods: {
  94. getDataAction() {
  95. // this.dataList = []
  96. // this.data1 = []
  97. // for (var i = 0; i < 3; i++) {
  98. // var num1 = Math.ceil(Math.random() * 50)
  99. // this.data1.push(num1)
  100. // this.dataList.push(num1)
  101. // }
  102. this.option.series[0].data = this.dataList
  103. // this.option.xAxis.data = this.dataList
  104. // console.log('数据刷新面积', this.option.xAxis, this.dataList)
  105. },
  106. onViewClick(options) {
  107. // console.log(options)
  108. }
  109. },
  110. watch: {
  111. chartId: {
  112. handler(e) {
  113. // console.log('走没走!!!!', e)
  114. // this.getDataAction()
  115. },
  116. immediate: true
  117. },
  118. dataList: {
  119. handler(e) {
  120. this.getDataAction()
  121. },
  122. immediate: true
  123. }
  124. },
  125. mounted() {
  126. let app = getApp()
  127. let globalData = app.globalData;
  128. this.themeColor = globalData.themeColor
  129. this.fuzhuColor = globalData.fuzhuColor
  130. this.themeColor25 = globalData.themeColor25
  131. let that = this;
  132. }
  133. }
  134. </script>
  135. <script module="echarts" lang="renderjs">
  136. let myChart
  137. export default {
  138. mounted() {
  139. this.initAction()
  140. },
  141. methods: {
  142. initAction() {
  143. if (typeof window.echarts === 'function') {
  144. this.initEcharts()
  145. } else {
  146. // 动态引入较大类库避免影响页面展示
  147. const script = document.createElement('script')
  148. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  149. script.src = 'static/echarts.js'
  150. script.onload = this.initEcharts.bind(this)
  151. document.head.appendChild(script)
  152. }
  153. },
  154. initEcharts() {
  155. // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
  156. myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
  157. // 观测更新的数据在 view 层可以直接访问到
  158. if(myChart){
  159. myChart.setOption(this.option)
  160. }
  161. },
  162. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  163. // 监听 service 层数据变更
  164. if(myChart){
  165. myChart.setOption(newValue)
  166. }
  167. },
  168. onClick(event, ownerInstance) {
  169. // 调用 service 层的方法
  170. ownerInstance.callMethod('onViewClick', {
  171. test: 'test'
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped lang="scss">
  178. .content {
  179. .top-Section {
  180. padding: 0 20rpx;
  181. display: flex;
  182. flex-direction: row;
  183. justify-content: space-between;
  184. font-family: Verdana;
  185. .title {
  186. font-size: 32rpx;
  187. font-weight: bold;
  188. color: #383838;
  189. }
  190. .rightBtn {
  191. font-size: 24rpx;
  192. color: #546074;
  193. margin-top: 5rpx;
  194. }
  195. }
  196. .echarts {
  197. width: 214rpx;
  198. margin-top: 0;
  199. height: 200rpx;
  200. }
  201. }
  202. </style>