<template>
  <div id="list-1">
    <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="title">
          {{ item.name }}
        </van-col>
        <van-col span="24" class="other">
          <van-col span="24" class="otherInfo">
            发问时间：<span>{{ item.ask_date || '暂无' }}</span>
          </van-col>
          <van-col span="24" class="otherInfo">
            答题时间：<span>{{ item.answer_date || '暂无' }}</span>
          </van-col>
          <van-col span="24" class="otherInfo">
            问题状态：<span>{{ getStu(item.status) }}</span>
          </van-col>
        </van-col>
        <van-col span="24" class="btn">
          <van-button type="info" size="small" @click="toView(item)">查看信息</van-button>
          <template v-if="user.role == '1'">
            <van-button type="info" size="small" @click="toAssign(item)" v-if="item.status == '0'">工作分派</van-button>
            <van-button type="info" size="small" @click="toIssue(item)" v-if="item.status == '2'">答案下发</van-button>
          </template>
          <template v-if="user.role == '3'">
            <van-button type="danger" size="small" @click="toDel(item)">删除信息</van-button>
            <van-button type="info" size="small" @click="toRead(item)" v-if="item.status == '3'">信息已读</van-button>
          </template>
          <template v-if="user.role == '5'">
            <van-button type="info" size="small" @click="toUpload(item)" v-if="item.status == '1'">答案上传</van-button>
          </template>
        </van-col>
      </van-col>
    </van-col>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'list-1',
  props: {
    list: { type: Array },
  },
  components: {},
  data: function () {
    return {};
  },
  created() {},
  methods: {
    // 公共
    // 查看信息
    toView(data) {
      this.$emit('toView', data);
    },
    // 个人用户
    // 删除信息
    toDel(data) {
      this.$emit('toDel', data);
    },
    // 信息已读
    toRead(data) {
      this.$emit('toRead', data);
    },
    // 管理員
    // 工作分派
    toAssign(data) {
      this.$emit('toAssign', data);
    },
    // 答题老师
    //答案上传
    toUpload(data) {
      this.$emit('toUpload', data);
    },
    // 答案下发
    toIssue(data) {
      this.$emit('toIssue', data);
    },
    // 整理状态
    getStu(data) {
      if (data == '0') return '待受理';
      else if (data == '1') return '已分配,待作答';
      else if (data == '2') return '已作答，待下发';
      else if (data == '3') return '已下发，待阅读';
      else if (data == '4') return '已阅读';
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .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 {
      .otherInfo {
        font-size: 14px;
        color: #666;
        margin: 0 0 5px 0;
        span {
          color: #000;
        }
      }
    }
    .btn {
      text-align: center;
      .van-button {
        margin: 0 10px;
      }
    }
  }
}
</style>
