cat-setting.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <app-layout>
  3. <view class='add-cat'>
  4. <view v-if="mch_id || mch_id == 0" @click="editCat" class='add-cat-btn main-center' :style="{'border-color': color,'color': color}">
  5. <image :src="mch_id == 0 ? './../image/add.png': './../image/mch-add.png'"></image>
  6. <view>新增分类</view>
  7. </view>
  8. </view>
  9. <view>
  10. <view class="cat" v-for="item in list" :key="item.value">
  11. <view class="main-between cat-item" @click="toggle(item)">
  12. <view class="dir-left-nowrap cat-name">
  13. <view v-if="item.children" class="show-more cross-center main-center">
  14. <image v-if="!item.show" src='/static/image/icon/right.png'></image>
  15. <image class="bottom" v-else src='/static/image/icon/bottom.png'></image>
  16. </view>
  17. <view :class="[`${item.children ? '' : 'cat-left'}`]">{{item.label}}</view>
  18. </view>
  19. <view class="cat-menu dir-left-nowrap cross-center">
  20. <image @click.stop='editCat(item)' src='./../image/edit.png'></image>
  21. <image @click.stop='pop(item.value)' src='./../image/low.png'></image>
  22. </view>
  23. </view>
  24. <view v-for="sec in item.children" :key="sec.value" v-if="item.children && item.show">
  25. <view class="main-between cat-item sec-cat" @click.stop="toggle(sec)">
  26. <view class="show-more"></view>
  27. <view class="dir-left-nowrap cat-name">
  28. <view v-if="sec.children" class="show-more cross-center main-center">
  29. <image v-if="!sec.show" src='/static/image/icon/right.png'></image>
  30. <image class="bottom" v-else src='/static/image/icon/bottom.png'></image>
  31. </view>
  32. <view :class="[`${sec.children ? '' : 'cat-left'}`]">{{sec.label}}</view>
  33. </view>
  34. <view class="cat-menu dir-left-nowrap cross-center">
  35. <image @click.stop='editCat(sec)' src='./../image/edit.png'></image>
  36. <image @click.stop='pop(sec.value)' src='./../image/low.png'></image>
  37. </view>
  38. </view>
  39. <view v-for="third in sec.children" :key="third.value" v-if="sec.children && sec.show">
  40. <view class="main-between cat-item sec-cat">
  41. <view class="show-more"></view>
  42. <view class="dir-left-nowrap cat-name">
  43. <view class="show-more"></view>
  44. <view>{{third.label}}</view>
  45. </view>
  46. <view class="cat-menu dir-left-nowrap cross-center">
  47. <image @click.stop='editCat(third)' src='./../image/edit.png'></image>
  48. <image @click.stop='pop(third.value)' src='./../image/low.png'></image>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class='dialog' v-if="value > -1">
  55. <view class='dialog-item'>
  56. <view class='dialog-title'>确定删除这个分类吗?</view>
  57. <view class="main-center btn-area">
  58. <view class="submit-btn" @click='close'>取消</view>
  59. <view class="line"></view>
  60. <view class="submit-btn be-submit" @click='toDelete'>删除</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </app-layout>
  66. </template>
  67. <script>
  68. import { mapState } from "vuex";
  69. export default {
  70. data() {
  71. return {
  72. mch_id: null,
  73. type: '',
  74. first: true,
  75. value: -1,
  76. color: '',
  77. list: [],
  78. }
  79. },
  80. computed: {
  81. ...mapState({
  82. userInfo: state => state.user.info,
  83. adminImg: state => state.mallConfig.__wxapp_img.app_admin
  84. })
  85. },
  86. methods: {
  87. editCat(item) {
  88. let id = item.value ? item.value : null;
  89. uni.navigateTo({
  90. url: `/pages/goods-edit/cat-edit/cat-edit?mch_id=`+this.mch_id+`&type=`+this.type+`&id=`+ id
  91. })
  92. },
  93. toggle(item) {
  94. item.show = !item.show;
  95. this.$forceUpdate();
  96. },
  97. getCat() {
  98. let that = this;
  99. let url = this.mch_id == 0 ? that.$api.app_admin.cat : that.type == 'mall' ? that.$api.mch.cat : that.$api.mch.mch_cat;
  100. let para;
  101. that.$request({
  102. url: url,
  103. data: {
  104. mch_id: that.mch_id
  105. }
  106. }).then(response=>{
  107. that.first = false;
  108. that.$hideLoading();
  109. uni.hideLoading();
  110. if(response.code == 0) {
  111. that.list = response.data.list;
  112. for(let item of that.list) {
  113. item.show = false;
  114. if(item.children) {
  115. for(let children of item.children) {
  116. children.show = false;
  117. }
  118. }
  119. }
  120. }else {
  121. uni.showToast({
  122. title: response.msg,
  123. icon: 'none',
  124. duration: 1000
  125. });
  126. }
  127. }).catch(response => {
  128. that.$hideLoading();
  129. uni.hideLoading();
  130. });
  131. },
  132. pop(value) {
  133. this.value = value;
  134. },
  135. close() {
  136. this.value = -1;
  137. },
  138. toDelete() {
  139. let that = this;
  140. uni.showLoading({
  141. mask: true,
  142. title: '删除中...',
  143. });
  144. let url = this.mch_id == 0 ? that.$api.app_admin.cat_destroy : that.$api.mch.mch_cat_destroy;
  145. let para;
  146. that.$request({
  147. url: url,
  148. data: {
  149. id: this.value,
  150. mch_id: that.mch_id
  151. },
  152. method: 'post'
  153. }).then(response=>{
  154. uni.hideLoading();
  155. if(response.code == 0) {
  156. this.value = -1;
  157. this.getCat();
  158. }else {
  159. uni.showToast({
  160. title: response.msg,
  161. icon: 'none',
  162. duration: 1000
  163. });
  164. }
  165. }).catch(response => {
  166. uni.hideLoading();
  167. });
  168. },
  169. },
  170. onShow() {
  171. if(!this.first) {
  172. uni.showLoading({
  173. mask: true,
  174. });
  175. this.getCat();
  176. }
  177. },
  178. onLoad(options) {
  179. let that = this;
  180. that.$showLoading({
  181. type: 'global',
  182. text: '加载中...'
  183. });
  184. this.type = options.type ? options.type : '';
  185. this.mch_id = options.mch_id ? options.mch_id : 0;
  186. this.color = this.mch_id > 0 ? '#ff4544' : '#446dfd';
  187. that.getCat();
  188. }
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. .cat {
  193. background-color: #fff;
  194. margin-bottom: #{20rpx};
  195. .cat-item {
  196. height: #{88rpx};
  197. line-height: #{88rpx};
  198. font-size: #{28rpx};
  199. color: #353535;
  200. >view {
  201. flex-shrink: 0;
  202. }
  203. .show-more {
  204. width: 45rpx;
  205. height: 88rpx;
  206. image {
  207. height: #{22rpx};
  208. width: #{12rpx};
  209. }
  210. .bottom {
  211. width: 22rpx;
  212. height: 12rpx;
  213. }
  214. }
  215. .cat-name {
  216. flex-grow: 1;
  217. .cat-left {
  218. margin-left: 16rpx;
  219. }
  220. }
  221. .cat-menu {
  222. margin-right: 16rpx;
  223. image {
  224. height: #{40rpx};
  225. width: #{40rpx};
  226. margin-left: 10rpx;
  227. }
  228. }
  229. &.sec-cat {
  230. .cat-name {
  231. border-top: 2rpx solid #e2e2e2;
  232. }
  233. .cat-menu {
  234. border-top: 2rpx solid #e2e2e2;
  235. }
  236. }
  237. }
  238. }
  239. .add-cat {
  240. height: #{120rpx};
  241. background-color: #fff;
  242. margin-bottom: #{20rpx};
  243. padding-top: #{24rpx};
  244. .add-cat-btn {
  245. height: #{72rpx};
  246. width: #{320rpx};
  247. border-radius: #{36rpx};
  248. border: #{1rpx} solid #446dfd;
  249. margin: 0 auto;
  250. color: #446dfd;
  251. font-size: #{26rpx};
  252. line-height: #{72rpx};
  253. image {
  254. height: #{28rpx};
  255. width: #{28rpx};
  256. margin-right: #{12rpx};
  257. margin-top: #{22rpx};
  258. }
  259. }
  260. }
  261. .dialog {
  262. position: fixed;
  263. height: 100%;
  264. width: 100%;
  265. bottom: 0;
  266. left: 0;
  267. z-index: 10;
  268. background-color: rgba(0, 0, 0, .3);
  269. .dialog-item {
  270. padding-top: #{20rpx};
  271. position: fixed;
  272. top: 25%;
  273. left: 0;
  274. right: 0;
  275. margin: 0 auto;
  276. width: #{620rpx};
  277. border-radius: #{16rpx};
  278. background-color: #fff;
  279. text-align: center;
  280. }
  281. .btn-area {
  282. height: #{88rpx};
  283. position: relative;
  284. border-top: #{1rpx} solid #e2e2e2;
  285. .line {
  286. height: #{32rpx};
  287. width: #{1rpx};
  288. background-color: #e2e2e2;
  289. position: absolute;
  290. top: #{28rpx};
  291. left: 0;
  292. right: 0;
  293. margin: 0 auto;
  294. }
  295. .submit-btn {
  296. height: #{88rpx};
  297. line-height: #{88rpx};
  298. font-size: #{32rpx};
  299. color: #666;
  300. width: #{310rpx};
  301. text-align: center;
  302. }
  303. .submit-btn.be-submit {
  304. color: #446dfd;
  305. }
  306. }
  307. .dialog-title {
  308. text-align: center;
  309. font-size: 32rpx;
  310. color: #353535;
  311. margin: #{66rpx} 0 #{76rpx};
  312. }
  313. }
  314. </style>