<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.patent_name }}
          </van-col>
          <van-col span="24" class="other">
            <van-col span="12" class="otherInfo">
              申请号：<span>{{ item.create_number || '暂无' }}</span>
            </van-col>
            <van-col span="12" 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="danger" size="small" @click="toDel(item)">刪除信息</van-button>
            </template>
            <template v-else-if="user.role == '2'">
              <van-button type="info" size="small" @click="toExamine(item)" v-if="item.status == '0'">交易审核</van-button>
              <van-button type="info" size="small" @click="toContact(item)" v-if="item.status == '2'">合同审核</van-button>
              <van-button type="info" size="small" @click="toCheck(item)" v-if="item.status == '4'">交易归档</van-button>
            </template>
            <template v-else-if="user.role == '3'">
              <van-button type="info" size="small" @click="toResult(item)" v-if="item.status == '-1'">审核结果</van-button>
              <van-button type="info" size="small" @click="toHeavy(item)" v-if="item.status == '-1'">重申交易</van-button>
              <van-button type="danger" size="small" @click="toRevoke(item)" v-if="item.status == '1'">撤回交易</van-button>
              <van-button type="info" size="small" @click="toContract(item)" v-if="item.status == '1' || item.status == '-3'">填写合同</van-button>
              <van-button type="info" size="small" @click="toEndtrans(item)" v-if="item.status == '1'">结束交易</van-button>
              <van-button type="info" size="small" @click="toConfirm(item)" v-if="item.status == '3'">用户确认</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);
    },
    // 重申交易
    toHeavy(data) {
      this.$emit('toHeavy', data);
    },
    // 撤回交易
    toRevoke(data) {
      this.$emit('toRevoke', data);
    },
    // 填写合同
    toContract(data) {
      this.$emit('toContract', data);
    },
    // 结束交易
    toEndtrans(data) {
      this.$emit('toEndtrans', data);
    },
    // 用户确定
    toConfirm(data) {
      this.$emit('toConfirm', data);
    },
    // 交易审核
    toExamine(data) {
      this.$emit('toExamine', data);
    },
    // 合同审核
    toContact(data) {
      this.$emit('toContact', data);
    },
    // 交易归档
    toCheck(data) {
      this.$emit('toCheck', data);
    },
    // 刪除信息
    toDel(data) {
      this.$emit('toDel', data);
    },
    // 整理状态
    getStu(data) {
      if (data == '0') return '待审中';
      else if (data == '1') return '审核通过';
      else if (data == '-1') return '审核拒绝';
      else if (data == '2') return '合同待审中';
      else if (data == '3') return '交易合同审核通过，待用户确认';
      else if (data == '-3') return '交易合同审核拒绝';
      else if (data == '4') return '用户已确认';
      else if (data == '5') 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: 0 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 8px;
      }
    }
  }
}
</style>
