Commit 91483a06 authored by Damon's avatar Damon

feat: 更多型号交互

parent 58f4c1c2
......@@ -2,7 +2,12 @@
<view class="u-flex content">
<view class="categary" v-if="type === '2'">
<view class="u-flex u-col-center">
<view :class="['txt', {'active': categoryId === item.categoryId }]" v-for="item in categary" :key="item.categoryId" @click="changeCategary(item)">{{item.label}}</view>
<view
:class="['txt', {'active': categoryId === item.categoryId }]"
v-for="item in categary"
:key="item.categoryId"
@click="changeCategary(item)"
>{{item.label}}</view>
</view>
</view>
......@@ -26,18 +31,24 @@
class="u-flex"
:scroll-into-view="scrollId"
>
<view :id="`brand${item.brandId}`" :class="['label-title', { selected: item.brandId == brandId }]" v-for="(item, index) in brand" :key="index" @click="selectBrand(item, index)">{{ item.label }}</view>
<view
:id="`brand${item.brandId}`"
:class="['label-title', { selected: item.brandId == brandId }]"
v-for="(item, index) in brand"
:key="index"
@click="selectBrand(item, index)"
>{{ item.label }}</view>
</scroll-view>
</view>
<view class="more u-flex" @click="handleClick">
<!-- <picker mode="selector" :value="brandIndex" range-key="label" :range="brand" @click="show = true" @change="changeBrand"> -->
<view class="more-text">更多</view>
<view class="more-text">更多</view>
<!-- </picker> -->
<u-icon class="input-icon" color="#2272FF" name="arrow-right"></u-icon>
</view>
</view>
<view class="model u-flex" v-if="brand.length > 0">
<view class="model u-flex" v-show="showMore !== true">
<view class="label-content u-flex">
<scroll-view
style="width:100%;white-space: nowrap;"
......@@ -45,18 +56,44 @@
class="u-flex"
:scroll-into-view="scrollId"
>
<view :id="`brand${item.brandId}`" :class="['label-title', { selected: item.brandId == brandId }]" v-for="(item, index) in brand" :key="index" @click="selectBrand(item, index)">{{ item.label }}</view>
<view
:id="`brand${item.brandId}`"
:class="['label-title', { selected: item.brandId == brandId }]"
v-for="(item, index) in brand"
:key="index"
@click="selectBrand(item, index)"
>{{ item.label }}</view>
</scroll-view>
</view>
<view class="more u-flex" @click="handleClick">
<!-- <picker mode="selector" :value="brandIndex" range-key="label" :range="brand" @click="show = true" @change="changeBrand"> -->
<!-- <view class="more-text">更多</view> -->
<!-- </picker> -->
<view class="more u-flex" @click="showMore = true">
<u-icon class="input-icon" color="#666" name="arrow-down"></u-icon>
</view>
</view>
<view class="allModel u-flex" v-show="showMore === true">
<view class="label-content u-flex">
<scroll-view
style="width:100%;height: 320rpx;"
scroll-y="true"
class="u-flex"
:scroll-into-view="scrollId"
>
<view
:id="`brand${item.brandId}`"
:class="['label-title', { selected: item.brandId == brandId }]"
v-for="(item, index) in brand"
:key="index"
@click="selectBrand(item, index)"
>{{ item.label }}</view>
</scroll-view>
</view>
<view class="more u-flex" @click="showMore = false">
<u-icon class="input-icon" color="#666" name="arrow-up"></u-icon>
</view>
</view>
<view class="lists">
<view class="mask" v-show="showMore === true" @click="showMore = false"></view>
<scroll-view
style="height:100%;"
:scroll-top="scrollTop"
......@@ -65,7 +102,7 @@
@scrolltolower="loadMore"
>
<select-parts
v-for="(item, index) in lists"
v-for="(item, index) in lists"
:key="index"
:info="item"
:show-checked="false"
......@@ -80,7 +117,7 @@
</view>
<view class="bar" v-show="partNum > 0">
<submit-bar
<submit-bar
:partNum="partNum"
:num="num"
:btnStatus="partNum > 0"
......@@ -93,87 +130,95 @@
</template>
<script>
import selectParts from "@/components/select-parts/index"
import submitBar from "@/components/submit-bar/index"
import selectParts from '@/components/select-parts/index'
import submitBar from '@/components/submit-bar/index'
export default {
components: {
selectParts,
submitBar
submitBar,
},
data() {
return {
keyword: '',
show: false,
showMore: false,
categary: [],
brand: [],
model: [],
categaryIndex: 0,
categoryId: '',
brandIndex: 0,
brandId: 0,
scrollId: '',
loadStatus: "loadmore",
loadStatus: 'loadmore',
lists: [],
submitList: [],
pageSize: 20,
pageNumber: 1,
type: '1',
};
}
},
computed: {
searchStyle() {
return {
color: "#2272FF"
};
color: '#2272FF',
}
},
// 配件数
partNum() {
return this.submitList.reduce((counter, item) => !item.disabled && item.quantity > 0 ? counter += 1 : counter, 0)
return this.submitList.reduce(
(counter, item) =>
!item.disabled && item.quantity > 0 ? (counter += 1) : counter,
0
)
},
// 总数
num() {
return this.submitList.reduce((counter, { disabled, quantity }) => !disabled ? counter += quantity : counter, 0)
return this.submitList.reduce(
(counter, { disabled, quantity }) =>
!disabled ? (counter += quantity) : counter,
0
)
},
loadText() {
return {
loadmore: '上拉加载更多',
loading: '努力加载中',
nomore: this.pageNumber > 1 ? '没有更多了' : '未找到物料',
}
},
loadText() {
return {
loadmore: '上拉加载更多',
loading: '努力加载中',
nomore: this.pageNumber > 1 ? '没有更多了' : '未找到物料'
}
}
},
onLoad(e) {
getApp().trackPage('选择配件页')
if (e) {
if (e.type == 1) {
this.categoryId = e.categaryId || ''
this.type = e.type
this.getBrandList(e.brandId)
} else if (e.type == 2) {
this.type = e.type
this.getCategaryList()
}
}
getApp().trackPage('选择配件页')
if (e) {
if (e.type == 1) {
this.categoryId = e.categaryId || ''
this.type = e.type
this.getBrandList(e.brandId)
} else if (e.type == 2) {
this.type = e.type
this.getCategaryList()
}
}
},
onShow() {
let pages = getCurrentPages();
let page = pages[pages.length - 1];
let selectedItem = page.selectedItem;
if (selectedItem) {
page.selectedItem = null
this.selectBrand(selectedItem.item, selectedItem.index)
this.scrollId = `brand${selectedItem.id}`
}
let pages = getCurrentPages()
let page = pages[pages.length - 1]
let selectedItem = page.selectedItem
if (selectedItem) {
page.selectedItem = null
this.selectBrand(selectedItem.item, selectedItem.index)
this.scrollId = `brand${selectedItem.id}`
}
},
methods: {
// 获取品类
getCategaryList() {
this.$u.api.getCategoryList().then(res => {
this.$u.api.getCategoryList().then((res) => {
if (res.code === 200) {
const data = res.data
if (data.length > 0) {
this.categary = data.map(v => {
this.categary = data.map((v) => {
v.label = v.categoryName
return v
})
......@@ -191,7 +236,7 @@ export default {
},
// 获取品牌
getBrandList(id) {
this.$u.api.getBrandList({categoryId: this.categoryId}).then(res => {
this.$u.api.getBrandList({ categoryId: this.categoryId }).then((res) => {
if (res.code === 200) {
const data = res.data
let item, index
......@@ -217,20 +262,20 @@ export default {
},
// 获取配件列表
getPartsList() {
this.page++;
this.loadStatus = "loading";
this.page++
this.loadStatus = 'loading'
const params = {
pageNumber: this.pageNumber,
pageSize: this.pageSize,
categoryId: this.categoryId || '',
brandId: this.brandId || '',
keyword: this.keyword
keyword: this.keyword,
}
this.$u.api.getPartsList(params).then(res => {
this.$u.api.getPartsList(params).then((res) => {
if (res.code === 200) {
const data = res.data
if (data.length > 0) {
const lists = data.map(v => {
const lists = data.map((v) => {
v.quantity = 0
v.disabled = true
v.max = 9999
......@@ -240,11 +285,11 @@ export default {
})
this.lists = this.lists.concat(lists)
this.pageNumber++
this.loadStatus = lists.length < this.pageSize ? "nomore" : "loadmore"
this.loadStatus =
lists.length < this.pageSize ? 'nomore' : 'loadmore'
} else {
this.loadStatus = "nomore"
this.loadStatus = 'nomore'
}
}
})
},
......@@ -283,21 +328,28 @@ export default {
},
// 加载更多
loadMore() {
if (this.loadStatus !== "nomore") {
this.getPartsList();
if (this.loadStatus !== 'nomore') {
this.getPartsList()
}
},
// 点击更多
handleClick() {
this.$u.route({url: 'pages/order/document-tag' + '?categoryId=' + this.categoryId + '&selectedId=' + this.brandId})
},
// 点击更多
handleClick() {
this.$u.route({
url:
'pages/order/document-tag' +
'?categoryId=' +
this.categoryId +
'&selectedId=' +
this.brandId,
})
},
// 加入申请
apply(item, index) {
this.$set(this.lists[index], 'disabled', false)
this.$set(this.lists[index], 'quantity', 1)
// 如果购物车没有该记录,则添加
const findIndex = this.submitList.findIndex(v => v.id === item.id)
const findIndex = this.submitList.findIndex((v) => v.id === item.id)
if (findIndex === -1) this.submitList.push(item)
},
// 改变数量
......@@ -305,25 +357,27 @@ export default {
this.$set(this.lists[index], 'quantity', val)
if (val === 0) this.$set(this.lists[index], 'disabled', true)
// 如果购物车有该记录,则更新
const findIndex = this.submitList.findIndex(v => v.id === item.id)
const findIndex = this.submitList.findIndex((v) => v.id === item.id)
this.$set(this.submitList[findIndex], 'quantity', val)
},
// 提交
submit() {
const lists = this.submitList.filter(v => !v.disabled && v.quantity > 0).map(v => {
return {
part_id: v.skuId,
name: v.name,
quantity: v.quantity
}
})
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2]; //上一个页面
const lists = this.submitList
.filter((v) => !v.disabled && v.quantity > 0)
.map((v) => {
return {
part_id: v.skuId,
name: v.name,
quantity: v.quantity,
}
})
let pages = getCurrentPages()
let prevPage = pages[pages.length - 2] //上一个页面
prevPage.$vm.updateParts(lists)
this.$u.route({ type: 'back' })
}
},
},
};
}
</script>
<style lang="scss" scoped>
......@@ -349,10 +403,9 @@ export default {
margin-right: 30rpx;
}
}
.warp {
border-radius: 30rpx 30rpx 0 0;
padding: 30rpx 30rpx 0 30rpx;
width: 100%;
background: #fff;
flex-direction: column;
......@@ -361,17 +414,17 @@ export default {
overflow: hidden;
.brand {
width: 100%;
padding-bottom: 20rpx;
padding: 20rpx 30rpx 0rpx 30rpx;
.label-content {
flex: 1;
overflow: hidden;
padding-right: 20rpx;
border-right: 2rpx solid #F4F5F7;
border-right: 2rpx solid #f4f5f7;
.label-title {
color:#666;
color: #666;
padding: 10rpx 0rpx;
margin-right: 40rpx;
display:inline-block;
display: inline-block;
font-size: 32rpx;
&.selected {
color: #2272ff;
......@@ -385,21 +438,20 @@ export default {
width: 100rpx;
padding-left: 20rpx;
.more-text {
color: #2272FF;
color: #2272ff;
font-size: 26rpx;
}
}
}
.model {
width: 100%;
padding: 20rpx 0;
padding: 30rpx 30rpx 0 30rpx;
.label-content {
flex: 1;
overflow: hidden;
padding-right: 20rpx;
border-right: 2rpx solid #F4F5F7;
.label-title {
background: #F4F5F7;
background: #f4f5f7;
color: #999;
padding: 7rpx 30rpx;
margin-right: 20rpx;
......@@ -408,22 +460,58 @@ export default {
border-radius: 30rpx;
&.selected {
color: #fff;
background: #2272FF;
background: #2272ff;
}
}
}
.more {
padding-left: 20rpx;
.more-text {
color: #2272FF;
}
}
.allModel {
width: 100%;
padding: 30rpx 30rpx 0 30rpx;
flex-flow: column;
border-radius: 0 0 30rpx 30rpx;
.label-content {
flex: 1;
overflow: hidden;
width: 100%;
.label-title {
background: #f4f5f7;
color: #999;
padding: 7rpx 30rpx;
margin: 0rpx 15rpx 20rpx 0;
display: inline-block;
font-size: 26rpx;
border-radius: 30rpx;
&.selected {
color: #fff;
background: #2272ff;
}
}
}
.more {
padding: 20rpx 0;
width: 100%;
justify-content: flex-end;
}
}
.lists {
width: 100%;
flex: 1;
overflow-y: auto;
padding: 30rpx 30rpx 0 30rpx;
position: relative;
.mask {
position: absolute;
z-index: 9;
background: #00000082;
width: 100%;
left: 0;
top: 0;
bottom: 0;
}
.load-more {
padding: 50rpx 0;
}
......@@ -431,7 +519,7 @@ export default {
}
.bar {
width: 100%;
border-top: 2rpx solid #F4F5F7;
border-top: 2rpx solid #f4f5f7;
padding: 0 20rpx;
background: #fff;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment