lableSetup.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. <u-loading-page :loading="viewload" iconSize="32" loadingColor="#3c9cff" fontSize="20"
  63. :loading-text="loadingtext" ></u-loading-page>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. getallTags,
  69. addCompanyLabel,
  70. deleteCompanyLabel
  71. } from "@/api/courseManage.js"
  72. export default {
  73. data() {
  74. return {
  75. viewload:true,
  76. loadingtext:"数据加载中...",
  77. isShowSelectAll:false,
  78. showlist:false,
  79. addlable:'',
  80. companylabel:[],
  81. isSelectAll:false,
  82. isSelected:false,
  83. selectedCount:0,
  84. selectidAll:[],
  85. tagpageNum:1,
  86. tagpageSize:13,
  87. tagkeywords:'',
  88. statusA:"nomore",
  89. triggereds:false,
  90. isEnabled:true
  91. }
  92. },
  93. mounted() {
  94. this.getcompanylabel()
  95. },
  96. watch:{
  97. selectedCount(oldVal,newVal){
  98. return oldVal
  99. console.log('message changed from', oldVal, 'to', newVal)
  100. }
  101. },
  102. methods: {
  103. getcompanyTag(value){
  104. this.companylabel=[]
  105. this.tagkeywords = value
  106. this.tagpageNum=1
  107. this.getcompanylabel()
  108. },
  109. reachBottoms() {
  110. // status这个是加载状态
  111. console.log(111);
  112. if (this.statusA === 'loadmore') {
  113. this.statusA = 'loading'
  114. uni.showNavigationBarLoading()
  115. setTimeout(() => {
  116. this.tagpageNum++
  117. this.getcompanylabel() //触底 不穿执行else
  118. uni.hideNavigationBarLoading()
  119. }, 1000);
  120. }
  121. },
  122. //标签展示下拉
  123. pullDownRefreshs() {
  124. // 下拉
  125. this.triggereds = true; //下拉了状态为true
  126. setTimeout(() => {
  127. this.triggereds = false;
  128. uni.stopPullDownRefresh()
  129. this.tagpageNum = 1;
  130. this.getcompanylabel('refresh') //触底 不穿执行else
  131. // 请求接口里面需要判断是不是最后一页 是最后一页 status赋值为‘loadmore’没有更多了
  132. // 请求接口
  133. }, 1000)
  134. },
  135. changeProhibit(){
  136. const alltag=this.selectidAll.join(',')
  137. console.log(this.selectidAll)
  138. //删除标签
  139. if(this.selectidAll==''){
  140. uni.showToast({
  141. icon: 'none',
  142. title: '请选择标签'
  143. })
  144. return
  145. }
  146. const params={
  147. tagIds:alltag
  148. }
  149. console.log(this.selectidAll)
  150. deleteCompanyLabel(alltag).then(res=>{
  151. if(res.code==200){
  152. this.companylabel=[]
  153. this.tagpageNum=1
  154. this.selectidAll=[]
  155. uni.showToast({
  156. icon: 'none',
  157. title: '标签删除成功'
  158. })
  159. this.isSelectAll=false
  160. this.selectedCount=0
  161. this.getcompanylabel()
  162. }else {
  163. uni.showToast({
  164. icon: 'none',
  165. title: res.msg
  166. })
  167. }
  168. })
  169. },
  170. getcompanylabel(type ){
  171. this.tagkeywords =this.tagkeywords.replace(/,/g,',')
  172. const data ={
  173. pageNum:this.tagpageNum,
  174. pageSize:this.tagpageSize,
  175. keyword:this.tagkeywords
  176. }
  177. getallTags(data).then(res=>{
  178. if(res.code==200){
  179. this.viewload=false
  180. const dataList = res.data.list.map(item => {
  181. return {
  182. ...item,
  183. checked: false,
  184. }
  185. })
  186. if (type == 'refresh') {
  187. this.companylabel = dataList
  188. }else {
  189. this.companylabel = [...this.companylabel, ...dataList]
  190. }
  191. if (res.data.isLastPage) {
  192. this.statusA = 'nomore'
  193. } else {
  194. this.statusA = 'loadmore'
  195. }
  196. }else {
  197. uni.showToast({
  198. icon: 'none',
  199. title: res.msg
  200. })
  201. }
  202. })
  203. },
  204. addcompanySingle(){
  205. const params={
  206. tag:this.addlable
  207. }
  208. addCompanyLabel(params).then(res=>{
  209. if(res.code==200){
  210. this.tagpageNum=1
  211. this.companylabel=[]
  212. this.addlable=''
  213. uni.showToast({
  214. icon: 'none',
  215. title: '标签添加成功'
  216. })
  217. this.getcompanylabel()
  218. }else {
  219. uni.showToast({
  220. icon: 'none',
  221. title: res.msg
  222. })
  223. }
  224. })
  225. },
  226. addLable(){
  227. this.showlist=!this.showlist
  228. },
  229. selectlist(i){
  230. // 单选 /反选
  231. let arr = {
  232. ...this.companylabel[i],
  233. checked: !this.companylabel[i].checked
  234. }
  235. this.$set(this.companylabel, i, arr)
  236. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  237. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  238. this.selectedCount=seletnum.length
  239. this.isSelectAll = this.companylabel.every(item => item.checked)
  240. if (this.isSelectAll) {
  241. this.companylabel = this.companylabel.map(item => {
  242. return {
  243. ...item,
  244. checked: this.isSelectAll
  245. }
  246. })
  247. }
  248. },
  249. selectAll(){
  250. // 全选
  251. this.isSelectAll = !this.isSelectAll
  252. console.log(this.isSelectAll)
  253. this.companylabel = this.companylabel.map(item => {
  254. // 每一项的 checked为 全选的状态
  255. return {
  256. ...item,
  257. checked: this.isSelectAll
  258. }
  259. })
  260. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  261. const seletnum = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  262. this.selectedCount=seletnum.length
  263. console.log(this.companylabel)
  264. },
  265. confirmchange(){
  266. if(this.addlable==''){
  267. uni.showToast({
  268. icon: 'none',
  269. title: "请输入标签"
  270. })
  271. }else{
  272. this.addcompanySingle()
  273. this.showlist=!this.showlist
  274. }
  275. },
  276. cancel(){
  277. this.showlist=!this.showlist
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss">
  283. .footbtn{
  284. position: fixed;
  285. bottom: 0;
  286. width: 100%;
  287. background-color: #fff;
  288. }
  289. </style>