/*增加子账户上限*/
<template>
  <div>
    <transition name="marsk-fade">
      <div v-show="limitConfig.isShow" class="marsk" />
    </transition>
    <transition name="slide-fade">
      <div v-show="limitConfig.isShow" class="action-limit">
        <div class="title">
          <p>增加子账户上限</p>
          <div class="operation">
            <i class="el-icon-circle-close" @click="close" />
          </div>
        </div>
        <p class="tips">
          剩余积分：<span>{{ limitConfig.point }}</span>
        </p>
        <div class="num-list">
          <div v-for="(item, index) in limitConfig.numList" :key="index">
            <el-radio
              v-if="item.saleUnit == 0"
              v-model="limitConfig.num"
              :label="item.returnGoods"
              @change="select"
            >
              <p>{{ item.returnGoods }}个上限</p>
              <span>{{ item.salePrice }}积分</span>
            </el-radio>
          </div>
        </div>
        <div class="btn-group">
          <el-button
            type="danger"
            size="small"
            class="next-btn"
            @click.native.prevent="sure"
            >确认</el-button
          >
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import { request } from '@/utils/request'
export default {
  name: 'Limit',
  props: {
    limitConfig: {
      isShow: {
        type: Boolean,
        default: () => false,
      },
      num: {
        type: Number,
        default: () => 10,
      },
      intergal: {
        type: Number,
        default: () => 100,
      },
      numList: {
        type: Array,
        default: () => [],
      },
      selectGoodsCode: {
        type: String,
        default: () => '',
      },
      point: {
        type: String,
        default: () => '0',
      },
    },
  },
  data() {
    return {}
  },
  methods: {
    // 点击关闭
    close() {
      this.$emit('putLimit', false)
    },
    // 选择
    select() {
      this.limitConfig.numList.map((item) => {
        if (this.limitConfig.num == item.returnGoods) {
          this.limitConfig.intergal = item.salePrice
          this.limitConfig.selectGoodsCode = item.goodsCode
        }
      })
    },
    // 点击确定
    sure() {
      const params = {
        transCode: 'C00018',
        count: this.limitConfig.num,
        goodsCode: this.limitConfig.selectGoodsCode,
      }
      request(params)
        .then((res) => {
          this.$message.success(
            `恭喜你，成功新增 ${this.limitConfig.num} 个子账户上限`
          )
          this.$emit('putLimit', this.limitConfig)
        })
        .catch((err) => {})
    },
  },
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';

.marsk-fade-enter-active,
.marsk-fade-leave-active {
  transition: all 0.5s;
}
.marsk-fade-enter,
.marsk-fade-leave-to {
  opacity: 0;
}
.marsk {
  @include position(fixed, 0, 0, 0, 0, 1000);
  background: rgba(4, 112, 204, 0.05);
}

.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateY(7.48rem);
}
.action-limit {
  @include position(absolute, 50%, auto, 55%, auto, 1001);
  @include w_h(400px);
  padding: 30px 40px;
  transform: translate(-50%, -50%);
  background: $color_f;
  box-shadow: 0 0 7px 7px rgba(0, 0, 0, 0.04);
  .title {
    @include flex();
    font-size: 18px;
    font-weight: 700;
    color: $color_3;
    .operation {
      font-size: 24px;
      color: $color_9;
      &:hover {
        cursor: pointer;
        color: $color_b;
      }
    }
  }
  .tips {
    margin-top: 10px;
    font-size: 12px;
    color: $color_9;
    span {
      font-size: 14px;
      color: $color_on;
    }
  }
  .num-list {
    @include w_h();
    @include flex(flex-start);
    flex-wrap: wrap;
    margin: 30px auto 20px;
  }
  .btn-group {
    @include w_h(70%);
    margin: 0 auto;
    .next-btn {
      @include w_h();
    }
  }
}
</style>

<style lang="scss">
@import '@/styles/variables.scss';
@import '@/styles/mixin.scss';
.num-list {
  .el-radio {
    margin: 0 10px 10px 0;
    padding: 8px 10px;
    min-width: 90px;
    line-height: 20px;
    font-size: 12px;
    border: 1px solid $color_b;
    border-radius: 4px;
    &.is-checked {
      border: 1px solid #0470cc;
      background: #e7f3fb;
    }
    &__input {
      display: none;
    }
    &__label {
      padding: 0;
    }
    &__label p,
    &__input.is-checked + &__label p {
      color: $color_3;
    }
    &__label span,
    &__input.is-checked + &__label span {
      color: #0470cc;
    }
  }
}
</style>
