main.vue 3.3 KB

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