<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <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 v-model="queryParams.waresCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'产品名称'" prop="waresName">
              <el-input v-model="queryParams.waresName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="SKU编码">
              <el-input v-model="queryParams.skuCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'订单类型'" prop="orderType">
              <el-select
                v-model="queryParams.orderType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in orderTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'订单编号'" prop="orderCode">
              <el-input v-model="queryParams.orderCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input v-model="queryParams.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'" prop="memberName">
              <el-input v-model="queryParams.memberName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'隶属体系'" prop="vertexId">
              <el-select
                v-model="queryParams.vertexId"
                clearable
              >
                <el-option
                  v-for="item in vertexList"
                  :key="item.pkId"
                  :label="item.vertexName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'联系方式'" prop="phone">
              <el-input v-model="queryParams.phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'商品编号'" prop="commodityCode">
              <el-input
                v-model="queryParams.commodityCode"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'商品名称'" prop="commodityName">
              <el-input
                v-model="queryParams.commodityName"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${'购买人' + '编号'}`"
              prop="buyMemberCode"
            >
              <el-input
                v-model="queryParams.buyMemberCode"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${'购买人' + '姓名'}`"
              prop="buyMemberName"
            >
              <el-input
                v-model="queryParams.buyMemberName"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'收货人'" prop="recName">
              <el-input v-model="queryParams.recName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'发货类型'" prop="shippingChannel">
              <el-select
                v-model="queryParams.shippingChannel"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in shippingTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="支付方式" prop="payType">
              <el-select
                v-model="queryParams.payType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in payTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item :label="'创建日期'">
              <el-date-picker
                v-model="queryParams.times1"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
                @change="changeTime"
              /></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'支付日期'">
              <el-date-picker
                v-model="queryParams.times2"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
                @change="changeTime2"
              /></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
          v-has-buttons="['ckspddExport']"
          size="small"
          class="thebtn2"
          @click="handleExport"
        >
          {{ '导出' }}</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"
          :span-method="objectSpanMethod"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" />
          <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="'产品编号'"
            min-width="120px"
          />

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

          <el-table-column
            align="center"
            prop="weight"
            :label="'重量' + 'KG'"
          />
          <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
            align="center"
            prop="productPriceTotal"
            min-width="120px"
            :formatter="productPriceTotal"
            :label="'产品总价' + '(￥)'"
          />
          <el-table-column
            align="center"
            min-width="200px"
            prop="commodityCode"
            :label="'商品编号'"
          />
          <el-table-column
            align="center"
            min-width="200px"
            prop="commodityName"
            :label="'商品名称'"
          />
          <el-table-column
            align="center"
            min-width="200px"
            prop="waresQuantity"
            :label="'商品数量'"
          />
          <el-table-column
            align="center"
            min-width="200px"
            prop="orderCode"
            :label="'订单编号'"
          />
          <el-table-column
            align="center"
            prop="orderTypeStr"
            :label="'订单类型'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          />
          <el-table-column
            align="center"
            prop="vertexName"
            :label="'隶属体系'"
            min-width="120"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="phone"
            :label="'联系方式'"
          />
          <el-table-column
            align="center"
            prop="shippingChannelStr"
            :label="'发货类型'"
          />
          <el-table-column
            align="center"
            prop="recName"
            :label="'收货人'"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="recPhone"
            :label="'收货电话'"
          />
          <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
            align="center"
            prop="recCityName"
            :label="'市'"
          />
          <el-table-column
            align="center"
            prop="recCountryName"
            :label="'区/县'"
          />
          <el-table-column
            align="center"
            prop="recAddress"
            :label="'详细地址'"
          />
          <el-table-column
            align="center"
            prop="orderAmount"
            :label="'订单金额'"
          />
          <el-table-column
            align="center"
            prop="orderAchieve"
            :label="'订单业绩'"
          />
          <el-table-column
            align="center"
            prop="orderAssAchieve"
            :label="'商品订单' + 'BV'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="postage"
            :label="'订单邮费'"
          />
          <el-table-column
            align="center"
            prop="deliveryWayStr"
            :label="'发货方式'"
          />
          <el-table-column
            align="center"
            prop="operateScope"
            :label="'供应方式'"
          />
          <el-table-column
            align="center"
            prop="tranTypeStr"
            :label="'运输方式'"
          />
          <el-table-column
            align="center"
            prop="preSaleStatusStr"
            :label="'预售状态'"
          />
          <el-table-column
            align="center"
            prop="orderStatusStr"
            :label="'订单状态'"
          />
          <el-table-column
            align="center"
            prop="payTypeStr"
            :label="'支付方式'"
          />
          <el-table-column
            align="center"
            prop="logisticsCompany"
            :label="'物流公司'"
          />
          <el-table-column
            align="center"
            prop="logisticsCode"
            :label="'快递单号'"
          />
          <el-table-column
            align="center"
            prop="remark"
            :label="'备注'"
          />

          <el-table-column
            align="center"
            prop="creationTime"
            :label="'创建日期'"
            min-width="160px"
          />
          <el-table-column
            align="center"
            prop="payTime"
            :label="'支付日期'"
            min-width="160px"
          />
        </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'
import { getVartexList } from '@/api/affiliatedteam'
export default {
  name: 'Ckspdd',
  components: {
    topBar
  },
  filters: {
    numFilter(value) {
      // 截取当前数据到小数点后两位
      const 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: '',
        vertexId: ''
      },
      orderStatusList: [],
      tableData: [],
      orderTypeList: [],
      shippingTypeList: [],
      payTypeList: [],
      total: 0,
      vertexList: []
    }
  },
  created() {
    this.queryParams.orderCode = this.$route.query.orderCode
    this.getOthers()
    this.getSearch()
    this.getOrderStatus()
    getVartexList().then((res) => {
      this.vertexList = res.data
    })
  },
  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>
