search.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div style="background: #fff;">
  3. <van-nav-bar title="选择项目" left-text="返回" @click-left="back()" fixed left-arrow/>
  4. <van-search v-model="value" placeholder="请输入项目名称" @clear="sea()" @blur="sea()" @search="sea()" style="margin-top: 45px;"/>
  5. <!-- <van-radio-group v-model="checkeds">
  6. <div v-for="item in project" :key="item.id" class="prejectList">
  7. <van-radio :name="item">{{item.projectName}}</van-radio>
  8. </div>
  9. </van-radio-group> -->
  10. <div class="list" v-for="item in project" :key="item.id" @click="addts(item)">{{item.projectName}}</div>
  11. <div v-if="project.length == 0" class="adds">暂无数据</div>
  12. <div style="width: 100%;height: 44px;"></div>
  13. <!-- <div class="qued" @click="qued()">确定</div>
  14. -->
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. props: {},
  20. components: {},
  21. data() {
  22. return {
  23. value: '',
  24. project: '',
  25. checkeds: '',
  26. pro: '',
  27. from: '',
  28. idx: 0,
  29. dingshiqiL: null
  30. };
  31. },
  32. computed: {},
  33. watch: {
  34. '$route': 'getParams',
  35. value(val) {
  36. var that = this
  37. if(that.dingshiqiL) {
  38. clearTimeout(that.dingshiqiL)
  39. }
  40. that.dingshiqiL = setTimeout(() => {
  41. that.sea()
  42. }, 500)
  43. }
  44. },
  45. created() {
  46. this.getParams()
  47. },
  48. mounted() {
  49. this.getPeoject()
  50. },
  51. methods: {
  52. // 接收传过来的参数
  53. getParams() {
  54. const routerParams = this.$route.query.from
  55. const idx = this.$route.query.idx
  56. this.from = routerParams
  57. this.idx = idx
  58. },
  59. // 获取项目
  60. getPeoject() {
  61. this.$axios.post("/project/getProjectList", {})
  62. .then(res => {
  63. if(res.code == "ok") {
  64. this.project = res.data;
  65. this.pro = res.data
  66. console.log(res.data)
  67. } else {
  68. this.$toast.fail('获取失败:'+res.msg);
  69. }
  70. }).catch(err=> {this.$toast.clear();});
  71. },
  72. back() {
  73. this.$router.go(-1);
  74. },
  75. addts(item) {
  76. this.checkeds = item
  77. this.qued()
  78. },
  79. qued() {
  80. console.log(this.checkeds)
  81. if(this.checkeds == '') {
  82. this.$toast('请选择项目');
  83. } else {
  84. this.from.domains[this.idx].projectId = this.checkeds.id
  85. this.from.domains[this.idx].projectName = this.checkeds.projectName
  86. localStorage.setItem('formVal', JSON.stringify(this.from))
  87. this.$router.go(-1);
  88. }
  89. },
  90. sea() {
  91. console.log(1234567)
  92. if(this.value.length > 0) {
  93. let text = this.value
  94. let reg = new RegExp(text)
  95. let data = this.project.filter(item => reg.test(item.projectName)) //返回
  96. this.project = data
  97. } else {
  98. this.project = this.pro
  99. }
  100. },
  101. },
  102. };
  103. </script>
  104. <style>
  105. .prejectList {
  106. padding: 10px 20px;
  107. background: #fff;
  108. border-bottom: 1px solid #f6f6f6;
  109. }
  110. .van-search {
  111. background: #fff !important;
  112. border-bottom: 1px solid #f6f6f6;
  113. }
  114. .van-search__content {
  115. border-radius: 20px !important;
  116. }
  117. .qued {
  118. width: 100%;
  119. height: 44px;
  120. background: #1989fa;
  121. text-align: center;
  122. line-height: 44px;
  123. color: #fff;
  124. position: fixed;
  125. left: 0;
  126. bottom: 0;
  127. }
  128. .adds {
  129. width: 100%;
  130. text-align: center;
  131. line-height: 85px;
  132. color: #b6b6b6;
  133. }
  134. .list {
  135. padding: 15px 20px;
  136. border-bottom: 1px solid #f6f6f6;
  137. }
  138. </style>