<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-04-12 17:56:45
 * @LastEditors: 无尘
 * @LastEditTime: 2019-12-10 14:33:27
 -->
<template>
  <div class="notice-list-wrap">
    <div class="notice-list">
      <common-detail-top :topMenuData="topMenuData" :activeId="activeId"></common-detail-top>
      <el-form :model="ruleFormData" :rules="rules" ref="noteForm" label-width="120px" class="demo-ruleForm">
        <el-form-item label="发送范围" class="input-item is-required" prop="">
          <div class="flex">
            <el-checkbox :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.adminCheck">行政架构</el-checkbox>
            <div v-if="ruleFormData.adminCheck" class="flex-column item-cell-select inline-block m-l-10">
              <div class="depart-item-wrap">
                <div style="width:470px" class="el-select el-select--large depart-item-content" @click="showDialogLayer('depart', defaultSelection)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!defaultSelection.length">请选择行政架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in defaultSelection">
                        <span class="el-tag el-tag--info el-tag--small" :key="index">
                          <span class="el-select__tags-text">{{ item.name || item.storeName }}</span
                          ><i class="el-tag__close el-icon-close" @click.stop="delDepart(index, defaultSelection, 'depart')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="flex m-t-20">
            <el-checkbox :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.storeCheck">门店架构</el-checkbox>
            <div v-if="ruleFormData.storeCheck" class="flex-column item-cell-select inline-block m-l-10">
              <div class="depart-item-wrap">
                <div style="width:330px" class="el-select el-select--large depart-item-content" @click="showDialogLayer('store', defaultStoreList)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!defaultStoreList.length">请选择门店架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in defaultStoreList">
                        <span class="el-tag el-tag--info el-tag--small" :key="index">
                          <span class="el-select__tags-text">{{ item.name || item.storeName }}</span
                          ><i class="el-tag__close el-icon-close" @click.stop="delDepart(index, defaultStoreList, 'store')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="depart-item-wrap" v-if="ruleFormData.storeCheck">
              <el-select :disabled="$route.query.announcementId ? true : false" class="m-l-10" v-model="ruleFormData.receiveType" placeholder="请选择">
                <el-option label="仅店长" value="0"></el-option>
                <el-option label="门店所有员工" value="1"></el-option>
              </el-select>
            </div>
          </div>
          <div v-show="(defaultStoreBool && !ruleFormData.adminCheck && !ruleFormData.storeCheck) || (defaultStoreBool && ruleFormData.adminCheck && !defaultSelection.length) || (defaultStoreBool && ruleFormData.storeCheck && (!defaultStoreList.length || ruleFormData.receiveType == ''))" class="el-form-item__error">请选择发送范围</div>
        </el-form-item>
        <el-form-item label="选择分类" prop="labelId">
          <el-select :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.labelId" placeholder="请选择" style="width:560px"> <el-option v-for="item in classifyOptions" :key="item.labelId" :label="item.labelName" :value="item.labelId"> </el-option> </el-select><el-button :disabled="$route.query.announcementId ? true : false" class="p-l-20" type="text" @click="newClassify">新建分类</el-button>
        </el-form-item>
        <!-- <el-form-item label="发送对象" prop="receiveType">
          <el-radio-group v-model="ruleFormData.receiveType">
            <el-radio label="0">仅店长</el-radio>
            <el-radio label="1">所有人</el-radio>
          </el-radio-group>
        </el-form-item> -->
        <el-form-item label="公告标题" prop="title" class="input-item">
          <limitInput :disflag="$route.query.announcementId ? true : false" :inputWidth="560" :inputValue.sync="ruleFormData.title" :holder="'请输入公告标题'" :maxLength="15"> </limitInput>
        </el-form-item>
        <el-form-item label="封面图片">
          <el-upload :disabled="$route.query.announcementId ? true : false" class="upload-demo" :action="uploadUrl()" :show-file-list="false" :before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess">
            <div v-if="ruleFormData.imgUrl" class="avatar-wrap flex flex-align-center flex-pack-center"><img :src="ruleFormData.imgUrl" class="avatar" /></div>
            <el-button :disabled="$route.query.announcementId ? true : false" v-else size="mini" type="primary">点击上传</el-button>
          </el-upload>
          <div class="el-upload__tip">建议尺寸大于690*300，支持 jpg、jpeg、bmp、png 类型文件，单张图片限制大小5M</div>
        </el-form-item>
        <el-form-item label="公告内容" prop="content" class="input-item w-1012">
          <!-- <limitTextarea :inputWidth="560" :inputValue.sync="ruleFormData.content" :holder="'请输入公告内容'" :maxLength="200"> </limitTextarea> -->
          <tinymce-edit :disabledEdit="$route.query.announcementId ? true : false" ref="tinymceWrap" :bodyHtml="ruleFormData.content" :projectName="projectName" @changeEditor="changeEditor"></tinymce-edit>
        </el-form-item>
        <el-form-item label="发送方式" prop="sendType">
          <el-radio-group :disabled="$route.query.announcementId ? true : false" @change="changeSendType" v-model="ruleFormData.sendType">
            <el-radio label="0">立即发送</el-radio>
            <el-radio label="1">定时发送</el-radio>
          </el-radio-group>
          <el-date-picker :disabled="$route.query.announcementId ? true : false" v-show="ruleFormData.sendType == '1'" @change="changeMyDate" class="my-date-picker" v-model="dateValue" type="datetime" placeholder="选择发送时间" value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker>
          <div v-show="ruleFormData.sendType == '1' && datePickerBool && !dateValue" class="date-picker-error el-form-item__error">请选择发送时间</div>
        </el-form-item>
        <el-form-item label="附件" prop="attachment" class="w-680">
          <el-upload :disabled="$route.query.announcementId ? true : false" class="upload-demo notice-upload-file" action="/haoban-manage-web/upload-file?fileType=report" :before-upload="beforeFileUpload" :on-success="handleFileSuccess" :on-change="handleFileChange" :on-remove="handleRemove" multiple :limit="3" :on-exceed="handleExceed" :file-list="fileDatas">
            <el-button :disabled="$route.query.announcementId ? true : false" size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">支持.doc，.docx，.pdf，.xls，.xlsx，.ppt，.pptx类型文件，单个附件大小不超过20M，最多添加3个附件</div>
          </el-upload>
          <div v-if="$route.query.announcementId" class="file-list">
            <ul class="el-upload-list el-upload-list--text">
              <template v-for="(item, index) in ruleFormData.attachment">
                <li tabindex="0" class="el-upload-list__item is-success" :key="index + 'file'">
                  <!----><a class="el-upload-list__item-name"><i class="el-icon-document"></i>{{ item.name }}</a
                  ><label class="el-upload-list__item-status-label"></label><i class="el-icon-close" style="display: block"></i><i class="el-icon-close-tip">按 delete 键可删除</i
                  ><!----><!---->
                </li>
              </template>
            </ul>
          </div>
        </el-form-item>
        <el-form-item label="更多设置" prop="pageTop">
          <!-- <el-radio-group v-model="ruleFormData.pageTop">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group> -->
          <div>
            <el-checkbox :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.pageTop">置顶公告</el-checkbox>
            <el-tooltip class="item" effect="dark" content="最多支持3条公告置顶，次数超出限制时，请在公告列表中设置公告置顶" placement="right">
              <span style="cursor: pointer"><i class="iconfont icon-xinxixianshi font-12 color-909399" style="font-size: 12px;"></i></span>
            </el-tooltip>
          </div>
          <div>
            <el-checkbox :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.newSeeFlag">新员工可见</el-checkbox>
            <el-tooltip class="item" effect="dark" content="新员工含义：新加入到公告发送范围内部门或门店的员工。最多支持10条公告新员工可见" placement="right">
              <span style="cursor: pointer"><i class="iconfont icon-xinxixianshi font-12 color-909399" style="font-size: 12px;"></i></span>
            </el-tooltip>
          </div>
          <div>
            <el-checkbox :disabled="$route.query.announcementId ? true : false" v-model="ruleFormData.watermarkFlag">公告加水印</el-checkbox>
            <el-tooltip class="item" effect="dark" content="水印格式：姓名+手机尾号后四位" placement="right">
              <span style="cursor: pointer"><i class="iconfont icon-xinxixianshi font-12 color-909399" style="font-size: 12px;"></i></span>
            </el-tooltip>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="btn-wrap">
            <el-button @click="cancelSend" plain>取消</el-button>
            <el-button :disabled="(!ruleFormData.adminCheck && !ruleFormData.storeCheck) || (ruleFormData.adminCheck && !defaultSelection.length) || (ruleFormData.storeCheck && (!defaultStoreList.length || ruleFormData.receiveType == '')) || !ruleFormData.title || !ruleFormData.content || (ruleFormData.sendType == '1' && !dateValue) ? true : false" @click="previewData('noteForm')" type="primary">预览</el-button>
            <el-button :disabled="$route.query.announcementId ? true : false" @click="sendData('noteForm')" type="primary">发布</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <create-classify :classifyName="classifyName" :showDialog="showDialog" @hideDialog="hideDialog"> </create-classify>
    <vue-select-employee :appScene="appScene" :defaultSelection="defaultSelection" :onlyPerson="onlyPerson" :treeSet="treeSet" :changed="changed" @handleSelectedList="handleSelectedList"> </vue-select-employee>
    <!-- 发送范围的门店选择 -->
    <vue-select-store ref="storeSelector" :currentBrand="activeGroup" :appScene="appScene" :treeSet="storeTreeSet" :selectType="'group-store'" :defaultList="defaultStoreList" @handleSelectedList="handleSelectedList"> </vue-select-store>
    <notice-preview ref="noticePreview" :noticePreviewData="noticePreviewData" v-model="previewVisible"></notice-preview>
  </div>
