main.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="project-manager">
  3. <el-select
  4. class="p-slesct"
  5. v-model="value"
  6. multiple
  7. filterable
  8. remote
  9. clearable
  10. collapse-tags
  11. :multiple-limit="1"
  12. reserve-keyword
  13. :size="size || 'medium'"
  14. placeholder="项目经理"
  15. :disabled="disabled"
  16. :remote-method="remoteMethod"
  17. :loading="selectLoading"
  18. @change="selectChange"
  19. >
  20. <el-option
  21. v-for="(item, index) in options"
  22. :key="item.id + index"
  23. :label="item.nickname"
  24. :value="item.id + ''"
  25. :disabled="item.status + '' !== '1'"
  26. />
  27. </el-select>
  28. <el-button :size="size || 'medium'" class="p-btn" @click="changeMe" :disabled="loading">选当前账号</el-button>
  29. </div>
  30. </template>
  31. <script>
  32. import asyncRequest from "@/apis/components/project-manager";
  33. import resToken from "@/mixins/resToken";
  34. import { mapGetters } from "vuex";
  35. export default {
  36. name: "ProjectManager",
  37. mixins: [resToken],
  38. computed: {
  39. ...mapGetters(["currentCompany"]),
  40. infoPowers() {
  41. return this.$store.getters.userInfo;
  42. }
  43. },
  44. props: ["size", "value", "isDetail", "disabled", "names"],
  45. /**
  46. * 属性集合
  47. * @param {String} size : 组件大小 非必填
  48. * @param {Array} value : 选中值 必填
  49. * @param {String} placeholder : 提示信息 非必填
  50. * @param {Boolean} isDetail : 是否是详情逻辑 必填
  51. * @param {Boolean} disabled : 是否禁用 必填
  52. * @param {String} names : 选中值label 展示详情必填
  53. * @param {String} type : 数据类型 非必填 1是平台供应商0非平台供应商
  54. */
  55. /**
  56. * 事件集合
  57. * @searchChange : 选中值变化调用 抛出选中数据
  58. */
  59. data() {
  60. return {
  61. loading: false,
  62. options: [],
  63. selectLoading: false,
  64. searchName: "",
  65. formValue: {
  66. page: 1,
  67. size: 99999,
  68. status: ""
  69. }
  70. };
  71. },
  72. watch: {
  73. names: function(val, old) {
  74. this.searchName = val;
  75. if (this.isDetail && this.searchName) {
  76. this.remoteMethod(this.searchName);
  77. }
  78. },
  79. isDetail: function(val, old) {
  80. if (val && this.searchName) {
  81. this.remoteMethod(this.searchName);
  82. }
  83. }
  84. },
  85. mounted() {
  86. this.options = [];
  87. this.selectLoading = false;
  88. },
  89. methods: {
  90. async changeMe() {
  91. if (this.loading) return;
  92. this.loading = true;
  93. const id = this.infoPowers.id ?? "";
  94. const userName = this.infoPowers.nickname ?? "";
  95. if (userName === "") {
  96. this.loading = false;
  97. this.$message.warning("当前账号异常,请重新登录!");
  98. return;
  99. }
  100. await this.getList(userName);
  101. let index = this.options.findIndex(s => s.id === id);
  102. if (index === -1) {
  103. this.loading = false;
  104. this.$message.warning("当前业务公司下,未找到当前账号!");
  105. return;
  106. }
  107. const model = {
  108. id: this.options[index].id + "",
  109. label: this.options[index].nickname
  110. };
  111. // console.log(model);
  112. this.$emit("searchChange", model);
  113. this.loading = false;
  114. },
  115. async selectChange(e) {
  116. if (e && e.length > 0) {
  117. const index = this.options.findIndex(v => v.id + "" === e[0]);
  118. if (index !== -1) {
  119. const model = {
  120. id: this.options[index].id + "",
  121. label: this.options[index].nickname
  122. };
  123. this.$emit("searchChange", model);
  124. } else {
  125. this.$emit("searchChange", {});
  126. }
  127. } else {
  128. this.$emit("searchChange", {});
  129. }
  130. },
  131. async remoteMethod(query) {
  132. if (query !== "") {
  133. await this.getList(query);
  134. } else {
  135. this.options = [];
  136. }
  137. },
  138. async getList(query) {
  139. if (this.selectLoading) return;
  140. this.selectLoading = true;
  141. this.options = [];
  142. const { code, data, message } = await asyncRequest.list({
  143. ...this.formValue,
  144. nickname: query,
  145. companyNo: this.currentCompany
  146. });
  147. if (code === 0) {
  148. const { list } = data;
  149. this.options = list;
  150. } else if (code >= 100 && code <= 104) {
  151. await this.logout();
  152. } else {
  153. this.$message.warning(message);
  154. }
  155. this.selectLoading = false;
  156. }
  157. }
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .project-manager {
  162. width: 100%;
  163. .p-btn {
  164. width: 80px;
  165. float: left;
  166. padding-left: 0;
  167. padding-right: 0;
  168. font-size: 12px;
  169. background-color: #f5f7fa;
  170. color: #909399;
  171. border: 1px solid #dcdfe6;
  172. border-left-width: 0;
  173. }
  174. .p-slesct {
  175. float: left;
  176. width: calc(100% - 80px);
  177. }
  178. }
  179. </style>