<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-04-12 17:56:45
 * @LastEditors: 无尘
 * @LastEditTime: 2019-12-17 17:36:44
 -->
<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="考勤组名称：" prop="attenceGroupName" class="input-item">
          <limitInput :disflag="$route.query.attenceGroupId ? true : false" :inputWidth="286" :inputValue.sync="ruleFormData.attenceGroupName" :holder="'请输入考勤组名称'" :getByType="'word'" :maxLength="15"> </limitInput>
        </el-form-item>
        <el-form-item label="参与考勤人员：" class="input-item" prop="">
          <div class="flex">
            <el-checkbox :disabled="$route.query.attenceGroupId ? true : false" v-model="ruleFormData.attenceRangeType">行政架构</el-checkbox>
            <div v-if="ruleFormData.attenceRangeType" 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', ruleFormData.adminList)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!ruleFormData.adminList.length">请选择行政架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in ruleFormData.adminList">
                        <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, ruleFormData.adminList, 'depart')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="flex m-t-20">
            <el-checkbox :disabled="$route.query.attenceGroupId ? true : false" v-model="ruleFormData.attenceRangeStoreType">门店架构</el-checkbox>
            <div v-if="ruleFormData.attenceRangeStoreType" 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', ruleFormData.storeList)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!ruleFormData.storeList.length">请选择门店架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in ruleFormData.storeList">
                        <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, ruleFormData.storeList, 'store')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="考勤白名单：" class="input-item" prop="">
          <div class="flex">
            <el-checkbox :disabled="$route.query.attenceGroupId ? true : false" v-model="ruleFormData.noAttenceRangeType">行政架构</el-checkbox>
            <div v-if="ruleFormData.noAttenceRangeType" 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', ruleFormData.noAdminList)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!ruleFormData.noAdminList.length">请选择行政架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in ruleFormData.noAdminList">
                        <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, ruleFormData.noAdminList, 'depart')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="flex m-t-20">
            <el-checkbox :disabled="$route.query.attenceGroupId ? true : false" v-model="ruleFormData.noAttenceRangeStoreType">门店架构</el-checkbox>
            <div v-if="ruleFormData.noAttenceRangeStoreType" 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', ruleFormData.noStoreList)">
                  <span class="font-14 color-c0c4cc p-l-10" v-if="!ruleFormData.noStoreList.length">请选择门店架构</span>
                  <div class="el-select__tags">
                    <span>
                      <template v-for="(item, index) in ruleFormData.noStoreList">
                        <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, ruleFormData.noStoreList, 'store')"></i>
                        </span>
                      </template>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="考勤类型：" prop="">
          <div class="work-type m-b-8">
            <el-radio v-model="ruleFormData.attenceType" :label="1">固定时间上下班【所有人按照相同时间打卡】</el-radio>
            <div class="line-h-15 font-14 color-909399">适用于：办公室等</div>
          </div>
          <div class="work-type m-b-8">
            <el-radio v-model="ruleFormData.attenceType" :label="2">排班时间上下班【不同人员根据各自排班打卡】</el-radio>
            <div class="line-h-15 font-14 color-909399">适用于：工厂、门店等</div>
          </div>
          <!--  <div class="work-type">
            <el-radio v-model="ruleFormData.attenceType" :label="3">自由时间上下班【上下班时间不固定，可随时打卡】</el-radio>
            <div class="line-h-15 font-14 color-909399">适用于：销售、计时工等</div>
          </div> -->
        </el-form-item>
        <el-form-item v-if="ruleFormData.attenceType == 1" label="工作日设置：" prop="">
          <!-- <div class="quick-set-class"><span>快捷设置班次：</span><el-button type="text" @click="showClasses()" plain>更改班次</el-button></div> -->
          <div class="quick-set-table">
            <el-table ref="multipleTable" :data="ruleFormData.attenceWorkJson" tooltip-effect="dark" style="width: 567px">
              <el-table-column width="55">
                <template slot-scope="scope">
                  <!-- <el-checkbox v-model="scope.row.workType"></el-checkbox> -->
                </template>
              </el-table-column>
              <el-table-column label="工作日" width="120">
                <template slot-scope="scope">{{ scope.row.weekDay }}</template>
              </el-table-column>
              <el-table-column prop="name" label="排班时间段" width="120">
                <template slot-scope="scope">
                  <div v-if="scope.row.workType">
                    <div v-for="(item, index) in scope.row.classessTimesJson" :key="index + 'time'">{{ item.startTime }}-{{ item.endTime }}</div>
                  </div>
                  <div v-else>休息</div>
                </template>
              </el-table-column>
              <el-table-column prop="address" label="操作" show-overflow-tooltip>
                <template slot-scope="scope">
                  <el-button type="text" @click.stop="modClasses(scope.$index, scope.row)">更改班次</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div><el-checkbox v-model="ruleFormData.lawFreeFlag">法定节假日自动排休</el-checkbox></div>
        </el-form-item>
        <!--  <el-form-item label="特殊日期：" prop="">
          <div class="must-clock">
            <span class="font-14 color-606266">必须打卡的日期</span><el-button @click="cancelSend" plain>添加</el-button>
            <div class="must-clock-table">
              <el-table :data="ruleFormData.mustJson" tooltip-effect="dark" style="width: 567px">
                <el-table-column label="日期" width="120">
                  <template slot-scope="scope">{{ scope.row.weekDay }}</template>
                </el-table-column>
                <el-table-column prop="name" label="考勤时间" width="120">
                  <template slot-scope="scope">{{ scope.row.weekDay }}</template>
                </el-table-column>
                <el-table-column prop="address" label="操作" show-overflow-tooltip>
                  <el-button type="text" @click="modMust(scope.row)" plain>编辑</el-button>
                  <el-button type="text" @click="delMust(scope.row)" plain>删除</el-button>
                </el-table-column>
              </el-table>
            </div>
          </div>
          <div class="must-clock">
            <span class="font-14 color-606266">不用打卡日期</span><el-button @click="cancelSend" plain>添加</el-button>
            <div class="must-clock-table">
              <el-table :data="ruleFormData.noMustJson" tooltip-effect="dark" style="width: 567px">
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="日期" width="120">
                  <template slot-scope="scope">{{ scope.row.weekDay }}</template>
                </el-table-column>
                <el-table-column prop="name" label="考勤时间" width="120">
                  <template slot-scope="scope">{{ scope.row.weekDay }}</template>
                </el-table-column>
                <el-table-column prop="address" label="操作" show-overflow-tooltip>
                  <el-button type="text" @click="modNoMust(scope.row)" plain>编辑</el-button>
                  <el-button type="text" @click="delNoMust(scope.row)" plain>删除</el-button>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-form-item> -->
        <el-form-item v-if="ruleFormData.attenceType == 2" label="考勤班次：" prop="">
          <div class="tags-classes">
            <div class="new-tag-schedule">
              <div class="attend-type-classes">
                <div class="attend-type-classes-display" data-spm-anchor-id="0.0.0.i25.23964ce3NvNZUj">
                  <div class="ant-tag ant-tag-blue" v-for="(pItem, pIndex) in ruleFormData.classesJson" :key="pIndex">
                    <span class="ant-tag-text">{{ pItem.classesName }}</span>
                    <span v-for="(item, index) in pItem.classessTimesJson" :key="index + 'time'">{{ item.startTime }}-{{ item.endTime }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item v-if="ruleFormData.attenceType == 2" label="排班周期：" prop="">
          <el-table :data="ruleFormData.attenceClassesRangeJSON" tooltip-effect="dark" style="width: 567px">
            <el-table-column prop="ranageName" label="周期名称">
              <template slot-scope="scope">{{ scope.row.ranageName }}</template>
            </el-table-column>
            <el-table-column prop="name" label="周期班次">
              <template slot-scope="scope">
                <div v-for="(item, index) in scope.row.classessTimesJson" :key="index + 'time'">{{ item.startTime }}-{{ item.endTime }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="ranageName" label="周期天数">
              <template slot-scope="scope">{{ scope.row.ranageName }}</template>
            </el-table-column>
            <el-table-column prop="address" label="操作" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-button type="text" @click="editRange(scope.$index, scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="考勤方式：" prop="">
          <div>
            <el-checkbox v-model="ruleFormData.gpsFlag">GPS打卡</el-checkbox>
          </div>
          <div class="gps-body p-20 bg-f7f8fa" style="width: 567px">
            <div>根据工作地点考勤（可添加多个考勤地点）</div>
            <div>
              <el-button type="primary" plain="" @click="addMap">添加考勤地点</el-button> <span>有效范围</span>
              <el-select v-model="ruleFormData.clockDistance" placeholder="请选择">
                <el-option v-for="item in distance" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </div>
            <div v-if="ruleFormData.distanceAddress.length" class="m-t-20">
              <el-table :data="ruleFormData.distanceAddress" tooltip-effect="dark" style="width: 567px">
                <el-table-column prop="name" label="考勤地址">
                  <template slot-scope="scope">{{ scope.row.address }}</template>
                </el-table-column>
                <el-table-column prop="address" label="操作" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-button type="text" @click="delGps(scope.$index, scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div>
              <el-checkbox v-model="ruleFormData.storeClockFlag">根据门店地址经纬度自动配置</el-checkbox>
              <p class="font-14 color-909399">如门店经纬度有误，请在通讯录修改门店相关信息，未设置门店打卡无须选择此项</p>
            </div>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="btn-wrap">
            <el-button @click="cancelSend" plain>取消</el-button>
            <el-button :disabled="$route.query.attenceGroupId ? true : false" @click="showEffect = true" type="primary">保存</el-button>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <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>
    <el-dialog title="选择规则生效时间" :visible.sync="showEffect" width="420px" :before-close="handleClose">
      <span>立即生效：今日考勤结果将按新规则重算</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="sendData('noteForm')">明天生效</el-button>
        <el-button type="primary" @click="sendData('noteForm')">立即生效</el-button>
      </span>
    </el-dialog>
    <class-select :workClassShow="workClassShow" :classesId="classesId" @hideClassDialog="hideClassDialog"> </class-select>
    <map-select :mapShow="mapShow" @hideMapDialog="hideMapDialog"> </map-select>
  </div>
</template>
<script>
import classSelect from '@/components/app/dailyAttendance/class-select.vue';
import mapSelect from '@/components/app/dailyAttendance/map-select.vue';
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 { 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: 'workGroupSet',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    },
    activeGroupId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      projectName: 'haoban-manage-web',
      topMenuData: [
        {
          id: '1',
          name: '考勤组管理',
          path: `/workSet?appIcon=${this.$route.query.appIcon}`
        },
        {
          id: '2',
          name: this.$route.query.attenceGroupId ? '编辑考勤组' : '新建考勤组',
          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: {
        attenceGroupId: '',
        attenceType: 1, // 考勤组类型1固定排班2排班制3自由排班
        attenceRangeType: false, // 是否设置行政架构考勤名单 1是0否
        attenceRangeStoreType: false, // 是否选择考勤范围门店结构1是0否
        adminList: [],
        storeList: [],
        noAttenceRangeType: false, // 是否设置白名单行政架构考勤名单 1是0否
        noAttenceRangeStoreType: false, // 是否选择考勤范围门店结构1是0否
        noAdminList: [],
        noStoreList: [],
        lawFreeFlag: false, // 是否法定节假日自动排休
        clockDistance: 300, // 考勤距离
        storeClockFlag: false, // 是否开启门店打卡
        gpsFlag: false, // 是否gps打卡1是0否
        distanceAddress: [], // 考勤地址范围集合{ address: '', longitude: '', latitude: '' }
        attenceRangeJson: [],
        // 需要打卡的范围1需要打卡的2无须打卡的 storeFlag 1门店架构0行政架构{ rangeType: '', userId: '', storeId: '', groupId: '', storeFlag: '' }
        sperialRangeJson: [{ attenceDate: '', sperialType: '' }],
        mustJson: [],
        noMustJson: [],
        //特殊考勤日期sperialType 1必须打卡0无须打卡
        attenceWorkJson: [{ weekDay: '周一', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周二', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周三', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周四', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周五', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周六', workType: false, classesName: '', classesId: '', classessTimesJson: '' }, { weekDay: '周日', workType: false, classesName: '', classesId: '', classessTimesJson: '' }],
        // 类型上班还是休息1上班0休息
        attenceClassesRangeJSON: [],
        classesJson: []
      },
      rules: {
        // receiveType: [{ required: true, message: '请选择发送对象', trigger: 'change' }],
        // img: [{ required: true, message: '请上传封面图片', trigger: 'blur' }],
        attenceGroupName: [{ 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,
      showEffect: false,
      // 工作日设置
      workClassShow: false,
      modIndex: '',
      modRow: {},
      showClassesFlag: false,
      multipleSelection: [],
      distance: [
        {
          value: '50',
          label: '50米'
        }
      ],
      mapShow: false,
      // 周期
      rangeShow: false
    };
  },

  methods: {
    /**
     * 周期
     */
    editRange(index, row) {
      const that = this;
      that.rangeShow = true;
    },
    /**
     * 地图
     */
    addMap() {
      const that = this;
      that.mapShow = true;
    },
    hideMapDialog(obj) {
      const that = this;
      console.log(obj);
      that.mapShow = false;
      if (!obj) {
        return false;
      }
      that.ruleFormData.distanceAddress.push({
        address: obj.address,
        longitude: obj.longitude,
        latitude: obj.latitude
      });
    },
    delGps(index, row) {
      const that = this;
      that.ruleFormData.distanceAddress.splice(index, 1);
    },
    /**
     * 工作日设置
     *
     */
    showClasses() {
      const that = this;
      that.workClassShow = true;
    },
    modClasses(index, row) {
      const that = this;
      console.log(row);
      that.modIndex = index;
      that.modRow = row;
      that.classesId = row.classesId || '';
      that.workClassShow = true;
    },
    hideClassDialog(val) {
      const that = this;
      that.workClassShow = false;
      that.classesId = '';
      if (!val) {
        return false;
      }
      that.modRow.workType = true;
      const obj = JSON.parse(JSON.stringify(val));
      that.modRow.classesName = obj.classesName;
      that.modRow.classesId = obj.classesId;
      that.modRow.classessTimesJson = obj.classessTimesJson;
    },
    handleSelectionChange(val) {
      const that = this;
      console.log(val);
      that.multipleSelection = val;
      // 设置班次
    },

    // 返回 的 brandId
    selectBrandId(id, groupId) {
      this.brandId = id;
    },

    // 取消
    cancelSend() {
      let that = this;
      if (that.$route.query.attenceGroupId) {
        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.attenceGroupId) {
        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.attenceGroupId) {
        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
          };
          if (that.saveDataBool) {
            postRequest('/haoban-app-attence-web/attence-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 = {
        enterpriseId: that.enterpriseId
      };
      getRequest('/haoban-app-attence-web/attence-classes-list', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (resData.result.list && resData.result.list.length) {
              resData.result.list.forEach(ele => {
                if (ele.classessTimesJson) {
                  ele.classessTimesJson = JSON.parse(ele.classessTimesJson);
                }
              });
            }
            that.classifyList = resData.result.list || [];
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取考勤组详情
     */
    getGroupData() {
      const that = this;
      let para = {
        attenceGroupId: that.$route.query.attenceGroupId
      };
      getRequest('/haoban-app-attence-web/attence-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
          });
        });
    },
    setDistance() {
      const that = this;
      for (let index = 1; index < 11; index++) {
        that.distance.push({
          value: index * 100,
          label: index * 100 + '米'
        });
      }
      that.distance.push({
        value: 2000,
        label: '2000米'
      });
    }
  },
  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,
    classSelect,
    mapSelect
  },
  mounted() {
    const that = this;
    that.setDistance();
    if (that.$route.query.attenceGroupId) {
      that.$nextTick(() => {
        that.getNoticeData();
      });
    }
  }
};
</script>
<style type="text/less" lang="less" scoped>
.line-h-15 {
  line-height: 15px;
}
.m-b-8 {
  margin-bottom: 8px;
}
.icon-xinxixianshi {
  .font-12 {
    font-size: 12px;
  }
}
.bg-f7f8fa {
  background-color: #f7f8fa;
}
.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>
