lableSetup.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="column hb bgf">
  3. <view class="align-center justify-between p20 bgf ">
  4. <view class="justify-start fs28 align-center">
  5. <u-icon name="bookmark-fill" color="#1677ff" size="28"></u-icon>
  6. <view>自定义标签</view>
  7. </view>
  8. <view class="fs28" @click="isShowSelectAll=!isShowSelectAll">
  9. {{isShowSelectAll?'取消多选':'多选'}}</view>
  10. </view>
  11. <view class="mtb20 mlr20" >
  12. <u-search placeholder="请输入标签 多个标签用 , 隔开" v-model="tagkeywords" :showAction="false" height="30px"
  13. @search='getcompanyTag' ></u-search>
  14. </view>
  15. <view class="column flex-1 scrolly plr20" >
  16. <scroll-view scroll-y="true" class="hb" :refresher-enabled="isEnabled" :refresher-triggered="triggereds"
  17. refresher-background="rgba(0,0,0,0)" @refresherrefresh="pullDownRefreshs"
  18. @refresherrestore="triggereds = false" :upper-threshold="100" :lower-threshold="100"
  19. @refresherabort="triggereds = false" @scrolltolower="reachBottoms">
  20. <view class="justify-start " v-for="(item,index) in companylabel"
  21. :key="index">
  22. <u-checkbox-group @change="selectlist(index)">
  23. <u-checkbox :checked="item.checked" shape="circle" activeColor="#FF6C47" :name="true"
  24. label=" " labelColor="#333" v-if="isShowSelectAll"/>
  25. </u-checkbox-group>
  26. <view class="justify-start align-center ptb16 flex-1"
  27. style="border-bottom: 2rpx solid #e7e7e7;" >
  28. <u-icon name="list" color="#666" size="24"></u-icon>
  29. <view class="fs28 ml12">{{item.tag}}</view>
  30. </view>
  31. </view>
  32. <u-loadmore :status="statusA" />
  33. </scroll-view>
  34. </view>
  35. <view class="h120"></view>
  36. <view class="footbtn">
  37. <view v-if="isShowSelectAll" class="justify-between p20 bgf">
  38. <view class="align-center justify-between" v-if="isShowSelectAll">
  39. <u-checkbox-group @change="selectAll">
  40. <u-checkbox :checked="isSelectAll" shape="circle" activeColor="#FF6C47"
  41. :name="true" label="全选" labelColor="#333" />
  42. <text class="fs24 base-color-9 ml12">已选 {{selectedCount}}
  43. 个</text>
  44. </u-checkbox-group>
  45. </view>
  46. <view class="justify-center ">
  47. <button class="base-bg-red radius100 colorf h62 fs28 lh62 mlr10 plr60"
  48. @click="changeProhibit">删除</button>
  49. </view>
  50. </view>
  51. <view class='base-bg radius50 m20 p20 center colorf'
  52. @click="addLable" v-else>新增标签</view>
  53. </view>
  54. <view>
  55. <u-modal :show="showlist" title="新增标签" @confirm="confirmchange"
  56. :showCancelButton="true" @cancel="cancel" style="flex: 0;">
  57. <view class="slot-content">
  58. <u-input placeholder="请输入新增标签" v-model="addlable"></u-input>
  59. </view>
  60. </u-modal>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. getallTags,
  67. addCompanyLabel,
  68. deleteCompanyLabel
  69. } from "@/api/courseManage.js"
  70. export default {
  71. data() {
  72. return {
  73. isShowSelectAll:false,
  74. showlist:false,
  75. addlable:'',
  76. companylabel:[],
  77. isSelectAll:false,
  78. isSelected:false,
  79. selectedCount:0,
  80. selectidAll:[],
  81. tagpageNum:1,
  82. tagpageSize:13,
  83. tagkeywords:'',
  84. statusA:"nomore",
  85. triggereds:false,
  86. isEnabled:true
  87. }
  88. },
  89. mounted() {
  90. this.getcompanylabel()
  91. },
  92. watch:{
  93. selectedCount(oldVal,newVal){
  94. return oldVal
  95. console.log('message changed from', oldVal, 'to', newVal)
  96. }
  97. },
  98. methods: {
  99. getcompanyTag(value){
  100. this.companylabel=[]
  101. this.tagkeywords = value
  102. this.tagpageNum=1
  103. this.getcompanylabel()
  104. },
  105. reachBottoms() {
  106. // status这个是加载状态
  107. console.log(111);
  108. if (this.statusA === 'loadmore') {
  109. this.statusA = 'loading'
  110. uni.showNavigationBarLoading()
  111. setTimeout(() => {
  112. this.tagpageNum++
  113. this.getcompanylabel() //触底 不穿执行else
  114. uni.hideNavigationBarLoading()
  115. }, 1000);
  116. }
  117. },
  118. //标签展示下拉
  119. pullDownRefreshs() {
  120. // 下拉
  121. this.triggereds = true; //下拉了状态为true
  122. setTimeout(() => {
  123. this.triggereds = false;
  124. uni.stopPullDownRefresh()
  125. this.tagpageNum = 1;
  126. this.getcompanylabel('refresh') //触底 不穿执行else
  127. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  128. // 请求接口
  129. }, 1000)
  130. },
  131. changeProhibit(){
  132. const alltag=this.selectidAll.join(',')
  133. console.log(this.selectidAll)
  134. //删除标签
  135. if(this.selectidAll==''){
  136. uni.showToast({
  137. icon: 'none',
  138. title: '请选择标签'
  139. })
  140. return
  141. }
  142. const params={
  143. tagIds:alltag
  144. }
  145. console.log(this.selectidAll)
  146. deleteCompanyLabel(alltag).then(res=>{
  147. if(res.code==200){
  148. this.companylabel=[]
  149. this.tagpageNum=1
  150. this.selectidAll=[]
  151. uni.showToast({
  152. icon: 'none',
  153. title: '标签删除成功'
  154. })
  155. this.getcompanylabel()
  156. }else {
  157. uni.showToast({
  158. icon: 'none',
  159. title: res.msg
  160. })
  161. }
  162. })
  163. },
  164. getcompanylabel(type ){
  165. this.tagkeywords =this.tagkeywords.replace(/,/g,',')
  166. const data ={
  167. pageNum:this.tagpageNum,
  168. pageSize:this.tagpageSize,
  169. keyword:this.tagkeywords
  170. }
  171. getallTags(data).then(res=>{
  172. if(res.code==200){
  173. const dataList = res.data.list.map(item => {
  174. return {
  175. ...item,
  176. checked: false,
  177. }
  178. })
  179. if (type == 'refresh') {
  180. this.companylabel = dataList
  181. }else {
  182. this.companylabel = [...this.companylabel, ...dataList]
  183. }
  184. if (res.data.isLastPage) {
  185. this.statusA = 'nomore'
  186. } else {
  187. this.statusA = 'loadmore'
  188. }
  189. }else {
  190. uni.showToast({
  191. icon: 'none',
  192. title: res.msg
  193. })
  194. }
  195. })
  196. },
  197. addcompanySingle(){
  198. const params={
  199. tag:this.addlable
  200. }
  201. addCompanyLabel(params).then(res=>{
  202. if(res.code==200){
  203. this.tagpageNum=1
  204. this.companylabel=[]
  205. this.addlable=''
  206. uni.showToast({
  207. icon: 'none',
  208. title: '标签添加成功'
  209. })
  210. this.getcompanylabel()
  211. }else {
  212. uni.showToast({
  213. icon: 'none',
  214. title: res.msg
  215. })
  216. }
  217. })
  218. },
  219. addLable(){
  220. this.showlist=!this.showlist
  221. },
  222. selectlist(i){
  223. // 单选 /反选
  224. let arr = {
  225. ...this.companylabel[i],
  226. checked: !this.companylabel[i].checked
  227. }
  228. this.$set(this.companylabel, i, arr)
  229. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  230. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  231. this.selectedCount=seletnum.length
  232. this.isSelectAll = this.companylabel.every(item => item.checked)
  233. if (this.isSelectAll) {
  234. this.companylabel = this.companylabel.map(item => {
  235. return {
  236. ...item,
  237. checked: this.isSelectAll
  238. }
  239. })
  240. }
  241. },
  242. selectAll(){
  243. // 全选
  244. this.isSelectAll = !this.isSelectAll
  245. console.log(this.isSelectAll)
  246. this.companylabel = this.companylabel.map(item => {
  247. // 每一项的 checked为 全选的状态
  248. return {
  249. ...item,
  250. checked: this.isSelectAll
  251. }
  252. })
  253. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  254. this.selectedCount=seletnum.length
  255. console.log(this.companylabel)
  256. },
  257. confirmchange(){
  258. if(this.addlable==''){
  259. uni.showToast({
  260. icon: 'none',
  261. title: "请输入标签"
  262. })
  263. }else{
  264. this.addcompanySingle()
  265. this.showlist=!this.showlist
  266. }
  267. },
  268. cancel(){
  269. this.showlist=!this.showlist
  270. }
  271. }
  272. }
  273. </script>
  274. <style lang="scss">
  275. .footbtn{
  276. position: fixed;
  277. bottom: 0;
  278. width: 100%;
  279. background-color: #fff;
  280. }
  281. </style>