zxl
2025-05-23 5d5b0f7ab0f34019e11901ddcd59cd8b51ea9ff9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
  <div>
    <div class="lum-dialog-mask" v-show="isShow">
      <el-container class="lum-dialog-box" v-outside="close">
        <el-header class="header" height="50px">
          <p>添加好友</p>
          <p class="tools">
            <i class="el-icon-close" @click="close" />
          </p>
        </el-header>
        <el-main class="main">
          <el-input
            v-model="mobile"
            id="serach-mobile"
            class="input"
            prefix-icon="el-icon-search"
            placeholder="请输入对方手机号(精确查找)"
            clearable
            @keyup.enter.native="onSubmit"
            @input="error = false"
          />
          <p v-show="error" class="error">
            无法找到该用户,请检查搜索内容并重试
          </p>
          <el-button
            type="primary"
            size="small"
            :loading="loading"
            @click="onSubmit"
            >立即查找
          </el-button>
        </el-main>
      </el-container>
    </div>
  </div>
</template>
<script>
import { ServeSearchContact } from '@/api/contacts'
 
export default {
  name: 'UserSearch',
  data() {
    return {
      loading: false,
      isShow: false,
      mobile: '',
      error: false,
    }
  },
  methods: {
    // 显示窗口
    open() {
      this.mobile = ''
      this.isShow = true
      this.$nextTick(() => {
        document.getElementById('serach-mobile').focus()
      })
    },
 
    // 关闭窗口
    close() {
      this.isShow = false
    },
 
    onSubmit() {
      let { mobile } = this
 
      if (mobile == '') return false
 
      this.loading = true
      ServeSearchContact({
        mobile,
      })
        .then(res => {
          if (res.code == 200) {
            this.$user(res.data.id)
            this.close()
          } else {
            this.error = true
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>
<style lang="less" scoped>
.lum-dialog-box {
  width: 450px;
  max-width: 450px;
  height: 250px;
 
  .main {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
 
    .input {
      width: 85%;
    }
 
    .error {
      width: 85%;
      color: red;
      font-size: 12px;
      height: 50px;
      line-height: 50px;
    }
 
    button {
      margin-top: 20px;
      width: 100px;
    }
  }
}
</style>