Bladeren bron

未来七天,商品销售占比接口完成

ltx529596 4 jaren geleden
bovenliggende
commit
6eb1ce7509
1 gewijzigde bestanden met toevoegingen van 48 en 45 verwijderingen
  1. 48 45
      src/pages/index/index.vue

+ 48 - 45
src/pages/index/index.vue

@@ -238,7 +238,7 @@ export default {
   name: 'Header',
   data() {
     return {
-      loading: false,
+      loading: true,
       shopArray: [{ name: '全部', id: 0 }],
       shopID: 0,
       index: 0,
@@ -248,8 +248,6 @@ export default {
       ordernum: null, // 订单号
       today: moment().format('YYYY-MM-DD'),
 
-      theKeyList: [],
-
       // 数据还可以优化
       sellSun: {
         num: 0,
@@ -300,12 +298,14 @@ export default {
     this.cHeight = uni.upx2px(300);
     this.bWidth = uni.upx2px(690);
     this.bHeight = uni.upx2px(300);
-    // this.getServerData();
 
     this.getShopList();
     this.getExponentData();
     this.getPendingData();
     this.futureDayData();
+    this.shopSellData();
+
+    this.loading = false
   },
   methods: {
     // 选择商铺
@@ -316,13 +316,14 @@ export default {
       this.getExponentData();
       this.getPendingData();
       this.futureDayData();
+      this.shopSellData();
     },
     // 跳转设置页
     tosetting() {
       this.$mRouter.push({ route: '/pages/index/setting/setting' });
     },
 
-    // 获取店铺列表
+    // 获取店铺列表h
     async getShopList() {
       await this.$http.get('/homePage/getShopByMerId').then((res) => {
         if (res.data && res.code === 200) {
@@ -407,10 +408,6 @@ export default {
           }
         });
     },
-
-    seting() {
-      console.log('设置');
-    },
     // 扫码订单
     scanCode() {
       // 允许从相机和相册扫码
@@ -440,49 +437,39 @@ export default {
         })
         .then(async (res) => {
           if (res.data) {
-            console.log(res.data);
             let LineA = {
               categories: [],
               series: [],
             };
             res.data.forEach((ele) => {
               LineA.series.push(ele.num);
-              LineA.categories.push(ele.date.slice(5))
+              LineA.categories.push(ele.date.slice(5));
             });
-            console.log(LineA);
-            this.showLineA('canvasLineA',LineA);
+            _self.showLineA('canvasLineA', LineA);
           }
         });
     },
 
-    // // 数据处理
-    // getServerData() {
-    //   uni.request({
-    //     url: 'https://www.ucharts.cn/data.json',
-    //     data: {},
-    //     success: function (res) {
-    //       let LineA = {
-    //         categories: [],
-    //         series: [],
-    //       };
-    //       //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
-    //       LineA.categories = res.data.data.LineA.categories;
-    //       LineA.series = res.data.data.LineA.series;
-    //       _self.showLineA('canvasLineA', LineA);
-
-    //       let pie = {
-    //         series: [],
-    //       };
-    //       pie.series = res.data.data.Pie.series;
-    //       _self.showPie('shopecharts', pie);
-    //     },
-    //     fail: () => {
-    //       _self.tips = '网络错误,小程序端请检查合法域名';
-    //     },
-    //   });
-    // },
-
-    // 图表
+    // 商品销售占比
+    async shopSellData() {
+      await this.$http.get('/homePage/getData1', {
+        date: this.today,
+        shopId: this.shopID,
+      }).then(async (res) => {
+        let pie = {
+          series: [],
+        };
+        if (res.data.length > 0) {
+          pie.series = res.data;
+          _self.showPie('shopecharts', pie);
+        } else {
+          pie.series = [{ name: '无数据', data: 0 }];
+          _self.showPie('shopecharts', pie);
+        }
+      });
+    },
+
+    // 折线图表
     showLineA(canvasId, chartData) {
       canvaLineA = new uCharts({
         $this: _self,
@@ -498,7 +485,16 @@ export default {
         background: '#FFFFFF',
         pixelRatio: _self.pixelRatio,
         categories: chartData.categories, // x轴数据
-        series: chartData.series, // 值
+        series: [
+          {
+            color: '#ffcc01',
+            data: chartData.series,
+            name: '人次',
+            pointShape: 'circle',
+            show: true,
+            type: 'line',
+          },
+        ], // 值
         animation: true,
         xAxis: {
           type: 'grid',
@@ -509,6 +505,7 @@ export default {
           gridColor: '#CCCCCC',
           min: 0,
           max: 180,
+          data: [{ axisLine: false }],
           format: (val) => {
             return val.toFixed(0) + '元';
           },
@@ -535,13 +532,19 @@ export default {
     showPie(canvasId, chartData) {
       canvaPie = new uCharts({
         $this: _self,
+        colors: ['#FFBC3C', '#F25051', '#FE7DDE', '#4880FF', '#47EDFB'],
         canvasId: canvasId,
         type: 'pie',
         fontSize: 12,
         legend: {
           show: true,
           position: 'left',
-          itemGap: 250,
+          float: 'center',
+          itemGap: 10,
+          padding: 5,
+          lineHeight: 20,
+          margin: 5,
+          borderWidth: 1,
         },
         background: '#FFFFFF',
         pixelRatio: _self.pixelRatio,
@@ -563,7 +566,7 @@ export default {
           return item.name + ':' + item.data;
         },
       });
-    },
+    }
   },
 };
 </script>
@@ -685,7 +688,7 @@ export default {
   background-color: #fff;
   width: 686upx;
   padding: 0 38upx;
-  box-shadow: 0 10upx 10upx rgba($color: #242424, $alpha: 0.1);
+  box-shadow: 0 10upx 10upx rgba($color: #f4f4f4, $alpha: 0.1);
   z-index: 100;
   border-radius: 10upx;
   box-sizing: border-box;