<template>
  <div>
    <q-card flat class="bg-white q-pa-md" style="width:400px;">
      <div class="text-h6">{{saveObj==2?'新增考试':"月度总结"}}</div>
      <template v-if="saveObj==2">
        <div class="row q-col-gutter-md">
          <q-input class="col-6" filled v-model="SaveMsg.StudyValue" dense label="时间"></q-input>
          <q-input class="col-6" filled v-model="SaveMsg.Words" maxlength="180" dense label="单词背诵"></q-input>
        </div>
        <div class="q-mt-xs row q-col-gutter-md">
          <q-input class="col-6" filled v-model="SaveMsg.Practice" maxlength="180" dense label="练习题"></q-input>
          <q-input class="col-6" filled v-model="SaveMsg.ReadingAloud" maxlength="180" dense label="朗读/背诵"></q-input>
        </div>
        <div class="q-mt-xs row q-col-gutter-md">
          <q-input class="col-6" filled v-model="SaveMsg.Other" maxlength="180" dense label="其他"></q-input>
          <!-- <p>其他 <i class="el-icon-plus text-blue cursor-pointer" @click="SetStudentStudyOther"></i></p> -->
        </div>
        <!-- <template v-if='SaveMsg.Other&& SaveMsg.Other.length>0'>
          <div class="q-mt-xs row q-col-gutter-md" v-for=" ( itemOther, indexOther ) in SaveMsg.Other "
            :key="indexOther">
            <q-input class="col-6" placeholder="请输入项目名称" filled v-model="itemOther.Name" autofocus :dense="true" />
            <q-input class="col-4" placeholder="请输入得分" filled v-model="itemOther.Score" type="number" :dense="true"
              autofocus />
            <i class="el-icon-delete text-blue cursor-pointer col-2" @click="DelStudentStudyOther(indexOther)"
              style="margin-top:11px;"></i>
          </div>
        </template> -->
      </template>
      <template v-if="saveObj==3">
        <div class="q-mt-xs row q-col-gutter-md">
          <q-input class="col-12" filled v-model="SaveMsg.StudyValue" dense label="月份"></q-input>
        </div>
        <div class="q-mt-xs row q-col-gutter-md">
          <q-input class="col-12" filled v-model="SaveMsg.Remarks" type="textarea" dense label="请输入学校情况"></q-input>
        </div>
      </template>
      <q-separator class="q-my-md" />
      <div class="text-right q-py-xs">
        <q-btn flat color="dark" @click="closeForm" class="q-mr-md q-px-xs" label="取消"></q-btn>
        <q-btn unelevated color="primary" class="q-px-md" label="保存" @click="SaveStudentStudy"></q-btn>
      </div>
    </q-card>
  </div>
</template>
<script>
  import {
    SetStuStudyInfo,
  } from '../../../api/studyabroad/index'
  export default {
    meta: {
      title: "学员考试信息"
    },
    components: {},
    props: {
      saveObj: {
        type: Number,
        default: null
      },
      //数据
      BaseInfo: {
        type: Object,
        default: null
      },
    },
    data() {
      return {
        //客户对象
        SaveMsg: {
          CourseId: 0,
          StuId: 0,
          GuestId: 0,
          ClassScrollType: 0,
          OrderId: 0,
          StudyID: 0,
          Words: '',
          Practice: '',
          ReadingAloud: '',
          Other: '',
          ChapterId: 0,
          StudyType: 0,
          Remarks: '到勤情况：\n课堂表现：\n作业情况：\n评价建议：',
          StudyValue: '',
        },
        nowOther: {
          Name: "",
          Score: "",
        },
      };
    },
    created() {},
    mounted() {},
    methods: {
      SetStudentStudyOther() {
        this.SaveMsg.Other.push(JSON.parse(JSON.stringify(this.nowOther)))
      },
      DelStudentStudyOther(indexOther) {
        if (this.SaveMsg.Other && this.SaveMsg.Other.length > 0) {
          this.SaveMsg.Other.splice(indexOther, 1);
        }
      },
      //保存信息
      SaveStudentStudy() {
        this.SaveMsg.CourseId = this.BaseInfo.CourseId;
        this.SaveMsg.StuId = this.BaseInfo.StuId;
        this.SaveMsg.GuestId = this.BaseInfo.GuestId;
        this.SaveMsg.OrderId = this.BaseInfo.OrderId;
        if (this.saveObj == 3) {
          this.SaveMsg.Words = '';
          this.SaveMsg.Practice = '';
          this.SaveMsg.ReadingAloud = '';
          this.SaveMsg.ChapterId = 0;
          this.SaveMsg.Other = '';
        } else {
          this.SaveMsg.Remarks = '';
        }
        this.SaveMsg.StudyType = this.saveObj;
        SetStuStudyInfo(this.SaveMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '数据保存成功！',
                position: 'top'
              })
            }
            this.$emit("success");
            this.closeSaveForm();
          })
          .catch(() => {
            this.loading = false;
          });
      },
      closeSaveForm() {
        this.$emit("close");
        this.persistent = false;
      },
      clearSaveMsg() {
        this.SaveMsg.CourseId = 0;
        this.SaveMsg.StuId = 0;
        this.SaveMsg.GuestId = 0;
        this.SaveMsg.ClassScrollType = 0;
        this.SaveMsg.OrderId = 0;
        this.SaveMsg.StudyID = 0;
        this.SaveMsg.Words = '';
        this.SaveMsg.Practice = '';
        this.SaveMsg.ReadingAloud = '';
        this.SaveMsg.Other = '';
        this.SaveMsg.ChapterId = 0;
        this.SaveMsg.StudyType = 0;
        this.SaveMsg.Remarks = '到勤情况：\n课堂表现：\n作业情况：\n评价建议：';
        this.SaveMsg.StudyValue = '';
      },
      closeForm() {
        this.clearSaveMsg();
        this.$emit("close");
      },
    }
  };

</script>
