diff --git a/pages/index/product.vue b/pages/index/product.vue
index bcb3ec8..670eaa5 100644
--- a/pages/index/product.vue
+++ b/pages/index/product.vue
@@ -1,43 +1,21 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
-
+
+
diff --git a/pages/product/components/item.vue b/pages/product/components/item.vue
index 815a9b5..0e68138 100644
--- a/pages/product/components/item.vue
+++ b/pages/product/components/item.vue
@@ -11,29 +11,31 @@
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -42,6 +44,7 @@
diff --git a/pages/product/js/sku.js b/pages/product/js/sku.js
index 1273e46..195cbdc 100644
--- a/pages/product/js/sku.js
+++ b/pages/product/js/sku.js
@@ -1,163 +1,179 @@
-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'
+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";
-const pickerRef = ref(null)
+const pickerRef = ref(null);
// 多属性商品 sku 列表
-const skus = ref([])
+const skus = ref([]);
-const propertyList = ref([])
+const propertyList = ref([]);
-const goodsPropertyList = ref([])
+const goodsPropertyList = ref([]);
-const propertyListRef = ref(null)
+const propertyListRef = ref(null);
+
+const canEdit = computed(() => peach.$store("trade").canEdit);
const formData = ref({
- specType: true,
- specText: SPEC_TYPE[0].label,
-})
+ specType: true,
+ specText: SPEC_TYPE[0].label,
+});
async function showPropertyList() {
- await getGoodsProperty()
- propertyListRef.value.onOpen()
+ await getGoodsProperty();
+ propertyListRef.value.onOpen();
}
function onRDPickerConfirm(e) {
- 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
+ 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;
}
function pickerProperty() {
- let index = specType.value ? 1 : 0
- pickerRef.value.onOpen([index])
+ if (canEdit.value) {
+ let index = specType.value ? 1 : 0;
+ pickerRef.value.onOpen([index]);
+ }
}
async function onPropertyConfirm(e) {
- await getGoodsProperty()
- console.log(e)
+ await getGoodsProperty();
+ console.log(e);
+}
+
+function onConfirm() {
+ console.log(skus.value);
}
async function getGoodsProperty() {
- let { data } = await GoodsApi.getHistoryProperty()
+ let { data } = await GoodsApi.getHistoryProperty();
- // 把 propertyList 中 id 相同的属性合并,并去重
- propertyList.value = peach.$store('trade').selectedProperty
+ // 把 propertyList 中 id 相同的属性合并,并去重
+ propertyList.value = peach.$store("trade").selectedProperty;
- console.log(propertyList.value)
+ console.log(propertyList.value);
- // 根据已经选择数据,设置默认选中
- data.forEach((item) => {
- // 判断属性是否已经选中
- let propertyParent = propertyList.value.find((sitem) => sitem?.id === item.id)
+ // 根据已经选择数据,设置默认选中
+ data.forEach((item) => {
+ // 判断属性是否已经选中
+ let propertyParent = propertyList.value.find(
+ (sitem) => sitem?.id === item.id
+ );
- item.checked = propertyParent ? true : false
+ item.checked = propertyParent ? true : false;
- // 如果属性已经选中,查询子类中是否有选中
- if (item.checked) {
- item.propertyValues.forEach((child) => {
- let childResult = propertyParent?.children.some((schild) => schild === child.id)
- child.checked = childResult ? true : false
- })
- }
- })
+ // 如果属性已经选中,查询子类中是否有选中
+ if (item.checked) {
+ item.propertyValues.forEach((child) => {
+ let childResult = propertyParent?.children.some(
+ (schild) => schild === child.id
+ );
+ child.checked = childResult ? true : false;
+ });
+ }
+ });
- goodsPropertyList.value = data
- console.log(goodsPropertyList.value)
+ goodsPropertyList.value = data;
+ console.log(goodsPropertyList.value);
}
function changeSubProperty() {
- // 修改子属性状态,需要同步更新 skus 的显示
- console.log(goodsPropertyList.value)
- // 过滤父属性 checked 选项,深拷贝避免后面循环改变元数据内容
- let temp = JSON.parse(JSON.stringify(goodsPropertyList.value.filter((item) => item.checked)))
- temp.forEach((item) => {
- item.propertyValues = item.propertyValues.filter((child) => child.checked)
- })
+ // 修改子属性状态,需要同步更新 skus 的显示
+ console.log(goodsPropertyList.value);
+ // 过滤父属性 checked 选项,深拷贝避免后面循环改变元数据内容
+ let temp = JSON.parse(
+ JSON.stringify(goodsPropertyList.value.filter((item) => item.checked))
+ );
+ temp.forEach((item) => {
+ item.propertyValues = item.propertyValues.filter((child) => child.checked);
+ });
- let result = temp.map((item) => {
- return item.propertyValues.map((child) => ({
- propertyId: item.id,
- propertyName: item.name,
- valueId: child.id,
- valueName: child.name,
- }))
- })
+ let result = temp.map((item) => {
+ return item.propertyValues.map((child) => ({
+ propertyId: item.id,
+ propertyName: item.name,
+ valueId: child.id,
+ valueName: child.name,
+ }));
+ });
- let tempSkus = []
+ let tempSkus = [];
- for (let item of reduceArr(result)) {
- let obj = {
- picUrl: '',
- barCode: '',
- price: 0,
- marketPrice: 0,
- costPrice: 0,
- stock: 0,
- weight: 0,
- volume: 0,
- properties: item,
- }
- tempSkus.push(obj)
- }
+ for (let item of reduceArr(result)) {
+ let obj = {
+ picUrl: "",
+ barCode: "",
+ price: 0,
+ marketPrice: 0,
+ costPrice: 0,
+ stock: 0,
+ weight: 0,
+ volume: 0,
+ properties: item,
+ };
+ tempSkus.push(obj);
+ }
- skus.value = tempSkus
+ skus.value = tempSkus;
}
function reduceArr(arr) {
- return arr.reduce((acc, cur) => {
- let tempAcc = []
+ return arr.reduce((acc, cur) => {
+ let tempAcc = [];
- if (acc.length < 1) {
- cur.forEach((item, index) => {
- if (tempAcc[index]) {
- tempAcc[index].push(item)
- } else {
- tempAcc[index] = [item]
- }
- })
+ if (acc.length < 1) {
+ cur.forEach((item, index) => {
+ if (tempAcc[index]) {
+ tempAcc[index].push(item);
} else {
- acc.forEach((item, index) => {
- cur.forEach((sitem, sindex) => {
- tempAcc.push([...item, sitem])
- })
- })
-
- if (cur.length < 1) {
- tempAcc = acc
- }
+ tempAcc[index] = [item];
}
- return tempAcc
- }, [])
+ });
+ } else {
+ acc.forEach((item, index) => {
+ cur.forEach((sitem, sindex) => {
+ tempAcc.push([...item, sitem]);
+ });
+ });
+
+ if (cur.length < 1) {
+ tempAcc = acc;
+ }
+ }
+ return tempAcc;
+ }, []);
}
-const specType = computed(() => peach.$store('trade').goodsInfo.specType)
+const specType = computed(() => peach.$store("trade").goodsInfo.specType);
function initial() {
- onLoad(() => {
- formData.value.specType = specType.value ? true : false
- formData.value.specText = SPEC_TYPE[specType.value ? 1 : 0].label
- skus.value = peach.$store('trade').skus
- if (specType.value) {
- getGoodsProperty()
- }
- })
+ onLoad(() => {
+ formData.value.specType = specType.value ? true : false;
+ formData.value.specText = SPEC_TYPE[specType.value ? 1 : 0].label;
+ skus.value = peach.$store("trade").skus;
+ if (specType.value) {
+ getGoodsProperty();
+ }
+ });
}
export {
- initial,
- skus,
- pickerRef,
- pickerProperty,
- propertyListRef,
- formData,
- onRDPickerConfirm,
- onPropertyConfirm,
- propertyList,
- showPropertyList,
- goodsPropertyList,
- changeSubProperty,
-}
+ initial,
+ canEdit,
+ skus,
+ pickerRef,
+ pickerProperty,
+ onConfirm,
+ propertyListRef,
+ formData,
+ onRDPickerConfirm,
+ onPropertyConfirm,
+ propertyList,
+ showPropertyList,
+ goodsPropertyList,
+ changeSubProperty,
+};
diff --git a/pages/product/manageGoods.vue b/pages/product/manageGoods.vue
index b0e9e57..0376f3e 100644
--- a/pages/product/manageGoods.vue
+++ b/pages/product/manageGoods.vue
@@ -1,22 +1,22 @@
-
-
-
+
-
+
-
@@ -24,8 +24,8 @@
-
+
@@ -37,21 +37,25 @@
-
+
-
+
+ :inputBorder="false" v-model="formData.deliveryText" :disabled="!canEdit" placeholder="请选择配送方式" disabled>
+
+
+
@@ -59,7 +63,7 @@
diff --git a/pages/product/sku.vue b/pages/product/sku.vue
index a19143c..7cb9ee9 100644
--- a/pages/product/sku.vue
+++ b/pages/product/sku.vue
@@ -1,57 +1,45 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
-
+
+
+
+
-
-
+
+
+
+
+
+
diff --git a/peach/components/p-picker/p-picker.vue b/peach/components/p-picker/p-picker.vue
index 0cbeb6d..829d16a 100644
--- a/peach/components/p-picker/p-picker.vue
+++ b/peach/components/p-picker/p-picker.vue
@@ -1,47 +1,35 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/peach/components/p-uploader/p-uploader.vue b/peach/components/p-uploader/p-uploader.vue
index 0030201..0330db9 100644
--- a/peach/components/p-uploader/p-uploader.vue
+++ b/peach/components/p-uploader/p-uploader.vue
@@ -282,6 +282,7 @@ export default {
return this.uploadFiles(files);
},
async setValue(newVal, oldVal) {
+
const newData = async (v) => {
const reg = /cloud:\/\/([\w.]+\/?)\S*/;
let url = '';
@@ -512,6 +513,7 @@ export default {
* @param {Object} index
*/
delFile(index) {
+
this.$emit('delete', {
tempFile: this.files[index],
tempFilePath: this.files[index].url,
@@ -541,11 +543,13 @@ export default {
setEmit() {
let data = [];
let updateUrl = [];
+ // 单文件
if (this.returnType === 'object') {
data = this.backObject(this.files)[0];
this.localValue = data ? data : null;
updateUrl = data ? data.url : '';
} else {
+ // 多文件
data = this.backObject(this.files);
if (!this.localValue) {
this.localValue = [];
@@ -568,16 +572,23 @@ export default {
backObject(files) {
let newFilesData = [];
files.forEach((v) => {
- newFilesData.push({
- extname: v.extname,
- fileType: v.fileType,
- image: v.image,
- name: v.name,
- path: v.path,
- size: v.size,
- fileID: v.fileID,
- url: v.url,
- });
+ if (v.fileID) {
+
+ newFilesData.push({
+ extname: v.extname,
+ fileType: v.fileType,
+ image: v.image,
+ name: v.name,
+ path: v.path,
+ size: v.size,
+ fileID: v.fileID,
+ url: v.url,
+ });
+ } else {
+ newFilesData.push({
+ url: v
+ })
+ }
});
return newFilesData;
},
diff --git a/peach/components/p-uploader/upload-image.vue b/peach/components/p-uploader/upload-image.vue
index 0ed1590..10a9a49 100644
--- a/peach/components/p-uploader/upload-image.vue
+++ b/peach/components/p-uploader/upload-image.vue
@@ -69,6 +69,7 @@ export default {
},
computed: {
list() {
+
if (typeof this.filesList === 'string') {
if (this.filesList) {
return [this.filesList];
diff --git a/peach/store/trade.js b/peach/store/trade.js
index cdb4cde..5ad9a10 100644
--- a/peach/store/trade.js
+++ b/peach/store/trade.js
@@ -1,4 +1,4 @@
-import { ref } from "vue";
+import { ref, computed } from "vue";
import { defineStore } from "pinia";
const useTradeStore = defineStore("trade", () => {
@@ -8,13 +8,21 @@ const useTradeStore = defineStore("trade", () => {
// 商品信息
const goodsInfo = ref(null);
+ // 详情标记
+ const detailTag = ref("edit");
+
// 商品属性
const skus = ref(null);
+ // 商品是否可编辑
+ const canEdit = computed(() => (detailTag.value === "detail" ? false : true));
+
return {
selectedProperty,
goodsInfo,
skus,
+ canEdit,
+ detailTag,
};
});