Commit 1b8c4d00 by 张立顺

feat 功能开发

1 parent 6e118926
// tabRepairOrder/components/servicePopup/index.js // tabRepairOrder/components/servicePopup/index.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/' const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import api from '../../api' import api from '../../api'
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
*/ */
properties: { properties: {
show: { show: {
type: Boolean, type: Boolean,
observer: function(n) { observer: function (n) {
if (n) { if (n) {
let { selected } = this.data let { selected } = this.data
this.setData({ this.setData(
searchValue: '', {
selectedData: wx.$util.deepClone(selected) searchValue: '',
}, () => { selectedData: wx.$util.deepClone(selected)
this.getList(true) },
}) () => {
this.getList(true)
}
)
} }
} }
}, },
selected: { selected: {
type: Array, type: Array,
observer: function(n) { observer: function (n) {}
} },
selectGoodsList: {
type: Array,
observer: function (n) {}
} }
}, },
...@@ -50,10 +56,10 @@ Component({ ...@@ -50,10 +56,10 @@ Component({
updateNumber(id, value, isBlur = false) { updateNumber(id, value, isBlur = false) {
let { servicesList, copyServicesList } = this.data let { servicesList, copyServicesList } = this.data
const finalValue = isBlur ? (value < 1 ? 1 : value) : value const finalValue = isBlur ? (value < 1 ? 1 : value) : value
const updateList = (list) => { const updateList = list => {
return list?.map(item => ({ return list?.map(item => ({
...item, ...item,
detailList: item?.detailList?.map(child => detailList: item?.detailList?.map(child =>
child.id === id ? { ...child, useNum: finalValue } : child child.id === id ? { ...child, useNum: finalValue } : child
) )
})) }))
...@@ -77,49 +83,60 @@ Component({ ...@@ -77,49 +83,60 @@ Component({
}, },
// 获取服务项目数据 // 获取服务项目数据
getList(firstFlag) { getList(firstFlag) {
let { searchValue } = this.data let { searchValue, selectGoodsList } = this.data
api.getServiceItemList({serviceItemsName: searchValue}).then(res => { const subOrderCodeList =
let { code, data, message } = res selectGoodsList?.map(item => item.subOrderCode) || []
if (code == 0) {
let {selectedData} = this.data api
const selectedIds = selectedData?.reduce((set, item) => { .getServiceItemList({ serviceItemsName: searchValue, subOrderCodeList })
item?.detailList?.forEach(({ serviceItemsId }) => set.add(serviceItemsId)) .then(res => {
return set let { code, data, message } = res
}, new Set()) ?? new Set() if (code == 0) {
const selectedItems = selectedData?.reduce((arr, item) => { let { selectedData } = this.data
item?.detailList?.forEach(({ serviceItemsId, useNum }) => { const selectedIds =
// 检查是否已存在相同的id selectedData?.reduce((set, item) => {
const existingItem = arr.find(obj => obj.id === serviceItemsId); item?.detailList?.forEach(({ serviceItemsId }) =>
if (!existingItem) { set.add(serviceItemsId)
arr.push({ )
id: serviceItemsId, return set
useNum: useNum }, new Set()) ?? new Set()
}); const selectedItems =
} selectedData?.reduce((arr, item) => {
}); item?.detailList?.forEach(({ serviceItemsId, useNum }) => {
return arr; // 检查是否已存在相同的id
}, []) ?? []; const existingItem = arr.find(
data?.forEach(val => { obj => obj.id === serviceItemsId
val.title = `${val.categoryName}-${val.itemName}` )
val.detailList = val.serviceItemList?.map(item => ({ if (!existingItem) {
...item, arr.push({
serviceItemsId: item.id, id: serviceItemsId,
active: selectedIds.has(item.id), useNum: useNum
useNum: selectedItems?.find(v => v.id == item.id)?.useNum })
})) }
}) })
this.setData({ return arr
servicesList: data }, []) ?? []
}) data?.forEach(val => {
if (firstFlag) { val.title = `${val.categoryName}-${val.itemName}`
val.detailList = val.serviceItemList?.map(item => ({
...item,
serviceItemsId: item.id,
active: selectedIds.has(item.id),
useNum: selectedItems?.find(v => v.id == item.id)?.useNum
}))
})
this.setData({ this.setData({
copyServicesList: wx.$util.deepClone(data || []) servicesList: data
}) })
if (firstFlag) {
this.setData({
copyServicesList: wx.$util.deepClone(data || [])
})
}
} else {
wx.$util.showToast(message)
} }
} else { })
wx.$util.showToast(message)
}
})
}, },
search() { search() {
this.getList() this.getList()
...@@ -148,13 +165,16 @@ Component({ ...@@ -148,13 +165,16 @@ Component({
}) })
return val return val
}) })
const filteredServicesList = copyServicesList?.map(val => { const filteredServicesList =
if (!val?.detailList) return null copyServicesList
return { ?.map(val => {
...val, if (!val?.detailList) return null
detailList: val.detailList.filter(v => v.active === true) return {
} ...val,
}).filter(val => val && val.detailList.length > 0) || [] detailList: val.detailList.filter(v => v.active === true)
}
})
.filter(val => val && val.detailList.length > 0) || []
this.setData({ this.setData({
servicesList, servicesList,
copyServicesList, copyServicesList,
...@@ -163,29 +183,33 @@ Component({ ...@@ -163,29 +183,33 @@ Component({
}, },
// 展开收起服务项目 // 展开收起服务项目
handleShowItem(e) { handleShowItem(e) {
let {index} = e.currentTarget.dataset let { index } = e.currentTarget.dataset
let {servicesList} = this.data let { servicesList } = this.data
this.setData({ this.setData({
[`servicesList[${index}].showItemFlag`]: !servicesList[index].showItemFlag [`servicesList[${index}].showItemFlag`]:
!servicesList[index].showItemFlag
}) })
}, },
cancel() { cancel() {
this.triggerEvent('cancel') this.triggerEvent('cancel')
}, },
confirm() { confirm() {
let {servicesList, copyServicesList} = this.data let { servicesList, copyServicesList } = this.data
const result = copyServicesList.map(item => ({ const result = copyServicesList
...item, .map(item => ({
detailList: item?.detailList.filter(child => child.active) ...item,
})).filter(item => item.detailList?.length > 0).map(val => ({ detailList: item?.detailList.filter(child => child.active)
...val, }))
useNum: val.useNum < 1 ? 1 : val.useNum // 兜底处理 当输入框为空值或0时默认赋值1 ,防止失去焦点赋值导致数据错误 .filter(item => item.detailList?.length > 0)
})) .map(val => ({
...val,
useNum: val.useNum < 1 ? 1 : val.useNum // 兜底处理 当输入框为空值或0时默认赋值1 ,防止失去焦点赋值导致数据错误
}))
const activeNum = result.reduce((total, item) => { const activeNum = result.reduce((total, item) => {
return total + (item?.detailList?.length || 0); return total + (item?.detailList?.length || 0)
}, 0); }, 0)
if (activeNum <= 0) return wx.$util.showToast('请选择服务项目') if (activeNum <= 0) return wx.$util.showToast('请选择服务项目')
this.triggerEvent('confirm', result) this.triggerEvent('confirm', result)
} }
} }
})
\ No newline at end of file \ No newline at end of file
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!