<template>
  <div class="child" v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <div class="title">
      <!-- 市价平仓 -->
      {{ $t('exchange.l35') }}
    </div>
    <div class="id">
      <!-- 订单ID -->
      {{ $t('exchange.l73') }}:{{ info.ticket }}</div>
    <!-- <div class="text">{{ info.cmd == 0 ? $t('exchange.l21') : $t('exchange.l22') }} {{ $bigDecimal.divide(info.volume, 100, 2) }} <span class="span">{{ info.symbol }}</span> {{ $t('exchange.l1') }} <span class="span">{{ $handleDigits(info.open_price, info.productBean.digits) }}</span></div> -->
    <div class="btn-box flex">
      <div class="btn ltn" @click="cancel">
        <!-- 取消 -->
        {{ $t('common.l2') }}
      </div>
      <div class="btn rth" @click="closePosition">
        <!-- 确定 -->
        {{ $t('common.l3') }}
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { closePosition } from "@/api/exchange";
import bus from '@/utils/bus'
export default {
  props: ['info'],
  data () {
    return {
      
    }
  },
  computed: {
    ...mapGetters(['accountList']),
    accountInfo() {
      var info = {}
      this.accountList.forEach(item => {
        if(item.server == this.info.mt_code) {
          info = item
        }
      })
      return info
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    closePosition() {
      // if (this.userInfo.group == 9999) {
      //   bus.$emit('abnormalPopSign')
      //   return
      // }
      this.fullscreenLoading = true
      closePosition({
        ticket: this.info.ticket,
        volume: Number(this.$bigDecimal.divide(this.info.volume, 100)),
        symbol: this.info.symbol,
        account: this.accountInfo.account,
        server: this.accountInfo.server
      }).then((res) => {
        this.$notify({
          // message: '平仓成功',
          message: this.$t('exchange.l34'),
          type: 'success'
        })
        this.$emit('closeSuccess')
      }).finally(() => {
        this.fullscreenLoading = false
      }).catch((err) => {
      })
    },
  },
  filters: {
    cmdtext(v) {
      if (v === 2 || v === 3) {
        return 'limit'
      } else {
        return 'stop'
      }
    },
    orderType(v) {
      if (v === 0 || v === 2 || v === 4) {
        return 'buy'
      }
      return 'sell'
    },
  }
}
</script>
<style lang="less" scoped>
.child {
  padding: 18px 20px 20px;
  text-align: center;
}
.title {
  font-size: 16px;
  font-weight: 600;
  color: #000000;
  padding-bottom: 26px;
}
.id {
  font-size: 14px;
  color: #888888;
}
.text {
  background: #F3F4F6;
  border-radius: 6px;
  font-size: 14px;
  color: #333;
  line-height: 18px;
  padding: 12px 6px;
  .span {
    color: var(--color-);
  }
}
.btn-box {
  padding-top: 26px;
  column-gap: 15px;
  .btn {
    border-radius: 4px;
    line-height: 48px;
    cursor: pointer;
    flex: 1;
    font-size: 16px;
  }
  .ltn {
    border: 1px solid #F6F6F6;
    color: #B6B6B6;
  }
  .rth {
    border: 1px solid #000000;
    background-color: #000000;
    color: #FFFFFF;
  }
}
</style>