<template>
  <q-dialog v-model="persistent" persistent content-class="bg-grey-1" transition-show="scale" transition-hide="scale">
    <q-card style="width: 600px;max-width:600px;">
      <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="row wrap">
          <q-input filled stack-label :dense="false" v-model="objOption.Name" ref="Name" class="col-6 q-pr-lg q-pb-lg"
            label="姓名" :rules="[val => !!val || '请输入姓名']" />
          <q-input filled stack-label :dense="false" v-model="objOption.Tel" ref="Tel" class="col-6 q-pb-lg" label="电话"
            :rules="[val => !!val || '请输入电话']" />
        </div>
        <div class="row wrap">
          <q-input filled stack-label :dense="false" v-model="objOption.WeChatNum" class="col-6 q-pr-lg q-pb-lg"
            label="微信号" />
          <q-input filled stack-label :dense="false" maxlength="50" v-model="objOption.CourseName" ref="CourseName"
            class="col-6 q-pb-lg" label="兴趣课程" :rules="[val => !!val || '请输入兴趣课程']" />
        </div>
        <div class="row wrap">
          <q-input filled stack-label :dense="false" v-model="objOption.StudyTime" ref="StudyTime"
            class="col-6 q-pr-lg q-pb-lg" label="学习时间" :rules="[val => !!val || '请输入学习时间']" />
          <q-select filled class="col-6" option-value="Name" option-label="Name"
            ref="LevelType" v-model="objOption.LevelType" :options="GBList" :rules="[val => !!val || '请选择当前水平']"
            emit-value map-options label="当前水平" />
        </div>
        <div class="row wrap">
          <q-select filled class="col-6 q-pr-lg" option-value="Id" option-label="Name"
            ref="VisitorStatus" v-model="objOption.VisitorStatus" :options="statusList"
            :rules="[val => !!val || '请选择状态']" emit-value map-options label="状态" />
          <q-input filled stack-label :dense="false" v-model="objOption.Evaluate" ref="Evaluate" class="col-6 q-pb-lg"
            label="意向评估" :rules="[val => !!val || '请输入意向评估']" />
        </div>
        <div class="row wrap">
          <q-input filled stack-label type="textarea" maxlength="500" :dense="false" v-model="objOption.Remark"
            ref="Remark" class="col-12 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="closeVisitForm" />
        <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" :loading="saveCourseLoading"
          @click="saveCourse" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    getGuestBasicsEnumList
  } from '../../api/sale/sale'
  import {
    setVisitor
  } from '../../api/scheduling/schedu'
  export default {
    components: {},
    props: {
      saveObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          Id: 0, //编号
          Name: "", //姓名
          Tel: "", //电话
          WeChatNum: "", //微信号
          CourseName: "", //兴趣课程
          StudyTime: "", //学习时间
          LevelType: "", //当前水平
          PlanId: 0, //值班编号
          VisitorStatus: '', //状态
          Evaluate: '', //意向评估
          Remark: '' //备注
        },
        GBList: [],
        statusList: [{
          Id: 1,
          Name: '正常'
        }, {
          Id: 2,
          Name: '贵宾'
        }, {
          Id: 3,
          Name: '黑名单'
        }],
        saveCourseLoading: false
      };
    },
    created() {
      this.getGuestBasics();
    },
    mounted() {
      if (this.saveObj && this.saveObj.Id > 0) {
        this.objOption.Id = this.saveObj.Id;
        this.objOption.Name = this.saveObj.Name;
        this.objOption.Tel = this.saveObj.Tel;
        this.objOption.WeChatNum = this.saveObj.WeChatNum;
        this.objOption.CourseName = this.saveObj.CourseName;
        this.objOption.StudyTime = this.saveObj.StudyTime;
        this.objOption.LevelType = this.saveObj.LevelType;
        this.objOption.PlanId = this.saveObj.PlanId;
        this.objOption.VisitorStatus = this.saveObj.VisitorStatus;
        this.objOption.Evaluate = this.saveObj.Evaluate;
        this.objOption.Remark = this.saveObj.Remark;
      }
    },
    methods: {
      //关闭弹窗
      closeVisitForm() {
        this.$emit("close");
        this.persistent = false;
      },
      //保存菜单
      saveCourse() {
        this.$refs.Name.validate();
        this.$refs.Tel.validate();
        this.$refs.CourseName.validate();
        this.$refs.StudyTime.validate();
        this.$refs.LevelType.validate();
        this.$refs.VisitorStatus.validate();
        this.$refs.Evaluate.validate();
        if (!this.$refs.Name.hasError && !this.$refs.Tel.hasError && !this.$refs.CourseName.hasError &&
          !this.$refs.StudyTime.hasError && !this.$refs.LevelType.hasError && !this.$refs.VisitorStatus.hasError && !
          this.$refs.Evaluate.hasError) {
          this.saveCourseLoading = true;
          setVisitor(this.objOption).then(res => {
            this.saveCourseLoading = false;
            this.closeVisitForm();
            this.$emit('success');
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '数据保存成功！',
              position: 'top'
            })
          })
        }
      },
      //日语基础枚举
      getGuestBasics() {
        getGuestBasicsEnumList({}).then(res => {
          if (res.Code == 1) {
            this.GBList = res.Data;
          }
        });
      },

    }
  };

</script>
