quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
    <div v-loading="loading" style="min-height: 400px;">
      <el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="商家名称">
          <el-autocomplete class="inline-input" v-model="searchForm.supplier_name" :fetch-suggestions="querySearch"
            placeholder="请输入商户名称"></el-autocomplete>
        </el-form-item>
        <el-form-item><el-button size="small" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button></el-form-item>
      </el-form>
      <!--汇总-->
      <Total v-if="!loading"></Total>
      <!--交易统计-->
      <Transaction v-if="!loading"></Transaction>
      <!--商品统计-->
      <Product v-if="!loading"></Product>
    </div>
</template>
 
<script>
  import StatisticsApi from '@/api/statistics.js';
  import Total from './part/Total.vue'
  import Transaction from './part/Transaction.vue'
  import Product from './part/Product.vue'
  export default{
    components:{
      Total,
      Transaction,
      Product
    },
    data(){
      return{
        /*是否正在加载*/
        loading:true,
        /*数据对象*/
        dataModel:{},
        restaurants: [],
        supplier_list:[],
        /*横向表单数据模型*/
        searchForm: {
          supplier_name:''
        },
      }
    },
    provide: function () {
      return {
        dataModel: this.dataModel,
        supplier_id: this.$route.query.supplier_id
      }
    },
    created() {
      if(this.$route.query.supplier_name){
        this.searchForm.supplier_name =this.$route.query.supplier_name;
      }
      this.getData();
    },
    methods:{
 
      /*获取数据*/
      getData() {
        let self = this;
        StatisticsApi.getOrderTotal({
          shop_supplier_id:this.$route.query.supplier_id
        }, true)
          .then(res => {
            Object.assign(self.dataModel, res.data);
            self.supplier_list = res.data.supplier_list;
            self.loading = false;
          })
          .catch(error => {});
      },
      querySearch(queryString, cb) {
        let self = this;
        if (self.restaurants.length == 0) {
          self.supplier_list.forEach((item, index) => {
            self.restaurants.push({
              value: item.name
            })
          })
        }
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      /*搜索查询*/
      onSubmit() {
        let self = this;
        var supplier_id = 0;
        self.supplier_list.forEach((item, index) => {
          if(item.name == self.searchForm.supplier_name){
             supplier_id = item.shop_supplier_id;
          }
        })
        if(supplier_id == 0){
          this.$message.error('该商户不存在');
          return;
        }
        self.$router.push({
          path: '/statistics/sales/index',
          query: {
            supplier_id: supplier_id,
            supplier_name: self.searchForm.supplier_name
          }
        });
        window.location.reload();
       // self.getData();
      },
 
    }
  }
</script>
 
<style>
</style>