execCntIndex.vue 9.61 KB
<route lang="yaml">
    name: execCntIndex
  </route>

<script lang="ts" setup name="execCntIndex">
import { changeNum } from '@/utils/common'
import {
  getContractStatis,
  getContractMonthStatis,
  getLogTableList
} from "@/api/modules/dataSmartContract";
import * as echarts from 'echarts';
import { commonPageConfig } from '@/utils/enum';

const { proxy } = getCurrentInstance() as any;
const detailInfo: any = ref({});

const logTableInfo: any = ref({
  id: "plan-detail-table",
  loading: false,
  // height: 'auto',
  // minPanelHeight: '60px',
  // minHeight: '60px',
  // maxHeight: '250px',
  fields: [
    { label: "序号", type: "index", width: 56, align: "center", fixed: true },
    { label: "合约标识", field: "contractId", width: 355 },
    { label: "合约名称", field: "contractName", width: 140 },
    { label: "执行策略id", field: "strategyId", width: 260 },
    { label: "执行时间", field: "operationTime", width: 170 },
    { label: "执行节点标识", field: "executionEntityId", width: 180 },
    { label: "上报时间", field: "operationTime", width: 170 },
    { label: "异常类型", field: "executionResult", width: 120 },
  ],
  data: [],
  page: {
    type: "normal",
    rows: 0,
    ...commonPageConfig,
  },
  actionInfo: {
    show: false
  }
});

const pageChange = (info) => {
  logTableInfo.value.page.curr = Number(info.curr);
  logTableInfo.value.page.limit = Number(info.limit);
  getLogTableListData(true);
};

const getLogTableListData = (isPage = false) => {
  isPage && (logTableInfo.value.loading = true);
  return getLogTableList({
    pageIndex: logTableInfo.value.page.curr,
    pageSize: logTableInfo.value.page.limit,
  }).then((res: any) => {
    logTableInfo.value.loading = false;
    if (res?.code == proxy.$passCode) {
      const data = res.data || {};
      logTableInfo.value.data = data.records || []
      logTableInfo.value.page.limit = data.pageSize
      logTableInfo.value.page.curr = data.pageIndex
      logTableInfo.value.page.rows = data.totalRows
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg)
    }
  })
}

let barChart: any = null;

const barChartData: any = ref([]);

onMounted(() => {
  barChart = echarts.init(document.getElementById('bar'));
  setBarChartOption(barChart);
})

watch(() => barChartData.value, (val) => {
  setBarChartOption(barChart);
}, {
  deep: true
})

/** 设置柱形图option,默认只 展示12次的 */
const setBarChartOption = (barChart) => {
  return new Promise((resolve, reject) => {
    if (!barChartData.value || !Object.keys(barChartData.value).length) {
      let option1 = {
        title: [
          {
            text: "",
            left: "30px",
            top: "30px",
          },
          {
            text: "暂无数据",
            left: "center",
            top: "center",
            textStyle: {
              fontFamily: 'SimSun',
              fontStyle: "normal",
              fontWeight: "400",
              fontSize: 18,
              color: '#999'
            },
          },
        ],
      };
      barChart.setOption(option1, true);
      window.addEventListener("resize", () => {
        barChart.resize();
      });
      return;
    }
    let getLast12Months = () => {
      const months: any = [];
      const currentDate = new Date();

      for (let i = 11; i >= 0; i--) {
        const targetDate = new Date(currentDate);
        targetDate.setMonth(targetDate.getMonth() - i);

        const year = targetDate.getFullYear();
        const month = String(targetDate.getMonth() + 1).padStart(2, '0');

        months.push(`${year}-${month}`);
      }

      return months;
    }

    // 使用示例
    const last12Months = getLast12Months();

    let itemXAxisData: any = last12Months;
    let itemYAxisData: any = last12Months.map(v => {
      return barChartData.value[v] || 0;
    });
    let option = {
      textStyle: {
        fontFamily: 'SimSun'
      },
      color: ['#5B8FF9', '#FF4E00', '#867EEC', '#FDBC3E', '#F48A64', '#276FF5', '#46D0B5'],
      title: {
        show: false,
        left: '30px',
        top: '30px',
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          crossStyle: {
            color: '#999'
          }
        },
        textStyle: {
          align: 'left'
        },
      },
      legend: {
        show: false,
        right: 0,
        textStyle: {
          fontSize: 14
        },
      },
      grid: {
        left: 30,
        right: 60,
        bottom: 5,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        nameTextStyle: {
          color: '#000000'
        },
        axisLabel: {
          interval: 'auto',
          textStyle: {
            color: '#000000'
          },
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          lineStyle: {
            color: '#d9d9d9'
          }
        },
        data: itemXAxisData
      },
      yAxis: {
        type: 'value',
        name: '',
        min: 0,
        minInterval: 1,
        nameTextStyle: {
          color: '#000000'
        },
        axisLabel: {
          textStyle: {
            color: '#000000'
          }
        },
        axisLine: {
          //y轴
          show: false
        }
      },
      series: [{
        name: '已签署合约数',
        type: 'line',
        data: itemYAxisData,
        label: {
          show: false,
        },
        tooltip: {
          valueFormatter: function (value) {
            return changeNum(value, 0);
          }
        },
        yAxisIndex: 0
      }]
    };
    option && barChart.setOption(option, true);
    barChart.on('finished', () => {
      resolve(true);
    });
    window.addEventListener('resize', () => {
      barChart.resize();
    });
  });
}

