<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'产品名称'" prop="productName">
              <el-input clearable v-model="select.productName"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="'订单类型'" prop="orderType">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="select.orderType"
              >
                <el-option
                  v-for="item in orderTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'订单日期'" prop="thetimes">
              <el-date-picker
                v-model="select.thetimes"
                @change="changeTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                :clearable="false"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button
                class="my_search"
                @click="
                  () => {
                    getSearch();
                    getCzNum();
                  }
                "
              >
                {{ '搜索' }}</el-button
              >
              <el-button class="my_reset" @click="reChongzhi">
                {{ '重置' }}</el-button
              >
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" class="thebtn1" @click="handleExport">
            {{ '导出' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="700px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="colsele" type="selection" width="55">
          </el-table-column>
          <el-table-column
            align="center"
            prop="productCode"
            :label="'产品编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="productName"
            :label="'产品名称'"
            min-width="180px"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="classifyName"
            :label="'产品分类'"
          >
          </el-table-column>

          <!-- <el-table-column
            align="center"
            prop="productPrice"
            :label="'产品价格' + `(${isLocalSymbol()})`"
          >
            <template slot-scope="scope">
              {{ scope.row.productPrice | numFilter }}
            </template>
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="productUnit"
            :label="'产品单位'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderTypeStr"
            :label="'订单类型'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="quantity"
            :label="'数量'"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="productTotalPrice"
            :label="'合计' + '价格' + `(${isLocalSymbol()})`"
          >
            <template slot-scope="scope">
              {{ scope.row.productTotalPrice | numFilter }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="colsele"
            :label="'操作'"
          >
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="goDetail(scope.row)"
                type="text"
                style="color: #48b2fd; padding: 0"
              >
                {{ '查看详情' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>
      
<script>
import topBar from "@/components/topBar";
import * as sta from "@/api/statistics";
import * as log from "@/api/logistics.js";
import { isLocals, isLocalSymbol } from "@/utils/numberToCurrency";
export default {
  name: "ShippingSummaryDetail",
  components: {
    topBar,
  },
  filters: {
    numFilter(value) {
      // 截取当前数据到小数点后两位
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
  },
  data() {
    return {
      moren: "shippingSummaryDetail",
      topList: [
        {
          name: '出货明细汇总统计',
          path: "shippingSummaryDetail",
        },
      ],
      tableData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      select: {
        thetimes: [],
      },
      total: 0,
      multipleSelection: [],
      orderTypeList: [],
    };
  },
  created() {
    this.getSearch();
    this.getOthers();
  },
  methods: {
    isLocalSymbol,
    isLocals,
    goDetail(val) {
      this.$router.push({
        path: "shippingSummaryDetail",
        query: {
          pkProduct: val.pkProduct,
          orderType: val.orderType,
          params: JSON.stringify(this.select),
        },
      });
    },
    changeTime(val) {
      this.select.startTime=val ? val[0] : "";
      this.select.endTime =val? val[1] : "";
    },
    getOthers() {
      // 获取订单类型
      log.getOrderTypeRepurchaseAll().then((res) => {
        this.orderTypeList = res.data;
      });
    },
    //导出
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/report/manager/member-report/product-shipping-details-export",
          Object.assign({}, this.queryParams, this.select),
          `${'出货明细汇总统计'}${new Date().getTime()}.xlsx`
        );
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.select={}
      this.getSearch();
    },
    getSearch() {
      this.loading = true;
      sta.getShippingSummary(Object.assign({}, this.queryParams, this.select)).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData = res.rows;
          this.total = res.total;
        }
      });
    },
    getCzNum() {
      this.queryParams.pageNum = 1;
    },
  },
};
</script>
      
      <style lang="scss" scoped>
::v-deep .el-image-viewer__close {
  right: 500px;
}
::v-deep .dizhi .el-cascader {
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #ffad41;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          color: #ffffff;
          background: #009b58;
          width: 68px;
          height: 32px;
        }
        .thebtn3 {
          color: #ffffff;
          background: #c8161d;
          width: 68px;
          height: 32px;
        }
      }
    }
  }
}
</style>
      