<template>
  <div v-loading="loading">
    <div class="base-dialog-body" style="height:380px;overflow-y: auto;">
      <el-form ref="otherForm" :model="form">
        <!-- 自动切换下一个任务不必提示 -->
        <el-form-item :label="$t('trials:reading:label:autoSwitch')" prop="AutoCutNextTask" :rules="[
          { required: true, message: $t('common:ruleMessage:select') }
        ]">
          <el-switch v-model="form.AutoCutNextTask" />
        </el-form-item>
        <el-form-item :label="$t('trials:reading:label:MultiScreen')" prop="IsDoubleScreen" :rules="[
          { required: true, message: $t('common:ruleMessage:select') }
        ]">
          <el-switch v-model="form.IsDoubleScreen" />
        </el-form-item>
        <el-form-item>
          <div><span>{{ $t("trials:reading:tip:MultiScreen") }}</span><a style="color:#409EFF"
              href="/screen.pdf"
              target="blank">{{
                $t("trials:reading:tip:openFile")
              }}</a></div>
        </el-form-item>
      </el-form>
    </div>
    <div class="base-dialog-footer" style="text-align:right;margin-top:10px;">
      <el-button size="small" type="primary" @click="handleSave"> {{ $t('common:button:save') }}</el-button>

    </div>
  </div>
</template>
<script>
import { setAutoCutNextTask, getAutoCutNextTask } from '@/api/user'
export default {
  name: 'Others',
  data() {
    return {
      form: {
        AutoCutNextTask: false,
        IsDoubleScreen: false
      },
      loading: false
    }
  },
  mounted() {
    this.initForm()
  },
  methods: {
    async initForm() {
      this.loading = true
      try {
        const res = await getAutoCutNextTask()
        if (res.IsSuccess) {
          this.form.AutoCutNextTask = res.Result.AutoCutNextTask
          this.form.IsDoubleScreen = res.Result.IsDoubleScreen
        }
        this.loading = false
      } catch (e) {
        this.loading = false
      }
    },
    async handleSave() {
      const valid = await this.$refs.otherForm.validate()
      if (!valid) return
      this.loading = true
      try {
        const res = await setAutoCutNextTask(this.form)
        if (res.IsSuccess) {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
        }
        this.loading = false
      } catch (e) {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss"></style>
