main.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <el-select
  3. v-model="value"
  4. :size="size || 'medium'"
  5. style="width: 100%"
  6. filterable
  7. :placeholder="placeholder || ''"
  8. :disabled="disabled"
  9. :loading="selectLoading"
  10. @change="selectChange"
  11. >
  12. <el-option
  13. v-for="(item, index) in options"
  14. :key="item.rate + index + ''"
  15. :label="item.rate + '%'"
  16. :value="item.rate + '%'"
  17. :disabled="item.status === '0'"
  18. />
  19. </el-select>
  20. </template>
  21. <script>
  22. import asyncRequest from "@/apis/components/search-tax";
  23. import resToken from "@/mixins/resToken";
  24. export default {
  25. name: "SearchTax",
  26. mixins: [resToken],
  27. props: [
  28. "size",
  29. "value",
  30. "placeholder",
  31. "isDetail",
  32. "disabled",
  33. "type",
  34. "names",
  35. ],
  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. */
  45. /**
  46. * 事件集合
  47. * @searchChange : 选中值变化调用 抛出选中数据
  48. */
  49. data() {
  50. return {
  51. options: [],
  52. selectLoading: false,
  53. searchName: "",
  54. };
  55. },
  56. // watch: {
  57. // names: function (val, old) {
  58. // // console.log(val, old);
  59. // this.searchName = val;
  60. // if (this.isDetail && this.searchName) {
  61. // this.remoteMethod(this.searchName);
  62. // }
  63. // },
  64. // },
  65. mounted() {
  66. this.options = [];
  67. this.selectLoading = false;
  68. this.remoteMethod();
  69. },
  70. methods: {
  71. async selectChange(e) {
  72. // console.log(e);
  73. let index = this.options.findIndex((v) => v.rate + "%" === e);
  74. if (index !== -1) {
  75. let model = {
  76. id: this.options[index].rate,
  77. code: this.options[index].rate,
  78. label: this.options[index].rate+"%",
  79. };
  80. this.$emit("searchChange", model);
  81. } else {
  82. this.$emit("searchChange", {});
  83. }
  84. },
  85. async remoteMethod() {
  86. this.selectLoading = true;
  87. const { code, data, message } = await asyncRequest.list({});
  88. if (code === 0) {
  89. this.options = data;
  90. } else if (code >= 100 && code <= 104) {
  91. await this.logout();
  92. } else {
  93. this.$message.warning(message);
  94. }
  95. this.selectLoading = false;
  96. },
  97. },
  98. };
  99. </script>
  100. <style>
  101. </style>