<template>
  <div id="index">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" @back="back" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <list-1 :list="list" @toView="toView" @toCheck="toCheck" @toFile="toFile"></list-1>
      </template>
    </admin-frame>
    <van-dialog class="dialog" v-model="dialog.show" :title="dialog.title" :show-confirm-button="false" show-cancel-button cancel-button-text="返回">
      <info-1 v-if="dialog.type == '1'" :info="info"></info-1>
      <check-1 v-else-if="dialog.type == '2'" :form="form" @onSubmit="checkSubmit"></check-1>
      <file-1 v-else-if="dialog.type == '3'" :form="form" @onSubmit="onSubmitfile"></file-1>
    </van-dialog>
  </div>
</template>

<script>
import list1 from '@/layout/safe/list-1.vue';
import info1 from '@/layout/safe/info-1.vue';
import check1 from '@/layout/safe/check-1.vue';
import file1 from '@/layout/safe/file-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentsafeg } = createNamespacedHelpers('patentsafeg');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
    check1,
    file1,
  },
  data: function () {
    return {
      list: [],
      limit: 5,
      total: 0,
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 信息详情
      info: {},
      // 审核申请&文件上传
      form: {},
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patentsafeg(['query', 'check', 'update']),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 查看信息
    toView(data) {
      this.$set(this, `info`, data);
      let dialog = { show: true, title: '详细信息', type: '1' };
      this.$set(this, `dialog`, dialog);
    },
    // 审核审核
    toCheck(data) {
      this.$set(this, `form`, data);
      let dialog = { show: true, title: '审核申请', type: '2' };
      this.$set(this, `dialog`, dialog);
    },
    // 提交审核
    async checkSubmit({ data }) {
      let res = await this.check(data);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作成功` });
        this.search();
        let dialog = { show: false, title: '审核申请', type: '2' };
        this.$set(this, `dialog`, dialog);
      } else {
        this.$toast({ type: `error`, message: `${res.errmsg}` });
      }
    },
    // 上传文件
    toFile(data) {
      this.$set(this, `form`, data);
      let dialog = { show: true, title: '报告文件', type: '3' };
      this.$set(this, `dialog`, dialog);
    },
    // 提交报告文件
    async onSubmitfile(data) {
      data.status = '2';
      let res = await this.check(data);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作成功` });
        this.search();
        let dialog = { show: false, title: '报告文件', type: '3' };
        this.$set(this, `dialog`, dialog);
      } else {
        this.$toast({ type: `error`, message: `${res.errmsg}` });
      }
    },
    // 返回
    back() {
      this.$router.push({ path: '/patent/index' });
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.dialog {
  /deep/.van-dialog__content {
    max-height: 355px;
    overflow-y: auto;
  }
}
</style>
