<template>
  <ContainerQuery>
    <el-form slot="more" :inline="true" size="small">
      <el-form-item>
        <el-input
          v-model="search_form.keyword"
          placeholder="调价单编码/商品名称"
          clearable
          @keyup.enter.native="pageChange(1)"
          @clear="pageChange(1)"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="pageChange(1)"
          ></el-button>
        </el-input>
      </el-form-item>
    </el-form>
    <!--    商品调价-->
    <div
      v-if="
        activeName === 'AdjustPrice'
          ? $accessCheck($Access.AdjustPriceAdd)
          : activeName === 'CostumeAdjustPrice'
          ? $accessCheck($Access.CostumeAdjustPriceAdd)
          : $accessCheck($Access.CustomerTypeAdjAdd)
      "
      slot="left"
    >
      <el-dropdown split-button type="primary" @click="addPriceAdjust">
        新建调价单
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <div class="dropdown-div" @click="exports(1)">导出</div>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

      <!--      <el-button size="small" type="primary" >-->
      <!--       -->
      <!--      </el-button>-->
    </div>

    <!--    客户调价单-->
    <div
      v-if="activeName === 'CostumeAdjustPrice'"
      slot="tip"
      class="page-tip-div"
    >
      <i class="el-icon-info"></i>
      温馨提示 1、选择客户与商品，针对不同的客户增减不同的价格！
      2、商品原价100元，针对A客户减去10元后，其他客户在商城看到的价格还是100，A客户看到的价格就是90元！
    </div>
    <!--    客户类型调价-->
    <div
      v-if="activeName === 'CostumeTypeAdjustPrice'"
      slot="tip"
      class="page-tip-div"
    >
      <i class="el-icon-info"></i>
      温馨提示： 1、选择客户类型与商品，针对不同的客户类型增减不同的价格！
      2、商品原价100元，针对A类型减去10元后，其他客户类型的客户在商城看到的价格还是100，A类型客户看到的价格就是90元！
      3、客户类型调价的前提是，需要在客户列表给每一个客户分好客户类型！
    </div>
    <el-tabs v-model="activeName" type="card" @tab-click="tabChange">
      <el-tab-pane label="商品调价" name="AdjustPrice">
        <AdjustPrice ref="AdjustPrice" :search-form="search_form"></AdjustPrice>
      </el-tab-pane>
      <el-tab-pane label="客户调价" name="CostumeAdjustPrice">
        <CostumeAdjustPrice
          ref="CostumeAdjustPrice"
          :search-form="search_form"
        ></CostumeAdjustPrice>
      </el-tab-pane>
      <el-tab-pane label="类型调价" name="CostumeTypeAdjustPrice">
        <CostumeTypeAdjustPrice
          ref="CostumeTypeAdjustPrice"
          :search-form="search_form"
        ></CostumeTypeAdjustPrice>
      </el-tab-pane>
    </el-tabs>
  </ContainerQuery>
</template>

<script>
  import {
    exportCustomerPriceAdjustment,
    exportPriceAdjustment,
    exportgetAllCustomerTypePriceAdjustment,
  } from "@/api/Price";
  import AdjustPrice from "./AdjustPrice";
  import CostumeAdjustPrice from "./CostumeAdjustPrice";
  import CostumeTypeAdjustPrice from "./CustomerTypeAdjustPrice";
  export default {
    name: "AdjustPriceGoods",
    components: {
      AdjustPrice,
      CostumeAdjustPrice,
      CostumeTypeAdjustPrice,
    },
    data() {
      return {
        search_form: {
          time: [],
          startTime: "",
          endTime: "",
          effectiveStatus: "",
          keyword: "",
        },
        price_status_list: [
          {
            label: "全部",
            value: 0,
          },
          {
            label: "已生效",
            value: 2,
          },
          {
            label: "未生效",
            value: 1,
          },
        ],
        activeName: "AdjustPrice",
      };
    },
    methods: {
      async exports(exports) {
        let params = {
          page: this.page,
          pageSize: this.pageSize,
          export: 1,
        };
        if (this.activeName === "AdjustPrice" && exports) {
          const res = await exportPriceAdjustment({
            ...params,
          });
        } else if (this.activeName === "CostumeAdjustPrice" && exports) {
          const res = await exportCustomerPriceAdjustment({
            ...params,
          });
        } else {
          const res = await exportgetAllCustomerTypePriceAdjustment({
            ...params,
          });
        }
      },
      tabChange() {},
      timeChange(date) {
        this.search_form.startTime = date ? parseInt(date[0] / 1000) : "";
        this.search_form.endTime = date ? parseInt(date[1] / 1000) + 86399 : "";
        this.pageChange(1);
      },
      pageChange(val) {
        if (this.activeName === "AdjustPrice") {
          this.$refs.AdjustPrice.pageChange(val);
        } else if (this.activeName === "CostumeAdjustPrice") {
          this.$refs.CostumeAdjustPrice.pageChange(val);
        } else {
          this.$refs.CostumeTypeAdjustPrice.pageChange(val);
        }
      },
      addPriceAdjust() {
        if (this.activeName === "AdjustPrice") {
          this.$router.push("/goods/sale/AddGoodsAdjustPrice");
        } else if (this.activeName === "CostumeAdjustPrice") {
          this.$router.push("/goods/sale/CostumeAdjustPriceAdd");
        } else {
          this.$router.push("/goods/sale/CostumeTypeAdjustPriceAdd");
        }
      },
    },
  };
</script>

<style scoped></style>
