index.vue 6.4 KB

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