<template>
  <div v-loading="loading">
    <div class="heior_box">
      <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="goAdd">新建套餐</el-button> -->
      <div class="search-box">
        <el-input v-model="searchModel.keyWord" placeholder="请输入套餐名称/标题" clearable size="small">
          <el-button slot="append" icon="el-icon-search" @click="get"></el-button>
        </el-input>
      </div>
    </div>
    <div>
      <el-tabs tab-position="left" :style="$getStyleHeight(100)">
        <el-tab-pane
          :label="item.Product.Name"
          v-for="(item,index) in productDiscount"
          :key="index"
        >
          <el-table
            :data="item.PackageDiscounts"
            row-key="Id"
            border
            size="medium"
            :height="$getHeight(100)"
          >
            <el-table-column prop="Package.Name" label="套餐名称"></el-table-column>
            <el-table-column prop="Package.Price" label="原价格"></el-table-column>
            <el-table-column prop="PriceDiscount.BuyPriceDiscount" label="购买折扣">
              <template slot-scope="scope">{{scope.row.PriceDiscount.BuyPriceDiscount||'--'}}</template>
            </el-table-column>
            <el-table-column prop="PriceDiscount.RefundDayPriceDiscount" label="退款折扣">
              <template slot-scope="scope">{{scope.row.PriceDiscount.RefundDayPriceDiscount||'--'}}</template>
            </el-table-column>
            <el-table-column prop="PriceDiscount.Remark" label="说明"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <span class="handel cursor edit" @click="goEdit(scope.row)">编辑</span>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </div>
    <el-dialog title="折扣维护" :visible.sync="showDialog" width="400px">
      <el-form :model="current" :rules="rules" ref="inputPackageForm" label-width="80px">
        <el-form-item prop="Name" label="套餐名称">
          <el-input v-model="current.Name" size="small" disabled></el-input>
        </el-form-item>
        <!-- <el-form-item prop="Price" label="原价格">
          <el-input v-model="current.Price" type="number" size="small" disabled></el-input>
        </el-form-item> -->
        <el-form-item prop="MinPrice" label="购买折扣">
          <el-input v-model="current.BuyPriceDiscount" type="number" size="small"></el-input>
        </el-form-item>
        <el-form-item prop="RefundDayPriceDiscount" label="退款折扣">
          <el-input v-model="current.RefundDayPriceDiscount" type="number" size="small"></el-input>
        </el-form-item>
        <el-form-item prop="Remark" label="说明">
          <el-input v-model="current.Remark" size="small"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button type="primary" @click="save">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "treeTable",
  components: {},
  data() {
    return {
      loading: false,
      showDialog: false,
      retData: { TotalCount: 0, Data: [] },
      searchModel: {
        PageIndex: 1,
        keyWord: ""
      },
      productDiscount: [],
      current: {
        Remark: "",
        BuyPriceDiscount: 0,
        SchemeId: 0,
        PackageId: 0,
        ProductId: 0,
        RefundDayPriceDiscount: 0
      },
      rules: {}
    };
  },
  created() {
    this.$store.commit("setCurrentNav", "产品管理>>产品折扣");
    this.current.SchemeId = this.$route.query.id;
    this.get();
  },
  methods: {
    get() {
      this.$api
        .get("course/v1/scheme/GetProductDiscount?id=" + this.current.SchemeId)
        .then(res => {
          this.productDiscount = res.Data;
        });
    },
    goEdit(item) {
      console.log(item);
      this.showDialog = true;
       this.current.Name = item.Package.Name;
      this.current.ProductId = item.Package.ProductId;
      this.current.PackageId = item.Package.Id;
      this.current.BuyPriceDiscount = item.PriceDiscount.BuyPriceDiscount;
      this.current.RefundDayPriceDiscount =
        item.PriceDiscount.RefundDayPriceDiscount;
    },
    save() {
      this.$api
        .post("course/v1/scheme/PutProductDiscount", this.current)
        .then(res => {
          this.resetForm();
          this.get();
        });
    },
    changeStatus(item) {
      this.$api
        .post("course/v1/scheme/SetUserPriceStatus?id=" + item.UserPrice.Id)
        .then(res => {
          item.Status = res.Data;
        });
    },
    resetForm() {
      this.$refs["inputPackageForm"].resetFields();
      this.showDialog = false;
    }
  }
};
</script>
<style scoped>
</style>
