<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 800px;max-width:900px;">
      <q-card-section>
        <div class="text-h6">{{objOption.Id==0?'新增合同':'修改合同'}}</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="text-caption q-mb-lg q-px-md text-grey-6">基本资料</div>
        <div class="row wrap">
          <q-select filled stack-label v-if="objOption.Id==0" option-value="Id" option-label="Name" v-model="objOption.CType" ref="CType"
            :options="CTypeList" label="类型" :dense="false" class="col-6 q-pr-lg q-pb-lg" emit-value map-options
            :rules="[val => !!val || '请选择所属校区']" />
          <q-select v-else filled stack-label option-value="Id" option-label="Name" v-model="objOption.CType" ref="CType"
            :options="CTypeList" label="类型" :dense="false" disable class="col-6 q-pr-lg q-pb-lg" emit-value map-options
            :rules="[val => !!val || '请选择所属校区']" />
          <q-input filled stack-label maxlength="20" :dense="false" v-model="objOption.StudentName" ref="StudentName"
            class="col-6 q-pb-lg" label="学生姓名" :rules="[val => !!val || '请填写学生姓名']" />
          <!-- <q-input filled stack-label maxlength="100" :dense="false" v-model="objOption.SchoolName" ref="SchoolName"
            class="col-6 q-pr-lg q-pb-lg" label="学校名称" :rules="[val => !!val || '请填写学校名称']" /> -->
          <q-input filled stack-label maxlength="100" :dense="false" v-model="objOption.CourseName" ref="CourseName"
            class="col-6 q-pr-lg q-pb-lg" label="课程名称" :rules="[val => !!val || '请填写课程名称']" />
          <q-input filled stack-label maxlength="300" :dense="false" v-model="objOption.CourseContent"
            ref="CourseContent" class="col-6 q-pb-lg" label="课程内容" :rules="[val => !!val || '请填写课程内容']" />
          <q-input filled stack-label :dense="false" @keyup.native="checkPrice(objOption,'Money')"
            v-model="objOption.Money" ref="Money" class="col-6 q-pb-lg q-pr-lg" label="金额"
            :rules="[val => !!val || '请填写金额']" />
          <q-input filled stack-label :dense="false" v-model="objOption.Exam" ref="Exam" class="col-6 q-pb-lg"
            label="乙方当前选择考试" />
        </div>
      </q-card-section>
      <q-separator />
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeSaveForm" />
        <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="saveContract" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    SetEducationContractInfo,
    GetEducationContractInfo
  } from '../../api/sale/contract'
  export default {
    props: {
      setingObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          Id: 0,
          CType: 1, //类型1培训 2留学
          StudentName: '', //学生姓名,
          SchoolName: '', //学校名称
          CourseName: '', //课程名称  
          CourseContent: '', //课程内容
          CNYCaps: '', //人民币大写
          Money: '', //金额
          Exam: '' //乙方当前选择考试
        },
        //类型下拉
        CTypeList: [{
          Id: 1,
          Name: '培训'
        }, {
          Id: 2,
          Name: '留学'
        }],
        saveLoading: false,
      }
    },
    created() {},
    mounted() {
      this.initObj()
    },
    methods: {
      //保存合同
      saveContract() {
        this.$refs.StudentName.validate()
        this.$refs.CourseName.validate()
        this.$refs.CourseContent.validate()
        this.$refs.Money.validate()
        if (!this.$refs.StudentName.hasError &&
          !this.$refs.CourseName.hasError &&
          !this.$refs.CourseContent.hasError &&
          !this.$refs.Money.hasError) {
          SetEducationContractInfo(this.objOption).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '修改成功！',
                position: 'top'
              })
            }
            this.$emit('success');
          })
        }
      },
      initObj() {
        if (this.setingObj && this.setingObj.Id > 0) {
          GetEducationContractInfo({
            ContractId: this.setingObj.Id
          }).then(res => {
            if (res.Code == 1) {
              var tempObj = res.Data;
              this.objOption.Id = tempObj.Id;
              this.objOption.CType = tempObj.CType;
              this.objOption.StudentName = tempObj.StudentName;
              this.objOption.SchoolName = tempObj.SchoolName;
              this.objOption.CourseName = tempObj.CourseName;
              this.objOption.CourseContent = tempObj.CourseContent;
              this.objOption.CNYCaps = tempObj.CNYCaps;
              this.objOption.Money = tempObj.Money;
              this.objOption.Exam = tempObj.Exam;
            }
          })
        }
      },
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
    },
    watch: {

    },
  }

</script>

<style>

</style>
