index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <el-select
  3. v-model="code"
  4. multiple
  5. filterable
  6. remote
  7. :multiple-limit="1"
  8. reserve-keyword
  9. :size="size"
  10. style="width: 100%"
  11. :placeholder="placeholder"
  12. :disabled="disabled"
  13. :remote-method="remoteMethod"
  14. :loading="selectLoading"
  15. @change="selectChange"
  16. >
  17. <el-option
  18. v-for="item in activeOptions"
  19. :key="item.code"
  20. :label="item.name"
  21. :value="item.code"
  22. />
  23. </el-select>
  24. </template>
  25. <script>
  26. import asyncRequest from "@/apis/caixiaoService/network/orderEntry";
  27. import asyncAoldRequest from "@/apis/aoldService/network/orderEntry";
  28. import resToken from "@/mixins/resToken";
  29. import { mapGetters } from "vuex";
  30. export default {
  31. name: "search-select",
  32. props: ["code", "placeholder", "size", "type", "isDetail", "disabled", "names"],
  33. computed: {
  34. ...mapGetters(["business_companyNo"]),
  35. },
  36. mixins: [resToken],
  37. data() {
  38. return {
  39. activeOptions: [],
  40. code: [],
  41. selectLoading: false,
  42. searchName: "",
  43. };
  44. },
  45. watch: {
  46. names: function (val) {
  47. this.searchName = val;
  48. if (this.isDetail && this.searchName) {
  49. this.remoteMethod(this.searchName);
  50. }
  51. },
  52. },
  53. created() {
  54. this.activeOptions = [];
  55. this.initForm();
  56. },
  57. methods: {
  58. async initForm() {
  59. this.selectLoading = false;
  60. },
  61. async selectChange() {
  62. this.$emit("end", this.code);
  63. },
  64. async remoteMethod(query) {
  65. this.selectLoading = true;
  66. if (query !== "") {
  67. this.activeOptions = [];
  68. let formValue = {
  69. page: 1,
  70. size: 50,
  71. name: query,
  72. company: query,
  73. };
  74. let res = {};
  75. const num = Number(this.type);
  76. if (this.business_companyNo === "1") {
  77. res = await asyncRequest[`list${num}`](num < 4 ? {} : formValue);
  78. } else {
  79. res = await asyncAoldRequest[`list${num}`](num < 4 ? {} : formValue);
  80. }
  81. if (num === 1) {
  82. delete formValue["name"];
  83. } else if (num === 2 || num === 3) {
  84. delete formValue["company"];
  85. }
  86. const { code, data, message } = res;
  87. if (code === 0) {
  88. this.activeOptions;
  89. let arr = [];
  90. if (this.type === "4") {
  91. arr = data;
  92. } else {
  93. const { list } = data;
  94. arr = list;
  95. }
  96. arr.forEach((v1) => {
  97. let item = {
  98. code:
  99. this.type === "1"
  100. ? v1.companyNo || ""
  101. : this.type === "2"
  102. ? v1.companyNo || ""
  103. : this.type === "3"
  104. ? v1.code || ""
  105. : v1.id || "",
  106. name:
  107. this.type === "1"
  108. ? v1.companyName || ""
  109. : this.type === "2"
  110. ? v1.company_name || ""
  111. : this.type === "3"
  112. ? v1.name || ""
  113. : v1.rate + "%" || "",
  114. };
  115. this.activeOptions.push(item);
  116. });
  117. } else if (code >= 100 && code <= 104) {
  118. await this.logout();
  119. } else {
  120. this.$message.warning(message);
  121. }
  122. } else {
  123. this.activeOptions = [];
  124. }
  125. this.selectLoading = false;
  126. },
  127. },
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. .search-select {
  132. }
  133. </style>