<template>
  <div>
    <!--        顶部条-->
    <div class="navBarTOP">
      <van-nav-bar class="navBar" title="周报详情" left-arrow @click-left="onClickLeft" />
    </div>
    <!--        主体内容-->
    <div class="container linep">
      <div class="lineGrey"></div>
      <div class="lineGrey"></div>
      <div class="lineGrey"></div>
      <div class="lineGrey"></div>
      <div class="lineGrey"></div>
      <p style="font-size: 16px; margin: 10px 0">{{ title }}</p>
      <van-collapse v-model="activeNames">
        <template v-if="!YFQuota">
          <!-- YFQuota:应用服务平台 不显示各项指标 -->
          <template v-if="reportTarget.postType == 'GZ' || reportTarget.BMDType == 'BMD'">
            <!-- 0-历史指标  1-动态指标，String类型 -->
            <template v-if="reportTarget.targetType == '1'">
              <target :homePageIndicatorDate="homePageIndicatorList"></target>
            </template>
            <template v-if="reportTarget.targetType == '0'">
              <Atarget :reportInfo="reportTarget"></Atarget>
              <Btarget :reportInfo="reportTarget"></Btarget>
            </template>
          </template>
          <template v-else>
            <Atarget :reportInfo="reportTarget"></Atarget>
            <Btarget :reportInfo="reportTarget"></Btarget>
          </template>
        </template>
        <div class="contentContainer" v-if="reportTarget.isHistory == '0'">
          <!-- isHistory 是否为历史汇报：0-新汇报 1-历史汇报 -->

          <reportCustom
            ref="reportCustom"
            :disabled="true"
            :reportCustomData="reportTarget.customTaskList"></reportCustom>
        </div>
        <template v-else>
          <van-collapse-item title="上周工作成果" name="8">
            <div style="margin-top: -10px">
              <div v-for="(item2, index2) in reportContentsList2" :key="index2">
                <div v-if="index2 < 7">
                  <p class="texttitle">
                    <span class="opint"></span
                    ><span v-if="!reportTarget.hideWeekDate">{{
                      weeklyTimeDivision(item2.contentTime, 0)
                    }}</span
                    ><span>{{ weeklyTimeDivision(item2.contentTime, 1) }}</span>
                  </p>
                  <p>
                    <span class="colorbalck">上午:</span
                    >{{ reportContentsList1[index2].weekContentAm }}
                  </p>
                  <p>
                    <span class="colorbalck">下午:</span
                    >{{ reportContentsList1[index2].weekContentPm }}
                  </p>
                  <p class="texttitle texttitle2">实际工作进度</p>
                  <p><span class="colorbalck">上午:</span>{{ item2.weekContentAm }}</p>
                  <p><span class="colorbalck">下午:</span>{{ item2.weekContentPm }}</p>
                </div>
                <p v-if="index2 == 7" class="texttitle"><span class="opint"></span>上周工作重点</p>
                <div v-if="index2 == 7" style="padding: 10px 0" class="contentContainer">
                  <van-field
                    v-model="reportContentsList1[index2].weekContentSummary"
                    rows="4"
                    autosize
                    readonly
                    type="textarea" />
                </div>
                <p v-if="index2 == 7" class="texttitle"><span class="opint"></span>上周工作成果</p>
                <div v-if="index2 == 7" style="padding: 10px 0" class="contentContainer">
                  <van-field
                    v-model="item2.weekContentSummary"
                    rows="4"
                    autosize
                    readonly
                    type="textarea" />
                </div>
              </div>
            </div>
          </van-collapse-item>
          <van-collapse-item title="本周工作规划" name="9">
            <div style="margin-top: -10px">
              <div v-for="(item, index) in reportContentsList3" :key="index">
                <p v-if="index < 7" class="texttitle">
                  <span class="opint"></span
                  ><span v-if="!reportTarget.hideWeekDate">{{
                    weeklyTimeDivision(item.contentTime, 0)
                  }}</span
                  ><span>{{ weeklyTimeDivision(item.contentTime, 1) }}</span>
                </p>
                <p v-if="index < 7">
                  <span class="colorbalck">上午:</span>{{ item.weekContentAm }}
                </p>
                <p v-if="index < 7">
                  <span class="colorbalck">下午:</span>{{ item.weekContentPm }}
                </p>
                <p v-if="index == 7" class="texttitle"><span class="opint"></span>本周工作重点</p>
                <div v-if="index == 7" style="padding: 10px 0" class="contentContainer">
                  <van-field
                    v-model="item.weekContentSummary"
                    rows="4"
                    autosize
                    readonly
                    type="textarea" />
                </div>
              </div>
            </div>
          </van-collapse-item>
        </template>
      </van-collapse>
      <div
        class="contentContainer"
        v-if="reportTarget.status > 1 || reportTarget.reportRemarks != null">
        <p class="texttitle texttitledaily" style="margin-top: 6px">
          <span class="opint"></span>
          <span v-if="reportTarget.status == 1">待审批</span>
          <span v-if="reportTarget.status == 3">审批完成</span>
          <span v-if="reportTarget.status == 2">退回重写</span>
          <span v-if="reportTarget.status == -1">过期未汇报</span>
          <span v-if="reportTarget.status > 1"><{{ ptitle }}审批></span>
        </p>
        <div style="padding: 10px 0" v-if="reportTarget.status > 1">
          <van-rate
            v-model="reportTarget.number"
            :size="25"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
            readonly />
          <span class="rateText">&nbsp;&nbsp;&nbsp;&nbsp;{{ reportTarget.number }}分</span>
        </div>
        <div style="padding: 10px 0" v-if="reportTarget.status > 1">
          <van-field v-model="successContent" rows="4" autosize readonly type="textarea" />
        </div>
      </div>
      <div class="contentContainer" v-if="reportTarget.reportRemarks != null">
        <div>
          <div v-for="(item, index) in reportTarget.reportRemarks" :key="index">
            <p class="contentContainerTitle">
              <template v-if="item.deptName">{{ item.deptName }}-</template>{{ item.postName }} -
              {{ item.nickName }}的点评
            </p>
            <div style="padding: 10px 0">
              <van-field v-model="item.remarkContent" rows="4" autosize readonly type="textarea" />
            </div>
            <!-- <p style="text-align: right">点评时间：{{ item.createTime }}</p> -->
          </div>
        </div>
      </div>
      <div class="contentContainer">
        <p class="contentContainerTitle">点评</p>
        <div style="padding: 10px 0">
          <van-field
            v-model="managerRemarkContent"
            rows="4"
            autosize
            maxlength="800"
            show-word-limit
            type="textarea"
            :formatter="formatter" />
        </div>
      </div>
    </div>
    <div class="lineGrey"></div>
    <div class="contentborder">
      <van-button type="info" size="small" plain class="Btn1" @click="submint">提交点评</van-button>
    </div>
    <br /><br />
    <!--    <div class="envelopes" @click="openEnterpriseChat" >-->
    <!--      <img :src="envelopes">-->
    <!--      <p>红包奖励</p>-->
    <!--    </div>-->
    <br /><br />
    <br /><br />
  </div>
