store_classification.vue 6.6 KB

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