<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">{{optionTitle}}</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-input filled stack-label maxlength="20" :dense="false" disable v-model="editObj.SourceName"
            class="col-6 q-pr-lg q-pb-lg" label="项目名称" />
          <q-input filled stack-label maxlength="100" :dense="false" disable v-model="editObj.LinkMan"
            class="col-6 q-pb-lg" label="联系人" />
        </div>
        <div class="row wrap">
          <q-input filled stack-label maxlength="100" :dense="false" disable v-model="editObj.LinkTel"
            class="col-6 q-pr-lg q-pb-lg" label="联系电话" />
        </div>
        <div class="row wrap">
          <div style="margin-bottom:5px;">咨询内容：</div>
        </div>
        <div class="row wrap">
          <q-input class="col-12 q-pb-lg" v-model="editObj.Remark" filled :disable="isEdit" type="textarea" placeholder="咨询内容" />
          <div style="margin-bottom:5px;">回复内容：</div>
          <q-input class="col-12 q-pb-lg" v-model="objOption.DealContent" :disable="isEdit" filled type="textarea" placeholder="回复内容" />
        </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="立即提交" v-if="saveObj.isView!=1" color="accent q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="saveConsult" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    GetWebAdvisory,
    UpdateWebAdvisory
  } from '../../api/system/webkit'
  export default {
    props: {
      saveObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          Id: 0,
          DealContent: '', //内容
          DealStatus: 1
        },
        editObj: {},
        optionTitle: "修改咨询",
        saveLoading: false,
        isEdit:false
      }
    },
    mounted() {
      if(this.saveObj.isView==1){
        this.isEdit=true;
        this.optionTitle='查看咨询';
      }
      this.initObj()
    },
    methods: {
      //初始化表单
      initObj() {
        if (this.saveObj && this.saveObj.Id > 0) {
          GetWebAdvisory({
            Id: this.saveObj.Id
          }).then(res => {
            if (res.Code == 1) {
              this.editObj.SourceName = res.Data.SourceName;
              this.editObj.LinkMan = res.Data.LinkMan;
              this.editObj.LinkTel = res.Data.LinkTel;
              this.editObj.Remark = res.Data.Remark;
              this.objOption.Id = res.Data.Id;
              this.objOption.DealContent = res.Data.DealContent;
              this.$forceUpdate();
            }
          })
        }
      },
      //关闭弹窗
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
      //保存菜单
      saveConsult() {
        this.saveLoading = true
        UpdateWebAdvisory(this.objOption).then(res => {
          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>
