index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <base-drawer mode="bottom" :visible="visible" background-color="transparent" mask maskClosable @close="closeDrawer">
  3. <view class="classify rd-t-40rpx">
  4. <view class="title">
  5. 修改分类
  6. <view class="close acea-row row-center-wrapper" @tap="closeDrawer">
  7. <text class="iconfont icon-iconfontguanbi"></text>
  8. </view>
  9. </view>
  10. <checkbox-group @change="checkboxChange($event)" v-if="categoryList.length">
  11. <view class="list acea-row">
  12. <view class="item">
  13. <view class="tips">一级分类</view>
  14. <scroll-view scroll-y="true" class="scroll-Y">
  15. <view
  16. class="itemn line1"
  17. :class="{
  18. checked: index == currentOne,
  19. on: checkedIds.includes(item.id + '')
  20. }"
  21. v-for="(item, index) in categoryList"
  22. :key="index"
  23. @click="categoryTap(index)"
  24. >
  25. <!-- #ifndef MP -->
  26. <checkbox
  27. :value="item.id.toString()"
  28. :checked="checkedIds.includes(item.id + '')"
  29. color="#ffffff"
  30. backgroundColor="#ffffff"
  31. activeBackgroundColor="#2A7EFB"
  32. activeBorderColor="#2A7EFB"
  33. style="transform: scale(0.9)"
  34. />
  35. <!-- #endif -->
  36. <!-- #ifdef MP -->
  37. <checkbox :value="item.id" :checked="checkedIds.includes(item.id + '')" style="transform: scale(0.9)" color="#ffffff" />
  38. <!-- #endif -->
  39. {{ item.title }}
  40. </view>
  41. </scroll-view>
  42. </view>
  43. <view class="item on" :class="!categoryList[currentOne].children.length ? 'on3' : ''" v-if="categoryList[currentOne]">
  44. <view class="tips">二级分类</view>
  45. <scroll-view scroll-y="true" class="scroll-Y">
  46. <view
  47. class="itemn line1"
  48. :class="{
  49. checked: jIndex == currentTwo,
  50. on: checkedIds.includes(j.id + '')
  51. }"
  52. v-for="(j, jIndex) in categoryList[currentOne].children"
  53. :key="jIndex"
  54. @click="categoryTwoTap(jIndex)"
  55. >
  56. <!-- #ifndef MP -->
  57. <checkbox
  58. :value="j.id.toString()"
  59. :checked="checkedIds.includes(j.id + '')"
  60. color="#ffffff"
  61. backgroundColor="#ffffff"
  62. activeBackgroundColor="#2A7EFB"
  63. activeBorderColor="#2A7EFB"
  64. style="transform: scale(0.9)"
  65. />
  66. <!-- #endif -->
  67. <!-- #ifdef MP -->
  68. <checkbox :value="j.id" :checked="checkedIds.includes(j.id + '')" style="transform: scale(0.9)" />
  69. <!-- #endif -->
  70. {{ j.title }}
  71. </view>
  72. </scroll-view>
  73. </view>
  74. </view>
  75. </checkbox-group>
  76. <view class="empty-box" v-else>
  77. <emptyPage title="暂无分类~" src="/statics/images/empty-box.png"></emptyPage>
  78. </view>
  79. <view class="footer acea-row row-between-wrapper">
  80. <view class="bnt acea-row row-center-wrapper" @tap="reset">重置</view>
  81. <view class="bnt on acea-row row-center-wrapper" @tap="define">确定</view>
  82. </view>
  83. </view>
  84. </base-drawer>
  85. </template>
  86. <script>
  87. import emptyPage from '@/components/emptyPage.vue';
  88. import baseDrawer from '@/components/tuiDrawer/tui-drawer.vue';
  89. import { getProductCate, postManageSaveCate } from '@/api/admin';
  90. export default {
  91. components: {
  92. emptyPage,
  93. baseDrawer
  94. },
  95. props: {
  96. visible: {
  97. type: Boolean,
  98. default: false
  99. },
  100. type: {
  101. type: Number,
  102. default: 0
  103. }
  104. },
  105. data: function () {
  106. return {
  107. categoryList: [],
  108. currentOne: 0,
  109. currentTwo: 0,
  110. checkedIds: [],
  111. ids: null //父级商品id
  112. };
  113. },
  114. mounted() {},
  115. methods: {
  116. checkboxChange(e, index, item) {
  117. this.checkedIds = e.detail.value;
  118. },
  119. categoryTwoTap(index) {
  120. this.currentTwo = index;
  121. },
  122. categoryTap(index) {
  123. this.currentOne = index;
  124. this.currentTwo = 0;
  125. },
  126. category(id, cateId) {
  127. this.ids = id;
  128. if (cateId) {
  129. this.checkedIds = cateId.split(',');
  130. } else {
  131. this.checkedIds = [];
  132. }
  133. if(!this.categoryList.length){
  134. getProductCate().then((res) => {
  135. this.categoryList = res.data;
  136. })
  137. .catch((err) => {
  138. this.$util.Tips({
  139. title: err
  140. });
  141. });
  142. }
  143. },
  144. reset() {
  145. this.checkedIds = [];
  146. },
  147. define() {
  148. if (!this.checkedIds.length) {
  149. this.$util.Tips({
  150. title: '请选择分类'
  151. });
  152. return;
  153. }
  154. let data = {
  155. cate_id: this.checkedIds,
  156. ids: this.ids
  157. };
  158. if (this.type) {
  159. this.$emit('successChange', this.checkedIds);
  160. } else {
  161. postManageSaveCate(data).then((res) => {
  162. this.$util.Tips({
  163. title: res.msg
  164. });
  165. this.$emit('successChange');
  166. })
  167. .catch((err) => {
  168. this.$util.Tips({
  169. title: err
  170. });
  171. });
  172. }
  173. },
  174. closeDrawer() {
  175. this.$emit('closeDrawer');
  176. }
  177. }
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. ::v-deep checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  182. border: 1px solid $primary-admin;
  183. background-color: $primary-admin;
  184. color: #fff;
  185. }
  186. ::v-deep checkbox {
  187. margin-right: 13rpx;
  188. }
  189. ::v-deep uni-checkbox .uni-checkbox-input {
  190. border-radius: 4rpx;
  191. width: 28rpx;
  192. height: 28rpx;
  193. }
  194. .classify {
  195. background-color: #fff;
  196. padding-bottom: 60rpx;
  197. .title {
  198. text-align: center;
  199. height: 108rpx;
  200. line-height: 108rpx;
  201. font-size: 32rpx;
  202. font-family: PingFang SC, PingFang SC;
  203. font-weight: 600;
  204. color: #333333;
  205. position: relative;
  206. padding: 0 30rpx;
  207. .close {
  208. width: 36rpx;
  209. height: 36rpx;
  210. line-height: 36rpx;
  211. background: #eeeeee;
  212. border-radius: 50%;
  213. position: absolute;
  214. right: 30rpx;
  215. top: 38rpx;
  216. .iconfont {
  217. font-weight: 300;
  218. font-size: 20rpx;
  219. }
  220. }
  221. }
  222. .list {
  223. height: 770rpx;
  224. .scroll-Y {
  225. height: 684rpx;
  226. }
  227. .item {
  228. width: 50%;
  229. padding-left: 32rpx;
  230. font-size: 26rpx;
  231. font-family: PingFang SC, PingFang SC;
  232. font-weight: 400;
  233. color: #666666;
  234. padding-top: 30rpx;
  235. .tips {
  236. color: #999;
  237. font-size: 24rpx;
  238. margin-bottom: 30rpx;
  239. }
  240. .itemn {
  241. margin-bottom: 58rpx;
  242. &.checked {
  243. color: #000;
  244. }
  245. &.on {
  246. color: $primary-admin;
  247. }
  248. }
  249. &.on {
  250. background-color: #fafafa;
  251. }
  252. &.on2 {
  253. background-color: #f5f5f5;
  254. }
  255. &.on3 {
  256. width: 66.66%;
  257. }
  258. }
  259. }
  260. .footer {
  261. box-sizing: border-box;
  262. padding: 0 20rpx;
  263. width: 100%;
  264. height: 112rpx;
  265. background-color: #fff;
  266. position: fixed;
  267. bottom: 0;
  268. z-index: 30;
  269. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  270. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  271. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  272. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  273. left: 0;
  274. .bnt {
  275. width: 347rpx;
  276. height: 72rpx;
  277. border-radius: 50rpx;
  278. border: 1px solid $primary-admin;
  279. color: $primary-admin;
  280. font-size: 26rpx;
  281. font-family: PingFang SC, PingFang SC;
  282. font-weight: 500;
  283. &.on {
  284. background-color: $primary-admin;
  285. color: #fff;
  286. }
  287. }
  288. }
  289. }
  290. </style>