Commit e3da77db authored by Damon's avatar Damon

feat: 完工备件页增加搜索

parent 62a8ef21
<template> <template>
<view class="u-flex det-wrap"> <view class="u-flex det-wrap">
<view class="search">
<u-search
:clearabled="true"
:action-style="searchStyle"
bg-color="#fff"
v-model="keyword"
@custom="searchParts"
@search="searchParts"
></u-search>
</view>
<view class="content" v-if="lists.length > 0"> <view class="content" v-if="lists.length > 0">
<scroll-view style="height: 100%;" scroll-y="true"> <scroll-view style="height: 100%;" scroll-y="true">
<select-parts <select-parts
v-for="(item, index) in lists" v-for="(item, index) in lists"
:key="index" :key="index"
:info="item" :info="item"
:show-checked="true" :show-checked="true"
...@@ -23,7 +34,7 @@ ...@@ -23,7 +34,7 @@
</view> </view>
<view class="bar" v-if="lists.length > 0"> <view class="bar" v-if="lists.length > 0">
<submit-bar <submit-bar
:partNum="partNum" :partNum="partNum"
:num="num" :num="num"
:btnStatus="partNum > 0" :btnStatus="partNum > 0"
...@@ -35,50 +46,72 @@ ...@@ -35,50 +46,72 @@
@cancel="cancel" @cancel="cancel"
/> />
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import selectParts from "@/components/select-parts/index" import selectParts from '@/components/select-parts/index'
import submitBar from "@/components/submit-bar/index" import submitBar from '@/components/submit-bar/index'
export default { export default {
components: { components: {
selectParts, selectParts,
submitBar submitBar,
},
data() {
return {
keyword: '',
lists: [],
workOrderId: null,
}
},
computed: {
// 配件数
partNum() {
return this.lists.reduce(
(counter, { checked }) => (checked ? (counter += 1) : counter),
0
)
}, },
data() { // 总数
return { num() {
lists: [], return this.lists.reduce(
workOrderId: null, (counter, { checked, quantity }) =>
} checked ? (counter += quantity) : counter,
0
)
}, },
computed: { // 全选状态
// 配件数 allChecked() {
partNum() { const count = this.lists.reduce(
return this.lists.reduce((counter, { checked }) => checked ? counter += 1 : counter, 0) (counter, { checked }) => (!checked ? (counter += 1) : counter),
}, 0
// 总数 )
num() { return count === 0 || false
return this.lists.reduce((counter, { checked, quantity }) => checked ? counter += quantity : counter, 0)
},
// 全选状态
allChecked() {
const count = this.lists.reduce((counter, { checked }) => !checked ? counter += 1 : counter, 0)
return count === 0 || false
}
}, },
onLoad(e) { searchStyle() {
this.workOrderId = parseInt(e.workOrderId) return {
this.categoryId = parseInt(e.categoryId) color: '#2272FF',
this.brandId = parseInt(e.brandId) }
this.getReserve()
}, },
methods: { },
getReserve() { onLoad(e) {
this.$u.api.getMyReserve({'categoryId': this.categoryId, 'brandId': this.brandId}).then(res => { this.workOrderId = parseInt(e.workOrderId)
this.categoryId = parseInt(e.categoryId)
this.brandId = parseInt(e.brandId)
this.getReserve()
},
methods: {
getReserve() {
this.$u.api
.getMyReserve({
categoryId: this.categoryId,
brandId: this.brandId,
keyword: this.keyword,
})
.then((res) => {
if (res.code === 200) { if (res.code === 200) {
const data = res.data || [] const data = res.data || []
this.lists = data.map(v => { this.lists = data.map((v) => {
v.min = 1 v.min = 1
v.max = v.stock v.max = v.stock
v.checked = false v.checked = false
...@@ -89,75 +122,83 @@ ...@@ -89,75 +122,83 @@
}) })
} }
}) })
}, },
numChange(val, index) { // 搜索配件
this.$set(this.lists[index], 'quantity', val) searchParts(val) {
}, this.keyword = val
selectChange(val, index) { this.lists = []
this.$set(this.lists[index], 'checked', val) this.getReserve()
}, },
allSelect(value) { numChange(val, index) {
const count = this.lists.filter(v => !v.checked).length this.$set(this.lists[index], 'quantity', val)
this.lists.forEach(v => { },
this.$set(v, 'checked', count !== 0 || false) selectChange(val, index) {
}) this.$set(this.lists[index], 'checked', val)
}, },
submit() { allSelect(value) {
const lists = this.lists.filter(v => v.checked).map(v => { const count = this.lists.filter((v) => !v.checked).length
this.lists.forEach((v) => {
this.$set(v, 'checked', count !== 0 || false)
})
},
submit() {
const lists = this.lists
.filter((v) => v.checked)
.map((v) => {
return { return {
name: v.name, name: v.name,
part_id: v.skuId, part_id: v.skuId,
quantity: v.quantity, quantity: v.quantity,
max: v.max, max: v.max,
cost: v.cost || 0 cost: v.cost || 0,
} }
}) })
let pages = getCurrentPages(); let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]; //上一个页面 let prevPage = pages[pages.length - 2] //上一个页面
prevPage.$vm.$refs['fileChildParts'][0].valChange(lists) prevPage.$vm.$refs['fileChildParts'][0].valChange(lists)
this.$u.route({ type: 'back' }) this.$u.route({ type: 'back' })
}, },
cancel() { cancel() {
let pages = getCurrentPages(); let pages = getCurrentPages()
let prevPage = pages[pages.length - 2]; //上一个页面 let prevPage = pages[pages.length - 2] //上一个页面
prevPage.$vm.$refs['fileChildParts'][0].valChange() prevPage.$vm.$refs['fileChildParts'][0].valChange()
this.$u.route({ type: 'back' }) this.$u.route({ type: 'back' })
}, },
qnFile(src) { qnFile(src) {
return process.uniEnv.qn_base_url + src return process.uniEnv.qn_base_url + src
} },
} },
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.det-wrap { .det-wrap {
flex-flow: column; flex-flow: column;
height: 100vh; height: 100vh;
.search { .search {
width: 100%; width: 100%;
padding: 30rpx; padding: 30rpx;
} }
.content { .content {
background: #fff; background: #fff;
border-radius: 30rpx 30rpx 0 0; border-radius: 30rpx 30rpx 0 0;
padding: 10rpx 10rpx 0 10rpx; padding: 10rpx 10rpx 0 10rpx;
width: 100%; width: 100%;
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
} }
.bar { .bar {
width: 100%; width: 100%;
border-top: 1px solid #F4F5F7; border-top: 1px solid #f4f5f7;
padding: 0 20rpx; padding: 0 20rpx;
background: #fff; background: #fff;
} }
.empty { .empty {
flex: 1; flex: 1;
justify-content: center; justify-content: center;
font-size: 26rpx; font-size: 26rpx;
color: #aaa; color: #aaa;
}
} }
}
</style> </style>
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