main.vue 3.2 KB

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