index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. console.log(res)
  85. this.orderList = res.data.data
  86. this.getPieData()
  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 * 100)
  113. console.log((val * 100).toFixed())
  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. this.data = this.orderList[i].storeMonthList[j].data
  129. console.log(this.orderList[i].storeMonthList[j].data)
  130. monthObj.name = this.orderList[i].storeMonthList[j].name+":"+this.orderList[i].storeMonthList[j].data
  131. monthObj.percent = this.orderList[i].storeMonthList[j].percent
  132. quarterObj.data = this.orderList[i].storeQuarterList[j].data
  133. quarterObj.name = this.orderList[i].storeQuarterList[j].name+":"+this.orderList[i].storeQuarterList[j].data
  134. quarterObj.percent = this.orderList[i].storeQuarterList[j].percent
  135. quarterPie.series.push(quarterObj)
  136. monthPie.series.push(monthObj)
  137. }
  138. this.showPie(`mouthPie${i}`, monthPie);
  139. this.showPie(`quarterPie${i}`, quarterPie)
  140. }
  141. },
  142. showPie(canvasId, chartData) {
  143. canvasObj[canvasId] = new uCharts({
  144. $this: _self,
  145. canvasId: canvasId,
  146. type: 'ring',
  147. fontSize: 9,
  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: 15 * _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. console.log(id)
  189. canvasObj[id].showToolTip(e, {
  190. format: function(item) {
  191. return item.name
  192. }
  193. });
  194. },
  195. }
  196. }
  197. </script>
  198. <style>
  199. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  200. .qiun-charts {
  201. width: 750rpx;
  202. height: 331rpx;
  203. background: url(../../../static/sailun/background.png) no-repeat;
  204. background-size: 750rpx 331rpx;
  205. }
  206. .qiun-charts-one {
  207. width: 6rpx;
  208. height: 30rpx;
  209. background: #0292FD;
  210. position: relative;
  211. top: 20rpx;
  212. left: 30rpx;
  213. }
  214. .qiun-charts-two {
  215. position: relative;
  216. top: -18rpx;
  217. left: 60rpx;
  218. font-size: 26rpx;
  219. font-weight: bold;
  220. }
  221. .content {
  222. width: 702rpx;
  223. height: 410rpx;
  224. background: #FFFFFF;
  225. box-shadow: 0px 10px 40px 0px rgba(223, 223, 223, 0.91);
  226. border-radius: 18px;
  227. margin: 0 auto;
  228. position: relative;
  229. top: 20rpx;
  230. margin-bottom: 40rpx;
  231. }
  232. .content-one {
  233. display: flex;
  234. justify-content: space-between;
  235. }
  236. .charts {
  237. width: 380rpx;
  238. height: 450rpx;
  239. position: relative;
  240. top: -20rpx;
  241. }
  242. .qiun-charts-three>view:nth-child(1) {
  243. width: 24rpx;
  244. height: 24rpx;
  245. border: 6rpx solid #0094FE;
  246. transform: rotate(50deg);
  247. position: relative;
  248. top: 20rpx;
  249. left: 30rpx;
  250. }
  251. .qiun-charts-three>view:nth-child(2) {
  252. width: 210rpx;
  253. line-height: 26rpx;
  254. background-color: #000000;
  255. color: #fff;
  256. font-size: 15rpx;
  257. opacity: 0.3;
  258. text-align: center;
  259. position: relative;
  260. top: -2rpx;
  261. left: 40rpx;
  262. border-top-right-radius: 12rpx;
  263. }
  264. .qiun-charts-four {
  265. position: relative;
  266. right: 200rpx;
  267. }
  268. .qiun-charts-four>view:nth-child(1) {
  269. width: 24rpx;
  270. height: 24rpx;
  271. border: 6rpx solid #0094FE;
  272. transform: rotate(50deg);
  273. position: relative;
  274. top: 20rpx;
  275. left: 30rpx;
  276. }
  277. .qiun-charts-four>view:nth-child(2) {
  278. width: 180rpx;
  279. line-height: 26rpx;
  280. background-color: #000000;
  281. color: #fff;
  282. font-size: 15rpx;
  283. opacity: 0.3;
  284. text-align: center;
  285. position: relative;
  286. top: -2rpx;
  287. left: 40rpx;
  288. border-top-right-radius: 12rpx;
  289. }
  290. </style>