2024-06-06 02:20:25 +08:00
|
|
|
import { ref, computed } from "vue";
|
|
|
|
import { onLoad } from "@dcloudio/uni-app";
|
|
|
|
import peach from "@/peach";
|
|
|
|
import GoodsApi from "@/peach/api/trade/goods";
|
|
|
|
import { SPEC_TYPE } from "./config";
|
2024-06-04 18:43:13 +08:00
|
|
|
|
2024-06-06 02:20:25 +08:00
|
|
|
const pickerRef = ref(null);
|
2024-06-04 18:43:13 +08:00
|
|
|
|
2024-06-06 02:20:25 +08:00
|
|
|
const propertyList = ref([]);
|
2024-06-05 18:58:12 +08:00
|
|
|
|
2024-06-06 02:20:25 +08:00
|
|
|
const goodsPropertyList = ref([]);
|
2024-06-04 18:43:13 +08:00
|
|
|
|
2024-06-06 02:20:25 +08:00
|
|
|
const propertyListRef = ref(null);
|
2024-06-04 18:43:13 +08:00
|
|
|
|
|
|
|
const formData = ref({
|
2024-06-06 02:20:25 +08:00
|
|
|
specType: true,
|
|
|
|
specText: SPEC_TYPE[0].label,
|
|
|
|
});
|
2024-06-04 18:43:13 +08:00
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
async function showPropertyList() {
|
2024-06-06 02:20:25 +08:00
|
|
|
await getGoodsProperty();
|
|
|
|
propertyListRef.value.onOpen();
|
2024-06-05 18:58:12 +08:00
|
|
|
}
|
|
|
|
|
2024-06-04 18:43:13 +08:00
|
|
|
function onRDPickerConfirm(e) {
|
2024-06-06 02:20:25 +08:00
|
|
|
peach.$store("trade").specType = SPEC_TYPE[e.value[0]].value;
|
|
|
|
formData.value.specText = SPEC_TYPE[e.value[0]].label;
|
|
|
|
formData.value.specType = SPEC_TYPE[e.value[0]].value;
|
2024-06-04 18:43:13 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
function pickerProperty() {
|
2024-06-06 02:20:25 +08:00
|
|
|
let index = specType ? 1 : 0;
|
|
|
|
pickerRef.value.onOpen([index]);
|
2024-06-05 18:58:12 +08:00
|
|
|
}
|
|
|
|
|
2024-06-04 18:43:13 +08:00
|
|
|
function onPropertyConfirm(e) {
|
2024-06-06 02:20:25 +08:00
|
|
|
getGoodsProperty();
|
|
|
|
console.log(e);
|
2024-06-04 18:43:13 +08:00
|
|
|
}
|
|
|
|
|
2024-06-05 18:58:12 +08:00
|
|
|
async function getGoodsProperty() {
|
2024-06-06 02:20:25 +08:00
|
|
|
let { data } = await GoodsApi.getHistoryProperty();
|
|
|
|
propertyList.value = [];
|
|
|
|
|
|
|
|
// 把 propertyList 中 id 相同的属性合并,并去重
|
|
|
|
propertyList.value = peach.$store("trade").selectedProperty;
|
|
|
|
|
|
|
|
// 根据已经选择数据,设置默认选中
|
|
|
|
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
|
|
|
|
);
|
|
|
|
console.log(childResult);
|
|
|
|
child.checked = childResult ? true : false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
goodsPropertyList.value = data;
|
2024-06-05 18:58:12 +08:00
|
|
|
}
|
|
|
|
|
2024-06-06 02:20:25 +08:00
|
|
|
const specType = computed(() => peach.$store("trade").specType);
|
2024-06-05 18:58:12 +08:00
|
|
|
|
|
|
|
function initial() {
|
2024-06-06 02:20:25 +08:00
|
|
|
onLoad(() => {
|
|
|
|
formData.value.specType = specType ? true : false;
|
|
|
|
formData.value.specText = SPEC_TYPE[specType ? 1 : 0].label;
|
|
|
|
getGoodsProperty();
|
|
|
|
});
|
2024-06-05 18:58:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2024-06-06 02:20:25 +08:00
|
|
|
initial,
|
|
|
|
pickerRef,
|
|
|
|
pickerProperty,
|
|
|
|
propertyListRef,
|
|
|
|
formData,
|
|
|
|
onRDPickerConfirm,
|
|
|
|
onPropertyConfirm,
|
|
|
|
propertyList,
|
|
|
|
showPropertyList,
|
|
|
|
goodsPropertyList,
|
|
|
|
};
|