index.vue 6.6 KB

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