search.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. list: [],
  17. companyName: ''
  18. };
  19. },
  20. watch: {
  21. companyName(val) {
  22. if (val.length > 3) {
  23. this.getData();
  24. }
  25. }
  26. },
  27. methods: {
  28. getData() {
  29. this.http.request({
  30. url: '/app/company/list',
  31. data: { companyName: this.companyName },
  32. success: (res) => {
  33. this.list = res.data.data;
  34. }
  35. });
  36. },
  37. detail(item) {
  38. uni.showModal({
  39. title: '提示',
  40. content: '确定关联该企业?',
  41. success: (res) => {
  42. if (res.confirm) {
  43. this.http.request({
  44. url: '/app/relate/add',
  45. data: { companyId: item.id, way: '手动关联' },
  46. method: 'POST',
  47. success: (res) => {
  48. uni.showModal({
  49. title: '提示',
  50. content: '关联成功',
  51. showCancel: false,
  52. success: (res) => {
  53. uni.$emit('company');
  54. uni.navigateBack();
  55. }
  56. });
  57. }
  58. });
  59. }
  60. }
  61. });
  62. },
  63. clear() {
  64. this.list = [];
  65. }
  66. }
  67. };
  68. </script>
  69. <style lang="scss">
  70. .search {
  71. padding: 12px 20px 12px 20px;
  72. background-color: white;
  73. }
  74. .list {
  75. .item {
  76. padding: 17px;
  77. background-color: white;
  78. margin-top: 10px;
  79. .icon {
  80. float: right;
  81. }
  82. }
  83. }
  84. </style>