<template>
  <div class="app-container">
    <el-dialog
      :title="$t('ec.resource.fixPath')"
      :close-on-click-modal="false"
      :visible.sync="visible"
      class="chooseDialog "
      top="4%"
    >
      <el-form label-suffix=":" label-width="120px">
        <!--        <el-form-item label="租户" prop="tenantId">-->
        <!--          <ec-tenant v-model="formItem.tenantId" />-->
        <!--        </el-form-item>-->
        <el-form-item :label="$t('ec.app.app')" prop="appId">
          <ec-register-app v-model="formItem.appId" />
          <el-alert :title="$t('ec.resource.fixAlert')" type="warning" :closable="false" show-icon />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('ec.table.cancel') }}</el-button>
        <el-button type="primary" :loading="saveLoading" @click="save">{{ $t('ec.table.confirm') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { fixResourcePath } from 'ecip-web/api/vue/resource/sysrResourceApi'

export default {
  name: 'FixAppResourceVue',
  data() {
    return {
      visible: false,
      saveLoading: false,
      formItem: {
        appId: '',
        tenantId: '',
        appIdList: ''
      }
    }
  },
  methods: {
    init(record) {
      this.visible = true
      this.saveLoading = false
      this.$nextTick(() => {
        Object.assign(this.$data.formItem, this.$options.data().formItem)
      })
    },
    save() {
      this.$confirm(this.$t('ec.resource.fixConfirm'), this.$t('ec.message.prompt'), {
        confirmButtonText: this.$t('ec.message.confirm'),
        cancelButtonText: this.$t('ec.message.cancel'),
        type: 'warning'
      }).then(async() => {
        try {
          this.saveLoading = true
          // let appIds = []
          // if (this.formItem.appIdList && this.formItem.appIdList.toString().length > 0) {
          //   appIds = this.formItem.appIdList.toString().split(',')
          // }
          await fixResourcePath(this.formItem.appId ? [this.formItem.appId] : [])
          this.$notify.success(this.$t('ec.resource.fixSuccess'))
          // this.visible = false
        } finally {
          this.saveLoading = false
        }
      })
    }
  }
}
</script>

<style scoped>
  .chooseDialog >>> .el-select {
    display: block;
  }
  .el-alert {
    margin-top: 10px;
  }
</style>
