index.vue 8.8 KB

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