<template>
  <div class="notice-editor-wrap" id="screenSet">
    <bread-crumb
      :curmbFirst="curmbFirst"
      :curmbSecond="curmbSecond"
      :curmbThird="curmbThird"
      :jumPathThird="jumPathThird"
    ></bread-crumb>

    <div class="add-content screenSet">
      <el-tabs
        v-model:value="activeName"
        @tab-click="handleClick"
        :before-leave="beforeLeave"
      >
        <el-tab-pane label="发送公告" name="first">
          <SendNotice
            :formData="noticeInfo.noticeInfo"
            @changeNum="sendChangeNum"
          ></SendNotice>
        </el-tab-pane>
        <el-tab-pane label="发送推送" name="second">
          <PushNotice
            :formData="noticeInfo.pushInfo"
            @changeNum="pushChangeNum"
          ></PushNotice>
        </el-tab-pane>
      </el-tabs>
    </div>

    <el-dialog
      class="prot-dialog"
      title="确认要离开吗？"
      v-model:visible="isShowDialog"
      width="30%"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
    >
      <p v-show="isCancleBtn" class="prot-dialog-tips-1">
        当前内容尚未发布，确认离开将丢失已填写的信息
      </p>
      <!-- <p v-show="!isCancleBtn" class="prot-dialog-tips-1">点击发布后将立即生效，是否继续发布？</p> -->
      <!-- <p class="prot-dialog-tips-2">若您选择暂不发送，您只能录入量表的非敏感信息</p> -->
      <!-- <p class="prot-dialog-tips-3">为避免打扰居民，7天内只能发送1次，您已发送过短信，请尽快联系居民同意授权</p> -->
      <template v-slot:footer>
        <span v-show="isCancleBtn" class="dialog-footer">
          <el-button size="small" @click="cancleConfirm"> 取消 </el-button>
          <el-button size="small" type="primary" @click="openFlagConfirm">
            离开
          </el-button>
        </span>
      </template>
      <!-- <span v-show="!isCancleBtn" slot="footer" class="dialog-footer">
            <el-button size="small" @click="openFlagCancle"> 取消 </el-button>
            <el-button size="small" type="primary" @click="openFlagConfirm"> 确定 </el-button>
          </span> -->
    </el-dialog>
  </div>
</template>

<script>
import BreadCrumb from '@/components/breadcrumb.vue'
import SendNotice from '@/components/education/notice/sendNotice'
import PushNotice from '@/components/education/notice/pushNotice'
import { openLoading, closeLoading } from '@/utils/utils'
import * as commonUtil from '@/utils/utils'
let vm = null
export default {
  components: {
    BreadCrumb,
    SendNotice,
    PushNotice,
  },
  data() {
    return {
      curmbFirst: '教培项目',
      curmbSecond: '项目管理',
      jumPathThird: '/item-manager',
      curmbThird: '发送通知',
      activeName: 'first',
      noticeInfo: {
        noticeInfo: {
          projectId: 0,
          noticeId: 0,
          noticeContent: '',
          noticeTitle: '',
          openFlag: 0,
        },
        pushInfo: {
          projectId: 0,
          noticeId: 0,
          channel: [1],
          customPushTime: '',
          noticeContent: '',
          noticeTitle: '',
          sendScopeType: 1,
        },
      },
      sendChangeN: 1,
      pushChangeN: 1,
      isShowDialog: false,
      gotoActiveName: '',
      isCancleBtn: true,
    }
  },

  created() {
    vm = this
    console.log('wwwwwwwww')
    vm.projectId = vm.getUrlSearch(window.location.href, 'projectId') || 1476
    // vm.formData.projectId = vm.projectId
    vm.getNoticeInfo2()
  },
  mounted() {
    commonUtil.resizeHeight()
  },
  methods: {
    beforeLeave(activeName, oldActiveName) {
      let rFlag = true
      // this.gotoActiveName = activeName;
      // if(activeName == 'second') {
      //   if(this.sendChangeN > 2) {
      //     this.isShowDialog = true;
      //     rFlag = false;
      //   }
      // } else if(activeName == 'first') {
      //   if(this.pushChangeN > 2) {
      //     this.isShowDialog = true;
      //     rFlag = false;
      //   }
      // }
      return rFlag
    },

    // 确认开启的取消
    openFlagCancle() {
      vm.isShowDialog = false
    },

    // 确认取消
    cancleConfirm() {
      vm.isShowDialog = false
      // vm.$router.push('/item-manager');
    },

    // 确认开启
    openFlagConfirm() {
      vm.isShowDialog = false
      this.sendChangeN = 2
      this.pushChangeN = 2
      vm.activeName = vm.gotoActiveName
      console.log(vm.activeName)
      // vm.confirmEdit();
    },

    handleClick(tab) {
      console.log(tab, this.sendChangeN, this.pushChangeN)
    },

    sendChangeNum(num) {
      this.sendChangeN = num
    },

    pushChangeNum(num) {
      this.pushChangeN = num
    },

    //获取推送信息
    getNoticeInfo2() {
      let req = {
        projectId: vm.projectId,
      }
      openLoading(vm)
      vm.GET('portal/noticeInfo/getNoticeInfo', req).then((res) => {
        closeLoading(vm)
        if (res.code == '000000') {
          let data = res.data
          data.pushInfo.channel = data.pushInfo.channel || []
          data.pushInfo.projectId = this.projectId
          data.noticeInfo.projectId = this.projectId
          data.pushInfo.sendScopeType = data.pushInfo.sendScopeType || ''
          console.log('$$$$$$$', data)
          vm.noticeInfo = data
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.notice-editor-wrap {
  background: #fff;
}
.prot-dialog-tips-1 {
  text-align: center !important;
}
</style>
