<template>
  <div class="user-swap-user">
    <el-form ref="userSwapUser" :model="form" :rules="rules" label-width="80px">
      <el-form-item :label="$t('pages.toolsOther.form.longUserId')" prop="sourceUserId">
        <el-input v-model="form.userId" v-number :placeholder="$t('pages.toolsOther.placeholder.enterSourceLongUserId')" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" :loading="checkCondtionLoading" @click="checkCondition()">{{ $t('pages.toolsOther.action.confirm') }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { executeUserCancelAndRestore } from '@/api/tools'
export default {
  name: 'UserSwapUser',
  data() {
    return {
      checkCondtionLoading: false,
      form: {
        userId: '',
        countryId: '11'
      },
    }
  },
  computed: {
    rules() {
      return {
        userId: [{ required: true, message: this.$t('pages.toolsOther.validation.requiredParam'), trigger: 'blur' }]
      }
    }
  },
  methods: {
    checkCondition() {
      const that = this
      that.$refs.userSwapUser.validate((valid) => {
        if (!valid) {
          console.error('error submit!!')
          return
        }
        that.checkCondtionLoading = true
        executeUserCancelAndRestore(that.form).then(res => {
          that.checkCondtionLoading = false
          const result = res.body || {}
          console.log(res.body);
          that.$opsMessage.success()
        }).catch(er => {
          that.checkCondtionLoading = false
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.check-condition {
  background: rgb(243, 240, 240);
  padding: 20px;
  .check-tips {
    font-size: 18px;
    padding-bottom: 10px;
    .tips {
      margin-bottom: 10px;
    }
    .error {
      color: rgb(201, 22, 22);
      padding: 0px 10px;
    }
    .warn {
      color: rgb(201, 159, 22);
      padding: 0px 10px;
    }
  }
}
</style>
