2024-06-05 18:58:12 +08:00
|
|
|
import { ref, computed } from 'vue'
|
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
|
|
import peach from '@/peach'
|
|
|
|
import GoodsApi from '@/peach/api/trade/goods'
|
2024-06-04 18:43:13 +08:00
|
|
|
import { SPEC_TYPE } from './config'
|
|
|
|
|
|
|
|
const pickerRef = ref(null)
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
const propertyList = ref([
|
|
|
|
{
|
|
|
|
id: 36,
|
|
|
|
children: [68],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 37,
|
|
|
|
children: [],
|
|
|
|
},
|
|
|
|
])
|
|
|
|
|
|
|
|
const goodsPropertyList = ref([])
|
2024-06-04 18:43:13 +08:00
|
|
|
|
|
|
|
const propertyListRef = ref(null)
|
|
|
|
|
|
|
|
const formData = ref({
|
|
|
|
specType: true,
|
|
|
|
specText: SPEC_TYPE[0].label,
|
|
|
|
})
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
async function showPropertyList() {
|
|
|
|
await getGoodsProperty()
|
|
|
|
propertyListRef.value.onOpen()
|
|
|
|
}
|
|
|
|
|
2024-06-04 18:43:13 +08:00
|
|
|
function onRDPickerConfirm(e) {
|
2024-06-05 18:58:12 +08:00
|
|
|
peach.$store('trade').specType = SPEC_TYPE[e.value[0]].value
|
2024-06-04 18:43:13 +08:00
|
|
|
formData.value.specText = SPEC_TYPE[e.value[0]].label
|
|
|
|
formData.value.specType = SPEC_TYPE[e.value[0]].value
|
|
|
|
}
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
function pickerProperty() {
|
|
|
|
let index = specType ? 1 : 0
|
|
|
|
pickerRef.value.onOpen([index])
|
|
|
|
}
|
|
|
|
|
2024-06-04 18:43:13 +08:00
|
|
|
function onPropertyConfirm(e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
async function getGoodsProperty() {
|
|
|
|
let { data } = await GoodsApi.getHistoryProperty()
|
|
|
|
// 根据已经选择数据,设置默认选中
|
|
|
|
data.forEach((item) => {
|
|
|
|
// 判断属性是否已经选中
|
|
|
|
let propertyParent = propertyList.value.find((sitem) => sitem?.id === item.id)
|
|
|
|
|
|
|
|
item.checked = propertyParent ? true : false
|
|
|
|
|
|
|
|
// 如果属性已经选中,查询子类中是否有选中
|
|
|
|
if (item.checked) {
|
|
|
|
item.propertyValues.forEach((child) => {
|
|
|
|
let childResult = propertyParent?.children.some((schild) => schild?.id === child.id)
|
|
|
|
child.checked = childResult ? true : false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
goodsPropertyList.value = data
|
|
|
|
}
|
|
|
|
|
|
|
|
const specType = computed(() => peach.$store('trade').specType)
|
|
|
|
|
|
|
|
function initial() {
|
|
|
|
onLoad(() => {
|
|
|
|
formData.value.specType = specType ? true : false
|
|
|
|
formData.value.specText = SPEC_TYPE[specType ? 1 : 0].label
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
initial,
|
|
|
|
pickerRef,
|
|
|
|
pickerProperty,
|
|
|
|
propertyListRef,
|
|
|
|
formData,
|
|
|
|
onRDPickerConfirm,
|
|
|
|
onPropertyConfirm,
|
|
|
|
propertyList,
|
|
|
|
showPropertyList,
|
|
|
|
goodsPropertyList,
|
|
|
|
}
|