<template>
  <div id="trans">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" @add="toAdd" @back="back" :useNav="false">
      <template v-slot:info>
        <van-col span="24" class="one">
          <van-button type="info" size="small" @click="toImport()">导入交易信息</van-button>
        </van-col>
        <span span="24" class="two">
          <list-1 :list="list" @toView="toView" @toDel="toDel"></list-1>
        </span>
      </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>
    </van-dialog>
  </div>
</template>

<script>
import list1 from '@/layout/trans/list-1.vue';
import info1 from '@/layout/trans/info-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patenttrans } = createNamespacedHelpers('patenttrans');
export default {
  name: 'trans',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
  },
  data: function () {
    return {
      list: [],
      limit: 4,
      total: 0,
      // 弹框
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patenttrans(['query', 'delete']),
    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);
    },
    // 删除信息
    async toDel(data) {
      let res = await this.delete(data.id);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作完成` });
        this.search();
      }
    },
    // 导入专利
    toImport() {
      this.$router.push({ path: '/patent/admin/patent/trans_import' });
    },
    // 添加
    toAdd() {
      this.$router.push({ path: '/patent/admin/patent/trans_create' });
    },
    // 返回
    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>
.one {
  text-align: center;
  margin: 8px 0;
  .van-button {
    margin: 0 5px 5px 0;
  }
  p {
    font-size: 16px;
    margin: 5px 0 0 0;
    span {
      color: #000;
      font-weight: bold;
    }
  }
}
.dialog {
  /deep/.van-dialog__content {
    max-height: 350px;
    overflow-y: auto;
  }
}
</style>
