<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 type="info" size="small" @click="toView(item)">详细信息</van-button>
            <template v-if="user.role == '1'">
              <van-button type="info" size="small" @click="download(item.agent_url)">申请文件</van-button>
              <van-button type="info" size="small" @click="toAccept(item)" v-if="item.status == '2' || item.status == '5'">受理</van-button>
              <van-button type="info" size="small" @click="gzjSubmit(item)" v-if="item.status == '6'">确认上传</van-button>
            </template>
            <template v-else-if="user.role == '2'">
              <van-button type="info" size="small" @click="download(item.check_url)">审查文件</van-button>
              <van-button type="info" size="small" @click="fileCheck(item)" v-if="item.status == '0'">文件审批</van-button>
              <van-button size="small" type="info" v-if="item.status == '7'" @click="toGzj(item)">国知局反馈信息</van-button>
            </template>
            <template v-else-if="user.role == '3'">
              <!-- <van-button size="small" type="info" v-if="item.status == '7'" @click="toGzj(item)">国知局反馈信息</van-button> -->
              <van-button type="info" size="small" @click="toResult(item)">审核结果</van-button>
              <van-button type="info" size="small" @click="toHeavy(item)" v-if="item.status == '-1'">重申</van-button>
              <van-button type="info" size="small" @click="selectMech(item)" v-if="item.status == '1' || item.status == '-4' || item.status == '-6'"
                >选择代理机构</van-button
              >
            </template>
            <template v-else-if="user.role == '4'">
              <van-button size="small" type="info" v-if="item.status == '7'" @click="toGzj(item)">国知局反馈信息</van-button>
              <!-- <van-button type="info" size="small" @click="toResult(item)">审核结果</van-button> -->
              <van-button type="info" size="small" @click="download(item.agent_url)">申请文件</van-button>
              <van-button type="info" size="small" @click="toAccept(item)" v-if="item.status == '3'">受理</van-button>
              <van-button type="info" size="small" @click="toOneself(item, '-5')" v-if="item.status == '4'">自行上报</van-button>
              <van-button type="info" size="small" @click="toOneself(item, '5')" v-if="item.status == '4'">科企上报</van-button>
              <van-button type="info" size="small" @click="toHeavy(item)" v-if="item.status == '-6'">重申</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);
    },
    // 科企受理
    toAccept(data) {
      this.$emit('toAccept', data);
    },
    // 机构文件审批
    fileCheck(data) {
      this.$emit('fileCheck', data);
    },
    // 用户查看审核结果
    toResult(data) {
      this.$emit('toResult', data);
    },
    // 用户重申
    toHeavy(data) {
      this.$emit('toHeavy', data);
    },
    // 用户选择代理机构
    selectMech(data) {
      this.$emit('selectMech', data);
    },
    // 确认上传国知局
    gzjSubmit(data) {
      this.$emit('gzjSubmit', data);
    },
    // 代理机构自行上报
    toOneself(data, status) {
      this.$emit('toOneself', { data, status });
    },
    // 国知局反馈信息
    toGzj(data) {
      this.$emit('toGzj', 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' || status == '3') return '已选机构，待受理';
      else if (status == '4') return '代理机构已受理';
      else if (status == '-4') return '代理机构拒绝受理';
      else if (status == '5') return '代理机构推送科企机构，待科企机构受理';
      else if (status == '-5') return '代理机构自行上报';
      else if (status == '6') return '机构已受理，待上报国知局';
      else if (status == '-6') return '机构未受理，请重新选择机构';
      else if (status == '7') 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>
