store_classification.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="area_container">
  3. <view class="area_container_title">
  4. <navigator :url="`/pages/product/storeClassification/index?mer_id=${mer_id}`" hover-class="none" class="manage_btn">管理</navigator>
  5. <view class="area_container_title_name">选择店铺分类</view>
  6. <view class="area_container_title_close" @click="close"><text class="iconfont" >&#xe62f;</text></view>
  7. </view>
  8. <view class="area_container_content">
  9. <view class="selectList_con">
  10. <view class="selectList_con_item" v-for="(item, index) in selectList" :key="index">
  11. <text>{{ item.label }}</text>
  12. <text class="iconfont" @click="delSelectItem(item, index)">&#xe62f;</text>
  13. </view>
  14. </view>
  15. <view class="selectList_tap">
  16. <view class="selectList_tap_item" v-for="(item, index) in tapList" :key="index" @click="selectTapItem(item, index)" :class="{ selectTap: selectTap == item.value }">
  17. {{ item.label }}
  18. </view>
  19. <view class="selectList_tap_item" @click="selectTapLastItem(-1)" v-if="isShowLastItem" :class="{ selectTap: selectTap == -1 }">请选择</view>
  20. </view>
  21. <view class="selectList_area">
  22. <scroll-view scroll-y="true" class="scroll">
  23. <view v-for="(item, index) in areaList" :key="index" class="selectList_area_item">
  24. <view class="selectList_area_item_name" @click="selectArea(item)">{{ item.label }}</view>
  25. <view @click="handlyAddSelect(item)" v-if="!item.children"><text class="iconfont">&#xe70e;</text></view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. <view class="handle"><view class="handle_button" @click="handleGetSelectArea">确定</view></view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. // +----------------------------------------------------------------------
  35. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  36. // +----------------------------------------------------------------------
  37. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  38. // +----------------------------------------------------------------------
  39. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  40. // +----------------------------------------------------------------------
  41. // | Author: CRMEB Team <admin@crmeb.com>
  42. // +----------------------------------------------------------------------
  43. import { serialize, Toast } from '../../../libs/uniApi.js';
  44. export default {
  45. props:{
  46. allReadySelect: {
  47. type: Array,
  48. default:() => {
  49. return []
  50. }
  51. },
  52. classifiedData: {
  53. type: Array,
  54. default:() => {
  55. return []
  56. }
  57. },
  58. mer_id: {
  59. type: Number,
  60. default: 0
  61. }
  62. },
  63. data() {
  64. return {
  65. selectList: [],
  66. selectTap: -1,
  67. selectTapIndex: -1, // 选择的列表下班
  68. tapList: [],
  69. isShowLastItem: true, // 是否展示最后一项请选择
  70. areaList: []
  71. };
  72. },
  73. watch: {
  74. classifiedData: {
  75. handler(val) {
  76. this.areaList = this.classifiedData
  77. },
  78. deep: true
  79. }
  80. },
  81. created() {
  82. this.areaList = serialize(this.classifiedData);
  83. console.log(this.areaList);
  84. },
  85. methods: {
  86. // 选择地址
  87. async selectArea(item) {
  88. // 当选择项没有子集时
  89. if (!(item.children && item.children.length)) {
  90. // Toast('该选项没有子集');
  91. return;
  92. if (this.isShowLastItem) {
  93. this.tapList.push(item);
  94. } else {
  95. this.tapList.splice(this.tapList.length - 1, 1, item);
  96. }
  97. this.isShowLastItem = false;
  98. return;
  99. }
  100. console.log(item);
  101. // 如果title被选中,选择子项时,删除后面所有title——item
  102. if (this.selectTapIndex > -1) {
  103. this.tapList.splice(this.selectTapIndex, 999);
  104. this.areaList = item.children;
  105. this.tapList.push(item);
  106. this.isShowLastItem = true;
  107. this.selectTap = -1;
  108. this.selectTapIndex = -1;
  109. return;
  110. }
  111. // 当所选择项拥有子集时
  112. if (item.children && item.children.length) {
  113. this.areaList = item.children;
  114. this.tapList.push(item);
  115. this.isShowLastItem = true;
  116. this.selectTap = -1;
  117. return;
  118. }
  119. },
  120. // 选择tap
  121. async selectTapItem(item, index) {
  122. if(index == 0) {
  123. this.areaList = serialize(this.classifiedData);
  124. this.selectTap = item.value; // 添加边框
  125. this.selectTapIndex = index; // 用于判断选择子集时,是否需要删除后面得选项
  126. return;
  127. }
  128. this.selectTap = item.value;
  129. this.areaList = item.children;
  130. },
  131. // 点击请选择
  132. selectTapLastItem(val) {
  133. this.selectTap = -1;
  134. if (!this.tapList.length) {
  135. // this.areaList = val.children;
  136. this.areaList = serialize(this.classifiedData);
  137. return;
  138. }
  139. this.areaList = this.tapList[this.tapList.length - 1].children;
  140. },
  141. // 点击加号事件
  142. handlyAddSelect(item) {
  143. if (this.selectList.some(val => val.value == item.value)) {
  144. Toast('已经选择过了')
  145. return
  146. }
  147. if (this.selectTapIndex > -1) {
  148. this.tapList.splice(this.selectTapIndex, 999);
  149. }
  150. if (!item.parent_id) {
  151. this.selectList.push(item);
  152. return;
  153. }
  154. let str = '';
  155. str =
  156. serialize(this.tapList)
  157. .map(val => val.name)
  158. .join('/') +
  159. '/' +
  160. item.name;
  161. this.selectList.push({ ...item, name: str });
  162. },
  163. // 删除所选地址
  164. delSelectItem(item, index) {
  165. this.selectList.splice(index, 1);
  166. },
  167. // 点击确定按钮,抛出已选项
  168. handleGetSelectArea() {
  169. this.$emit('handleGetSelectArea', this.selectList);
  170. },
  171. close() {
  172. this.$emit('close');
  173. },
  174. // 数组去重
  175. unique(arr) {
  176. var obj = {};
  177. return arr.filter(ele => {
  178. if (!obj[ele]) {
  179. obj[ele] = true;
  180. return true;
  181. }
  182. });
  183. }
  184. }
  185. };
  186. </script>
  187. <style lang="scss" scoped>
  188. .area_container {
  189. background: #fff;
  190. border-radius: 16px 16px 0px 0px;
  191. &_title {
  192. text-align: center;
  193. padding: 36rpx 30rpx 46rpx 0;
  194. position: relative;
  195. &_close {
  196. position: absolute;
  197. top: 20rpx;
  198. right: 20rpx;
  199. }
  200. .manage_btn{
  201. font-weight: normal;
  202. color: #e93323;
  203. font-size: 24rpx;
  204. position: absolute;
  205. left: 30rpx;
  206. top: 40rpx;
  207. }
  208. }
  209. &_content {
  210. padding: 0 30rpx;
  211. .selectList_con {
  212. display: flex;
  213. flex-wrap: wrap;
  214. margin-bottom: 50rpx;
  215. &_item {
  216. padding: 3rpx 10rpx;
  217. background: #fff6f5;
  218. color: #e93323;
  219. margin-right: 20rpx;
  220. margin-bottom: 20rpx;
  221. display: flex;
  222. align-items: center;
  223. font-size: 22rpx;
  224. > span:nth-child(1) {
  225. display: inline-block;
  226. margin-right: 14rpx;
  227. white-space: nowrap;
  228. }
  229. .iconfont {
  230. font-size: 24rpx;
  231. }
  232. }
  233. }
  234. .selectList_tap {
  235. border-bottom: 1px solid #eeeeee;
  236. display: flex;
  237. &_item {
  238. font-size: 28rpx;
  239. margin-right: 60rpx;
  240. white-space: nowrap;
  241. }
  242. .selectTap {
  243. color: #e93323;
  244. border-bottom: 3rpx solid #e93323;
  245. padding-bottom: 21rpx;
  246. }
  247. }
  248. .selectList_area {
  249. .scroll {
  250. height: 597rpx;
  251. }
  252. .selectList_area_item {
  253. padding: 40rpx 0;
  254. display: flex;
  255. justify-content: space-between;
  256. font-size: 28rpx;
  257. .iconfont {
  258. color: #e93323;
  259. font-size: 40rpx;
  260. }
  261. .selectList_area_item_name {
  262. flex: 0.7;
  263. }
  264. }
  265. }
  266. .handle {
  267. height: 126rpx;
  268. &_button {
  269. width: 690rpx;
  270. height: 86rpx;
  271. background: #e93323;
  272. border-radius: 43rpx;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. font-size: 32rpx;
  277. color: #fff;
  278. }
  279. }
  280. }
  281. }
  282. </style>