<template>
  <div id="search-user">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="one">
          <van-col span="24" class="one_1">
            <van-search v-model="searchName" show-action placeholder="请输入联系电话" @search="searchUser">
              <template #action>
                <div @click="searchUser">搜索</div>
              </template>
            </van-search>
          </van-col>
          <van-col span="24" class="one_2">
            <van-col span="24" class="list" v-for="(item, index) in list" :key="index">
              <van-col span="24" class="name"> {{ item.name }} </van-col>
              <van-col span="24" class="other">
                <van-col span="24" class="otherInfo">
                  联系电话:<span>{{ item.phone }}</span>
                </van-col>
              </van-col>
              <van-col span="24" class="btn">
                <van-button type="info" size="mini" @click="conFirm(item)">确认选择</van-button>
              </van-col>
            </van-col>
            <van-col span="24" class="page">
              <page @search="searchUser" :limit="limit" :total="total"></page>
            </van-col>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: personal } = createNamespacedHelpers('personal');
export default {
  name: 'search-user',
  props: {},
  components: {},
  data: function () {
    return {
      searchName: '',
      list: [],
      limit: 2,
      total: 0,
    };
  },
  created() {},
  methods: {
    ...personal({ personalQuery: 'query' }),
    // 查询用户
    async searchUser({ skip = 0, limit = this.limit, ...info } = {}) {
      if (this.searchName) info.phone = this.searchName;
      let res = await this.personalQuery({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
      }
    },
    // 确认选择
    conFirm(data) {
      this.$router.push({ path: '/patent/admin/message/service_detail', query: { sender_id: data.id, sender_name: data.name } });
    },
  },
  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 {
    .one_2 {
      .list {
        border-bottom: 1px dashed #ccc;
        margin: 0 0 8px 0;
        padding: 0 8px 5px 8px;
        .name {
          font-size: 16px;
          margin: 0 0 5px 0;
        }
        .other {
          margin: 0 0 5px 0;
          .otherInfo {
            font-size: 14px;
            color: #666;
            span {
              color: #000;
            }
          }
        }
        .btn {
          text-align: center;
        }
      }
    }
  }
}
</style>
