index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="top">
  3. <view class="qiun-charts">
  4. <view v-for="(item,index) in orderList" :key="index">
  5. <view class="content">
  6. <view class="qiun-charts-one">
  7. </view>
  8. <text class="qiun-charts-two">{{item.brand}}</text>
  9. <view style="display: flex;justify-content: space-between;">
  10. <view class="qiun-charts-three">
  11. <view>
  12. </view>
  13. <view>
  14. {{item.month}}
  15. </view>
  16. </view>
  17. <view class="qiun-charts-four">
  18. <view>
  19. </view>
  20. <view>
  21. {{item.quarter}}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="content-one">
  26. <!-- -->
  27. <canvas :canvas-id="'mouthPie' + index" :id="'mouthPie' + index" class="charts" @touchstart="touchPie($event,'mouthPie' + index)"></canvas>
  28. <!-- -->
  29. <canvas :canvas-id="'quarterPie' + index" :id="'quarterPie' + index" class="charts" @touchstart="touchPie($event,'quarterPie' + index)"></canvas>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. var canvasObj = {};
  38. import {
  39. request
  40. } from '../../../common/request/request'
  41. require("promise.prototype.finally").shim()
  42. import uCharts from '@/components/u-charts/u-charts.js';
  43. import {
  44. isJSON
  45. } from '@/common/checker.js';
  46. var _self;
  47. // var canvaPie = null;
  48. export default {
  49. data() {
  50. return {
  51. orderList: [],
  52. cWidth: '',
  53. cHeight: '',
  54. pixelRatio: 1,
  55. piearr: [],
  56. textarea: '',
  57. }
  58. },
  59. onLoad() {
  60. _self = this;
  61. _self.cWidth = uni.upx2px(370);
  62. _self.cHeight = uni.upx2px(320);
  63. // this.showPie('canvasRing')
  64. },
  65. created() {
  66. },
  67. onShow() {
  68. this.getDate()
  69. },
  70. methods: {
  71. getDate() {
  72. uni.showLoading({
  73. title: '加载中...'
  74. });
  75. request({
  76. url: '/myapp/storeBrandTask',
  77. method: 'post',
  78. data: {
  79. "storeId": this.$store.state.storeInfo.storeId,
  80. 'userId': this.$store.state.storeInfo.userId
  81. }
  82. }).then(res => {
  83. console.log(res)
  84. this.orderList = res.data.data
  85. this.getPieData()
  86. // this.showPie('mouthPie0',monthPie);
  87. }).catch(err => {
  88. console.log(err)
  89. })
  90. .finally(() => {
  91. setTimeout(() => {
  92. uni.hideLoading();
  93. this.loading = false;
  94. }, 300)
  95. })
  96. },
  97. getPieData() {
  98. console.log('5555')
  99. for (var i = 0; i < this.orderList.length; i++) {
  100. var monthPie = {
  101. series: []
  102. };
  103. var quarterPie = {
  104. series: []
  105. }
  106. for (var j = 0; j < this.orderList[i].storeMonthList.length; j++) {
  107. let monthObj = {
  108. data: null,
  109. name: '',
  110. percent: '',
  111. format: (val) => {
  112. console.log(val)
  113. // return val.toFixed(0) + ''
  114. return val * 100 + '%'
  115. }
  116. }
  117. let quarterObj = {
  118. data: null,
  119. name: '',
  120. percent: '',
  121. format: (val) => {
  122. console.log(val)
  123. return val * 100 + '%'
  124. }
  125. }
  126. monthObj.data = this.orderList[i].storeMonthList[j].data
  127. monthObj.name = this.orderList[i].storeMonthList[j].name
  128. monthObj.percent = this.orderList[i].storeMonthList[j].percent
  129. quarterObj.data = this.orderList[i].storeQuarterList[j].data
  130. quarterObj.name = this.orderList[i].storeQuarterList[j].name
  131. quarterObj.percent = this.orderList[i].storeQuarterList[j].percent
  132. monthPie.series.push(monthObj)
  133. quarterPie.series.push(quarterObj)
  134. }
  135. this.showPie(`mouthPie${i}`, monthPie);
  136. this.showPie(`quarterPie${i}`, quarterPie)
  137. }
  138. },
  139. showPie(canvasId, chartData) {
  140. console.log('88888')
  141. console.log(canvasId, chartData)
  142. canvasObj[canvasId] = new uCharts({
  143. $this: _self,
  144. canvasId: canvasId,
  145. type: 'ring',
  146. fontSize: 11,
  147. padding: [5, 5, 5, 5],
  148. legend: {
  149. show: true,
  150. position: 'bottom',
  151. float: 'center',
  152. itemGap: 10,
  153. padding: 0,
  154. lineHeight: 26,
  155. margin: 6,
  156. borderWidth: 1
  157. },
  158. background: '#fff',
  159. pixelRatio: _self.pixelRatio,
  160. series: chartData.series,
  161. animation: true,
  162. width: _self.cWidth,
  163. height: _self.cHeight,
  164. disablePieStroke: true,
  165. dataLabel: true,
  166. subtitle: {
  167. name: chartData.series[0].percent,
  168. color: '#7cb5ec',
  169. fontSize: 12 * _self.pixelRatio,
  170. },
  171. title: {
  172. name: '已完成',
  173. color: '#666666',
  174. fontSize: 13 * _self.pixelRatio,
  175. },
  176. extra: {
  177. pie: {
  178. ringWidth: 12 * _self.pixelRatio,
  179. labelWidth: 0.1,
  180. offsetAngle: 0
  181. }
  182. },
  183. });
  184. },
  185. touchPie(e, id) {
  186. console.log(e, id)
  187. canvasObj[id].showToolTip(e, {
  188. format: function(item) {
  189. return item.name + ':' + item.data
  190. }
  191. });
  192. },
  193. }
  194. }
  195. </script>
  196. <style>
  197. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  198. .qiun-charts {
  199. width: 750rpx;
  200. height: 331rpx;
  201. background: url(../../../static/sailun/background.png) no-repeat;
  202. background-size: 750rpx 331rpx;
  203. }
  204. .qiun-charts-one {
  205. width: 6rpx;
  206. height: 30rpx;
  207. background: #0292FD;
  208. position: relative;
  209. top: 20rpx;
  210. left: 30rpx;
  211. }
  212. .qiun-charts-two {
  213. position: relative;
  214. top: -18rpx;
  215. left: 60rpx;
  216. font-size: 26rpx;
  217. font-weight: bold;
  218. }
  219. .content {
  220. width: 702rpx;
  221. height: 410rpx;
  222. background: #FFFFFF;
  223. box-shadow: 0px 10px 40px 0px rgba(223, 223, 223, 0.91);
  224. border-radius: 18px;
  225. margin: 0 auto;
  226. position: relative;
  227. top: 20rpx;
  228. margin-bottom: 40rpx;
  229. }
  230. .content-one {
  231. display: flex;
  232. justify-content: space-between;
  233. }
  234. .charts {
  235. width: 380rpx;
  236. height: 450rpx;
  237. position: relative;
  238. top: -20rpx;
  239. }
  240. .qiun-charts-three>view:nth-child(1) {
  241. width: 24rpx;
  242. height: 24rpx;
  243. border: 6rpx solid #0094FE;
  244. transform: rotate(50deg);
  245. position: relative;
  246. top: 20rpx;
  247. left: 30rpx;
  248. }
  249. .qiun-charts-three>view:nth-child(2) {
  250. width: 210rpx;
  251. line-height: 26rpx;
  252. background-color: #000000;
  253. color: #fff;
  254. font-size: 15rpx;
  255. opacity: 0.3;
  256. text-align: center;
  257. position: relative;
  258. top: -2rpx;
  259. left: 40rpx;
  260. border-top-right-radius: 12rpx;
  261. }
  262. .qiun-charts-four {
  263. position: relative;
  264. right: 200rpx;
  265. }
  266. .qiun-charts-four>view:nth-child(1) {
  267. width: 24rpx;
  268. height: 24rpx;
  269. border: 6rpx solid #0094FE;
  270. transform: rotate(50deg);
  271. position: relative;
  272. top: 20rpx;
  273. left: 30rpx;
  274. }
  275. .qiun-charts-four>view:nth-child(2) {
  276. width: 180rpx;
  277. line-height: 26rpx;
  278. background-color: #000000;
  279. color: #fff;
  280. font-size: 15rpx;
  281. opacity: 0.3;
  282. text-align: center;
  283. position: relative;
  284. top: -2rpx;
  285. left: 40rpx;
  286. border-top-right-radius: 12rpx;
  287. }
  288. </style>