<template>
  <div class="app-container">
    <el-card>
      <template #header>审核设置</template>
      <el-form :model="form" :rules="rules" label-position="right" label-width="200px">
        <el-form-item label="班主任变更审核模式" prop="classTeacher" class="form-item-readonly">
          <el-radio-group v-model="form.classTeacher">
            <el-radio v-for="(opt,idx) in auditOptions" :key="idx" :label="opt.value">{{ opt.text }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="授课班级变更审核模式" prop="classChange" class="form-item-readonly">
          <el-radio-group v-model="form.classChange">
            <el-radio v-for="(opt,idx) in auditOptions" :key="idx" :label="opt.value">{{ opt.text }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <div class="fx-row fx-cen-cen">
          <el-button type="primary" round class="mt20" style="width: 150px" @click="handleSubmit">保存</el-button>
        </div>
      </el-form>
    </el-card>
    <el-tabs class="mt20" type="border-card" v-model="currentTab">
      <el-tab-pane v-for="tab in tabs" :key="tab" :name="tab" :label="tab">
        <template v-if="tab==currentTab">
          <div class="fx-row jc-end">
            <mx-date-range-picker v-model="dateRange"></mx-date-range-picker>
          </div>
          <headteacher-form-list :options="formListOption" class="mt20">
          </headteacher-form-list>
        </template>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import formTranslateMixin from '@/components/Cache/modules/mx-form-translate-mixin'
import HeadteacherFormList from '@/views/system/user/profile/components/headteacher-form-list'
import consts from '@/common/mx-const'
import * as ext from '@/utils'
import { getForms, getSchoolParams, updateSchoolAudit } from '@/api/webApi/form'

export default {
  mixins: [formTranslateMixin],
  name: 'form-approve',
  components: { HeadteacherFormList },
  data() {
    return {
      //
      form: {
        classChange: '',
        classTeacher: ''
      },
      rules: {},
      settings: {},
      //
      tabs: ['待审核', '已审核'],
      currentTab: '待审核',
      dateRange: ext.getDefaultDateRange(1)
    }
  },
  computed: {
    auditOptions() {
      return this.formAuditList.map(a => ({
        text: a.label,
        value: a.value
      }))
    },
    queryFormStatus() {
      if (this.currentTab == '待审核') {
        return [consts.enum.formStatus.init]
      }
      return [consts.enum.formStatus.approved, consts.enum.formStatus.rejected]
    },
    formListOption() {
      return {
        latestApplyStatus: '',
        queryApi: getForms,
        queryParams: {
          begin: this.dateRange.first(),
          end: this.dateRange.last(),
          formStatus: this.queryFormStatus.toString()
        }
      }
    }
  },
  mounted() {
    this.loadSchoolSettings()
  },
  methods: {
    loadSchoolSettings() {
      getSchoolParams().then(res => {
        this.settings = res.data
        this.form.classTeacher = this.settings.classTeacher
        this.form.classChange = this.settings.classChange
        console.log('settings', this.settings)
      })
    },
    handleSubmit() {
      updateSchoolAudit({
        classTeacher: this.form.classTeacher,
        classChange: this.form.classChange
      }).then(res => {
        this.msgSuccess('保存成功')
        this.loadSchoolSettings()
      })
    }
  }
}
</script>

<style scoped>

</style>
