index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. postUserUpdateOther
  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. postUserUpdateOther(this.num?this.ids:this.goodsInfo.uid,{
  79. type:6,
  80. label_id:labelIds
  81. }).then(res=>{
  82. this.$util.Tips({
  83. title: res.msg
  84. });
  85. this.$emit('closeDrawer',1);
  86. }).catch(err=>{
  87. this.$util.Tips({
  88. title: err
  89. });
  90. })
  91. },
  92. reset(){
  93. this.productLabel(this.goodsInfo,this.num,this.ids);
  94. },
  95. inArray: function (search, array) {
  96. for (let i in array) {
  97. if (array[i].id == search) {
  98. return true;
  99. }
  100. }
  101. return false;
  102. },
  103. productLabel(data,num,ids){
  104. this.dataLabel = data.label_id || [];
  105. this.goodsInfo = JSON.parse(JSON.stringify(data));
  106. this.num = num;
  107. this.ids = ids;
  108. getUserLabel(0).then(res=>{
  109. res.data.map(el => {
  110. if (el.label && el.label.length) {
  111. this.isStore = true;
  112. el.label.map(label => {
  113. if (this.inArray(label.id, this.dataLabel)) {
  114. label.disabled = true;
  115. } else {
  116. label.disabled = false;
  117. }
  118. })
  119. }
  120. })
  121. this.labelList = res.data
  122. }).catch(err=>{
  123. this.$util.Tips({
  124. title: err
  125. });
  126. })
  127. },
  128. selectLabel(label) {
  129. if (label.disabled) {
  130. let index = this.dataLabel.indexOf(this.dataLabel.filter(d => d.id == label.id)[0]);
  131. this.dataLabel.splice(index, 1);
  132. label.disabled = false
  133. } else {
  134. this.dataLabel.push({
  135. id:label.id,
  136. label_name:label.label_name
  137. });
  138. label.disabled = true
  139. }
  140. },
  141. closeDrawer() {
  142. this.$emit('closeDrawer');
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .accountTitle{
  149. position: fixed;
  150. left:0;
  151. top:0;
  152. width: 100%;
  153. z-index: 99;
  154. padding-bottom: 6rpx;
  155. .sysTitle{
  156. width: 100%;
  157. position: relative;
  158. font-weight: 600;
  159. color: #333333;
  160. font-size: 34rpx;
  161. font-family: PingFang SC, PingFang SC;
  162. }
  163. }
  164. .edit-lable{
  165. background-color: #fff;
  166. width: 670rpx;
  167. border-radius: 40rpx 0 0 40rpx;
  168. height: 100%;
  169. padding: 20rpx 34rpx 0 32rpx;
  170. .header{
  171. text-align: center;
  172. height: 96rpx;
  173. line-height: 96rpx;
  174. font-size: 34rpx;
  175. font-family: PingFang SC, PingFang SC;
  176. font-weight: 600;
  177. color: #333333;
  178. position: relative;
  179. }
  180. .list{
  181. overflow: auto;
  182. height: calc(100% - 208rpx );
  183. height: calc(100% - (208rpx + constant(safe-area-inset-bottom)));
  184. height: calc(100% - (208rpx + env(safe-area-inset-bottom)));
  185. .item{
  186. margin-top: 48rpx;
  187. .title{
  188. font-size: 28rpx;
  189. font-family: PingFang SC, PingFang SC;
  190. font-weight: 600;
  191. color: #333333;
  192. }
  193. .listn{
  194. .name{
  195. width: 184rpx;
  196. height: 56rpx;
  197. background-color: #F5F5F5;
  198. border-radius: 50rpx;
  199. border:1rpx solid #F5F5F5;
  200. font-size: 24rpx;
  201. font-family: PingFang SC, PingFang SC;
  202. font-weight: 400;
  203. color: #333333;
  204. margin-right: 26rpx;
  205. margin-top: 24rpx;
  206. padding: 0 8rpx;
  207. &.on {
  208. background-color:#E9F2FE;
  209. border-color:#2A7EFB;
  210. color: #2A7EFB;
  211. }
  212. &:nth-of-type(3n){
  213. margin-right: 0;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. .footer{
  220. width: 100%;
  221. height: 112rpx;
  222. position: fixed;
  223. bottom: 0;
  224. left:0;
  225. padding: 0 32rpx;
  226. background-color: #fff;
  227. border-radius: 0 0 0 40rpx;
  228. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  229. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  230. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  231. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  232. .bnt{
  233. width: 296rpx;
  234. height: 72rpx;
  235. border: 1px solid #2A7EFB;
  236. border-radius: 200rpx;
  237. font-size: 26rpx;
  238. font-family: PingFang SC, PingFang SC;
  239. font-weight: 600;
  240. color: #2A7EFB;
  241. &.on{
  242. background: #2A7EFB;
  243. border-color: #2A7EFB;
  244. color: #fff;
  245. }
  246. }
  247. }
  248. }
  249. </style>