index.vue 7.6 KB

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