</template>
<script>
import commonDetailTop from '@/components/app/common-detail-top.vue';
import limitInput from '@/components/limit-input.vue';
import vueSelectStore from 'components/common/vueSelectStore';
import vueSelectEmployee from '@/components/common/vueSelectEmployee.vue';
import limitTextarea from '@/components/limit-textarea.vue';
import tinymceEdit from 'components/tinymce-edit';
import createClassify from '@/components/app/create-classify.vue';
import noticePreview from '@/components/app/notice-preview.vue';
import { getRequest, postRequest } from '@/api/api';
import showMsg from '@/common/js/showmsg';
import { _debounce, formatDate } from '@/common/js/public';
import errMsg from '@/common/js/error';
export default {
  name: 'addNotice',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    },
    activeGroupId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      projectName: 'haoban-manage-web',
      topMenuData: [
        {
          id: '1',
          name: '企业公告列表',
          path: `/noticeList?appIcon=${this.$route.query.appIcon}`
        },
        {
          id: '2',
          name: this.$route.query.announcementId ? '查看公告' : '新建公告',
          path: ''
        }
      ],
      classifyOptions: [], // 分类列表
      activeId: '2', // 详情头部选中 id
      activeBrand: this.brandId, // 商户(品牌) id
      activeGroup: this.activeGroupId, // 商户(品牌) groupId
      enterpriseId: JSON.parse(localStorage.getItem('userInfo')).enterpriseId,
      userId: JSON.parse(localStorage.getItem('userInfo')).userId,
      ruleFormData: {
        announcementId: '',
        adminCheck: false,
        storeCheck: false,
        adminStructor: [],
        storeStructor: [],
        receiveType: '0',
        labelId: '',
        title: '',
        imgUrl: '',
        content: '',
        sendType: '0',
        attachment: [],
        pageTop: false,
        newSeeFlag: false,
        watermarkFlag: false
      },
      rules: {
        // receiveType: [{ required: true, message: '请选择发送对象', trigger: 'change' }],
        // img: [{ required: true, message: '请上传封面图片', trigger: 'blur' }],
        title: [{ required: true, message: '请输入公告标题', trigger: 'blur' }],
        content: [{ required: true, message: '请输入公告内容', trigger: 'blur' }],
        sendType: [{ required: true, message: '请选择发送方式', trigger: 'change' }]
      },
      wxFlag: 1,
      actionUrl: '/haoban-manage-web/upload-img',
      datePickerBool: false,
      dateValue: '',
      // 行政
      selectType: '',
      treeSet: {
        isSelectPerson: false, // 控制只能选部门(false)
        dialogVisible: false, // 控制显示/隐藏
        isSingle: false, // 是否单选
        openNextBool: true // 展开下级不调用接口
      },
      defaultSelection: [],
      changed: '',
      onlyPerson: false, // 控制只能选人(true)
      // 门店选择
      appScene: 2,
      defaultStoreList: [], //  默认的数据
      storeTreeSet: {
        isSelectPerson: true, // 控制只能选部门(false)
        dialogVisible: false, // 控制显示/隐藏
        isSingle: false // 是否单选
      },
      defaultStoreBool: false,
      // 是否保存的标识
      saveDataBool: true,
      fileDatas: [],
      // 分类
      classifyName: '',
      showDialog: false,
      // 预览
      noticePreviewData: {},
      previewVisible: false
    };
  },

  methods: {
    /**
     * 富文本输入回调
     *
     */
    changeEditor(value) {
      const that = this;
      that.ruleFormData.content = value;
    },
    /**
     * 预览
     */
    previewData(formName) {
      const that = this;
      // 发送范围
      if (!that.ruleFormData.adminCheck && !that.ruleFormData.storeCheck) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      if (that.ruleFormData.adminCheck && !that.ruleFormData.adminStructor.length) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      if (that.ruleFormData.storeCheck && !that.ruleFormData.storeStructor.length) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      // 发送方式
      if (that.ruleFormData.sendType == '1' && !that.dateValue) {
        that.datePickerBool = true;
        that.saveDataBool = false;
      }
      if (that.$refs.tinymceWrap.tinymceHtml != '') {
        that.ruleFormData.content = that.$refs.tinymceWrap.tinymceHtml;
      }
      that.$refs[formName].validate(valid => {
        if (valid) {
          that.noticePreviewData = that.ruleFormData;
          that.previewVisible = true;
        }
      });
    },
    /**
     * 新建分类
     */
    newClassify() {
      const that = this;
      that.classifyName = '';
      that.showDialog = true;
    },
    /**
     * 确定新增分类
     *
     */
    hideDialog(name, id) {
      const that = this;
      if (name == '') {
        that.showDialog = false;
        that.classifyName = '';
        return false;
      }
      let para = {
        enterpriseId: that.enterpriseId,
        brandId: that.activeBrand,
        labelName: name
      };
      getRequest('/haoban-app-announcement-web/create-label', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            showMsg.showmsg('新建成功', 'success');
            that.showDialog = false;
            that.classifyName = '';
            that.getClassifyData();
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    // 返回 的 brandId
    selectBrandId(id, groupId) {
      this.brandId = id;
    },
    // 获取 action 的 url
    uploadUrl() {
      let host = window.location.origin;
      let baseUrl;
      if (host.indexOf('localhost') != '-1') {
        baseUrl = 'http://www.gicdev.com';
      } else {
        baseUrl = host;
      }
      let upUrl = baseUrl + this.actionUrl + '?wxFlag=' + this.wxFlag + '&requestProject=' + this.projectName + '&w=690&h=300';
      return upUrl;
    },
    // 上传之前回调
    beforeAvatarUpload(file) {
      let that = this;
      const isJPG = file.type === 'image/jpg' || file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/bmp';
      const isLt5M = file.size / 1024 / 1024 <= 5;
      if (!isJPG) {
        that.$message.error('上传图片必须是JPG/JPEG/BMP/PNG 格式!');
      }
      if (!isLt5M) {
        that.$message.error('上传图片大小不能超过 5MB!');
      }
      const isSize = new Promise(function(resolve, reject) {
        let width = 690;
        let height = 300;
        let _URL = window.URL || window.webkitURL;
        let img = new Image();
        img.onload = function() {
          let valid = img.width >= width && img.height >= height;
          valid ? resolve() : reject();
        };
        img.src = _URL.createObjectURL(file);
      }).then(
        () => {
          return file;
        },
        () => {
          this.$message.error('上传图片的长度和高度必须在690*300以上!');
          return Promise.reject();
        }
      );
      return isJPG && isLt5M && isSize;
    },
    /**
     * 上传成功
     */
    handleAvatarSuccess(res, file) {
      let that = this;
      if (res.errorCode == 1) {
        that.$message.success('上传成功');
        that.ruleFormData.imgUrl = res.result[0].qcloudImageUrl;
      } else {
        this.$message.error(res.message);
      }
    },
    /**
     * 附件上传
     *
     */
    beforeFileUpload(file) {
      let that = this;
      const isFiles = file.name.includes('pdf') || file.name.includes('doc') || file.name.includes('xls') || file.name.includes('ppt');
      const isLt20M = file.size / 1024 / 1024 <= 20;
      if (!isLt20M) {
        that.$message.error('文件大小超出限制，无法上传');
      }
      if (!isFiles) {
        that.$message.error('仅支持.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx类型文件');
        return false;
      }
      return isLt20M && isFiles;
    },
    handleRemove(file, fileList) {
      let that = this;
      /* eslint-disable */
      // console.log('del:', file, fileList);
      that.postDelFile(file, fileList);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleFileSuccess(res, file) {
      // let that = this;
      /* eslint-disable */
      // console.log(res, file)
      // that.ruleFormData.attachment.push(res.result); // 不能动态修改绑定的fileList 否则只拿到最后一个回调
    },
    handleFileChange(files, fileList) {
      let that = this;
      /* eslint-disable */
      // console.log('handleFileChange:',that.fileDatas)
      that.fileDatas = fileList;
    },
    postDelFile(file, fileList) {
      let that = this;
      let para = {
        url: file.response.result.url
      };
      postRequest('/haoban-manage-web/delete-cloud-file', para).then(res => {
        let data = res.data;
        if (data.errorCode == 1) {
          that.$message.success('删除成功');
          that.fileDatas = fileList;
        } else {
          that.$message.error(data.message);
        }
      });
    },
    // 取消
    cancelSend() {
      let that = this;
      if (that.$route.query.announcementId) {
        that.$router.go(-1);
        return false;
      }
      that
        .$confirm('是否确认返回，返回后当前页面内容将丢失', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          that.$router.go(-1);
        })
        .catch(() => {});
    },
    // 门店弹窗显示
    showDialogLayer(type, selData) {
      const that = this;
      // 查看不能操作
      if (that.$route.query.announcementId) {
        return false;
      }
      that.selectType = type;
      that.changed = type;
      if (type === 'store') {
        that.defaultStoreList = selData;
        that.storeTreeSet = {
          dialogVisible: true,
          isSingle: false,
          isSelectPerson: true,
          openNextBool: true // 展开下级不调用接口
        };
        return;
      }
      that.treeSet = {
        dialogVisible: true,
        isSingle: false,
        isSelectPerson: true,
        openNextBool: true // 展开下级不调用接口
      };
      that.defaultSelection = selData;
    },
    /**
     * 处理已选部门
     */
    handleSelectedList(group) {
      // type:	1:员工,2:部门,3:门店;
      const that = this;
      if (that.selectType === 'store') {
        that.ruleFormData.storeStructor = group;
        that.defaultStoreList = group;
      } else {
        that.ruleFormData.adminStructor = group;
        that.defaultSelection = group;
      }
      that.ruleFormData.sendArea = group;
    },
    /**
     * 删除选的部门
     */
    delDepart(index, obj, type) {
      const that = this;
      if (that.$route.query.announcementId) {
        return false;
      }
      obj.splice(index, 1);
    },
    // 选择定时发送的日期
    changeMyDate() {
      if (!this.dateValue) {
        this.datePickerBool = true;
      } else {
        this.saveDataBool = true;
      }
    },
    // 改变发送方式
    changeSendType(val) {
      if (val == '0') {
        this.saveDataBool = true;
      }
    },
    // 发布
    sendData: _debounce(function(formName) {
      const that = this;
      // 发送范围
      if (!that.ruleFormData.adminCheck && !that.ruleFormData.storeCheck) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      if (that.ruleFormData.adminCheck && !that.ruleFormData.adminStructor.length) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      if (that.ruleFormData.storeCheck && !that.ruleFormData.storeStructor.length) {
        that.defaultStoreBool = true;
        that.saveDataBool = false;
      }
      // 发送方式
      if (that.ruleFormData.sendType == '1' && !that.dateValue) {
        that.datePickerBool = true;
        that.saveDataBool = false;
      }
      if (that.$refs.tinymceWrap.tinymceHtml != '') {
        that.ruleFormData.content = that.$refs.tinymceWrap.tinymceHtml;
      }
      let adminStructor = [];
      if (that.ruleFormData.adminCheck && that.ruleFormData.adminStructor.length) {
        adminStructor = that.ruleFormData.adminStructor.map(item => {
          return {
            id: item.id,
            name: item.name || item.label,
            type: item.type
          };
        });
      }
      let storeStructor = [];
      if (that.ruleFormData.storeCheck && that.ruleFormData.storeStructor.length) {
        storeStructor = that.ruleFormData.storeStructor.map(item => {
          return {
            id: item.id,
            name: item.name || item.label,
            type: item.type
          };
        });
      }
      that.$refs[formName].validate(valid => {
        if (valid) {
          let para = {
            adminCheck: that.ruleFormData.adminCheck ? 1 : 0,
            storeCheck: that.ruleFormData.storeCheck ? 1 : 0,
            adminStructor: JSON.stringify(adminStructor),
            storeStructor: JSON.stringify(storeStructor),
            receiveType: that.ruleFormData.receiveType,
            labelId: that.ruleFormData.labelId || '',
            title: that.ruleFormData.title,
            imgUrl: that.ruleFormData.imgUrl,
            content: that.ruleFormData.content,
            sendType: that.ruleFormData.sendType,
            sendTime: that.dateValue,
            brandId: that.brandId,
            userId: that.userId,
            enterpriseId: that.enterpriseId,
            pageTop: that.ruleFormData.pageTop ? 1 : 0,
            newSeeFlag: that.ruleFormData.newSeeFlag ? 1 : 0,
            watermarkFlag: that.ruleFormData.watermarkFlag ? 1 : 0,
            attachment: that.fileDatas.length ? JSON.stringify(that.fileDatas.map(item => item.response.result)) : ''
          };
          if (that.saveDataBool) {
            postRequest('/haoban-app-announcement-web/announcement-add', para).then(res => {
              let data = res.data;
              if (data.errorCode == 1) {
                that.$message.success('发布成功');
                that.$router.go(-1);
              } else {
                that.$message.error(data.message);
              }
            });
          }
        } else {
          return false;
        }
      });
    }, 500),
    /**
     * 获取公告分类列表
     */
    getClassifyData() {
      const that = this;
      let para = {
        brandId: that.activeBrand
      };
      getRequest('/haoban-app-announcement-web/list-label', para)
        .then(res => {
          let data = res.data;
          if (data.errorCode == 1) {
            that.classifyOptions = data.result || [];
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取公告详情
     */
    getNoticeData() {
      const that = this;
      let para = {
        announcementId: that.$route.query.announcementId
      };
      getRequest('/haoban-app-announcement-web/get-announcement-detail', para)
        .then(res => {
          let data = res.data;
          if (data.errorCode == 1) {
            data.result.adminCheck = data.result.adminCheck == 0 ? false : true;
            data.result.storeCheck = data.result.storeCheck == 0 ? false : true;
            data.result.adminStructor = data.result.adminStructor ? JSON.parse(data.result.adminStructor) : [];
            data.result.storeStructor = data.result.storeStructor ? JSON.parse(data.result.storeStructor) : [];
            that.defaultSelection = data.result.adminStructor;
            that.defaultStoreList = data.result.storeStructor;
            data.result.pageTop = data.result.pageTop ?  true :false;
            data.result.newSeeFlag = data.result.newSeeFlag ? true :false;
            data.result.watermarkFlag = data.result.watermarkFlag ? true :false;
            data.result.sendType = String(data.result.sendType);
            data.result.receiveType = String(data.result.receiveType);
            that.dateValue = formatDate(data.result.sendTime);
            that.noticePreviewData = JSON.parse(JSON.stringify(data.result));
            that.ruleFormData = JSON.parse(JSON.stringify(data.result));
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      if (!!newData) {
        that.activeBrand = newData;
        that.getClassifyData();
      }
    },
    activeGroupId: function(newData, oldData) {
      const that = this;
      if (!!newData) {
        that.activeGroup = newData;
      }
    }
  },
  components: {
    commonDetailTop,
    limitInput,
    limitTextarea,
    vueSelectStore,
    vueSelectEmployee,
    tinymceEdit,
    createClassify,
    noticePreview
  },
  mounted() {
    const that = this;
    that.getClassifyData();
    if (that.$route.query.announcementId) {
      that.$nextTick(() => {
        that.getNoticeData();
      });
    }
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.icon-xinxixianshi {
  .font-12 {
    font-size: 12px;
  }
}
.notice-list-wrap {
  height: 100%;

  .notice-list {
    background: #fff;
    margin-bottom: 34px;
    min-height: 100%;
    // min-height: calc(100% + 24px);
  }
}
.demo-ruleForm {
  padding-top: 30px;
}

.input-item {
  width: 680px;
  position: relative;
  &.w-1012 {
    width: 1012px;
  }
}

.input-item-textarea /deep/ textarea {
  height: 94px;
  font-size: 14px;
  color: #606266;
  font-family: 'Helvetica Neue';
}

.el-upload__tip {
  line-height: 20px;
}

.active-info-num {
  position: absolute;
  right: 0;
  bottom: -31px;
  color: #909399;
  font-size: 12px;
}
.my-date-picker {
  margin-left: 15px;
}
.demo-ruleForm /deep/ .el-form-item__label {
  color: #606266;
}
.btn-wrap {
  font-size: 0;
}
.el-button {
  &.p-l-20 {
    padding-left: 20px;
    -webkit-transform: translateY(2px);
    -moz-transform: translateY(2px);
    -ms-transform: translateY(2px);
    transform: translateY(2px);
  }
}
// 发送范围
.depart-item-content {
  width: 100%;
  height: 32px;
  overflow: hidden;
  white-space: nowrap;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  cursor: pointer;
  box-sizing: border-box;
}

.item-cell-select {
  /deep/ .el-select__tags {
    white-space: nowrap;
    overflow: hidden;
  }
}

.avatar-wrap {
  width: 100px;
  img {
    width: 100%;
  }
}
.date-picker-error {
  padding-left: 193px;
}
.el-form-item {
  /deep/ .file-list {
    .notice-upload-file .el-icon-circle-check:before {
      content: '\E60F';
    }
  }
}
</style>
