index.vue 6.4 KB

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