<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" :loading="loading" :disabled="loading" @click="handleSave"> {{ $t('common:button:save') }}</el-button>

    </div>
  </div>
</template>
<script>
import { setAutoCutNextTask, getAutoCutNextTask } from '@/api/user'
export default {
  name: 'Others',
  props: {
    imageToolType: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      form: {
        AutoCutNextTask: false,
        IsDoubleScreen: false
      },
      loading: false
    }
  },
  mounted() {
    this.initForm()
  },
  methods: {
    async initForm() {
      this.loading = true
      try {
        const res = await getAutoCutNextTask({imageToolType: this.imageToolType})
        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() {
      if (this.loading) return
      this.loading = true
      try {
        const valid = await this.$refs.otherForm.validate()
        if (!valid) return
        let params = Object.assign(this.form, {imageToolType: this.imageToolType})
        const res = await setAutoCutNextTask(params)
        if (res.IsSuccess) {
          this.$message.success(this.$t('common:message:savedSuccessfully'))
        }
      } catch (e) {
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

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