<template>
  <div class="app-container">
      <div class="app-content">
        <div class="title" style="display: flex; justify-content: center; align-items: center;">药品销售统计</div>
        <el-form class="search-form" :inline="true" label-width="90px">
                <el-form-item   label="统计">
                  <el-select v-model="queryParams.type" placeholder="请选择日期" size="small">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item>
                   <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                   <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form>
              </div>
              <el-button class="export" size="small"  @click="handleExport" style="float: right; margin-bottom: 15px; margin-right: 40px;" >导出</el-button>
              <div class="table-box" style="margin-left: 40px; margin-right: 40px;">
                <el-table
                :data="list"
                border
                show-summary
                style="width: 100%;" class="centered-table">
                <el-table-column
                  label="商品名称"  >
                  <template slot-scope="scope">
                <span>{{ JSON.parse(scope.row.json).productName}}</span>
                 </template>
                </el-table-column>
               <el-table-column
                 label="商品编号"  >
                 <template slot-scope="scope">
               <span>{{ JSON.parse(scope.row.json).barCode}}</span>
                </template>
               </el-table-column>
               <el-table-column
                 label="组合编号"  >
                 <template slot-scope="scope">
               <span>{{ JSON.parse(scope.row.json).groupBarCode}}</span>
                </template>
               </el-table-column>
                <el-table-column
                  label="单价"  >
                  <template slot-scope="scope">
                <span>{{ JSON.parse(scope.row.json).price}}</span>
                 </template>
                </el-table-column>
                <el-table-column
                  label="销售金额"  >
                  <template slot-scope="scope">
                <span>{{ JSON.parse(scope.row.json).price * scope.row.num}}</span>
                 </template>
                </el-table-column>
                <el-table-column
                  prop="num"
                  label="销售数量" >
                </el-table-column>
              </el-table>
          </div>
  </div>
</template>

<script>
import { storeProduct,exportStoreProduct } from "@/api/company/statistics";
export default {
  data() {
    return {
      exportLoading: false,
      queryParams:{
        type: "9",
        storeId: null,
      },
      options: [{
         value: '1',
         label: '今天'
       }, {
         value: '2',
         label: '昨天'
       }, {
         value: '3',
         label: '本周'
       }, {
         value: '4',
         label: '上周'
       }, {
         value: '5',
         label: '本月'
       }
       , {
         value: '6',
         label: '上月'
       },
       {
         value: '7',
         label: '本季度'
       },
       {
         value: '8',
         label: '上季度'
       }
       , {
         value: '9',
         label: '本年'
       }
       , {
         value: '10',
         label: '去年'
       }],
      list:[],
      storeOPtions:[],
      chart: null,
      data: [
      ],
    };
  },
  created() {
    storeProduct(this.queryParams).then(response => {
      this.list = response.list;
    });
  },

  methods: {

 /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
            this.exportLoading = true;
          return exportStoreProduct(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },

    handleQuery(){
      storeProduct(this.queryParams).then(response => {
        this.list = response.list;
      });
    },
 /** 重置按钮操作 */
    resetQuery() {
     this.queryParams={
       type: null,
       storeId: null,
     }
     this.getorderChartData()
    },

  },
};
</script>
<style>
  .title{
    padding: 20px 30px 0px 30px;
    font-size: 18px;
    font-weight: bold;
    color: black;

  }
  .search-form{
    margin: 20px 30px 0px 30px;
  }
  .echart-box{
    margin: 0 auto;
    text-align: center;
  }
  .el-select{
    margin: 5px 10px;
  }
  .table-box{
    margin-top: 15px;
    .export{
      float: right;
      margin: 10px 0px;
    }
  }
.app-container{
    border: 1px solid #e6e6e6;
    padding: 12px;


}
 .app-content{
      background-color: white;



    }
    .data-box{
      padding: 30px;
      background-color:  rgb(255, 255, 255);
      height: 100%;


    }


    .centered-table .cell {
      text-align: center;
    }
</style>
