<style scoped lang="scss">
::v-deep a {
  color: #409eff;
  display: block;
}

.item-name-calss p {
  margin: 0;
  text-align: left;
}

.tableBox {
  width: 100%;
}

::v-deep .el-table {

  height: calc(100vh - 280px);
}
</style>
<template>
  <div class="app-container" style="height: 100%">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="店铺Id" prop="sellerId">
        <el-input
          v-model.number="queryParams.sellerId"
          placeholder="请输入商品Id"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出单日期">
        <el-date-picker
          v-model="uploadDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </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>

    <div class="tableBox">
      <el-table
        v-loading="loading"
        :data="typeList"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        @sort-change="sortChange"
        height="calc(100vh - 100px);"
      >
        <el-table-column
          label="店铺信息"
          align="center"
          prop="itemTitle"
          width="120"
        >
          <template slot-scope="scope">
            <div style="width: 100%" class="item-name-calss">
              <p class="item-name-calss">
                <a
                  @click="toShopDetail(scope.row)"
                  style="
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    overflow: hidden;
                    width: 100%;
                  "
                >
                  {{ scope.row.sellerId }}
                </a>

              </p>
              <p class="item-name-calss">

                <a
                  @click="toShopDetail(scope.row)"
                  style="
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    overflow: hidden;
                    width: 100%;
                  "

                >
                  {{ scope.row.sellerName }}
                </a>
              </p>
            </div>
          </template>
        </el-table-column>


        <el-table-column
          label="单数"
          align="center"
          prop="orderNum"
          sortable="custom"
        >
        </el-table-column>
        <el-table-column
          label="有效单数"
          align="center"
          prop="validOrderNUm"
          sortable="custom"
        />
        <el-table-column
          label="有效率"
          align="center"
          prop="validRadio"
          sortable="custom"
        >
          <template slot-scope="scope">
            {{
              scope.row.validRadio
                ? scope.row.validRadio + "%"
                : "-"
            }}
          </template>
        </el-table-column>

        <el-table-column
          label="已结单数"
          align="center"
          prop="settledOrderNUm"
          sortable="custom"
        />


        <el-table-column
          label="已结率"
          align="center"
          prop="settledOrderRate"
          sortable="custom"
        >
          <template slot-scope="scope">
            {{
              scope.row.settledOrderRate
                ? scope.row.settledOrderRate + "%"
                : "-"
            }}
          </template>
        </el-table-column>

        <el-table-column
          label="订单金额"
          align="center"
          prop="payAmount"
          sortable="custom"
        >
        </el-table-column>

        <el-table-column
          label="发货数"
          align="center"
          prop="deliveryNum"
          sortable="custom"
        >
        </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"
          sortable="custom"
        >
        </el-table-column>

        <el-table-column
          label="有效发货率"
          align="center"
          prop="deliveryRadio"
          sortable="custom"
        >
          <template slot-scope="scope">
            {{
              scope.row.deliveryRadio
                ? scope.row.deliveryRadio + "%"
                : "-"
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="未发货数"
          align="center"
          prop="notDeliveryNum"
          sortable="custom"
        >
        </el-table-column>

        <el-table-column
          label="预估服务费收入"
          align="center"
          prop="regimentalPromotionAmount"
          sortable="custom"
          v-if="this.$store.getters.userId == 1  || this.$store.getters.userId == 510127"
        >
          <template slot-scope="scope">
            {{
              scope.row.regimentalPromotionAmount

            }}
          </template>
        </el-table-column>
        <el-table-column
          label="结算服务费收入"
          align="center"
          prop="totalRegimentalSettleAmount"
          sortable="custom"
          v-if="this.$store.getters.userId == 1  || this.$store.getters.userId == 510127"
        >
          <template slot-scope="scope">
            {{
              scope.row.totalRegimentalSettleAmount

            }}
          </template>
        </el-table-column>


      </el-table>

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

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

export default {
  name: "ShopList",
  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,
        userId: undefined,
        itemId: undefined,
        itemTitle: undefined,
        orderStartDate: undefined,
        orderEndDate: undefined,
      },
      uploadDate: [new Date(), new Date()],
      //查询参数所用下拉数据
      queryParamsList: {
        personList: [],
      },
      videoTag: [],
      videoVisibleChange: undefined,
      prop: "orderNum",
      sort: "desc",
    };
  },
  created() {
    this.userId = this.$store.getters.userId;
    this.queryParams.userId = this.$store.getters.userId;
    let date = new Date();
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? "0" + MM : MM;
    let dd = date.getDate();
    dd = dd < 10 ? "0" + dd : dd;
    this.uploadDate = [`${y}-${MM}-${dd}`, `${y}-${MM}-${dd}`];
  },
  mounted() {
    this.$nextTick(() => {

      this.getList();
    });
  },
  methods: {

    /** 导出按钮操作 */
    handleExport() {
      this.downLoadLoading = true;
      downFilePost(
        "/isv/supply_chain/exportShopList",
        this.addDateRange(
          this.queryParams,
          this.uploadDate,
          "orderStartDate",
          "orderEndDate"
        )
      ).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 = `商品列表.xlsx`; //下载后文件名
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
        this.downLoadLoading = false;
      });
    },
    toShopDetail(item) {
      this.$router.replace({
        path: "/supplyChain/kuaishou/shopDetails",
        query: {
          sellerId: item.sellerId,
          sellerName: item.sellerName,
          orderStartDate: this.uploadDate[0],
          orderEndDate: this.uploadDate[1],
        },
      });
    },
    sortChange(col, prop, order) {
      this.prop = col.prop;
      this.sort = !!col.order
        ? col.order == "descending"
          ? "desc"
          : "asc"
        : "desc";
      this.handleQuery();
    },
    getPersonList() {
      getSupplyChainCourtshipList().then((response) => {
        this.queryParamsList.personList = response.rows;
      });
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;

      getShopList(
        this.addDateRange(
          {...this.queryParams, fieId: this.prop, sort: this.sort},
          this.uploadDate,
          "orderStartDate",
          "orderEndDate"
        )
      ).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.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      let date = new Date();
      let y = date.getFullYear();
      let MM = date.getMonth() + 1;
      MM = MM < 10 ? "0" + MM : MM;
      let dd = date.getDate();
      dd = dd < 10 ? "0" + dd : dd;
      this.uploadDate = [`${y}-${MM}-${dd}`, `${y}-${MM}-${dd}`];
      this.resetForm("queryForm");
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
    },
  }
  ,
}
;
</script>
