<template>
  <div id="info-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="one">
          <van-form>
            <van-field v-model="info.name" name="name" label="问题名称" readonly />
            <van-field v-model="info.ask_name" name="ask_name" label="发问人" readonly />
            <van-field v-model="info.ask_date" name="ask_date" label="发问时间" readonly />
            <van-field v-model="info.ask_explain" name="ask_explain" label="问题说明" autosize type="textarea" rows="1" readonly />
            <van-field v-model="info.answer_name" name="answer_name" label="答题人" readonly />
            <van-field v-model="info.answer_date" name="answer_date" label="答题时间" readonly />
            <van-field v-model="info.answer_explain" name="ask_explain" label="答题说明" autosize type="textarea" rows="1" readonly />
            <van-col span="24" class="btn">
              <van-button type="info" size="small" @click="download(info.ask_file)">问题文件下载</van-button>
              <van-button type="info" size="small" @click="download(info.answer_file)" v-if="info.status == '3' || info.status == '4'">答案文件下载</van-button>
            </van-col>
          </van-form>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
export default {
  name: 'info-1',
  props: {
    info: { type: Object },
  },
  components: {},
  data: function () {
    return {};
  },
  created() {},
  methods: {
    onSubmit() {
      this.$emit('onSubmit', { data: this.info });
    },
    // 下载文件
    download(data) {
      if (data && 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: `非正常文件，无法下载` });
      }
    },
  },
  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 {
    .btn {
      text-align: center;
      margin: 10px 0;
      .van-button {
        margin: 0 10px;
      }
    }
  }
}
</style>
