<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="$t('MY_ORD_1')" prop="orderCode">
              <el-input v-model="queryParams.orderCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MN_T_1')" prop="memberCode">
              <el-input v-model="queryParams.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('CK_KS_14')" prop="memberName">
              <el-input v-model="queryParams.memberName" clearable />
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="$t('w_0052')" prop="phone">
              <el-input v-model="queryParams.phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('MY_ORD_2')" prop="orderType">
              <el-select
                v-model="queryParams.orderType"
                clearable
                :placeholder="$t('CK_KS_38')"
              >
                <el-option
                  v-for="(item, index) in typeList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="$t('w_0061')" prop="deliveryWay">
              <el-select
                v-model="queryParams.deliveryWay"
                clearable
                :placeholder="$t('CK_KS_38')"
              >
                <el-option
                  v-for="(item, index) in fhwayList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <el-form-item :label="$t('MY_ORD_10')" prop="recName">
              <el-input v-model="queryParams.recName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="$t('w_0242')" prop="recPhone">
              <el-input v-model="queryParams.recPhone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item class="dizhi" :label="$t('S_C_27')" prop="teamCode">
              <el-cascader
                v-model="queryParams.shoppingAddress"
                :options="areaData"
                :props="regionParams"
                clearable
                @change="handleChange1"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label-width="30px" label="" prop="recAddress">
              <el-input v-model="queryParams.recAddress" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${$t('ENU_GIFT_T_2') + $t('MN_F_T_228')}`"
              prop="buyMemberCode"
            >
              <el-input
                clearable
                v-model="queryParams.buyMemberCode"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="`${$t('ENU_GIFT_T_2') + $t('PER_DA_14')}`"
              prop="buyMemberName"
            >
              <el-input
                clearable
                v-model="queryParams.buyMemberName"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-collapse-transition>
          <div v-show="isActive">
            <el-row>
              <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="$t('w_0215')" prop="payType">
                  <el-select
                    v-model="queryParams.payType"
                    clearable
                    :placeholder="$t('CK_KS_38')"
                  >
                    <el-option
                      v-for="(item, index) in paywayList"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item :label="$t('PER_DA_9')" prop="teamCode">
                  <el-date-picker
                    v-model="queryParams.cjsj"
                    type="daterange"
                    range-separator="——"
                    :start-placeholder="$t('CK_KS_4')"
                    :end-placeholder="$t('CK_KS_5')"
                    value-format="yyyy-MM-dd"
                    :unlink-panels="true"
                    @change="changeCjsj"
                  />
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item :label="$t('MN_F_T_914')" prop="teamCode">
                  <el-date-picker
                    v-model="queryParams.zfsj"
                    type="daterange"
                    range-separator="——"
                    :start-placeholder="$t('CK_KS_4')"
                    :end-placeholder="$t('CK_KS_5')"
                    value-format="yyyy-MM-dd"
                    :unlink-panels="true"
                    @change="changeZfsj"
                  />
                </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-row>
          </div>
        </el-collapse-transition>
        <el-row style="margin-left: 20px">
          <el-col :span="4">
            <div class="searchbox">
              <el-button class="searchbtn" @click="getSearch">
                {{ $t("MN_T_2") }}</el-button
              >
              <el-button @click="reChongzhi"> {{ $t("MN_T_3") }}</el-button>
            </div>
          </el-col>
          <div class="openClose" @click="changeActive">
            <i :class="isActive ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" />
            <div>{{ isActive ? $t("MN_F_T_545") : $t("MN_F_T_546") }}</div>
          </div>
        </el-row>
      </el-form>
    </div>
    <div class="maintop">
      <div class="mainbtn">
        <el-button
          size="small"
          v-hasButtons="['CommodityExport']"
          class="thebtn2"
          @click="handleExport"
        >
          {{ $t("MN_T_8") }}</el-button
        >
      </div>
    </div>
    <div class="main">
      <div class="maintable">
        <el-table
          v-if="flag"
          :data="tableData"
          v-loading="loading"
          style="width: 100%"
          height="600px"
          :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"
            min-width="200px"
            prop="orderCode"
            :label="$t('MY_ORD_1')"
            v-if="dataList[0].key"
          />
          <el-table-column
            align="center"
            prop="orderTypeStr"
            :label="$t('MY_ORD_2')"
            v-if="dataList[1].key"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="memberCode"
            :label="$t('MN_T_1')"
            v-if="dataList[2].key"
          />
          <el-table-column
            align="center"
            prop="memberName"
            :label="$t('CK_KS_14')"
            v-if="dataList[3].key"
          />

          <el-table-column
            align="center"
            min-width="120px"
            prop="phone"
            :label="$t('w_0052')"
            v-if="dataList[4].key"
          />
          <el-table-column
            align="center"
            prop="recName"
            :label="$t('MY_ORD_10')"
            v-if="dataList[5].key"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="recPhone"
            :label="$t('w_0242')"
            v-if="dataList[6].key"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="buyMemberCode"
            v-if="dataList[19].key"
            :label="`${$t('ENU_GIFT_T_2') + $t('MN_F_T_228')}`"
          />
          <el-table-column
            align="center"
            min-width="120px"
            prop="buyMemberName"
            v-if="dataList[20].key"
            :label="`${$t('ENU_GIFT_T_2') + $t('PER_DA_14')}`"
          />
          <el-table-column
            align="center"
            prop="recProvinceName"
            :label="$t('MY_ORD_11')"
            v-if="dataList[7].key"
          />
          <el-table-column
            align="center"
            prop="recCityName"
            :label="$t('MY_ORD_12')"
            v-if="dataList[8].key"
          />
          <el-table-column
            align="center"
            prop="recCountryName"
            :label="$t('MY_ORD_13')"
            v-if="dataList[9].key"
          />
          <el-table-column
            align="center"
            min-width="200px"
            prop="recAddress"
            :label="$t('S_C_27')"
            v-if="dataList[10].key"
          />
          <el-table-column
            align="center"
            min-width="100px"
            prop="orderAmount"
            :label="`${$t('MY_ORD_6')}(${isLocalSymbol()})`"
            v-if="dataList[11].key"
          />

          <el-table-column
            align="center"
            min-width="100px"
            prop="orderAssAchieve"
            :label="$t('MN_F_T_69') + 'BV'"
            v-if="dataList[21].key"
          />
          <el-table-column
            align="center"
            min-width="100px"
            prop="postage"
            :label="$t('MN_F_T_237')"
            v-if="dataList[12].key"
          />
          <el-table-column
            align="center"
            min-width="100px"
            prop="orderAchieve"
            :label="$t('MY_ORD_16') + '($)'"
            v-if="dataList[13].key"
          />
          <el-table-column
            align="center"
            prop="deliveryWayStr"
            :label="$t('w_0061')"
            min-width="100px"
            v-if="dataList[14].key"
          />
          <el-table-column
            min-width="100px"
            align="center"
            prop="payTypeStr"
            :label="$t('w_0215')"
            v-if="dataList[15].key"
          />
          <el-table-column
            min-width="100px"
            align="center"
            prop="remark"
            :label="$t('MY_WAL_22')"
            v-if="dataList[16].key"
          />
          <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
            min-width="150px"
            align="center"
            prop="creationTime"
            :label="$t('PER_DA_9')"
            v-if="dataList[17].key"
          />
          <el-table-column
            min-width="150px"
            align="center"
            prop="payTime"
            :label="$t('MN_F_T_914')"
            v-if="dataList[18].key"
          />
          <el-table-column
            align="center"
            prop="time"
            :label="$t('MY_ORD_14')"
            fixed="right"
            min-width="120px"
            width="auto"
          >
            <template slot-scope="scope">
              <div>
                <el-button
                  type="text"
                  v-hasButtons="['CommodityOpen']"
                  size="small"
                  @click.native.prevent="findDetail(scope.row, tableData)"
                >
                  {{ $t("MY_CK_18") }}
                </el-button>
              </div>
            </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 log from "@/api/logistics";
import * as api from "@/api/site.js";
import { getRoleMenu, roleDetails, getStatus } from "@/api/notice";
export default {
  name: "Spdd",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "spdd",
      dataList: [
        {
          name: "orderCode",
          key: "",
        },
        {
          name: "orderTypeStr",
          key: "",
        },
        {
          name: "memberCode",
          key: "",
        },
        {
          name: "memberName",
          key: "",
        },
        {
          name: "phone",
          key: "",
        },
        {
          name: "recName",
          key: "",
        },
        {
          name: "recPhone",
          key: "",
        },
        {
          name: "recProvinceName",
          key: "",
        },
        {
          name: "recCityName",
          key: "",
        },
        {
          name: "recCountryName",
          key: "",
        },
        {
          name: "recAddress",
          key: "",
        },
        {
          name: "orderAmount",
          key: "",
        },
        {
          name: "postage",
          key: "",
        },
        {
          name: "orderAchieve",
          key: "",
        },
        {
          name: "deliveryWayStr",
          key: "",
        },
        {
          name: "payTypeStr",
          key: "",
        },
        {
          name: "remark",
          key: "",
        },

        {
          name: "creationTime",
          key: "",
        },
        {
          name: "payTime",
          key: "",
        },
        {
          name: "buyMemberCode",
          key: "",
        },
        {
          name: "buyMemberName",
          key: "",
        },
        {
          name: "orderAssAchieve",
          key: "",
        },
      ],
      topList: [
        {
          name: this.$t("MN_F_T_69"),
          path: "spdd",
        },
        {
          name: this.$t("MY_ORD_5"),
          path: "ckspdd",
        },
      ],

      multipleSelection: [],
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        shoppingAddress: [],
        orderCode: "", // 订单编号
        memberCode: "", // 会员编号
        memberName: "", // 会员名称
        phone: "", // 电话
        orderType: "", // 订单类型
        deliveryWay: "", // 发货方式
        payType: "", // 支付方式
        recName: "", // 收货人
        recPhone: "", // 收货电话
        recProvince: "",
        recCity: "",
        recCountry: "",
        recAddress: "", // 详细地址
        startCreateDate: "",
        endCreateDate: "",
        startPayDate: "",
        endPayDate: "",
        orderStatus: "",
      },
      loading: false,
      tableData: [],
      // 折叠搜索框
      isActive: false,
      areaData: [],
      regionParams: {
        label: "name",
        value: "id",
        children: "children",
        expandTrigger: "hover",
      },
      typeList: [],
      fhwayList: [],
      paywayList: [],
      orderStatusList: [],
      total: 0,
      flag: false,
    };
  },
  created() {
    this.getData();
    this.getSearch();
    this.getUserRole();
    this.getOrderStatus();
  },
  methods: {
    getOrderStatus() {
      getStatus().then((res) => {
        this.orderStatusList = res.data;
      });
    },

    getUserRole() {
      getRoleMenu("Commodity").then((res) => {
        this.dataList.forEach((item) => {
          res.data.forEach((items) => {
            if (item.name == items) {
              item.key = items;
            }
            this.flag = true;
          });
        });
      });
    },
    // 导出
    handleExport() {
      this.$confirm(this.$t("MN_F_T_407"), this.$t("MN_F_T_304"), {
        confirmButtonText: this.$t("w_0035"),
        cancelButtonText: this.$t("ENU_P_TYPE0"),
        type: "warning",
      }).then((_) => {
        this.download(
          "/sale/manage/order/get-order-list-export",
          { ...this.queryParams },
          `${this.$t("MN_F_T_69")}${new Date().getTime()}.xlsx`
        );
      });
    },
    handleChange1() {},
    findDetail(row, data) {
      this.$router.push({
        path: "/logistics/commodity/ckspdd",
        query: { orderCode: row.orderCode },
      });
    },
    getData() {
      api.areaList().then((res) => {
        this.areaData = res.data;
      });
      log.getOrderType().then((res) => {
        this.typeList = res.data;
      });
      log.getDeliveryList().then((res) => {
        this.fhwayList = res.data;
      });
      log.getOrderPayType().then((res) => {
        this.paywayList = res.data;
      });
    },
    // 展开折叠
    changeActive() {
      this.isActive = !this.isActive;
    },
    changeCjsj(val) {
      this.queryParams.startCreateDate = val[0];
      this.queryParams.endCreateDate = val[1];
    },
    changeZfsj(val) {
      this.queryParams.startPayDate = val[0];
      this.queryParams.endPayDate = val[1];
    },
    getSearch() {
      this.loading = true;
      this.queryParams.recProvince = this.queryParams.shoppingAddress[0];
      this.queryParams.recCity = this.queryParams.shoppingAddress[1];
      this.queryParams.recCountry = this.queryParams.shoppingAddress[2];
      log.getOrderList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    // 重置
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        shoppingAddress: [],
      };
      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>
.el-range-editor.el-input__inner {
  width: 100%;
}
.el-date-editor--datetimerange.el-input,
.el-date-editor--datetimerange.el-input__inner {
  width: 100%;
}
::v-deep .dizhi {
  width: 100%;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::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: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 20px 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: 10px 20px;
    justify-content: space-between;
    align-items: center;
    .mainbtn {
      .thebtn2 {
        color: #ffffff;
        background: #ffad41;
      }
    }
  }
  .main {
    // margin-top: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
  }
}
</style>
