lableSetup.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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,alltag)
  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.isSelectAll=false
  156. this.selectedCount=0
  157. this.getcompanylabel()
  158. }else {
  159. uni.showToast({
  160. icon: 'none',
  161. title: res.msg
  162. })
  163. }
  164. })
  165. },
  166. getcompanylabel(type ){
  167. this.tagkeywords =this.tagkeywords.replace(/,/g,',')
  168. const data ={
  169. pageNum:this.tagpageNum,
  170. pageSize:this.tagpageSize,
  171. keyword:this.tagkeywords
  172. }
  173. getallTags(data).then(res=>{
  174. if(res.code==200){
  175. const dataList = res.data.list.map(item => {
  176. return {
  177. ...item,
  178. checked: false,
  179. }
  180. })
  181. if (type == 'refresh') {
  182. this.companylabel = dataList
  183. }else {
  184. this.companylabel = [...this.companylabel, ...dataList]
  185. }
  186. if (res.data.isLastPage) {
  187. this.statusA = 'nomore'
  188. } else {
  189. this.statusA = 'loadmore'
  190. }
  191. }else {
  192. uni.showToast({
  193. icon: 'none',
  194. title: res.msg
  195. })
  196. }
  197. })
  198. },
  199. addcompanySingle(){
  200. const params={
  201. tag:this.addlable
  202. }
  203. addCompanyLabel(params).then(res=>{
  204. if(res.code==200){
  205. this.tagpageNum=1
  206. this.companylabel=[]
  207. this.addlable=''
  208. uni.showToast({
  209. icon: 'none',
  210. title: '标签添加成功'
  211. })
  212. this.getcompanylabel()
  213. }else {
  214. uni.showToast({
  215. icon: 'none',
  216. title: res.msg
  217. })
  218. }
  219. })
  220. },
  221. addLable(){
  222. this.showlist=!this.showlist
  223. },
  224. selectlist(i){
  225. // 单选 /反选
  226. let arr = {
  227. ...this.companylabel[i],
  228. checked: !this.companylabel[i].checked
  229. }
  230. this.$set(this.companylabel, i, arr)
  231. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  232. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  233. this.selectedCount=seletnum.length
  234. this.isSelectAll = this.companylabel.every(item => item.checked)
  235. if (this.isSelectAll) {
  236. this.companylabel = this.companylabel.map(item => {
  237. return {
  238. ...item,
  239. checked: this.isSelectAll
  240. }
  241. })
  242. }
  243. },
  244. selectAll(){
  245. // 全选
  246. this.isSelectAll = !this.isSelectAll
  247. console.log(this.isSelectAll)
  248. this.companylabel = this.companylabel.map(item => {
  249. // 每一项的 checked为 全选的状态
  250. return {
  251. ...item,
  252. checked: this.isSelectAll
  253. }
  254. })
  255. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  256. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  257. this.selectedCount=seletnum.length
  258. console.log(this.companylabel)
  259. },
  260. confirmchange(){
  261. if(this.addlable==''){
  262. uni.showToast({
  263. icon: 'none',
  264. title: "请输入标签"
  265. })
  266. }else{
  267. this.addcompanySingle()
  268. this.showlist=!this.showlist
  269. }
  270. },
  271. cancel(){
  272. this.showlist=!this.showlist
  273. }
  274. }
  275. }
  276. </script>
  277. <style lang="scss">
  278. .footbtn{
  279. position: fixed;
  280. bottom: 0;
  281. width: 100%;
  282. background-color: #fff;
  283. }
  284. </style>