index.vue 8.8 KB

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