index.vue 7.8 KB

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