<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 400px;max-width:400px;">
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <q-card-section>
          <div class="text-h6">
            <span v-if="ChoiceType==3">取消预约</span>
            <span v-if="ChoiceType==2">流单</span>
          </div>
        </q-card-section>
        <div class="row wrap">
          <template v-if="ChoiceType==3">
            <q-input filled stack-label :dense="false" v-model="msg.Remark" type="textarea" class="col-12" label="备注" />
          </template>
          <template v-if="ChoiceType==2">
            <q-select filled stack-label option-value="Id" option-label="Name" v-model="chooseLiudan" ref="remark"
              :options="reasonList" label="流单原因" :dense="false" class="col-12 q-pb-lg" emit-value map-options
              multiple />
          </template>
        </div>
        </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="saveYueke" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script>
  import {
    setVisitorReserveStatus
  } from '../../api/scheduling/schedu'
  export default {
    props: {
      ChoiceType: {
        type: Number,
        default: 2
      },
      saveObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        saveLoading: false,
        msg: {
          Id: 0,
          ReserveStatus: 0,
          Remark: '',
        },
        chooseLiudan: [],
        reasonList: [{
          Id: "教学环境",
          Name: '教学环境'
        }, {
          Id: "教学内容",
          Name: '教学内容'
        }, {
          Id: "讲师",
          Name: '讲师'
        }, {
          Id: "价格",
          Name: '价格'
        }, {
          Id: "销售跟进",
          Name: '销售跟进'
        }, {
          Id: "同行竞争",
          Name: '同行竞争'
        }, {
          Id: "其他",
          Name: '其他'
        }]
      }
    },
    mounted() {
      if (this.saveObj) {
        if (this.saveObj.Id) {
          this.msg.Id = this.saveObj.Id;
        }
      }
    },
    methods: {
      //关闭弹窗
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false;
      },
      //保存菜单
      saveYueke() {
        this.saveLoading = true;
        if (this.ChoiceType == 2) {
          this.msg.ReserveStatus = 2;
        }
        if (this.ChoiceType == 3) {
          this.msg.ReserveStatus = 3;
        }
        if (this.ChoiceType == 2) {
          this.msg.Remark = this.chooseLiudan.toString();
        }
        setVisitorReserveStatus(this.msg).then(res => {
          if (res.Code == 1) {
            this.saveLoading = false
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '数据保存成功！',
              position: 'top'
            })
            this.$emit("success")
            this.closeSaveForm()
          }
        }).catch(() => {
          this.saveLoading = false
        });
      },
    }
  }

</script>
