<template>
  <div class="card">
    <div class="card-title">{{ data.form[title.name] }}</div>
    <div class="card-main">
      <div class="card-content">
        <template v-for="item in fields">
          <div class="p-item" :key="item.name">
            <div class="p-title">{{ item.label }}：</div>
            <div class="p-content">{{ data.form[item.name] }}</div>
          </div>
        </template>
        <div class="p-item">
          <div class="p-title">审核状态：</div>
          <div class="p-content" :class="{ 'is-red': notPass }">
            {{ statusText }}
          </div>
        </div>
        <div class="p-item">
          <div class="p-title">审核时间：</div>
          <div class="p-content">
            {{ data.approve_time1 || data.approve_time2 }}
          </div>
        </div>
        <div class="p-item" v-if="data.remark1 || data.remark2">
          <div class="p-title">备注：</div>
          <div class="p-content is-red">
            {{ data.remark1 || data.remark2 }}
          </div>
        </div>
      </div>
      <div class="card-aside">
        <div class="card-status" v-if="isPass">
          <div class="icon-seal"></div>
        </div>
        <div class="card-tools" v-if="!isPass">
          <div class="card-button" @click="onEdit">编辑</div>
          <div class="card-button" @click="onRemove">删除</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Card',
  props: {
    data: Object,
    title: {
      type: Object,
      default() {
        return {}
      }
    },
    fields: {
      type: Array,
      default() {
        return []
      }
    }
  },
  computed: {
    statusText() {
      const map = {
        '-1': '待审核',
        '0': '未通过',
        '1': '通过',
        '2': '通过',
        '3': '未通过',
        '4': '通过'
      }
      return map[this.data.status]
    },
    isPass() {
      return [1, 2, 4].includes(this.data.status)
    },
    notPass() {
      return [0, 3].includes(this.data.status)
    }
  },
  methods: {
    onEdit() {
      this.$router.push({
        name: 'edit',
        query: Object.assign({}, this.$route.query, { view_id: this.data.id })
      })
    },
    onRemove() {
      this.$emit('remove', this.data)
    }
  }
}
</script>
<style lang="scss" scoped>
.card {
  margin: 15px 0 20px;
  padding: 10px 20px 20px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 3px 15px 0px rgba(0, 0, 0, 0.06);
}
.is-red {
  color: #ab2824 !important;
}
.card-title {
  font-size: 15px;
  color: #333;
}
.p-item {
  margin-top: 10px;
  display: flex;
}
.p-title {
  font-size: 12px;
  color: #999;
}
.p-content {
  font-size: 12px;
  color: #333;
}
.card-main {
  display: flex;
}
.card-content {
  flex: 1;
  overflow: hidden;
}
.card-aside {
  width: 60px;
  margin-left: 20px;
  display: flex;
  flex-direction: column;
}
.card-status {
  flex: 1;
  .icon-seal {
    margin-left: -10px;
    width: 90px;
    height: 70px;
    background: url('~@/assets/img/icon_seal.png') no-repeat;
    background-size: contain;
  }
}
.card-tools {
  padding: 10px 0 0 0;
}
.card-button {
  margin-top: 18px;
  width: 60px;
  height: 25px;
  font-size: 12px;
  line-height: 25px;
  text-align: center;
  color: #999;
  border-radius: 5px;
  border: 1px solid rgba(153, 153, 153, 1);
  cursor: pointer;

  &:first-child {
    margin-top: 0;
  }
}
</style>