const fullscreenloading = ref(false);

onBeforeMount(() => {
  fullscreenloading.value = true;
  let ps1 = getContractStatis().then((res: any) => {
    if (res?.code == proxy.$passCode) {
      detailInfo.value = res.data || {};
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg)
    }
  })
  let ps2 = getContractMonthStatis().then((res: any) => {
    if (res?.code == proxy.$passCode) {
      barChartData.value = res.data || {};
    } else {
      res?.msg && proxy.$ElMessage.error(res?.msg)
    }
  })
  let ps3 = getLogTableListData();
  Promise.all([ps1, ps2, ps3]).then(() => {
    fullscreenloading.value = false;
  }).catch(() => {
    fullscreenloading.value = false;
  })
})

</script>

<template>
  <div class="content-main" v-loading="fullscreenloading">
    <div class="title">合约备案执行统计</div>
    <div class="kpi-content">
      <div class="border-content">
        <span class="text">备案合约数</span>
        <span class="number num-color">{{ detailInfo.registerNum != null ? changeNum(detailInfo.registerNum ?? 0) : '--'
          }}<span class="unit" v-show="detailInfo.registerNum != null"></span></span>
      </div>
      <div class="border-content ml16">
        <span class="text">备案策略数</span>
        <span class="number num-color">{{ detailInfo.registerPolicyNum != null ? changeNum(detailInfo.registerPolicyNum
          ?? 0) : '--'
        }}<span class="unit" v-show="detailInfo.registerPolicyNum != null"></span></span>
      </div>
      <div class="border-content ml16">
        <span class="text">策略执行数</span>
        <span class="number num-color">{{ detailInfo.registerPolicyExecutionNum != null ?
          (changeNum(detailInfo.registerPolicyExecutionNum ?? 0)) :
          '--'
        }}<span class="unit" v-show="detailInfo.registerPolicyExecutionNum != null"></span></span>
      </div>
      <div class="border-content ml16">
        <span class="text">签署合约主体数</span>
        <span class="number num-color">{{ detailInfo.registerSignatureNum != null ?
          changeNum(detailInfo.registerSignatureNum ?? 0) : '--'
        }}<span class="unit" v-show="detailInfo.registerSignatureNum != null"></span></span>
      </div>
      <div class="border-content ml16">
        <span class="text">策略执行节点数</span>
        <span class="number num-color">{{ detailInfo.registerExecutionNodeNum != null ?
          changeNum(detailInfo.registerExecutionNodeNum ?? 0) : '--'
        }}<span class="unit" v-show="detailInfo.registerExecutionNodeNum != null"></span></span>
      </div>
    </div>
    <div class="title">合约履行异常预警记录</div>
    <Table class="table-h" :tableInfo="logTableInfo" @tablePageChange="pageChange" />
    <div class="title">近12个月备案合约趋势</div>
    <div class="content-chart-bar" id="bar">
    </div>
  </div>
</template>

<style lang="scss" scoped>
.content-main {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0px 16px 16px;
}

.title {
  line-height: 24px;
  font-size: 16px;
  color: #212121;
  font-weight: 600;
  margin-top: 12px;
  margin-bottom: 8px;
}

.kpi-content {
  display: flex;
  flex-direction: row;
}

.border-content {
  height: 76px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-left: 16px;
  justify-content: center;
  border: 1px solid #d9d9d9;
  //width: 160px;
  flex: 1;
  min-width: 150px;
  border-radius: 2px;

  .number {
    line-height: 30px;
    font-weight: 700;
    font-size: 20px;

    .unit {
      font-size: 18px;
      font-weight: 400;
    }
  }

  .num-color {
    color: #212121;
  }

  .text {
    font-size: 14px;
    color: #666666;
    display: flex;

    .el-icon {
      color: #b2b2b2;
    }
  }
}

.ml16 {
  margin-left: 16px;
}

.content-chart-bar {
  height: 300px;
  border: 1px solid #d9d9d9;
  padding: 8px;
}

.table-h {
  height: 300px !important;
}
</style>