<template>
  <BasicModal centered v-bind="$attrs" @register="registerModal" title="查看详情" :showCancelBtn="false" :showOkBtn="false">
    <Card class="daily-article">
      <CardMeta :title="content.titile" :description="'发布人：' + content.sender + ' 发布时间： ' + content.sendTime" />
      <Divider />
      <span v-html="content.msgContent" class="article-content"></span>

      <div>
        <c-button v-if="hasHref" @click="jumpToHandlePage">前往办理<ArrowRightOutlined /></c-button>
      </div>
    </Card>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { BasicModal, useModalInner } from '@jdlinker/ui';
  import { ArrowRightOutlined } from '@ant-design/icons-vue';
  import { useRouter } from 'vue-router';
  import xss from 'xss';
  import { ref, unref } from 'vue';
  import { Card, CardMeta, Divider } from 'ant-design-vue';

  const router = useRouter();
  const isUpdate = ref(true);
  const content = ref<any>({});
  //表单赋值
  const [registerModal, { closeModal }] = useModalInner(async (data) => {
    isUpdate.value = !!data?.isUpdate;
    if (unref(isUpdate)) {
      if (data.record.msgContent) {
        data.record.msgContent = xss(data.record.msgContent);
      }
      content.value = data.record;
      showHrefButton();
    }
  });

  const hasHref = ref(false);
  //查看消息详情可以跳转
  function showHrefButton() {
    if (content.value.busId) {
      hasHref.value = true;
    }
  }
  //跳转至办理页面
  function jumpToHandlePage() {
    let temp: any = content.value;
    if (temp.busId) {
      //这个busId是 任务ID
      let jsonStr = temp.msgAbstract;
      let query = {};
      try {
        if (jsonStr) {
          let temp = JSON.parse(jsonStr);
          if (temp) {
            Object.keys(temp).map((k) => {
              query[k] = temp[k];
            });
          }
        }
      } catch (e) {
        console.log('参数解析异常', e);
      }

      console.log('query', query, jsonStr);
      console.log('busId', temp.busId);

      if (Object.keys(query).length > 0) {
        router.push({ path: '/task/MyTaskList/' + temp.busId, query: query });
      } else {
        router.push({ path: '/task/MyTaskList/' + temp.busId });
      }
    }
    closeModal();
  }
</script>

<style scoped lang="less">
  .detail-iframe {
    border: 0;
    width: 100%;
    height: 100%;
    min-height: 600px;
  }
</style>
