<template>
  <auth-wrap ref="authWrap">
    <view class="regmeeting-content-info-container" slot="content">
      <u-cell-group :border="false">
        <u-cell title="姓名" :label="meetingInfo.usrName">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="单位名称" :label="meetingInfo.orgUnitName">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="职务" :label="meetingInfo.uniLevel">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="联系电话" :label="meetingInfo.tel">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="邮箱" :label="meetingInfo.email">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="人员类型" :label="USR_TYPE[meetingInfo.usrType].name">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false"
                    v-if="rules.conferenceFlag && meetingInfo.conferenceFlag && [0,1].includes(meetingInfo.conferenceFlag)">
        <u-cell title="是否参加现场调研">
          <view
              slot="label"
          >
            <u-tag
                plain
                :text="SYS_YES_NO[meetingInfo.conferenceFlag].name"
                :type="meetingInfo.conferenceFlag == SYS_YES_NO['0'].value ? 'success' : 'warning'">
            </u-tag>
          </view>
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="rules.contentId && meetingInfo.contentTitle">
        <u-cell title="调研会场" :label="meetingInfo.contentTitle">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="rules.themeFlag">
        <u-cell title="是否参加主题研讨">
          <view
              slot="label"
          >
            <u-tag
                plain
                :text="SYS_YES_NO[meetingInfo.themeFlag].name"
                :type="meetingInfo.themeFlag == SYS_YES_NO['0'].value ? 'success' : 'warning'">
            </u-tag>
          </view>
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="rules.themeId && meetingInfo.themeTitle">
        <u-cell title="研讨主题" :label="meetingInfo.themeTitle">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="来程交通方式" :label="TFC_TYPE[meetingInfo.wayComing].name">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="meetingInfo.comInfo && meetingInfo.wayComing!='3'">
        <u-cell :title="TFC_INFO[meetingInfo.wayComing].name" :label="meetingInfo.comInfo">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="回程交通方式" :label="TFC_TYPE[meetingInfo.wayBack].name">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="meetingInfo.backInfo  && meetingInfo.wayBack!='3'">
        <u-cell :title="TFC_INFO[meetingInfo.wayBack].name" :label="meetingInfo.backInfo">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="备注" :label="meetingInfo.remark">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false">
        <u-cell title="审核状态">
          <view
              slot="label"
          >
            <u-tag
                plain
                :text="REVIEW_STATUS[meetingInfo.reviewState].name"
                :color="REVIEW_STATUS[meetingInfo.reviewState].color"
                :borderColor="REVIEW_STATUS[meetingInfo.reviewState].color"
            >
            </u-tag>
          </view>
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-if="REVIEW_STATUS.noPass.value == meetingInfo.reviewState">
        <u-cell title="不通过原因" :label="meetingInfo.reviewMsg">
        </u-cell>
      </u-cell-group>
      <u-cell-group :border="false" v-for="(item,index) in meetingInfo.follows" :key="index">
        <u-cell :border="false" :title="`随行人员${index+1}`" :label="item.usrName">
        </u-cell>
        <u-cell title="联系电话" :label="item.tel">
        </u-cell>
      </u-cell-group>
      <view style="margin-top: 20px">
        <rich-text
            v-if="REVIEW_STATUS[meetingInfo.reviewState]"
            :content="tips[REVIEW_STATUS[meetingInfo.reviewState].tip].content">
        </rich-text>
      </view>

      <view class="u-page__button-item">
        <u-button
            :disabled="[REVIEW_STATUS.pass.value].includes(meetingInfo.reviewState)"
            text="重新申请"
            size="normal"
            type="primary"
            @click="onRegistClick"
        ></u-button>
      </view>
    </view>
  </auth-wrap>
</template>

<script>
import { fetchMeetingTips, fetchUsrApplyDetail, formCfg } from '@/common/api';
import { FORM_MOD, MEETING_TYPE, REVIEW_STATUS, SYS_YES_NO, TFC_INFO, TFC_TYPE, USR_TYPE } from '@/common/EnumConst';
import AuthWrap from '@/components/AuthComp/index.vue';
import RichText from '@/components/RichText/index.vue';
import { setStorageObj, storageKey } from '@/util';

export default {
  name: 'content',
  components: {
    RichText,
    AuthWrap,
  },
  props: {},
  data() {
    return {
      SYS_YES_NO,
      REVIEW_STATUS,
      USR_TYPE,
      MEETING_TYPE,
      TFC_INFO,
      TFC_TYPE,
      meetingInfo: {},
      tips: {},
      rules: {},
    };
  },
  created() {

  },
  onLoad(res) {
    // 登录返回之后的页面
    if (res) {
      this.queryParams = res;
    }
    this.getRules(() => {
      this.getUsrMeetingInfo();
      this.getTips();
    });
  },
  onUnload() {
    let pages = getCurrentPages();//获取所有界面栈的实例列表
    let prePage = pages[pages.length - 2];//上一个界面的实例
    prePage.onLoad();
  },
  methods: {
    async getRules(callback) {
      const { msg } = await formCfg('meet_form_cfg');
      if (msg) {
        const cfg = JSON.parse(msg);
        const formatCfg = {};
        Object.keys(cfg).forEach(key => {
          formatCfg[key.split('.')[1]] = cfg[key];
        });
        this.rules = formatCfg;
      }
      callback();
    },
    async getUsrMeetingInfo() {
      const { data } = await fetchUsrApplyDetail(this.queryParams.id);
      if (!data) {
        return;
      }
      this.meetingInfo = data;
    },
    async getTips() {
      const { data } = await fetchMeetingTips();
      if (!data) {
        return;
      }
      const result = {};
      data.forEach((item) => {
        result[item.id] = item;
      });
      this.tips = result;
    },
    onRegistClick() {
      if (this.meetingInfo.applyType == MEETING_TYPE.meeting.value) {
        uni.navigateTo({
          url: `/pasb/pages/regist/index?mode=${FORM_MOD.modify}&apply=${this.meetingInfo.id}`,
        });
        return;
      }
      setStorageObj(storageKey.regtheme, {
        id: this.meetingInfo.contentId,
        mode: 'mod',
        apply: this.meetingInfo.id,
      });
      uni.navigateTo({
        url: `/pasbrg/pages/regtheme/index?mode=${FORM_MOD.modify}&apply=${this.meetingInfo.id}`,
      });
    },
  },
};
</script>
<style lang="scss" src="./index.scss" />;
