zjf
2023-03-08 51468f93275c2bcfcc7ad25bf05f3d6a079ff764
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
  <div :class="isProduct?'':'input-container'">
      <el-autocomplete
      ref="elautocomplete"
      v-model="state"
      :class="isProduct?'search-container':''"
      :fetch-suggestions="querySearchAsync"
      :placeholder="isProduct?'输入产品名称':'请输入内容'"
      :trigger-on-focus="false"
      @blur='blurInput'
      @select="handleSelect"
    ></el-autocomplete>
    </div>
</template>
<script type="text/javascript">
import { GetCustomerPageList } from '@/api/customermanagement/customerManage'
import { GetSalesChanceList } from '@/api/customermanagement/business'
import { GetContacterList } from '@/api/customermanagement/contacts'
import { GetAgreementList, GetManagementAgreementList } from '@/api/customermanagement/contract'
import { GetQuotationSheetList, GetManagementQuotationSheetList } from '@/api/customermanagement/offer'
import { GetOtherCustomerPageList, GetOtherSalesChanceList, GetOtherAgreementList } from '@/api/businessIntelligence/index'
export default {
  name: 'XhInputSelect', // 新建 multiple select
  components: {},
  data () {
    return {
      options: [],
      value: [],
      inputVal: '',
      list: [],
      states: [],
      allInfos: [],
      state: '',
      isSelect: false,
      timeout: null
    }
  },
  props: {
    arrayList: { // 下拉列表的数据
      type: Array
    },
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    },
    isProduct: {
      type: Boolean,
      default: true
    }
  },
  watch: {
    state: {
      handler (val) {
        console.log(val)
        this.$emit('getName', {'name': val})
      },
      deep: true,
      immediate: true
    }
  },
  mounted () {
    console.log(this.isProduct)
  },
  methods: {
    querySearchAsync (queryString, cb) {
      this.getList(queryString)
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        cb(this.allInfos)
      }, 3000 * Math.random())
    },
    handleSelect (item) {
      this.isSelect = true
      this.$emit('getName', {'name': item.value})
    },
    blurInput () {
      if (!this.isSelect) {
        console.log('blurrrrrrr')
        this.$emit('getName', {'name': this.state})
      }
    },
    resetInput () {
      this.state = ''
    },
    getList (query) {
      if (query !== '') {
        let params = []
        if (this.crmType === 'contract' || this.crmType === 'offers') {
          params = {
            'PageIndex': 1,
            'PageSize': 20,
            'SelectOwnedType': 0,
            'AuditStatus': 0,
            'SealStatus': 0,
            'Name': query,
            'CreateStartTime': '',
            'CreateEndTime': ''
          }
        } else if (this.crmType === 'sealContract' || this.crmType === 'sealOffers') {
          params = {
            'PageIndex': 1,
            'PageSize': 20,
            'DepartmentUserType': 0,
            'SelectOwnedType': 0,
            'AuditStatus': 0,
            'SealStatus': 0,
            'Name': query,
            'CreateStartTime': '',
            'CreateEndTime': ''
          }
        } else {
          params = {
            'PageIndex': 1,
            'PageSize': 20,
            'SelectOwnedType': 0,
            'Name': query,
            'CreateStartTime': '',
            'CreateEndTime': '',
            'StartFollowTime': '',
            'EndFolowTime': ''
          }
        }
        const request = {
          customer: GetCustomerPageList,
          business: GetSalesChanceList,
          contacts: GetContacterList,
          contract: GetAgreementList,
          offers: GetQuotationSheetList,
          sealContract: GetManagementAgreementList,
          sealOffers: GetManagementQuotationSheetList,
          businessCustomer: GetOtherCustomerPageList,
          businessContract: GetOtherAgreementList,
          businessChances: GetOtherSalesChanceList
        }[this.crmType]
        setTimeout(() => {
          if (!this.isProduct) {
            request(params)
              .then(res => {
                console.log(res)
                if (res.data.ErrorCode === 200) {
                  this.options = res.data.Result.List || []
                  this.allInfos = this.options.map((terminal) => {
                    if (this.crmType === 'customer' || this.crmType === 'businessCustomer') {
                      return {
                        value: terminal.CustomerName,
                        name: terminal.CustomerName
                      }
                    } else if (this.crmType === 'business' || this.crmType === 'businessChances') {
                      return {
                        value: terminal.ChanceName,
                        name: terminal.ChanceName
                      }
                    } else if (this.crmType === 'contacts') {
                      return {
                        value: terminal.ChanceName,
                        name: terminal.ChanceName
                      }
                    } else if (this.crmType === 'offers' || this.crmType === 'sealOffers') {
                      return {
                        value: terminal.QuotationName,
                        name: terminal.QuotationName
                      }
                    } else if (this.crmType === 'contract' || this.crmType === 'sealContract' || this.crmType === 'businessContract') {
                      return {
                        value: terminal.AgreeName,
                        name: terminal.AgreeName
                      }
                    }
                  })
                  console.log(this.allInfos)
                } else {
                  this.options = []
                  this.allInfos = []
                  this.$message.error(res.data.Message)
                }
              })
          }
        }, 300)
      } else {
        this.options = []
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.input-container {
    width: 224px;
    height: 32px;
    border-radius: 4px;
    margin-right: 40px
}
.search-container{
  width: 224px;
  height: 32px;
}
.search-container.el-autocomplete /deep/ .el-input__inner{
  height: 32px;
}
</style>