 <template>
  <div class="m-container">
    <div>
      <!-- <el-button  type="primary">添加规则</el-button> -->

      <el-form :inline="true" :model="form" ref="form">
        <el-alert
          style="margin: 20px 0 40px"
          title="商品销售收款账户设置"
          :closable="false"
          type="info"
        >
        </el-alert>
        <el-row>
                商品销售收款账户：
          <el-form-item
            prop="231"
            :rules="[
              {
                required: true,
                message: '请输入收款账户',
              },
            ]"
          >

            <el-input v-model="form['231']" placeholder="请输入收款账户">
            </el-input>

          </el-form-item>
          <el-button
            type="primary"
            @click="save"

            v-permission="'sysConfig/batchUpdate_dayaTeamRules'"
            >保存</el-button
          >
        </el-row>
      </el-form>
    </div>
  </div>
</template>
<script>
import {
  getSysTenantConfig,
  setSysTenantConfig,
} from "@/views/courseRulersManager/api";
import { sysConfigList, sysConfigUpdate } from "@/api/generalSettings"; // 平台的修改和查
export default {
  props: ["isPlatform"],
  data() {
    return {
      form: {},
      questionList: [],
      rulesVisiable: false,
    };
  },
  async mounted() {
    this.getRules();
  },
  methods: {
    getRules() {
      if (this.isPlatform) {
        this.getPlatformRules();
      } else {
        this.getInstitutionRules();
      }
    },
    async getPlatformRules() {
      try {
        const res = await sysConfigList({ group: "COLLECTION" });
        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 getInstitutionRules() {
      try {
        const res = await getSysTenantConfig({ group: "COLLECTION" });
        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);
      }
    },
    savePlatform() {
      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);
          }
        }
      });
    },
    saveInstitution() {
      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 setSysTenantConfig(param);
            this.$message.success("保存成功");
            this.getRules();
          } catch (e) {
            console.log(e);
          }
        }
      });
    },
    save() {
      if (this.isPlatform) {
        this.savePlatform();
      } else {
        this.saveInstitution();
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "~@scss/views/courseRulersManager/index.scss";
</style>
