<template>
  <div id="index">
    <admin-frame @search="search" :limt="limit" :total="total" topType="2" @back="back" @add="toAdd" :useNav="false">
      <template v-slot:info>
        <van-col span="24" class="one">
          <p>书面咨询请点右上方+</p>
          <p>联系电话：13944105166 18514329613</p>
        </van-col>
        <van-col span="24">
          <list-1 :list="list" @toView="toView" @toDel="toDel" @toRead="toRead"></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="返回">
      <info-1 :info="info" v-if="dialog.type == '1'"></info-1>
    </van-dialog>
  </div>
</template>

<script>
import list1 from '@/layout/question/list-1.vue';
import info1 from '@/layout/question/info-1.vue';
import adminFrame from '@frame/src/components/mobile-frame/mobile-main.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: problem_service } = createNamespacedHelpers('problem_service');
export default {
  name: 'index',
  props: {},
  components: {
    adminFrame,
    list1,
    info1,
  },
  data: function () {
    return {
      list: [],
      limit: 4,
      total: 0,
      dialog: { show: false, title: '详细信息', type: '1' },
      // 详细信息
      info: {},
    };
  },
  async created() {
    this.search();
  },
  methods: {
    ...problem_service(['query', 'update', 'delete']),
    async search({ skip = 0, limit = this.limit, ...info } = {}) {
      let res = await this.query({ skip, limit, ask_id: this.user.id, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 添加
    toAdd() {
      this.$router.push({ path: '/patent/user/chat/detail' });
    },
    // 查看信息
    toView(data) {
      this.$set(this, `info`, data);
      this.dialog = { show: true, title: '详细信息', type: '1' };
    },
    // 删除信息
    async toDel(data) {
      let res = await this.delete(data.id);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作完成` });
        this.search();
      }
    },
    // 已读
    async toRead(data) {
      data.status = '4';
      let res = await this.update(data);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作完成` });
        this.search();
      }
    },
    // 返回
    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 {
  background-color: #fff;
  text-align: center;
  font-size: 15px;
  color: #ff0000;
  padding: 8px 0;
  font-weight: bold;
  p:nth-child(1) {
    margin: 0 0 10px 0;
  }
}
.dialog {
  /deep/.van-dialog__content {
    max-height: 350px;
    overflow-y: auto;
  }
}
</style>
