补充代码

This commit is contained in:
wyy
2023-11-23 17:34:34 +08:00
parent 6f1218b4a9
commit 0230b22090
3 changed files with 17 additions and 27 deletions

View File

@@ -18,24 +18,19 @@ export const scoreProdStore = defineStore('prod', {
} }
}, },
actions: { actions: {
// eslint-disable-next-line no-unused-vars updateSkuTags (skuTags) {
updateSkuTags (state, skuTags) {
this.skuTags = skuTags this.skuTags = skuTags
}, },
// eslint-disable-next-line no-unused-vars addSkuTag (skuTag) {
addSkuTag (state, skuTag) {
this.skuTags.push(skuTag) this.skuTags.push(skuTag)
}, },
// eslint-disable-next-line no-unused-vars removeSkuTag (tagIndex) {
removeSkuTag (state, tagIndex) {
this.skuTags.splice(tagIndex, 1) this.skuTags.splice(tagIndex, 1)
}, },
// eslint-disable-next-line no-unused-vars removeSkuTagItem ({ tagIndex, tagItemIndex }) {
removeSkuTagItem (state, { tagIndex, tagItemIndex }) {
this.skuTags[tagIndex].tagItems.splice(tagItemIndex, 1) this.skuTags[tagIndex].tagItems.splice(tagItemIndex, 1)
}, },
// eslint-disable-next-line no-unused-vars addSkuTagItem ({ tagIndex, tagItem }) {
addSkuTagItem (state, { tagIndex, tagItem }) {
this.skuTags[tagIndex].tagItems.push(tagItem) this.skuTags[tagIndex].tagItems.push(tagItem)
} }
} }

View File

@@ -142,7 +142,6 @@
</template> </template>
<script setup> <script setup>
import PicUpload from '@/components/pic-upload'
import { scoreProdStore } from '@/stores/prod.js' import { scoreProdStore } from '@/stores/prod.js'
const props = defineProps({ const props = defineProps({

View File

@@ -138,20 +138,7 @@ const skuTags = computed({
set (val) { prod.updateSkuTags(val) } set (val) { prod.updateSkuTags(val) }
}) })
/** const unUseTags = ref([])
* 未使用的规格, 通过计算属性计算
*/
const unUseTags = computed(() => {
const res = []
for (let i = 0; i < dbTags.length; i++) {
const dbTag = dbTags[i]
const specIndex = skuTags.value?.findIndex(tag => tag.tagName === dbTag.propName)
if (specIndex === -1) {
res.push(dbTag)
}
}
return res
})
const defalutSku = computed(() => { const defalutSku = computed(() => {
return prod.defalutSku return prod.defalutSku
@@ -177,7 +164,7 @@ watch(() => skuTags.value,
const properties = tagName + ':' + tagItemName.value const properties = tagName + ':' + tagItemName.value
// 增加或删除规格 // 增加或删除规格
let tempSkuList = [] let tempSkuList = []
val.forEach(tag => { val?.forEach(tag => {
if (skuList.length === 0) { if (skuList.length === 0) {
if (tagName === tag.tagName) { if (tagName === tag.tagName) {
const sku = Object.assign({}, defalutSku.value) const sku = Object.assign({}, defalutSku.value)
@@ -220,7 +207,7 @@ watch(() => skuTags.value,
} else { } else {
// 增加或删除规格 // 增加或删除规格
let tempSkuList = [] let tempSkuList = []
val.forEach(tag => { val?.forEach(tag => {
if (skuList.length === 0) { if (skuList.length === 0) {
tag.tagItems.forEach(tagItem => { tag.tagItems.forEach(tagItem => {
const sku = Object.assign({}, defalutSku.value) const sku = Object.assign({}, defalutSku.value)
@@ -258,6 +245,15 @@ onMounted(() => {
dbTags = data dbTags = data
if (data) { if (data) {
maxPropId = Math.max.apply(Math, data.map(item => item.propId)) maxPropId = Math.max.apply(Math, data.map(item => item.propId))
const res = []
for (let i = 0; i < dbTags.length; i++) {
const dbTag = dbTags[i]
const specIndex = skuTags.value?.findIndex(tag => tag.tagName === dbTag.propName)
if (specIndex === -1) {
res.push(dbTag)
}
}
unUseTags.value = res
} else { } else {
maxPropId = 0 maxPropId = 0
} }