<template>
  <el-dialog
    :title="$t('organization.setting' + settingType)"
    v-model="visible"
    :width="800"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="dialogForm"
      label-width="100px"
      label-position="right"
    >
      <el-form-item :label="$t('version')" prop="SettingVersion">
        <el-input v-model="form.SettingVersion" disabled></el-input>
      </el-form-item>
      <el-form-item
        :label="$t('organization.setting' + settingType)"
        prop="SettingJson"
      >
        <el-input
          v-model="form.SettingJson"
          :autosize="{ minRows: 5, maxRows: 10 }"
          type="textarea"
          class="filter-item"
        ></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="visible = false">{{
        $t("dialogBox.cancelButtonText")
      }}</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">{{
        $t("dialogBox.saveButtonText")
      }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      rules: {},
      visible: false,
      isSaveing: false,
      settingType: "",
    };
  },
  methods: {
    //显示
    open(settingType) {
      this.visible = true;
      this.settingType = settingType;
      return this;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          await this.$API.wing.post(
            "ModifyOrganizationSetting",
            this.form,
            () => {
              this.$message.success(this.$t("response.operateSuccess"));
              this.visible = false;
            }
          );
          this.isSaveing = false;
        } else {
          return false;
        }
      });
    },
    //表单注入数据
    async setData(data) {
      this.form = {
        OrganizationCode: data.OrganizationCode,
        SettingType: this.settingType,
      };
      var res = await this.$API.wing.post("GetOrganizationSetting", this.form);
      this.form.SettingVersion = res.SettingVersion;
      this.form.SettingJson = res.SettingData;
    },
  },
};
</script>

<style>
</style>
