lableSetup.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="column flex-1 hb">
  3. <view class="align-center justify-between p20">
  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="column flex-1 scrolly plr20" >
  12. <view class="justify-start" v-for="(item,index) in companylabel"
  13. :key="index">
  14. <u-checkbox-group @change="selectlist(index)">
  15. <u-checkbox :checked="item.checked" shape="circle" activeColor="#FF6C47" :name="true"
  16. label="" labelColor="#333" v-if="isShowSelectAll"/>
  17. </u-checkbox-group>
  18. <view class="justify-start align-center ptb16 flex-1"
  19. style="border-bottom: 2rpx solid #e7e7e7;" >
  20. <u-icon name="list" color="#666" size="24"></u-icon>
  21. <view class="fs28 ml12">{{item.tag}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="footbtn">
  26. <view v-if="isShowSelectAll" class="justify-between p20">
  27. <view class="align-center justify-between" v-if="isShowSelectAll">
  28. <u-checkbox-group @change="selectAll">
  29. <u-checkbox :checked="isSelectAll" shape="circle" activeColor="#FF6C47"
  30. :name="true" label="全选" labelColor="#333" />
  31. <text class="fs24 base-color-9 ml12">已选 {{selectedCount}}
  32. 个</text>
  33. </u-checkbox-group>
  34. </view>
  35. <view class="justify-center ">
  36. <button class="base-bg-red radius100 colorf h62 fs28 lh62 mlr10 plr60"
  37. @click="changeProhibit">删除</button>
  38. </view>
  39. </view>
  40. <view class='base-bg radius50 m20 p20 center colorf'
  41. @click="addLable" v-else>新增标签</view>
  42. </view>
  43. <u-modal :show="showlist" title="新增标签" @confirm="confirmchange"
  44. :showCancelButton="true" @cancel="cancel" style="flex: 0;">
  45. <view class="slot-content">
  46. <u-input placeholder="请输入新增标签" v-model="addlable"></u-input>
  47. </view>
  48. </u-modal>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. getcompanyTaglist,
  54. addCompanyLabel,
  55. deleteCompanyLabel
  56. } from "@/api/courseManage.js"
  57. export default {
  58. data() {
  59. return {
  60. isShowSelectAll:false,
  61. showlist:false,
  62. addlable:'',
  63. companylabel:[],
  64. isSelectAll:false,
  65. isSelected:false,
  66. selectedCount:0,
  67. selectidAll:[]
  68. }
  69. },
  70. mounted() {
  71. this.getcompanylabel()
  72. },
  73. methods: {
  74. changeProhibit(){
  75. //删除标签
  76. const params={
  77. tagIds:this.selectidAll
  78. }
  79. console.log(this.selectidAll)
  80. deleteCompanyLabel(params).then(res=>{
  81. if(res.code==200){
  82. uni.showToast({
  83. icon: 'none',
  84. title: '标签删除成功'
  85. })
  86. this.getcompanylabel()
  87. }else {
  88. uni.showToast({
  89. icon: 'none',
  90. title: res.msg
  91. })
  92. }
  93. })
  94. },
  95. getcompanylabel(){
  96. getcompanyTaglist().then(res=>{
  97. if(res.code==200){
  98. this.companylabel = res.data.map(item => {
  99. return {
  100. ...item,
  101. checked: false,
  102. }
  103. })
  104. }else {
  105. uni.showToast({
  106. icon: 'none',
  107. title: res.msg
  108. })
  109. }
  110. })
  111. },
  112. addcompanySingle(){
  113. const params={
  114. tag:this.addlable
  115. }
  116. addCompanyLabel(params).then(res=>{
  117. if(res.code==200){
  118. uni.showToast({
  119. icon: 'none',
  120. title: '标签添加成功'
  121. })
  122. this.getcompanylabel()
  123. }else {
  124. uni.showToast({
  125. icon: 'none',
  126. title: res.msg
  127. })
  128. }
  129. })
  130. },
  131. addLable(){
  132. this.showlist=!this.showlist
  133. },
  134. selectlist(i){
  135. // 单选 /反选
  136. console.log(i)
  137. let arr = {
  138. ...this.companylabel[i],
  139. checked: !this.companylabel[i].checked
  140. }
  141. this.$set(this.companylabel, i, arr)
  142. this.selectidAll = this.companylabel.filter(item => item.checked).map(item => item.tagId)
  143. console.log(this.selectidAll)
  144. this.isSelectAll = this.companylabel.every(item => item.checked)
  145. if (this.isSelectAll) {
  146. this.companylabel = this.companylabel.map(item => {
  147. return {
  148. ...item,
  149. checked: this.isSelectAll
  150. }
  151. })
  152. }
  153. },
  154. selectAll(){
  155. // 全选
  156. this.isSelectAll = !this.isSelectAll
  157. console.log(this.isSelectAll)
  158. this.companylabel = this.companylabel.map(item => {
  159. // 每一项的 checked为 全选的状态
  160. return {
  161. ...item,
  162. checked: this.isSelectAll
  163. }
  164. })
  165. console.log(this.companylabel)
  166. },
  167. confirmchange(){
  168. if(this.addlable==''){
  169. uni.showToast({
  170. icon: 'none',
  171. title: "请输入标签"
  172. })
  173. }else{
  174. this.addcompanySingle()
  175. this.showlist=!this.showlist
  176. }
  177. },
  178. cancel(){
  179. this.showlist=!this.showlist
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. </style>