index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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: this.$t('uView.finished'),
  169. color: '#666666',
  170. offsetX: 12,
  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. canvasObj[id].showToolTip(e, {
  184. format: function(item) {
  185. return item.name
  186. }
  187. });
  188. },
  189. }
  190. }
  191. </script>
  192. <style>
  193. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  194. .qiun-charts {
  195. width: 750rpx;
  196. height: 331rpx;
  197. background: url(../../../static/sailun/background.png) no-repeat;
  198. background-size: 750rpx 331rpx;
  199. }
  200. .qiun-charts-one {
  201. width: 6rpx;
  202. height: 30rpx;
  203. background: #0292FD;
  204. position: relative;
  205. top: 20rpx;
  206. left: 30rpx;
  207. }
  208. .qiun-charts-two {
  209. position: relative;
  210. top: -18rpx;
  211. left: 60rpx;
  212. font-size: 26rpx;
  213. font-weight: bold;
  214. }
  215. .content {
  216. width: 702rpx;
  217. height: 410rpx;
  218. background: #FFFFFF;
  219. box-shadow: 0px 10px 40px 0px rgba(223, 223, 223, 0.91);
  220. border-radius: 18px;
  221. margin: 0 auto;
  222. position: relative;
  223. top: 20rpx;
  224. margin-bottom: 40rpx;
  225. }
  226. .content-one {
  227. display: flex;
  228. justify-content: space-between;
  229. }
  230. .charts {
  231. width: 380rpx;
  232. height: 450rpx;
  233. position: relative;
  234. top: -20rpx;
  235. }
  236. .qiun-charts-three>view:nth-child(1) {
  237. width: 24rpx;
  238. height: 24rpx;
  239. border: 6rpx solid #0094FE;
  240. transform: rotate(50deg);
  241. position: relative;
  242. top: 20rpx;
  243. left: 30rpx;
  244. }
  245. .qiun-charts-three>view:nth-child(2) {
  246. width: 210rpx;
  247. line-height: 26rpx;
  248. background-color: #000000;
  249. color: #fff;
  250. font-size: 15rpx;
  251. opacity: 0.3;
  252. text-align: center;
  253. position: relative;
  254. top: -2rpx;
  255. left: 40rpx;
  256. border-top-right-radius: 12rpx;
  257. }
  258. .qiun-charts-four {
  259. position: relative;
  260. right: 200rpx;
  261. }
  262. .qiun-charts-four>view:nth-child(1) {
  263. width: 24rpx;
  264. height: 24rpx;
  265. border: 6rpx solid #0094FE;
  266. transform: rotate(50deg);
  267. position: relative;
  268. top: 20rpx;
  269. left: 30rpx;
  270. }
  271. .qiun-charts-four>view:nth-child(2) {
  272. width: 180rpx;
  273. line-height: 26rpx;
  274. background-color: #000000;
  275. color: #fff;
  276. font-size: 15rpx;
  277. opacity: 0.3;
  278. text-align: center;
  279. position: relative;
  280. top: -2rpx;
  281. left: 40rpx;
  282. border-top-right-radius: 12rpx;
  283. }
  284. </style>