<template>
    <el-form v-model="form" ref="form" label-width="120px" :inline="false" :rules="rules" label-position="right">
      <div class="setting-top">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="配置状态：" prop="type">
              <el-radio-group v-model="form.rulesType" size="mini">
                <el-radio :label="'2'">关闭</el-radio>
                <el-radio :label="'1'">开启(默认)</el-radio>
              </el-radio-group>
              <i class="remark">开启：使用当前结论配置</i>
              <i class="remark">关闭：使用自定义公式逻辑配置</i>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="naxtBox">
              <el-button v-show="showPreviousBtn" type="primary" size="mini" @click="previousTab()">上一步</el-button>
              <el-button type="primary" size="mini" @click="submitForm('form')">下一步</el-button>
            </div>
          </el-col>
        </el-row>
      <el-row :gutter="20">
        <el-col :span="20">
          <el-form-item label="结论状态：" prop="resource">
            <el-radio-group v-model="form.conclusionStatus" size="medium">
              <el-radio :label="'2'">关闭</el-radio>
              <el-radio :label="'1'">开启(默认)</el-radio>
            </el-radio-group>
            <i class="remark">开启：作答完成会生成结论报告且推送数据</i>
            <i class="remark">关闭：作答完成不会生成结论报告但会推送数据</i>
          </el-form-item>
        </el-col>
      </el-row>
      </div>
    </el-form>
    <!--    <el-button type="primary" size="mini" @click="submitForm()">保存</el-button>-->
</template>

<script>
import config from './config'

export default {
  name: 'other',
  components: {},
  inject: ['getToken', 'getSetting'],
  data () {
    return {
      configName: 'other', // 配置名称
      showPreviousBtn: false,

      rules: {},
      form: {
        rulesType: '1',
        conclusionStatus: '1'
      },
    }
  },
  methods: {
    loadData () {
      console.log('加载-配置')
      if (config.localGetConclusionList('updateData', this.configName)) {
        this.form = config.localGetConclusionList('updateData', this.configName)
      } else if (config.localGetConclusionList('requestData', this.configName)) {
        this.form = config.localGetConclusionList('requestData', this.configName)
      } else {
        this.form = {
          rulesType: '1',
          conclusionStatus: '1'
        }
      }
      this.showPreviousBtn = config.permissionIndex(this.configName)
    },
    // 上一步
    previousTab () {
      this.$emit('PreviousTab')
    },

    // 提交表单验证
    submitForm (formName) {
      config.localSetConclusionList('updateData', this.configName, this.form)
      this.$emit('NextTab')
      // 保存接口
    },
    // 保存
    // submitForm () {
    //   let updateData = this.conclusionList.updateData
    //   let shortId = this.conclusionList.shortId
    //   Object.keys(updateData).forEach((key) => {
    //     this.moduleSave(shortId, key, updateData[key])
    //   })
    //   this.configurationSave(shortId)
    // },

    // 模块保存 todo 暂时不用
    moduleSave (shortId, configName, value) {
      const { host, hostSuffix, savePath } = this.getSetting()
      console.log(this.setting)
      this.$tool.request({
        url: host + hostSuffix + savePath,
        method: 'PUT',
        data: {
          shortId: shortId,
          configName: configName,
          form: value
        },
        headers: {
          Authorization: this.setting.token,
          way: 1
        }
      }).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err)
      })
    },
    // 配置保存
    configurationSave (shortId) {
      const { host, hostSuffix, upRulesTypePath } = this.setting

      this.$tool.request({
        url: host + hostSuffix + upRulesTypePath,
        method: 'PUT',
        data: {
          shortId: shortId,
          ...this.form
        },
        headers: {
          Authorization: this.setting.token,
          way: 1
        }
      }).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      }).catch(err => {
        this.$message.error(err)
      })
    },
  }
}
</script>

<style scoped>
.changmo-setting-content {
  padding: 0 20px;
  position: relative;
}

.remark {
  display: block;
  height: 20px;
  line-height: 20px;
  color: #b0afaf;
}

.naxtBox {
  position: absolute;
  right: 50px;
}

.setting-top {
  /* width: calc(100% - 40px) !important; */
  padding-top: 20px;
}
</style>
