index.vue 6.4 KB

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