<template>
  <div class="child" v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <div class="title">
      <!-- 修改挂单 -->
      {{ $t('exchange.l11') }}
    </div>
    <div class="id">
      <!-- 订单ID -->
      {{ $t('exchange.l73') }}:{{ info.ticket }}</div>
    <div class="text">{{ cmdText[info.cmd] }} {{ $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="row">
      <div class="label">
        <!-- 止损价 -->
        {{ $t('exchange.l12') }}
      </div>
      <el-input-number v-model="form.sl" :precision="info.productBean.digits" :step="info.productBean.point" :min="0"></el-input-number>
    </div>
    <div class="row">
      <div class="label">
        <!-- 止盈价 -->
        {{ $t('exchange.l13') }}
      </div>
      <el-input-number v-model="form.tp" :precision="info.productBean.digits" :step="info.productBean.point" :min="0"></el-input-number>
    </div>
    <div class="btn-box flex">
      <div class="btn ltn" @click="cancel">
        <!-- 取消 -->
        {{ $t('common.l2') }}
      </div>
      <div class="btn rth" @click="updateEntrust">
        <!-- 确定 -->
        {{ $t('common.l3') }}
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { updateEntrust } from "@/api/exchange";
export default {
  props: ['info'],
  data () {
    return {
      form: {
        sl: 0,
        tp: 0,
      },
    }
  },
  computed: {
    ...mapGetters(['accountList']),
    accountInfo() {
      let info = {}
      this.accountList.forEach(item => {
        if(item.server == this.info.mt_code) {
          info = item
        }
      })
      return info
    },
    cmdText() {
      return {
        // '2': '低价买入',
        // '3': '高价卖出',
        // '4': '高价买入',
        // '5': '低价卖出',
        '2': this.$t('exchange.l7'),
        '3': this.$t('exchange.l8'),
        '4': this.$t('exchange.l9'),
        '5': this.$t('exchange.l10'),
      }
    }
  },
  created() {
    this.form.sl = this.info.sl
    this.form.tp = this.info.tp
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    updateEntrust() {
      this.fullscreenLoading = true
      updateEntrust({
        ticket: this.info.ticket,
        symbol: this.info.symbol,
        sl: this.form.sl,
        tp: this.form.tp,
        account: this.accountInfo.account,
        server: this.accountInfo.server
      }).then((res) => {
        this.$notify({
          // message: '更新成功',
          message: this.$t('common.l28'),
          type: 'success'
        })
        this.$emit('updateSuccess')
      }).finally(() => {
        this.fullscreenLoading = false
      }).catch((err) => {
      })
    },
  }
}
</script>
<style lang="less" scoped>
.child {
  padding: 24px 21px 20px;
  text-align: center;
}
.title {
  font-size: 18px;
  font-weight: 600;
  color: #000000;
  padding-bottom: 11px;
}
.id {
  font-size: 14px;
  color: #767676;
  padding-bottom: 12px;
}
.text {
  background: #F3F4F6;
  border-radius: 6px;
  font-size: 14px;
  color: #333;
  line-height: 18px;
  padding: 12px 6px;
  .span {
    color: var(--color-);
  }
}
.row {
  margin-top: 15px;
  .label {
    color: #767676;
    margin-bottom: 4px;
    text-align: left;
    font-size: 14px;
  }
}
.btn-box {
  padding-top: 29px;
  column-gap: 16px;
  .btn {
    border-radius: 6px;
    line-height: 38px;
    cursor: pointer;
    flex: 1;
    font-size: 16px;
    font-weight: 600;
  }
  .ltn {
    border: 1px solid #DEDEDE;
    color: #000000;
  }
  .rth {
    border: 1px solid #000000;
    background-color: #000000;
    color: #FEFFFF;
  }
}
.el-input-number {
  display: block;
  width: 100%;
}
::v-deep {
  .el-input__inner {
    background: #F3F4F6;
    border-radius: 6px;
    border: 1px solid #E8E8E8 !important;
    height: 42px;
    line-height: 42px;
    color: #AEB0B2;
  }
  .el-input-number__decrease, .el-input-number__increase {
    top: 3px;
    bottom: 3px;
    background: #FFFFFF;
    box-shadow: 0px 2px 5px 0px rgba(188,192,193,0.31);
    border-radius: 4px;
    width: 36px;
    font-size: 18px;
    color: #000 !important;
  }
  .el-input-number__decrease {
    left: 3px;
  }
  .el-input-number__increase {
    right: 3px;
  }
}
</style>