index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <base-drawer mode="right" :visible="visible" background-color="transparent" mask maskClosable @close="closeDrawer">
  3. <view class="edit-lable">
  4. <!-- #ifdef MP -->
  5. <view class="accountTitle">
  6. <view :style="{height:getHeight.barTop+'px'}"></view>
  7. <view class="sysTitle acea-row row-center-wrapper" :style="{height:getHeight.barHeight+'px'}">
  8. <view>添加标签</view>
  9. </view>
  10. </view>
  11. <view :style="{height:(getHeight.barTop+getHeight.barHeight)+'px'}"></view>
  12. <view class="list" v-if="isStore"
  13. :style="'height: calc(100% - '+(getHeight.barTop+getHeight.barHeight*2+150)+'rpx - constant(safe-area-inset-bottom));height: calc(100% - '+(getHeight.barTop+getHeight.barHeight*2+150)+'rpx - env(safe-area-inset-bottom))'">
  14. <!-- #endif -->
  15. <!-- #ifndef MP -->
  16. <view class="header">添加标签</view>
  17. <view class="list" v-if="isStore">
  18. <!-- #endif -->
  19. <scroll-view scroll-y="true" style="height: 100%">
  20. <view class="item" v-for="(item, index) in labelList" :key="index">
  21. <view class="title" v-if="item.label && item.label.length">{{item.name}}</view>
  22. <view class="listn acea-row row-middle" v-if="item.label && item.label.length">
  23. <view class="name acea-row row-center-wrapper" :class="{on:j.disabled}" v-for="(j, indexn) in item.label" :key="indexn" @click="selectLabel(j)">
  24. <text class="line1">{{j.label_name}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. <view class="empty-box" v-else>
  31. <emptyPage title="暂无标签~" src="/statics/images/empty-box.png"></emptyPage>
  32. </view>
  33. <view class="footer acea-row row-between-wrapper">
  34. <view class="bnt acea-row row-center-wrapper" @tap="reset">重置</view>
  35. <view class="bnt on acea-row row-center-wrapper" @tap="define">确定</view>
  36. </view>
  37. </view>
  38. </base-drawer>
  39. </template>
  40. <script>
  41. import emptyPage from '@/components/emptyPage.vue';
  42. import {
  43. getUserLabel,
  44. postUserUpdate
  45. } from "@/api/admin";
  46. import { handleError } from "vue";
  47. export default {
  48. components: {
  49. emptyPage
  50. },
  51. props:{
  52. visible: {
  53. type: Boolean,
  54. default: false,
  55. },
  56. },
  57. data: function() {
  58. return {
  59. // #ifdef MP
  60. getHeight: this.$util.getWXStatusHeight(),
  61. // #endif
  62. labelList:[],
  63. goodsInfo:{}, //列表中已存在id(固定不变)
  64. dataLabel: [], //已存在选中id(随着选中可以变化)
  65. isStore:false, //判断是否存在标签
  66. num:0, // 判断是否为批量
  67. ids:[] //批量时的id集合
  68. };
  69. },
  70. mounted() {
  71. },
  72. methods:{
  73. define(){
  74. let labelIds = []
  75. this.dataLabel.forEach(item=>{
  76. labelIds.push(item.id)
  77. })
  78. postUserUpdate({
  79. type:5,
  80. uid:this.num?this.ids:this.goodsInfo.uid,
  81. label_id:labelIds
  82. }).then(res=>{
  83. this.$util.Tips({
  84. title: res.msg
  85. });
  86. this.$emit('closeDrawer',1);
  87. }).catch(err=>{
  88. this.$util.Tips({
  89. title: err
  90. });
  91. })
  92. },
  93. reset(){
  94. this.productLabel(this.goodsInfo,this.num,this.ids);
  95. },
  96. inArray: function (search, array) {
  97. for (let i in array) {
  98. if (array[i].id == search) {
  99. return true;
  100. }
  101. }
  102. return false;
  103. },
  104. productLabel(data,num,ids){
  105. this.dataLabel = data.label_id || [];
  106. this.goodsInfo = JSON.parse(JSON.stringify(data));
  107. this.num = num;
  108. this.ids = ids;
  109. getUserLabel().then(res=>{
  110. res.data.map(el => {
  111. if (el.label && el.label.length) {
  112. this.isStore = true;
  113. el.label.map(label => {
  114. if (this.inArray(label.id, this.dataLabel)) {
  115. label.disabled = true;
  116. } else {
  117. label.disabled = false;
  118. }
  119. })
  120. }
  121. })
  122. this.labelList = res.data
  123. }).catch(err=>{
  124. this.$util.Tips({
  125. title: err
  126. });
  127. })
  128. },
  129. selectLabel(label) {
  130. if (label.disabled) {
  131. let index = this.dataLabel.indexOf(this.dataLabel.filter(d => d.id == label.id)[0]);
  132. this.dataLabel.splice(index, 1);
  133. label.disabled = false
  134. } else {
  135. this.dataLabel.push({
  136. id:label.id,
  137. label_name:label.label_name
  138. });
  139. label.disabled = true
  140. }
  141. },
  142. closeDrawer() {
  143. this.$emit('closeDrawer');
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .accountTitle{
  150. position: fixed;
  151. left:0;
  152. top:0;
  153. width: 100%;
  154. z-index: 99;
  155. padding-bottom: 6rpx;
  156. .sysTitle{
  157. width: 100%;
  158. position: relative;
  159. font-weight: 600;
  160. color: #333333;
  161. font-size: 34rpx;
  162. font-family: PingFang SC, PingFang SC;
  163. }
  164. }
  165. .edit-lable{
  166. background-color: #fff;
  167. width: 670rpx;
  168. border-radius: 40rpx 0 0 40rpx;
  169. height: 100%;
  170. padding: 20rpx 34rpx 0 32rpx;
  171. .header{
  172. text-align: center;
  173. height: 96rpx;
  174. line-height: 96rpx;
  175. font-size: 34rpx;
  176. font-family: PingFang SC, PingFang SC;
  177. font-weight: 600;
  178. color: #333333;
  179. position: relative;
  180. }
  181. .list{
  182. overflow: auto;
  183. height: calc(100% - 208rpx );
  184. height: calc(100% - (208rpx + constant(safe-area-inset-bottom)));
  185. height: calc(100% - (208rpx + env(safe-area-inset-bottom)));
  186. .item{
  187. margin-top: 48rpx;
  188. .title{
  189. font-size: 28rpx;
  190. font-family: PingFang SC, PingFang SC;
  191. font-weight: 600;
  192. color: #333333;
  193. }
  194. .listn{
  195. .name{
  196. width: 184rpx;
  197. height: 56rpx;
  198. background-color: #F5F5F5;
  199. border-radius: 50rpx;
  200. border:1rpx solid #F5F5F5;
  201. font-size: 24rpx;
  202. font-family: PingFang SC, PingFang SC;
  203. font-weight: 400;
  204. color: #333333;
  205. margin-right: 26rpx;
  206. margin-top: 24rpx;
  207. padding: 0 8rpx;
  208. &.on {
  209. background-color:#E9F2FE;
  210. border-color:#2A7EFB;
  211. color: #2A7EFB;
  212. }
  213. &:nth-of-type(3n){
  214. margin-right: 0;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. .footer{
  221. width: 100%;
  222. height: 112rpx;
  223. position: fixed;
  224. bottom: 0;
  225. left:0;
  226. padding: 0 32rpx;
  227. background-color: #fff;
  228. border-radius: 0 0 0 40rpx;
  229. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  230. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  231. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  232. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  233. .bnt{
  234. width: 296rpx;
  235. height: 72rpx;
  236. border: 1px solid #2A7EFB;
  237. border-radius: 200rpx;
  238. font-size: 26rpx;
  239. font-family: PingFang SC, PingFang SC;
  240. font-weight: 600;
  241. color: #2A7EFB;
  242. &.on{
  243. background: #2A7EFB;
  244. border-color: #2A7EFB;
  245. color: #fff;
  246. }
  247. }
  248. }
  249. }
  250. </style>