<style scoped lang="scss">
.item-name-calss p {
  margin: 0;
  text-align: left;
}

::v-deep a {
  color: #409eff;
  display: block;
}
</style>
<template>
  <div class="app-container">
    <div></div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="店铺名称" prop="sellerName">
        {{ $route.query ? $route.query.sellerName : "-" }}
      </el-form-item>
      <el-form-item label="店铺Id" prop="sellerId">
        {{ $route.query ? $route.query.sellerId : "-" }}
      </el-form-item>
      <br/>
      <el-form-item label="商品名称" prop="itemTitle">
        <el-input
          v-model="queryParams.itemTitle"
          placeholder="请输入商品名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品Id" prop="itemId">
        <el-input
          v-model.number="queryParams.itemId"
          placeholder="请输入商品Id"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </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-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          :loading="downLoadLoading"
        >导出
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="typeList"
      @selection-change="handleSelectionChange"
      ref="multipleTable"
    >
      <el-table-column
        label="商品名称"
        align="center"
        prop="itemTitle"
        width="350"
        fixed="left"
      >
        <template slot-scope="scope">
          <div style="display: flex; width: 100%">
            <div style="width: 40%">
              <img
                :src="scope.row.imageUrl"
                alt=""
                style="width: 70px; height: auto"
              />
            </div>
            <div style="width: 60%" class="item-name-calss">
              <a
                style="
                      text-overflow: ellipsis;
                      white-space: nowrap;
                      overflow: hidden;
                      width: 100%;
                    "
                :title="scope.row.itemTitle"
              >
                {{ scope.row.itemTitle }}
              </a>
              <p>商品Id： {{ scope.row.itemId }}</p>
              <p>商品单价： {{ scope.row.reservePrice }}元</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="归属人" align="center" prop="userName"></el-table-column>
      <el-table-column
        label="ccr"
        align="center"
        prop="ccrValue"
        sortable="custom"
      >
        <template slot-scope="scope">
          <font v-if="scope.row.ccrInt >= 1.5" color="red">
            {{ scope.row.ccrValue }}
          </font>
          <font v-if="scope.row.ccrInt < 1.5">
            {{ scope.row.ccrValue }}
          </font>
        </template>
      </el-table-column>


      <el-table-column label="订单数" align="center" prop="orderNum"></el-table-column>
      <el-table-column label="有效数" align="center" prop="validOrderNUm"/>
      <el-table-column label="有效率" align="center" prop="validRadio" width="100">
        <template slot-scope="scope">
          {{ scope.row.validRadio ? scope.row.validRadio + "%" : "-" }}
        </template>
      </el-table-column>
      <el-table-column label="发货数" align="center" prop="deliveryNum" width="100">
      </el-table-column>
      <el-table-column
        label="发货率"
        align="center"
        prop="shippingGreen"
      >
        <template slot-scope="scope">
          {{
            scope.row.shippingGreen
              ? scope.row.shippingGreen + "%"
              : "-"
          }}
        </template>
      </el-table-column>
      <el-table-column label="有效发货数" align="center" prop="effDeliveryNum" width="100">
      </el-table-column>
      <el-table-column label="有效发货率" align="center" prop="deliveryRadio" width="100">
        <template slot-scope="scope">
          {{
            scope.row.deliveryRadio
              ? scope.row.deliveryRadio + "%"
              : "-"
          }}
        </template>
      </el-table-column>
      <el-table-column label="未发货数" align="center" prop="notDeliveryNum" width="100">
      </el-table-column>
      <el-table-column label="付款金额" align="center" prop="payAmount">
        <template slot-scope="scope">
          {{ scope.row.payAmount }}
        </template>
      </el-table-column>
      <el-table-column label="服务费率" align="center" prop="regimentalPromotionRate">
        <template slot-scope="scope">
          {{ scope.row.regimentalPromotionRate + "%" }}
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getShopDetail"
    />

  </div>
</template>

<script>
import {
  listType,
  getType,
  delType,
  addType,
  updateType,
  refreshCache,
} from "@/api/system/dict/type";
import {
  downFilePost,
  samplesCheck, getShopDetail,
} from "@/api/supplyChain/supplyChain";

var echarts = require("echarts");
export default {
  name: "ShopDetail",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      downLoadLoading: false,
      dialogTableVisible: false,
      logPage: {
        pageNum: 1,
        pageSize: 10,
      },
      logData: [],
      logTotal: 0,
      logLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 分配销售
      openAllocation: false,
      // 选择的销售id
      saleId: undefined,
      // 获取用户id
      userId: undefined,
      // 销售列表
      saleList: [],
      // 分配销售确定loading
      confirmLoadingSale: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemId: undefined,
        userId: undefined,
        itemTitle: undefined,
        orderStartDate: undefined,
        orderEndDate: undefined,
      },
      uploadDate: [new Date(), new Date()],
      //查询参数所用下拉数据
      queryParamsList: {},
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  filters: {},
  created() {
    this.queryParams.userId = this.$store.getters.userId;
    let start = new Date();
    let end = new Date();

    let y = end.getFullYear();
    let MM = end.getMonth() + 1;
    MM = MM < 10 ? "0" + MM : MM;
    let dd = end.getDate();
    dd = dd < 10 ? "0" + dd : dd;

    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
    let sy = start.getFullYear();
    let sMM = start.getMonth() + 1;
    sMM = sMM < 10 ? "0" + sMM : sMM;
    let sdd = start.getDate();
    sdd = sdd < 10 ? "0" + sdd : sdd;
    this.uploadDate = [`${sy}-${sMM}-${sdd}`, `${y}-${MM}-${dd}`];
    if (
      this.$route &&
      this.$route.query.sellerId &&
      this.$route.query.orderStartDate &&
      this.$route.query.orderEndDate
    ) {
      this.getShopDetail();
    }
  },
  mounted() {
    this.$nextTick(() => {
      //   this.getList();
    });
  },
  methods: {
    /** 导出按钮操作 */
    handleExport() {
      this.downLoadLoading = true;
      downFilePost("/isv/supply_chain/exportShopDetail", {
        ...this.queryParams,
        orderStartDate: this.$route.query.orderStartDate,
        orderEndDate: this.$route.query.orderEndDate,
        sellerId: this.$route.query.sellerId,
      }).then((res) => {
        let blob = new Blob([res], {
          type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        });
        let downloadElement = document.createElement("a");
        let href = window.URL.createObjectURL(blob); //创建下载的链接
        downloadElement.href = href;
        downloadElement.download = `店铺_${this.$route.query.sellerName}${this.$route.query.orderStartDate}-${this.$route.query.orderEndDate}商品详情.xlsx`; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
        this.downLoadLoading = false;
      });
    },
    toDetail(id) {
    },
    toIndexDetail(item) {
      this.$router.replace({
        path: "/supplyChain/kuaishou/goodsDetails",
        query: {
          id: item.itemId,
          name: item.itemTitle,
          orderStartDate: this.$route.query.orderStartDate,
          orderEndDate: this.$route.query.orderEndDate,
        },
      });
    },
    getShopDetail() {
      this.loading = true;
      getShopDetail({
        ...this.queryParams,
        orderStartDate: this.$route.query.orderStartDate,
        orderEndDate: this.$route.query.orderEndDate,
        sellerId: this.$route.query.sellerId,
      }).then((response) => {
        this.typeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    // 取消按钮
    cancel() {
      this.open = false;
      this.confirmLoading = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.dateFile = null;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getShopDetail();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },
  },
};
</script>
