<template>
  <div id="list-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col :span="24" class="one">
          <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.create_number || '暂无' }}</span>
              </van-col>
              <van-col span="24" class="otherInfo">
                状态：<span>{{ getStu(item.status) }}</span>
              </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="toCheck(item)" v-if="item.status == '0'">审核申请</van-button>
                  <van-button type="info" size="small" @click="toFile(item)" v-if="item.status == '1'">报告文件</van-button>
                </template>
                <template v-if="user.role == '3'">
                  <van-button type="info" size="small" @click="toResult(item)">审核结果</van-button>
                  <van-button type="info" size="small" @click="download(item.file)" v-if="item.status == '2'">报告文件</van-button>
                </template>
              </van-col>
            </van-col>
          </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);
    },
    // 下載報告
    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: `未上传文件` });
      }
    },
    // 管理员
    // 审核申请
    toCheck(data) {
      this.$emit('toCheck', data);
    },
    // 报告文件
    toFile(data) {
      this.$emit('toFile', data);
    },
    // 状态
    getStu(data) {
      if (data == '0') return '待审中';
      else if (data == '1') return '审核通过，请等待报告文件';
      else if (data == '-1') return '审核未通过';
      else if (data == '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 {
  .one {
    .list {
      background-color: #fff;
      margin: 0 0 10px 0;
      box-shadow: 0 0 5px #f1f1f1;
      padding: 8px;
      .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 8px;
        }
      }
    }
  }
}
</style>
