lableSetup.vue 7.8 KB

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