index.vue 7.0 KB

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