hiddenCompany.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="hidden-management">
  3. <nav-bar title="屏蔽管理"></nav-bar>
  4. <view class="search-bar flex align-center justify-between">
  5. <view class="search-input flex align-center">
  6. <image src="@/static/images/svg/search.svg" class="search-icon"></image>
  7. <input v-model="searchValue" type="text" placeholder="输入的是一个公司的名称,全模糊搜索" class="input" />
  8. </view>
  9. <view class="search-btn" @click="getData">搜索</view>
  10. </view>
  11. <view class="content">
  12. <scroll-view :scroll-y="true" class="scroll-view">
  13. <view class="scroll-wrapper">
  14. <view class="company-item" v-for="company in companys" :key="company.companyId">
  15. <u-checkbox
  16. v-model="company.checked"
  17. :name="company.companyId"
  18. @change="checkboxChange"
  19. >{{company.companyName}}</u-checkbox>
  20. </view>
  21. </view>
  22. </scroll-view>
  23. </view>
  24. <view class="button-section">
  25. <view class="submit-btn" @click="handleSave">屏蔽所选公司({{ selectCount }})</view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import navBar from '@/components/nav-bar/index.vue'
  31. export default {
  32. components: {
  33. navBar
  34. },
  35. data() {
  36. return {
  37. searchValue: '',
  38. selectCount: 0,
  39. companys: [],
  40. selectCompanyIds: [],
  41. selectCompanyList: [],
  42. searching: false,
  43. loading: false
  44. };
  45. },
  46. methods: {
  47. getData() {
  48. if (this.searching) return
  49. this.searching = true
  50. uni.showLoading({
  51. title: '搜索中'
  52. })
  53. this.$Request
  54. .getT('/app/shieldCompany/selectCompanyListByName', {
  55. companyName: this.searchValue
  56. })
  57. .then(res => {
  58. if (res.code === 0) {
  59. this.selectCompanyIds = []
  60. this.selectCompanyList = []
  61. this.companys = res.data
  62. }
  63. })
  64. .finally(() => {
  65. this.searching = false
  66. uni.hideLoading()
  67. })
  68. },
  69. // 选择公司
  70. checkboxChange(item) {
  71. const company = this.companys.find(c => c.companyId == item.name)
  72. if (!item.value) {
  73. // 删除
  74. let deleteId = 0
  75. this.selectCompanyIds.forEach((id, index) => {
  76. if (id == item.name) {
  77. deleteId = index
  78. }
  79. })
  80. this.selectCompanyIds.splice(deleteId, 1)
  81. this.selectCompanyList.splice(deleteId, 1)
  82. this.selectCount--
  83. } else {
  84. // 新增
  85. this.selectCompanyIds.push(item.name)
  86. this.selectCompanyList.push(company)
  87. this.selectCount++
  88. }
  89. },
  90. // 提交数据
  91. handleSave() {
  92. if (this.loading) return
  93. if (!this.selectCompanyIds.length) {
  94. return uni.showToast({
  95. title: '请选择屏蔽公司',
  96. icon: 'none'
  97. })
  98. return
  99. }
  100. this.loading = true
  101. uni.showLoading({
  102. title: '保存中'
  103. })
  104. this.$Request
  105. .postJson('/app/shieldCompany/insertShieldCompanys', {
  106. shieldCompanyList: this.selectCompanyList
  107. })
  108. .then(res => {
  109. if (res.code === 0) {
  110. uni.navigateBack()
  111. uni.$emit('refreshList')
  112. }
  113. })
  114. .finally(() => {
  115. this.loading = false
  116. uni.hideLoading()
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. @import '@/common.scss';
  124. .hidden-management {
  125. display: flex;
  126. flex-direction: column;
  127. height: 100vh;
  128. font-family: DM Sans;
  129. .content {
  130. flex: 1;
  131. padding: 0 40rpx;
  132. overflow: auto;
  133. }
  134. .search-bar {
  135. margin: 32rpx 40rpx 40rpx;
  136. .search-input {
  137. flex: 1;
  138. box-sizing: border-box;
  139. border: 1px solid rgba(227, 231, 236, 1);
  140. border-radius: 48rpx;
  141. background: rgba(241, 241, 241, 1);
  142. padding: 8rpx 32rpx;
  143. .search-icon {
  144. display: block;
  145. width: 36rpx;
  146. height: 36rpx;
  147. margin-right: 16rpx;
  148. }
  149. .input {
  150. width: 500rpx;
  151. font-size: 20rpx;
  152. font-weight: 500;
  153. color: rgba(51, 51, 51, 1);
  154. }
  155. }
  156. .search-btn {
  157. width: 60rpx;
  158. font-size: 20rpx;
  159. font-weight: 500;
  160. line-height: 48rpx;
  161. color: rgba(1, 107, 246, 1);
  162. padding-left: 16rpx;
  163. }
  164. }
  165. .scroll-view {
  166. .scroll-wrapper {
  167. padding-bottom: 100rpx;
  168. }
  169. }
  170. }
  171. </style>