TaskSearch.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <el-select v-model="selectedTaskCode" filterable :filter-method="taskDataFilter" @click.native="eqNoClick">
  3. <el-option
  4. v-for="task in searchTasks"
  5. :key="task.code"
  6. :label="task.name"
  7. :value="task.code"
  8. />
  9. </el-select>
  10. </template>
  11. <script>
  12. import Api from '@/js/api'
  13. import Http from '@/js/http'
  14. import {notify} from '@/constants'
  15. import {mapActions} from 'vuex'
  16. export default {
  17. name: 'TaskSearch',
  18. data: function () {
  19. return {
  20. tasks: [],
  21. searchTasks: [],
  22. selectedTaskCode: ''
  23. }
  24. },
  25. props: {
  26. firstSelectedTaskCode: {
  27. type: String,
  28. default: ''
  29. },
  30. selectedProjectCode: {
  31. type: String,
  32. default: ''
  33. },
  34. selectedCallback: {
  35. type: Function
  36. }
  37. },
  38. created () {
  39. this.selectedTaskCode = this.firstSelectedTaskCode
  40. this.setRefreshTaskListFunc(this.getSimpleTaskDatas)
  41. },
  42. watch: {
  43. 'selectedTaskCode': {
  44. immediate: false,
  45. handler: function () {
  46. if (this.selectedCallback) {
  47. this.selectedCallback(this.selectedTaskCode)
  48. }
  49. }
  50. }
  51. },
  52. methods: {
  53. ...mapActions(['setRefreshTaskListFunc']),
  54. taskDataFilter (val) {
  55. if (val) {
  56. this.searchTasks = this.tasks.filter(task => {
  57. return task.name.includes(val)
  58. })
  59. } else {
  60. this.searchTasks = this.tasks
  61. }
  62. },
  63. eqNoClick () {
  64. this.searchTasks = this.tasks
  65. },
  66. getSimpleTaskDatas (projectCode) {
  67. Http.get(Api.TASK.GET_SIMPLE_DATAS_BY_PROJECT.replace('{projectCode}', projectCode)).then((res) => {
  68. this.tasks = res.data
  69. this.searchTasks = res.data
  70. this.selectedTaskData = this.searchTasks.find(task => task.code === this.selectedTaskCode)
  71. if (!this.selectedTaskData) {
  72. this.selectedTaskData = this.tasks[0]
  73. this.selectedTaskCode = this.selectedTaskData.code
  74. }
  75. }).catch((error) => {
  76. notify('error', '获取任务列表数据失败:系统异常')
  77. })
  78. }
  79. }
  80. }
  81. </script>
  82. <style scoped>
  83. </style>