<template>
  <div id="list-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="list" v-for="(item, index) in list" :key="index">
          <van-col span="24" class="name">
            {{ getName(item) }}
          </van-col>
          <van-col span="24" class="other">
            <van-col span="24" class="otherInfo"> 发送时间：{{ item.send_time || '暂无' }} </van-col>
            <van-col span="24" class="otherInfo textOver"> 发送内容：{{ item.type == '1' ? item.content : '文件' }} </van-col>
          </van-col>
          <van-col span="24" class="btn">
            <van-button type="info" size="small" @click="detail(item)">查看消息</van-button>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'list-1',
  props: {
    list: { type: Array },
  },
  components: {},
  data: function () {
    return {
      otherInfo: {},
    };
  },
  created() {},
  methods: {
    detail(data) {
      if (data.sender_id == this.user._id) {
        this.$set(this, `otherInfo`, { sender_id: data.receiver_id, sender_name: data.receiver_name });
      } else {
        this.$set(this, `otherInfo`, { sender_id: data.sender_id, sender_name: data.sender_name });
      }
      this.$router.push({ path: '/patent/admin/message/service_detail', query: { ...this.otherInfo } });
    },
    // 整理名称
    getName(data) {
      if (data.sender_id == this.user._id) return data.receiver_name;
      else return data.sender_name;
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding: 8px 8px 0 8px;
  .list {
    background-color: #fff;
    margin: 0 0 8px 0;
    padding: 8px;
    border-radius: 5px;
    .title {
      font-size: 16px;
      font-weight: bold;
      margin: 0 0 5px 0;
    }
    .other {
      margin: 0 0 5px 0;
      .otherInfo {
        font-size: 14px;
        color: #666;
        margin: 0 0 5px 0;
        span {
          color: #000;
        }
      }
    }
    .btn {
      text-align: center;
      .van-button {
        margin: 0 5px;
      }
    }
  }
}
</style>
