index.vue 6.8 KB

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