<template>
  <div class="components">
    <div class="header">
      <img class="close" @click="cancel" src="/img/home/nav/close.png" alt="极度证券">
      <!-- 筛选 -->
      {{ $t('option.l') }}
    </div>
    <div class="label">
      <!-- 收入类型 -->
      {{ $t('account.l57') }}
    </div>
    <div class="ul">
      <div class="li" :class="{active: form.path == 1}" @click="form.path = 1">
        <!-- 收入 -->
        {{ $t('account.l58') }}
      </div>
      <div class="li" :class="{active: form.path == 2}" @click="form.path = 2">
        <!-- 支出 -->
        {{ $t('account.l59') }}
      </div>
    </div>
    <div class="label">
      <!-- 交易类型 -->
      {{ $t('account.l43') }}
    </div>
    <div class="ul">
      <div class="li" :class="{active: (form.type == '[100]' && form.path == 1)}" @click="form.type = '[100]'; form.path = 1">
        <!-- 存款 -->
        {{ $t('home.l13') }}
      </div>
      <div class="li" :class="{active: form.type == '[100]' && form.path == 2}" @click="form.type = '[100]'; form.path = 2">
        <!-- 取款 -->
        {{ $t('home.l14') }}
      </div>
      <div class="li" :class="{active: form.type == '[200]'}" @click="form.type = '[200]'">
        <!-- 转账 -->
        {{ $t('home.l15') }}
      </div>
      <div class="li" :class="{active: form.type == '[1,2,3,4]'}" @click="form.type = '[1,2,3,4]'">
        <!-- 兑换 -->
        {{ $t('account.l28') }}
      </div>
      <div class="li" :class="{active: form.type == '[300]'}" @click="form.type = '[300]'">
        <!-- 期权 -->
        {{ $t('account.l55') }}
      </div>
    </div>
    <div class="label">
      <!-- 交易金额 -->
      {{ $t('exchange.l45') }}
    </div>
    <div class="ul">
      <div class="li" :class="{active: form.min_amount == '' && form.max_amount == 5000}" @click="changeAmount('', 5000)">
        <!-- 小于5千 -->
        {{ $t('account.l62') }}
      </div>
      <div class="li" :class="{active: form.min_amount == 5000 && form.max_amount == 10000}" @click="changeAmount(5000, 10000)">
        <!-- 5千-1万 -->
        {{ $t('account.l63') }}
      </div>
      <div class="li" :class="{active: form.min_amount == 10000 && form.max_amount == 50000}" @click="changeAmount(10000, 50000)">
        <!-- 1万-5万 -->
        {{ $t('account.l64') }}
      </div>
      <div class="li" :class="{active: form.min_amount == 50000 && form.max_amount == ''}" @click="changeAmount(50000, '')">
        <!-- 大于5万 -->
        {{ $t('account.l65') }}
      </div>
      <div class="box flex">
        <div class="input-box">
          <!-- 最低金额 -->
          <van-field :placeholder="$t('account.l60')" :border="false" v-model="min_amount" type="number" />
        </div>
        <div>—</div>
        <div class="input-box">
          <!-- 最高金额 -->
          <van-field :placeholder="$t('account.l61')" :border="false" v-model="max_amount" type="number" />
        </div>
      </div>
    </div>
    <div class="label">
      <!-- 交易币种 -->
      {{ $t('account.l56') }}
    </div>
    <div class="ul">
      <div class="li" :class="{active: form.currency == 'USD' }" @click="form.currency = 'USD'">
        USD
      </div>
      <div class="li" :class="{active: form.currency == 'HKD' }" @click="form.currency = 'HKD'">
        HKD
      </div>
      <div class="li" :class="{active: form.currency == 'CNY' }" @click="form.currency = 'CNY'">
        CNY
      </div>
    </div>
    <div class="btn-box flex">
      <div class="btn ltn" @click="reset">
        <!-- 重置 -->
        {{ $t('common.l44') }}
      </div>
      <div class="btn rtn" @click="submit">
        <!-- 确定 -->
        {{ $t('common.l50') }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ['filterObj', 'maxAmount', 'minAmount'],
  data () {
    return {
      form: {
        path: '',
        currency: '',
        type: '',
        min_amount: '',
        max_amount: '',
      },
      min_amount: '',
      max_amount: '',
    }
  },
  created () {
    this.form = {
      ...this.filterObj
    }
    this.min_amount = this.minAmount
    this.max_amount = this.maxAmount
  },
  watch: {
    min_amount(val) {
      if (val == '-') {
        this.min_amount = ''
      }
      if (val) {
        this.form.min_amount = ''
        this.form.max_amount = ''
      }
    },
    max_amount(val) {
      if (val == '-') {
        this.max_amount = ''
      }
      if (val) {
        this.form.min_amount = ''
        this.form.max_amount = ''
      }
    },
  },
  methods: {
    submit() {
      this.$emit('filterBack', this.form, this.min_amount, this.max_amount)
    },
    cancel() {
      this.$emit('cancel')
    },
    changeAmount(min, max) {
      this.form.min_amount = min
      this.form.max_amount = max
      this.max_amount = ''
      this.min_amount = ''
    },
    reset() {
      this.form = {
        path: '',
        currency: '',
        type: '',
        min_amount: '',
        max_amount: '',
      }
      this.min_amount = ''
      this.max_amount = ''
    }
  }
}
</script>
<style lang="less" scoped>
.components {
  padding: 27px 17px;
  color: #000;
}
.header {
  position: relative;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  margin-bottom: 27px;
  .close {
    position: absolute;
    top: 0;
    left: 0;
    width: 15px;
    cursor: pointer;
  }
}
.label {
  margin-bottom: 20px;
}
.ul {
  display: flex;
  flex-wrap: wrap;
  column-gap: 8px;
  row-gap: 9px;
  padding-bottom: 26px;
  .li {
    height: 36px;
    // line-height: 36px;
    width: 79px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 2px;
    background-color: #F7F7F7;
    cursor: pointer;
    color: #0D0D0D;
    font-size: 13px;
    &.active {
      background-color: #FFF0EA;
      color: var(--color-);
    }
  }
}
.box {
  width: 100%;
  column-gap: 4px;
  font-size: 13px;
  color: #8A8A8A;
  .input-box {
    flex: 1;
    min-width: 10%;
    max-width: 50%;
  }
  .van-field {
    background-color: #F7F7F7;
    border-radius: 2px;
    line-height: 36px;
    padding: 0;
  }
}
.btn-box {
  padding-top: 6px;
  column-gap: 11px;
  .btn {
    cursor: pointer;
    flex: 1;
    border-radius: 6px;
    border: 1px solid var(--color-);
    text-align: center;
    line-height: 39px;
    font-size: 16px;
    font-weight: 600;
  }
  .ltn {
    color: var(--color-);
  }
  .rtn {
    color: #fff;
    background-color: var(--color-);
  }
}
::v-deep {
  .van-field__control {
    text-align: center;
  }
}
</style>