search.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view>
  3. <view class="search"><u-search placeholder="企业名称" v-model="companyName" :showAction="false" @search="getData()" @clear="clear()"></u-search></view>
  4. <view class="list">
  5. <view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
  6. <text>{{ item.companyName }}</text>
  7. <text class="icon">&#xe62b;</text>
  8. </view>
  9. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  10. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. list: [],
  19. companyName: '',
  20. param: { pageNum: 1, pageSize: 10 },
  21. loadMore: false
  22. };
  23. },
  24. watch: {
  25. companyName(val) {
  26. if (val.length > 3) {
  27. this.refresh();
  28. }
  29. }
  30. },
  31. methods: {
  32. getData() {
  33. this.http.request({
  34. url: '/app/company/list',
  35. data: { companyName: this.companyName },
  36. success: (res) => {
  37. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  38. res.data.rows.forEach((item) => {
  39. this.list.push(item);
  40. });
  41. }
  42. });
  43. },
  44. detail(item) {
  45. uni.showModal({
  46. title: '提示',
  47. content: '确定关联该企业?',
  48. success: (res) => {
  49. if (res.confirm) {
  50. this.http.request({
  51. url: '/app/relate/add',
  52. data: { companyId: item.id, way: '手动关联' },
  53. method: 'POST',
  54. success: (res) => {
  55. uni.showModal({
  56. title: '提示',
  57. content: '关联成功',
  58. showCancel: false,
  59. success: (res) => {
  60. uni.$emit('company');
  61. uni.navigateBack();
  62. }
  63. });
  64. }
  65. });
  66. }
  67. }
  68. });
  69. },
  70. clear() {
  71. this.list = [];
  72. },
  73. //刷新数据
  74. refresh() {
  75. this.loadMore = true;
  76. this.param.pageNum = 1;
  77. this.list = [];
  78. this.getData();
  79. }
  80. },
  81. //上拉加载
  82. onReachBottom() {
  83. if (this.loadMore) {
  84. this.param.pageNum++;
  85. this.getData();
  86. }
  87. }
  88. };
  89. </script>
  90. <style lang="scss">
  91. .search {
  92. padding: 12px 20px 12px 20px;
  93. background-color: white;
  94. }
  95. .list {
  96. .item {
  97. padding: 17px;
  98. background-color: white;
  99. margin-top: 10px;
  100. .icon {
  101. float: right;
  102. }
  103. }
  104. }
  105. </style>