Timeline.vue 3.9 KB
<template>
  <el-dialog title="新增信息" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
    <div class="dialog-body">
      <el-timeline v-if="lineList.length">
        <el-timeline-item :timestamp="line.time" placement="top" v-for="(line, index) in lineList" :key="index"">
          <div class=" card-box">
          <div class="card-item" v-for="(card, cardIndex) in line.list"" :key="cardIndex">
            <div class=" card-content">运营{{ card.createdBy }}</div>
            <div class="card-content" v-if="card.opType == 0">原保管人:{{ card.oldCustodian }}</div>
            <div class="card-content">
              现保管人:{{ card.newCustodian }}<span v-if="card.opType == 1">派发时间:{{ card.disDate }}</span>
            </div>
            <div class="card-content" v-if="card.remark">备注:{{ card.remark }}</div>
            <div class="card-content">{{ card.createdTime }}</div>
            <div class="card-btn">

              {{ card.opType === 1 ? '新增' : '变更' }}
            </div>
          </div>
    </div>
    </el-timeline-item>
    </el-timeline>
    <div class="empty-box" v-else>
      <img src="@/assets/empty.png">
      <div class="empty-text">暂无记录</div>
    </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleClose">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script type="text/ecmascript-6">
import { Util } from "@/common/util"
import { findAllRecord } from "@api/tablet"
export default {
  name: 'Timeline',
  props: {
    dialogVisible: {
      type: Boolean,
      default: true
    },
    recordId: [Number, String]
  },
  data() {
    return {
      lineList: [{
        time: '2020-10-02',
        cardList: [1, 2, 3]
      }, {
        time: '2020-10-02',
        cardList: [1, 2, 3]
      }]
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.findAllRecord()
      }
    }
  },
  mounted() {

  },
  methods: {
    findAllRecord() {
      findAllRecord({ id: this.recordId }).then((res) => {
        const groupedByDisDate = res.reduce((acc, current) => {
          current.disDate = Util.dateFormate(current.disDate, "YYYY-MM-DD")
          current.createdTime = Util.dateFormate(current.createdTime, "YYYY-MM-DD HH:mm:ss")
          current.time = Util.dateFormate(current.createdTime, "YYYY-MM-DD")
          if (!acc[current.time]) {
            acc[current.time] = [];
          }
          acc[current.time].push(current);
          return acc;
        }, {});
        const result = Object.values(groupedByDisDate);

        console.log(groupedByDisDate);
        const resultWithListField = Object.keys(groupedByDisDate).map(time => ({
          time,
          list: groupedByDisDate[time]
        }));

        this.lineList = resultWithListField
      })
    },
    handleClose() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped lang="scss">
.dialog-body {
  max-height: calc(100vh - 400px);
  overflow-y: auto;

  .card-box {
    .card-item {
      width: 90%;
      padding: 12px;
      opacity: 1;
      border: 1px solid #e5e5e5;
      background: #ffffff6b;
      margin-bottom: 8px;
      position: relative;

      .card-btn {
        background: #e7eefe;
        line-height: 20px;
        text-align: center;
        position: absolute;
        width: 40px;
        height: 20px;
        border-radius: 2px;
        opacity: 1;
        background: #e7eefe;
        color: #185efe;
        font-size: 12px;
        right: 0px;
        top: 0px;
      }

      .card-content {
        color: #666666;
        font-size: 12px;
        line-height: 26px;

        span {
          margin-left: 20px;
        }
      }
    }
  }
}

.empty-box {
  text-align: center;

  img {
    width: 64px;
    height: 40px;
    margin-top: 100px;
  }

  .empty-text {
    color: #666666;
  }
}
</style>