main.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <el-select
  3. v-model="value"
  4. multiple
  5. filterable
  6. remote
  7. clearable
  8. collapse-tags
  9. :multiple-limit="1"
  10. reserve-keyword
  11. :size="size || 'medium'"
  12. style="width: 100%"
  13. :placeholder="placeholder || ''"
  14. :disabled="disabled"
  15. :remote-method="remoteMethod"
  16. :loading="selectLoading"
  17. @change="selectChange"
  18. >
  19. <el-option
  20. v-for="(item, index) in options"
  21. :key="item.id + index"
  22. :label="item.search"
  23. :value="item.id + ''"
  24. :disabled="item.status + '' !== '1'"
  25. >
  26. </el-option>
  27. </el-select>
  28. </template>
  29. <script>
  30. import asyncRequest from "@/apis/components/search-sort";
  31. import resToken from "@/mixins/resToken";
  32. export default {
  33. name: "SearchSort",
  34. mixins: [resToken],
  35. props: ["size", "value", "placeholder", "isDetail", "disabled", "names", "type"],
  36. /**
  37. * 属性集合
  38. * @param {String} size : 组件大小 非必填
  39. * @param {Array} value : 选中值 必填
  40. * @param {String} placeholder : 提示信息 非必填
  41. * @param {Boolean} isDetail : 是否是详情逻辑 必填
  42. * @param {Boolean} disabled : 是否禁用 必填
  43. * @param {String} names : 选中值label 展示详情必填
  44. * @param {String} type : 数据类型 非必填 1是平台供应商0非平台供应商
  45. */
  46. /**
  47. * 事件集合
  48. * @searchChange : 选中值变化调用 抛出选中数据
  49. */
  50. data() {
  51. return {
  52. options: [],
  53. selectLoading: false,
  54. searchName: "",
  55. };
  56. },
  57. watch: {
  58. names: function (val, old) {
  59. // console.log(val, old, this.isDetail, "1");
  60. this.searchName = val;
  61. if (this.isDetail && this.searchName) {
  62. this.remoteMethod(this.searchName);
  63. }
  64. },
  65. isDetail: function (val, old) {
  66. // console.log(val, old, this.isDetail, "2");
  67. if (val && this.searchName) {
  68. this.remoteMethod(this.searchName);
  69. }
  70. },
  71. },
  72. mounted() {
  73. this.options = [];
  74. this.selectLoading = false;
  75. },
  76. methods: {
  77. async selectChange(e) {
  78. if (e && e.length > 0) {
  79. let index = this.options.findIndex((v) => v.id + "" === e[0]);
  80. if (index !== -1) {
  81. let model = {
  82. pid: this.options[index].item[0] + "",
  83. id: this.options[index].id + "",
  84. code: this.options[index].id + "",
  85. label: this.options[index].search + "",
  86. cat_desc: this.options[index].cat_desc,
  87. item: this.options[index].item + "",
  88. };
  89. console.log(model);
  90. this.$emit("searchChange", model);
  91. } else {
  92. this.$emit("searchChange", {});
  93. }
  94. } else {
  95. this.$emit("searchChange", {});
  96. }
  97. },
  98. async remoteMethod(query) {
  99. this.selectLoading = true;
  100. if (query !== "") {
  101. this.options = [];
  102. let formValue = {
  103. page: 1,
  104. size: 100,
  105. search: query,
  106. cat_name: "",
  107. pid: "",
  108. status: "",
  109. };
  110. let res = await asyncRequest.list(formValue);
  111. if (res && res.code === 0 && res.data) {
  112. const { list } = res.data;
  113. this.options = list;
  114. } else if (res && res.code >= 100 && res.code <= 104) {
  115. await this.logout();
  116. } else {
  117. this.$message.warning(res.message);
  118. }
  119. } else {
  120. this.options = [];
  121. }
  122. this.selectLoading = false;
  123. },
  124. },
  125. };
  126. </script>
  127. <style></style>