selectAutoSelect.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <script setup lang="ts">
  2. import { ref, watch } from 'vue'
  3. import IconDropDown from '@/components/IconDropDown'
  4. interface TypeItem {
  5. partyType: ''
  6. partyname: []
  7. }
  8. interface ListItem {
  9. value: string
  10. label: string
  11. }
  12. interface dateoptions {
  13. value: string
  14. label: string
  15. }
  16. interface Props {
  17. AddDateType: TypeItem[]
  18. ASPlaceholder: string
  19. DateTypeoptions: dateoptions[]
  20. selectedPartyTypeoptions: Array<string>
  21. ASSearchMode: String
  22. ASSearchObj: Object
  23. }
  24. interface optionsItem {
  25. value: string
  26. label: string
  27. }
  28. const list = ref<ListItem[]>([])
  29. const options = ref<ListItem[]>([])
  30. const loading = ref(false)
  31. const props = withDefaults(defineProps<Props>(), {})
  32. const AddType = ref(props.AddDateType)
  33. watch(
  34. () => props.AddDateType,
  35. (val) => {
  36. AddType.value = val
  37. },
  38. {
  39. immediate: true,
  40. deep: true
  41. }
  42. )
  43. // const ErrorNumber = ref(0)
  44. const dataTypeoptions = ref<optionsItem[]>([])
  45. const typeSelectIndex = ref(-1)
  46. watch(
  47. () => props.selectedPartyTypeoptions,
  48. (newV) => {
  49. let arr: any = []
  50. if (newV.length == 0) {
  51. arr = props.DateTypeoptions
  52. } else {
  53. props.DateTypeoptions.forEach((item: any) => {
  54. let index = newV.findIndex((con: any) => {
  55. return con == item.value
  56. })
  57. if (index < 0) {
  58. arr.push(item)
  59. }
  60. })
  61. }
  62. dataTypeoptions.value = arr
  63. },
  64. {
  65. immediate: true,
  66. deep: true
  67. }
  68. )
  69. const ErrorNumber = ref(true)
  70. const str = ref()
  71. const search_field = ref()
  72. const InputAutoSelect = (val: any) => {
  73. search_field.value = val
  74. if (val.includes('Agent')) {
  75. str.value = 'apex'
  76. } else {
  77. str.value = 'sales'
  78. }
  79. }
  80. const remoteMethod = (query: string) => {
  81. if (query) {
  82. loading.value = true
  83. setTimeout(() => {
  84. $api
  85. .getMoreFiltersData({
  86. term: query,
  87. type: str.value,
  88. search_field: search_field.value,
  89. search_mode: props.ASSearchMode,
  90. ...props.ASSearchObj
  91. })
  92. .then((res: any) => {
  93. if (res.code == 200) {
  94. loading.value = false
  95. list.value = res.data.map((item: any) => {
  96. return { value: item, label: item }
  97. })
  98. options.value = list.value.filter((item) => {
  99. return item.label.toLowerCase().includes(query.toLowerCase())
  100. })
  101. }
  102. })
  103. }, 200)
  104. } else {
  105. options.value = []
  106. }
  107. }
  108. // 删除当前more type
  109. const deleteType = (i: any) => {
  110. emit('delSelect', i, AddType.value[i].partyType)
  111. AddType.value.splice(i, 1)
  112. }
  113. // 选中type改变
  114. const changeSelect = (val: any) => {
  115. emit('changeAutoSelectAddType', typeSelectIndex.value, val)
  116. }
  117. // 选中name改变
  118. const emit = defineEmits(['changeAutoSelectAddType', 'delSelect', 'changeAutoSelect'])
  119. let AutoSelectObj: any = {}
  120. let AutoSelectObj2: any = {}
  121. const changeAutoSelect = (val: any, value: any) => {
  122. AutoSelectObj[val] = value.join()
  123. AutoSelectObj2[val] = value
  124. if (value.length) {
  125. ErrorNumber.value = true
  126. } else {
  127. ErrorNumber.value = false
  128. }
  129. emit('changeAutoSelect', AutoSelectObj, AutoSelectObj2, ErrorNumber.value)
  130. }
  131. const typeSelectFocus = (index: any, e: any) => {
  132. typeSelectIndex.value = index
  133. }
  134. const typeSelectBlur = () => {
  135. typeSelectIndex.value = -1
  136. let arr: any = []
  137. if (props.selectedPartyTypeoptions.length == 0) {
  138. arr = props.DateTypeoptions
  139. } else {
  140. props.DateTypeoptions.forEach((item: any) => {
  141. let index = props.selectedPartyTypeoptions.findIndex((con: any) => {
  142. return con == item.value
  143. })
  144. if (index < 0) {
  145. arr.push(item)
  146. }
  147. })
  148. }
  149. dataTypeoptions.value = arr
  150. }
  151. const typeSelectClick = (index: any, val: any) => {
  152. if (AddType.value[index].partyType) {
  153. let j = props.DateTypeoptions.findIndex((item: any) => {
  154. return item.value == AddType.value[index].partyType
  155. })
  156. let i = dataTypeoptions.value.findIndex((item: any) => {
  157. return item.value == AddType.value[index].partyType
  158. })
  159. if (i < 0) {
  160. dataTypeoptions.value.push(props.DateTypeoptions[j])
  161. }
  162. } else {
  163. let arr: any = []
  164. if (props.selectedPartyTypeoptions.length == 0) {
  165. arr = props.DateTypeoptions
  166. } else {
  167. props.DateTypeoptions.forEach((item: any) => {
  168. let index = props.selectedPartyTypeoptions.findIndex((con: any) => {
  169. return con == item.value
  170. })
  171. if (index < 0) {
  172. arr.push(item)
  173. }
  174. })
  175. }
  176. dataTypeoptions.value = arr
  177. }
  178. }
  179. </script>
  180. <template>
  181. <div class="AddType" v-for="(item, index) in AddType" :key="index">
  182. <div>
  183. <div class="Date_Title">
  184. <div class="ETD_title">Party Type</div>
  185. <span class="iconfont_icon" @click="deleteType(index)">
  186. <svg class="iconfont icon_delete" aria-hidden="true">
  187. <use xlink:href="#icon-icon_delete_b"></use>
  188. </svg>
  189. </span>
  190. </div>
  191. <el-select
  192. v-model="AddType[index].partyType"
  193. :suffix-icon="IconDropDown"
  194. @blur="typeSelectBlur"
  195. class="testname"
  196. @focus="typeSelectFocus(index, $event)"
  197. @click="typeSelectClick(index, $event)"
  198. @change="changeSelect(AddType[index].partyType)"
  199. placeholder="Please Select Party Type"
  200. >
  201. <el-option
  202. v-for="item in dataTypeoptions"
  203. :key="item.value"
  204. :label="item.label"
  205. :value="item.value"
  206. >
  207. </el-option>
  208. </el-select>
  209. </div>
  210. <div style="margin-top: 16px">
  211. <div class="ETD_title">Party Details</div>
  212. <el-select
  213. v-model="AddType[index].partyname"
  214. multiple
  215. filterable
  216. remote
  217. :class="{
  218. is_error: AddType[index].partyType != '' && AddType[index].partyname.length == 0
  219. }"
  220. reserve-keyword
  221. :placeholder="props.ASPlaceholder"
  222. collapse-tags
  223. @input="InputAutoSelect(AddType[index].partyType)"
  224. @change="changeAutoSelect(AddType[index].partyType, AddType[index].partyname)"
  225. :disabled="AddType[index].partyType ? false : true"
  226. collapse-tags-tooltip
  227. :max-collapse-tags="3"
  228. :remote-method="remoteMethod"
  229. :loading="loading"
  230. >
  231. <el-option
  232. v-for="item in options"
  233. :key="item.value"
  234. :label="item.label"
  235. :value="item.value"
  236. >
  237. <el-checkbox :checked="AddType[index].partyname?.includes(item.value)"></el-checkbox>
  238. <div class="label">{{ item.value }}</div>
  239. </el-option>
  240. </el-select>
  241. <div
  242. class="error"
  243. v-if="AddType[index].partyType != '' && AddType[index].partyname.length == 0"
  244. >
  245. Please Input Party Details
  246. </div>
  247. </div>
  248. </div>
  249. </template>
  250. <style lang="scss" scoped>
  251. .AddType {
  252. background-color: var(--addparties-background-color);
  253. margin: 0 16px 8px 16px;
  254. padding: 8px;
  255. border-radius: var(--border-radius-6);
  256. }
  257. .ETD_title {
  258. font-size: var(--font-size-2);
  259. color: var(--color-neutral-2);
  260. }
  261. .Date_Title {
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. }
  266. .icon_delete {
  267. fill: var(--color-danger);
  268. cursor: pointer;
  269. }
  270. .el-select-dropdown__item.is-selected {
  271. div {
  272. color: var(--badge__content--warning);
  273. }
  274. background-color: transparent;
  275. }
  276. .el-select-dropdown__item {
  277. padding-left: 7.7px;
  278. display: flex;
  279. align-items: center;
  280. }
  281. .label {
  282. margin-left: 8px;
  283. }
  284. .el-select-dropdown__item.is-hovering {
  285. div {
  286. color: var(--badge__content--warning);
  287. }
  288. }
  289. .is_error {
  290. :deep(.el-select__wrapper) {
  291. box-shadow: 0 0 0 0.5px var(--color-danger);
  292. }
  293. }
  294. .error {
  295. font-size: 12px;
  296. color: var(--color-danger);
  297. line-height: 14px;
  298. margin-top: 5px;
  299. }
  300. </style>