<template>
  <div class="">
    <div class="m-core">
      <el-form :inline="true" :model="form" ref="form">
        <el-alert
          style="margin: 10px 0"
          title="账号登录设置"
          :closable="false"
          type="info"
        >
        </el-alert>
        <el-row>
          <el-form-item
            prop="190"
            :rules="[
              {
                required: false,
                pattern: /^[1-9][0-9]*$/,
                message: '请输入正确的账号数量',
              },
            ]"
          >
            教务端每台设备可登录:
            <el-input
              v-model="form['190']"
              placeholder="请输入账号数量"

            >
              <template slot="append">个</template>
            </el-input>
            员工
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item
            prop="191"
            :rules="[
              {
                required: false,
                pattern: /^[1-9][0-9]*$/,
                message: '请输入正确的账号数量',
              },
            ]"
          >
            老师端每台设备可登录:
            <el-input
              v-model="form['191']"
              placeholder="请输入账号数量"

            >
              <template slot="append">个</template>
            </el-input>
            老师
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item
            prop="192"
            :rules="[
              {
                required: false,
                pattern: /^[1-9][0-9]*$/,
                message: '请输入正确的设备数量',
              },
            ]"
          >
            学生端每个账号可登录:
            <el-input v-model="form['192']" placeholder="请输入设备数量" >
              <template slot="append">台</template>
            </el-input>
            设备
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <el-button  type="primary" @click="save" class="saveBtn"
     v-permission="'sysConfig/batchUpdate_loginRules'"
      >保存</el-button
    >
  </div>
</template>
<script>
import {
  // 机构的修改和查
  getSysTenantConfig,
  questionnaireTopicQueryPage, // 问卷
  setSysTenantConfig,
} from "@/views/courseRulersManager/api";
import { sysConfigList, sysConfigUpdate } from "@/api/generalSettings"; // 平台的修改和查
export default {
  data() {
    return {
      form: {},
      questionList: [],
      rulesVisiable: false,
    };
  },
  async mounted() {
    this.getRules();
    // try {
    //   const res = await questionnaireTopicQueryPage({ page: 1, rows: 999 });
    //   this.questionList = res.data.rows.map((item) => {
    //     return {
    //       label: item.title,
    //       value: String(item.id),
    //     };
    //   });
    // } catch (e) {
    //   console.log(e);
    // }
  },
  methods: {
    async getRules() {
      try {
        const res = await sysConfigList({ group: "LOGIN" });
        res.data.forEach((item) => {
          // this.form[item.paramName] = item.paranValue
          this.$set(this.form, item.id, item.paranValue);
        });
        // this.$forceUpdate()
        console.log(this.form);
      } catch (e) {
        console.log(e);
      }
    },
    async save() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          let param = [];
          for (let i in this.form) {
            param.push({
              id: i,
              paranValue: this.form[i],
            });
          }
          try {
            const res = await sysConfigUpdate(param);
            this.$message.success("保存成功");
            this.getRules();
          } catch (e) {
            console.log(e);
          }
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "~@scss/views/courseRulersManager/index.scss";
</style>
