123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <template>
- <view class="select_popup_container">
- <view class="popup_title">
- <navigator v-if="mer_id" :url="`pages/product/addGoods/freightTemplate?mer_id=${mer_id}`" hover-class="none" class="manage_btn">管理</navigator>
- <view class="popup_title_msn">{{ selectProductTitle }}</view>
- <view class="close" @click="close"><text class="iconfont"></text></view>
- </view>
-
- <view class="selected_list" v-if="selectProductItem.multiple && multipleList.length">
- <view class="selected_list_item" v-for="(item, index) in multipleList" :key="index">
- <view>{{ item.label }}</view>
- <view @click="deleteSelectedList(item, index)"><view class="iconfont"></view></view>
- </view>
- </view>
-
- <view class="tap">
- <scroll-view scroll-x="true" class="popup_tap">
- <view class="popup_tap_content">
- <view class="popup_tap_item" v-for="(item, index) in tap" :key="index" @click="handleSelectTapId(item, index)" :class="{ selectTapEd: selectTapId == item.value }">
- <view>{{ item.label }}</view>
- </view>
- </view>
- </scroll-view>
- </view>
-
- <view class="content">
- <scroll-view scroll-y="true" class="popup_sroll" @scrolltolower="scrolltolower">
- <view class="content_list">
- <view v-for="(item, index) in assemblyList" :key="index" class="content_list_item" :class="{ selectSingleCase: item.selectEd }">
- <view @click="selectItem(item, assemblyList)">{{ item.label }}</view>
- <view v-if="selectProductItem.multiple && !item.children"><text class="iconfont" @click="selectPushMultiple(item, assemblyList)"></text></view>
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- import { serialize } from '../../../libs/uniApi.js';
- export default {
- props: {
- selectProductTitle: {
- type: String,
- default: ''
- },
-
- classifiedData: {
- type: Array,
- default: () => {
- return [];
- }
- },
-
- form: {
- type: Object,
- default: () => {
- return {};
- }
- },
-
- selectProductItem: {
- type: Object,
- default: () => {
- return {
-
-
-
-
-
- };
- }
- },
- mer_id: {
- type: Number,
- default: 0
- }
-
- },
- data() {
- return {
- assemblyList: [],
- tap: [],
- selectTapId: '',
- tapIndex: '',
- multipleList: []
- };
- },
- watch: {
- tap: {
- handler(val) {
-
- },
- deep: true
- },
- multipleList: {
- handler(val) {
- this.$emit('multipleList', val, this.selectProductItem.model);
- }
- },
-
- classifiedData: {
- handler(val) {
- this.initData();
- },
- deep: true
- }
- },
- created() {
- this.initData();
- this.tap.push({ value: '', label: '请选择', samelevel: this.assemblyList });
- },
- methods: {
- initData() {
- this.addClassifiedAttr(this.classifiedData, 'children', 'selectEd', false);
-
- if (this.selectProductItem.singleColumn && (this.selectProductItem.allreadySelect && this.selectProductItem.allreadySelect.length) ) {
- this.assemblyList = serialize(this.classifiedData);
- this.assemblyList.forEach(item => {
- if (this.selectProductItem.allreadySelect.map(val => val.value).includes(item.value)) {
- item.selectEd = true;
- }
- });
- return;
- }
-
- if (this.selectProductItem.allreadySelect && this.selectProductItem.allreadySelect.length && !this.selectProductItem.multiple) {
- this.tap = this.selectProductItem.allreadySelect;
- this.selectTapId = this.tap[0].value;
- this.handleSelectTapId(this.tap[0], 0);
- return;
- }
-
- this.classifiedData.forEach(item => {
- if (!item.value) {
- this.$set(item, 'value', item.brand_id);
- }
- if (!item.label) {
- this.$set(item, 'label', item.brand_name);
- }
- });
- this.assemblyList = serialize(this.classifiedData);
- },
- selectItem(item, samelevel) {
- console.log(item);
- if (this.selectProductItem.multiple) {
-
- if (!item.children || !item.children.length) {
- item.selectEd = !item.selectEd;
- }
- } else {
- this.assemblyList.forEach(val => {
- val.selectEd = false;
- });
- item.selectEd = true;
- }
- if (this.tap.filter(val => val.value === item.value).length) {
- return;
- }
- this.$set(item, 'samelevel', samelevel);
- if (this.selectTapId !== '') {
- if (!item.children || !item.children.length) {
- this.tap[this.tap.length - 1].label = item.label;
- this.tap[this.tap.length - 1].value = item.value;
- this.$emit('getLinkageData', this.tap, this.selectProductItem.model);
- return;
- }
- this.tap.splice(this.tapIndex, 1, item);
- this.tap.splice(this.tapIndex + 1, this.tap.length);
- this.selectTapId = '';
- this.assemblyList = item.children;
- this.tap.push({ value: '', label: '请选择', samelevel: this.assemblyList });
- return;
- }
- if (item.children && item.children.length && !this.selectTapId) {
- this.tap.splice(this.tap.length - 1, 0, item);
- this.assemblyList = item.children;
- } else {
- this.tap[this.tap.length - 1].label = item.label;
- this.tap[this.tap.length - 1].value = item.value;
- if (this.selectProductItem.multiple) {
- return;
- }
- this.$emit('getLinkageData', this.tap, this.selectProductItem.model);
- }
- },
-
- selectPushMultiple(item, samelevel) {
-
- item.selectEd = true;
-
- this.multipleList.push(item);
- this.multipleList = this.unique(this.multipleList);
- },
-
- unique(arr) {
- var obj = {};
- return arr.filter(ele => {
- if (!obj[ele]) {
- obj[ele] = true;
- return true;
- }
- });
- },
-
- deleteSelectedList(item, index) {
- this.multipleList.splice(index, 1);
- this.assemblyList.forEach(val => {
- if (item.value == val.value) {
- val.selectEd = false;
- }
- });
- },
-
- connectionString(arr, lab = '/') {
- return arr.map(item => item.label).join('/');
- },
- handleSelectTapId(item, index) {
- if (!item.value) {
- this.assemblyList = this.tap[this.tap.length - 2].children;
- this.selectTapId = '';
- return;
- }
- if (index == this.tap.length - 1) {
- this.selectTapId = item.value;
- this.assemblyList = this.tap[this.tap.length - 2].children;
- return;
- }
- this.selectTapId = item.value;
- this.tapIndex = index;
- this.assemblyList = item.samelevel;
- },
-
- addClassifiedAttr(arr, childKey, addkey, value) {
- arr.forEach(item => {
- this.$set(item, addkey, value);
- if (item[childKey] && item[childKey].length) {
- this.addClassifiedAttr(item[childKey], childKey, addkey, value);
- }
- });
- },
- close() {
- this.$emit('close');
- },
-
- scrolltolower() {
- this.$emit('scrolltolower', this.selectProductItem.model);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .select_popup_container {
- background: #fff;
- border-radius: 16rpx 16rpx 0 0;
- }
- .popup_title {
- display: flex;
- justify-content: flex-end;
- padding: 36rpx 30rpx;
- position: relative;
- .manage_btn{
- font-weight: normal;
- color: #e93323;
- font-size: 24rpx;
- position: absolute;
- left: 30rpx;
- top: 40rpx;
- }
- &_msn {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- color: #282828;
- font-size: 32rpx;
- font-weight: bold;
- }
-
- .close {
- position: relative;
- z-index: 10;
- font-size: 28rpx;
- color: #8a8a8a;
- }
- }
- .selected_list {
- display: flex;
- flex-wrap: wrap;
- padding: 50rpx 30rpx;
- &_item {
- display: flex;
- align-items: center;
- color: #e93323;
- margin-right: 31rpx;
- margin-bottom: 40rpx;
- padding: 3rpx 11rpx;
- background: #fff6f5;
- .iconfont {
- display: inline-block;
- margin-left: 14rpx;
- font-size: 24rpx;
- }
- }
- }
- .popup_tap {
- display: flex;
- padding: 0 30rpx;
- color: #333333;
- font-size: 28rpx;
- border-bottom: 1px solid #eeeeee;
- margin-bottom: 40rpx;
- .popup_tap_content {
- display: flex;
- }
- &_item {
- margin-right: 60rpx;
- padding-bottom: 21rpx;
- white-space: nowrap;
- }
- .selectTapEd {
- color: #e93323;
- border-bottom: 3rpx solid #e93323;
- }
- }
- .content {
- .popup_sroll {
- max-height: 742rpx;
- min-height: 300rpx;
- }
- &_list {
- &_item {
- color: #333333;
- margin-bottom: 50rpx;
- margin-left: 40rpx;
- margin-right: 40rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- > view {
- flex: 0.6;
- }
- > view:nth-child(2) {
- flex: 0.4;
- display: flex;
- justify-content: flex-end;
- }
- .iconfont {
- color: #e93323;
- font-size: 36rpx !important;
- }
- }
- }
- }
- .selectSingleCase {
- color: #e93323;
- }
- .selectTapEd {
- color: #e93323;
- border-bottom: 3rpx solid #e93323;
- }
- </style>
|