<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form ref="form" :model="queryParams" label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'产品编号'" prop="waresCode">
              <el-input clearable v-model="queryParams.waresCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'产品名称'" prop="waresName">
              <el-input clearable v-model="queryParams.waresName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="SKU编码">
              <el-input clearable v-model="queryParams.skuCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'订单类型'" prop="orderType">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.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="4">
            <el-form-item :label="'订单编号'" prop="orderCode">
              <el-input clearable v-model="queryParams.orderCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input clearable v-model="queryParams.memberCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'" prop="memberName">
              <el-input clearable v-model="queryParams.memberName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'联系方式'" prop="phone">
              <el-input clearable v-model="queryParams.phone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'商品编号'" prop="commodityCode">
              <el-input
                clearable
                v-model="queryParams.commodityCode"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'商品名称'" prop="commodityName">
              <el-input
                clearable
                v-model="queryParams.commodityName"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${'购买人' + '编号'}`"
              prop="buyMemberCode"
            >
              <el-input
                clearable
                v-model="queryParams.buyMemberCode"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${'购买人' + '姓名'}`"
              prop="buyMemberName"
            >
              <el-input
                clearable
                v-model="queryParams.buyMemberName"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'收货人'" prop="recName">
              <el-input clearable v-model="queryParams.recName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'发货类型'" prop="shippingChannel">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.shippingChannel"
              >
                <el-option
                  v-for="item in shippingTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('系统类型')">
              <el-select clearable v-model="queryParams.systemType">
                <el-option
                  v-for="item in systemTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="支付方式" prop="payType">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.payType"
              >
                <el-option
                  v-for="item in payTypeList"
                  :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="'创建日期'">
              <el-date-picker
                v-model="queryParams.times1"
                type="daterange"
                @change="changeTime"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker
            ></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'支付日期'">
              <el-date-picker
                v-model="queryParams.times2"
                type="daterange"
                @change="changeTime2"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker
            ></el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'快递单号'" prop="logisticsCode">
              <el-input v-model="queryParams.logisticsCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="订单状态" prop="orderStatus">
              <el-select
                v-model="queryParams.orderStatus"
                clearable
                placeholder="请选择订单状态"
              >
                <el-option
                  v-for="(item, index) in orderStatusList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="padding-left: 30px">
            <div class="searchbox">
              <el-button class="searchbtn" @click="getSearch">
                {{ '搜索' }}</el-button
              >
              <el-button @click="reChongzhi"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="maintop">
      <div class="mainbtn">
        <el-button
          size="small"
          class="thebtn2"
          @click="handleExport"
          v-has-buttons="['ckspddExport']"
        >
          {{ '导出' }}</el-button
        >
      </div>
    </div>
    <div class="main">
      <div class="maintable">
        <el-table
          height="600px"
          :data="tableData"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
          :span-method="objectSpanMethod"
        >
          <el-table-column type="selection"> </el-table-column>
          <el-table-column align="center" prop="" :label="'产品主图'">
            <template slot-scope="scope">
              <img
                style="
                  width: 44px;
                  height: 44px;
                  border-radius: 8px 8px 8px 8px;
                "
                :src="scope.row.cover1"
                alt=""
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="waresCode"
            :label="'产品编号'"
          >
          </el-table-column>

          <el-table-column
            min-width="200px"
            align="center"
            prop="waresName"
            :label="'产品名称'"
          >
          </el-table-column>
          <el-table-column
            min-width="200px"
            align="center"
            prop="specsName"
            :label="'产品规格'"
          >
          </el-table-column>
          <el-table-column
            min-width="200px"
            align="center"
            prop="skuCode"
            label="SKU编码"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="weight"
            :label="'重量' + 'KG'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="120px"
            prop="productPrice"
            :label="'产品单价' + '(￥)'"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.productPrice | numFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="quantity"
            :label="'产品数量'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="productPriceTotal"
            min-width="120px"
            :formatter="productPriceTotal"
            :label="'产品总价' + '(￥)'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="200px"
            prop="commodityCode"
            :label="'商品编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="200px"
            prop="commodityName"
            :label="'商品名称'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="200px"
            prop="waresQuantity"
            :label="'商品数量'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="200px"
            prop="orderCode"
            :label="'订单编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderTypeStr"
            :label="'订单类型'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="120px"
            prop="phone"
            :label="'联系方式'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="shippingChannelStr"
            :label="'发货类型'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recName"
            :label="'收货人'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="120px"
            prop="recPhone"
            :label="'收货电话'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            min-width="120px"
            prop="buyMemberCode"
            :label="`${'购买人' + '编号'}`"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="buyMemberName"
            :label="`${'购买人' + '姓名'}`"
          />
          <el-table-column
            align="center"
            prop="recProvinceName"
            :label="'省'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recCityName"
            :label="'市'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recCountryName"
            :label="'区/县'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recAddress"
            :label="'详细地址'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderAmount"
            :label="'订单金额'"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="orderAssAchieve"
            :label="'商品订单' + 'BV'"
          />
          <el-table-column
            align="center"
            prop="postage"
            :label="'订单邮费'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderAchieve"
            :label="'订单业绩'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="deliveryWayStr"
            :label="'发货方式'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="operateScope"
            :label="'供应方式'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="tranTypeStr"
            :label="'运输方式'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="preSaleStatusStr"
            :label="'预售状态'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderStatusStr"
            :label="'订单状态'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="payTypeStr"
            :label="'支付方式'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="logisticsCompany"
            :label="'物流公司'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="logisticsCode"
            :label="'快递单号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="remark"
            :label="'备注'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="systemType"
            :label="$t('系统类型')"
          >
            <template slot-scope="scope">
              <div
                v-for="item in systemTypes"
                :key="item.value"
                v-if="scope.row.systemType == item.value"
              >
                {{ item.label }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'创建日期'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="payTime"
            :label="'支付日期'"
          >
          </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 class="footer">
      <el-button size="small" class="thebtn2" @click="goBack"> {{ '返回' }}</el-button>
    </div> -->
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as log from "@/api/logistics";
import * as del from "@/api/delivery";
import { getStatus } from "@/api/notice";

export default {
  name: "Ckspdd",
  components: {
    topBar,
  },
  filters: {
    numFilter(value) {
      // 截取当前数据到小数点后两位
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
  },
  data() {
    return {
      moren: "ckspdd",
      topList: [
        {
          name: '商品订单',
          path: "spdd",
        },
        {
          name: '订单详情',
          path: "ckspdd",
        },
      ],

      multipleSelection: [],
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        orderCode: "",
        orderStatus: "",
      },
      orderStatusList: [],
      tableData: [],
      orderTypeList: [],
      shippingTypeList: [],
      payTypeList: [],
      total: 0,
    };
  },
  created() {
    this.queryParams.orderCode = this.$route.query.orderCode;
    this.getOthers();
    this.getSearch();
    this.getOrderStatus();
  },
  methods: {
    getOrderStatus() {
      getStatus().then((res) => {
        this.orderStatusList = res.data;
      });
    },
    changeTime(val) {
      this.queryParams.startCreateDate = val[0];
      this.queryParams.endCreateDate = val[1];
    },
    changeTime2(val) {
      this.queryParams.startPayDate = val[0];
      this.queryParams.endPayDate = val[1];
    },
    // 导出
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/sale/manage/order/get-order-info-export",
          { ...this.queryParams },
          `商品订单详情${new Date().getTime()}.xlsx`
        );
      });
    },
    getOthers() {
      log.getOrderType().then((res) => {
        this.orderTypeList = res.data;
      });
      del.getShippingChannelList().then((res) => {
        this.shippingTypeList = res.data;
      });
      del.getOrderPayType().then((res) => {
        this.payTypeList = res.data;
      });
    },
    totalAmount(row) {
      let total = "";

      total = row.orderAmount * row.quantity;
      return total;
    },
    goBack() {
      this.$router.go(-1);
    },
    handleChange1() {},

    getSearch() {
      log.getFindOrderList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
    //重置
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.getSearch();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (columnIndex === 0) {
      //   if (rowIndex % 2 === 0) {
      //     return {
      //       rowspan: 2,
      //       colspan: 1,
      //     };
      //   } else {
      //     return {
      //       rowspan: 0,
      //       colspan: 0,
      //     };
      //   }
      // }
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .dizhi {
  width: 100%;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.footer {
  height: 68px;
  background: #ffffff;
  box-shadow: 0px -3px 20px 0px rgba(204, 204, 204, 0.5);
  // margin: 0 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  .thebtn1 {
    background: #3181e5;
    color: #ffffff;
    padding: 9px 45px;
  }
  .thebtn2 {
    background: #cccccc;
    color: #ffffff;
    padding: 9px 45px;
  }
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 20px 20px 0 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #c8161d;
        color: #ffffff;
      }
    }
  }
  .maintop {
    display: flex;
    padding: 0px 20px;
    justify-content: space-between;
    align-items: center;
    .mainbtn {
      .thebtn2 {
        color: #ffffff;
        background: #ffad41;
      }
    }
  }
  .main {
    // margin-top: 10px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      padding: 10px 20px;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
        }
      }
    }
  }
}
</style>