</template>

<script>
import history from '@/assets/Icon/history.png';
import { loginLog, insertRemark, getDetailById, updateReport } from '@/api/index';
import envelopes from '@/assets/envelopes.png';
import axios from 'axios';
import createStoreBJ from '@/views/componentsTarget/createStoreBJ';
import ZYPlaceOrder from '@/views/componentsTarget/ZYPlaceOrder';
import performanceSAP from '@/views/componentsTarget/performanceSAP';
import ZYSAP from '@/views/componentsTarget/ZYSAP';
import veryGoodPlaceOrder from '@/views/componentsTarget/veryGoodPlaceOrder';
import neiwaiqiangpingtu from '@/views/componentsTarget/neiwaiqiangpingtu';
import zhiganwaiqiangSAP from '@/views/componentsTarget/zhiganwaiqiangSAP';
import cizhuanjiaoSAP from '@/views/componentsTarget/cizhuanjiaoSAP';
import neiqiangzhonggaoduanSAP from '@/views/componentsTarget/neiqiangzhonggaoduanSAP';
import moshouqiSAP from '@/views/componentsTarget/moshouqiSAP';
import fangshuiSAP from '@/views/componentsTarget/fangshuiSAP';
import Atarget from '@/views/home/Atarget.vue';
import Btarget from '@/views/home/Btarget.vue';
import reportCustom from './reportCustom.vue';
import target from './target.vue';
export default {
  name: 'home',
  components: {
    createStoreBJ,
    ZYPlaceOrder,
    performanceSAP,
    ZYSAP,
    veryGoodPlaceOrder,
    neiwaiqiangpingtu,
    zhiganwaiqiangSAP,
    cizhuanjiaoSAP,
    neiqiangzhonggaoduanSAP,
    moshouqiSAP,
    fangshuiSAP,
    Atarget,
    Btarget,
    reportCustom,
    target,
  },
  data() {
    return {
      envelopes: envelopes,
      show: true,
      num: 0,
      todayGoal: {},
      title: '',
      ptitle: '',
      progressWidth: 0,
      history: history,
      imgArr: [],
      activeNames: [
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
        '8',
        '9',
        '11',
        '12',
        '16',
        '17',
        '27',
        '28',
        '29',
      ],
      powerGrade: '',
      value: 2,
      timeList: [],
      reportTargetAll: {},
      Content: '',
      number: '',
      successContent: '',
      reportContentsList1: [],
      reportContentsList2: [],
      reportContentsList3: [],
      updateReport: {},
      reportTarget: {},
      managerRemarkContent: '',
      isDiy: false,
      type: '-1',
      JZQuota: false,
      YFQuota: false, //应用服务
      GZdata: false,
      homePageIndicatorList: null,
    };
  },
  created() {
    this.powerGrade = localStorage.getItem('powerGrade');
    this.isDiy = localStorage.getItem('isDiy');
    this.getDetailById();
  },
  watch: {
    $route(to, from) {
      this.powerGrade = localStorage.getItem('powerGrade');
      this.isDiy = localStorage.getItem('isDiy');
      if (to.path == '/weeklyHistoricalDetils') {
        this.getDetailById();
      }
    },
  },
  methods: {
    openEnterpriseChat(val) {
      let loading1 = this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true,
      });
      let url = window.location.href;
      let that = this;
      let wx = this.wx;
      let qiyeData;
      var userIds = this.reportTarget.reportContents[0].createBy;
      const instance = axios.create();
      instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
      instance
        .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
          params: {
            url: url,
          },
        })
        .then((response) => {
          if (response.status == 200) {
            loading1.clear();
            qiyeData = response.data.data;
            wx.config({
              beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
              appId: qiyeData.appId, // 必填，企业微信的corpID
              timestamp: qiyeData.timestamp, // 必填，生成签名的时间戳
              nonceStr: qiyeData.nonceStr, // 必填，生成签名的随机串
              signature: qiyeData.signature, // 必填，签名，见 附录-JS-SDK使用权限签名算法
              jsApiList: ['ready', 'openEnterpriseChat'], // 必填，需要使用的JS接口列表，凡是要调用的接口都需要传进来
            });
            wx.ready(function () {
              wx.openEnterpriseChat({
                userIds: userIds,
                groupName: '我的红包群', // 会话名称。单聊时该参数传入空字符串""即可。localStorage.getItem("loginName")
                chatId: '', //CHATID 若要打开已有会话，需指定此参数。如果是新建会话，chatId必须为空串
                success: function (res) {
                  var chatId = res.chatId; //返回当前群聊ID，仅当使用agentConfig注入该接口权限时才返回chatId
                },
                fail: function (res) {
                  if (res.errMsg.indexOf('function not exist') > -1) {
                    alert('版本过低请升级');
                  }
                },
              });
            });
          } else {
            this.$toast.fail(dataList.msg);
          }
        });
    },
    formatter(value) {
      return value.replace(
        /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi,
        '',
      );
    },
    submint() {
      let loading1 = this.$toast.loading({
        duration: 0,
        message: '数据提交中...',
        forbidClick: true,
      });
      if (this.managerRemarkContent.trim() == '') {
        this.$toast('点评内容未填写');
        return false;
      }
      if (this.managerRemarkContent.length > 800) {
        this.$toast('点评内容超过800字');
        return false;
      }
      var remak = {
        remarkContent: this.managerRemarkContent,
        reportId: this.$route.query.reportId,
      };
      insertRemark(remak).then((res) => {
        loading1.clear();
        if (res.code == 200) {
          this.$dialog
            .alert({
              title: '系统提示',
              message: '提交成功',
            })
            .then(() => {
              this.managerRemarkContent = '';
              this.getDetailById();
            });
        } else {
          this.$toast.fail(res.msg);
        }
      });
    },
    getDetailById() {
      let loading1 = this.$toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true,
      });
      getDetailById({ reportId: this.$route.query.reportId }).then((res) => {
        loading1.clear();
        if (res.code == 200) {
          this.YFQuota = res.data.postType == 'YF' ? true : false;
          this.JZQuota = false;
          if (res.data.postType == 'JZ') {
            this.JZQuota = true;
          }
          if (res.data.postType == 'GZ') {
            this.GZdata = true;
          } else {
            this.GZdata = false;
          }
          this.homePageIndicatorList = res.data.homePageIndicatorList || null;
          var dayTime = res.data.date;
          this.type = res.data.userType;
          this.title =
            res.data.deptName + '-' + res.data.postName + '-' + res.data.nickName + '的周报';
          this.ptitle = res.data.pdeptName + '-' + res.data.ppostName + '-' + res.data.pnickName;
          this.timeList = this.parseTimeParagraph(
            dayTime.slice(0, 4) + '-' + dayTime.slice(4, 6) + '-' + dayTime.slice(6, 8),
          );
          this.reportTargetAll = res.data.reportTargetAll;
          this.reportTarget = res.data;
          this.reportContents = res.data.reportContents;
          var reportContentsList1 = [];
          var reportContentsList2 = [];
          var reportContentsList3 = [];
          var reportContentsdata = res.data.reportContents;
          if (res.data.status == 3) {
            this.successContent = res.data.successContent;
          } else {
            this.successContent = res.data.failContent;
          }
          for (var i = 0; i < reportContentsdata.length; i++) {
            if (reportContentsdata[i].type == '1') {
              reportContentsList1.push(reportContentsdata[i]);
            }
            if (reportContentsdata[i].type == '2') {
              reportContentsList2.push(reportContentsdata[i]);
            }
            if (reportContentsdata[i].type == '3') {
              reportContentsList3.push(reportContentsdata[i]);
            }
          }
          var ln1 = reportContentsList1.length;
          var ln2 = reportContentsList2.length;
          if (reportContentsList1.length < reportContentsList2.length) {
            var len2 = ln2 - ln1;
            for (var x = 0; x < len2; x++) {
              reportContentsList1.push({
                contentTime: '',
                weekContentAm: '',
                weekContentPm: '',
              });
            }
          }
          this.reportContentsList1 = reportContentsList1;
          this.reportContentsList2 = reportContentsList2;
          this.reportContentsList3 = reportContentsList3;
        }
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>
<style scoped>
.container {
  margin: 10px;
}
.container .van-collapse-item {
  margin-bottom: 10px;
  border-radius: 6px;
  overflow: hidden;
}
.linep p {
  margin: 14px 0 0 0;
  font-size: 14px;
  color: #666;
  padding-left: 6px;
}
.linep .texttitle {
  color: #0057ba;
  position: relative;
  padding-left: 10px;
  margin-top: 16px;
}
.linep .texttitledaily {
  color: #000;
  position: relative;
  padding-left: 10px;
}
.linep .texttitle2 {
  padding-left: 6px;
}
.linep .texttitle .opint {
  position: absolute;
  left: 0px;
  top: 6px;
  margin-right: 6px;
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 10px;
  background-color: #0057ba;
}
.linep .texttitledaily .opint {
  position: absolute;
  left: 0px;
  top: 6px;
  margin-right: 6px;
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 10px;
  background-color: #0057ba;
}
.leftTitle {
  background-color: #a6c9f1;
  color: #fff;
  display: inline-block;
  padding: 0 4px;
  border-radius: 2px;
}
.Btn1 {
  display: block;
  width: 100%;
  border-radius: 6px;
  color: #fff !important;
  background-color: #0057ba;
  border: 1px solid #0057ba;
  height: 44px;
}
.rightTitle {
  background-color: #ffb5bb;
  color: #fff;
  display: inline-block;
  padding: 0 4px;
  border-radius: 2px;
}
</style>
<style>
.linep .van-cell__title {
  color: #1e5398;
  font-weight: 500;
}
.linep .contentContainer {
  background-color: white;
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 10px;
}
.linep .contentContainer .contentContainerTitle {
  color: #222;
  margin-top: 10px;
}
.linep .contentContainer .contentContainerTitle span {
  font-size: 12px;
  color: #333;
}
.linep .contentContainer .van-field__control {
  background-color: #ebf4ff;
  padding: 10px;
  border-radius: 8px;
}
.linep .contentContainer .van-cell {
  padding: 0;
}
.van-dialog__confirm,
.van-dialog__confirm:active {
  color: #0057ba;
}
</style>
