<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="title textOver">
            {{ item.name }}
          </van-col>
          <van-col span="24" class="other">
            <van-col span="24" class="otherInfo">
              专利类型：<span>{{ item.type || '暂无' }}</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 size="small" type="info" @click="toView(item)">详细信息</van-button>
            <template v-if="user.role == '1'">
              <van-button size="small" type="info" @click="toCheck(item)" v-if="item.status == '0'">申请审核</van-button>
              <van-button size="small" type="info" @click="toFile(item)" v-if="item.status == '1'">报告文件</van-button>
            </template>
            <template v-else-if="user.role == '3'">
              <van-button size="small" type="info" @click="toResult(item)">审核结果</van-button>
              <van-button size="small" type="info" @click="download(item.file)" v-if="item.status == '2'">报告文件</van-button>
            </template>
          </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 {};
  },
  created() {},
  methods: {
    // 查看信息
    toView(data) {
      this.$emit('toView', data);
    },
    // 查看结果
    toResult(data) {
      this.$emit('toResult', data);
    },
    // 申请审核
    toCheck(data) {
      this.$emit('toCheck', data);
    },
    // 报告文件
    toFile(data) {
      this.$emit('toFile', data);
    },
    // 下载文件
    download(data) {
      if (data.length > 0) {
        let url = data.map((i) => i.url);
        window.location.href = `${process.env.VUE_APP_HOST}${url[0]}`;
      } else {
        this.$toast({ type: `fail`, message: `非正常文件，无法下载` });
      }
    },
    // 整理状态
    getStu(status) {
      if (status == '0') return '待审中';
      else if (status == '1') return '审核通过，待发报告文件';
      else if (status == '-1') return '审核未通过！';
      else if (status == '2') 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 {
  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>
