<template>
  <div id="service">
    <admin-frame @search="search" :limit="limit" :total="total" topType="2" @back="back" :rightArrow="false" :useNav="false">
      <template v-slot:info>
        <van-col span="24" class="one">
          <van-button type="info" size="small" @click="toSelect()">选择用户</van-button>
        </van-col>
        <van-col span="24" class="two">
          <list-1 :list="list"></list-1>
        </van-col>
      </template>
    </admin-frame>
    <van-dialog class="dialog" v-model="dialog.show" :title="dialog.title" :show-confirm-button="false" show-cancel-button cancel-button-text="返回">
      <search-user v-if="dialog.type == '1'" @conFirm="toConUser"></search-user>
    </van-dialog>
  </div>
</template>

<script>
import list1 from './parts/list-1.vue';
import searchUser from '@/layout/chatCommon/search-user.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: patentchat } = createNamespacedHelpers('patentchat');
export default {
  name: 'service',
  props: {},
  components: {
    adminFrame,
    list1,
    searchUser,
  },
  data: function () {
    return {
      list: [],
      limit: 5,
      total: 0,
      // 弹框
      dialog: { show: false, title: '查询用户', type: '1' },
    };
  },
  async created() {
    await this.search();
  },
  methods: {
    ...patentchat(['adminQuery']),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      info.id = this.user._id;
      let res = await this.adminQuery({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 选择用户
    toSelect() {
      let dialog = { show: true, title: '查询用户', type: '1' };
      this.$set(this, `dialog`, dialog);
    },
    // 确认选择
    toConUser(data) {
      console.log(data);
    },
    // 返回
    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;
  padding: 10px 0;
  background-color: #ffffff;
}
.dialog {
  /deep/.van-dialog__content {
    max-height: 350px;
    overflow-y: auto;
  }
}
</style>
