index.vue 6.5 KB

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