@ -1,36 +1,53 @@
< template >
< template >
< view class = "content p-2 bg-gray-100" >
< view v-if ="load" class="content p-2 bg-gray-100" >
< wd -toast / >
< wd -form ref = "form" :model ="model" >
< wd -form ref = "form" :model ="model" >
< wd -cell -group border >
< wd -cell -group border >
< div class = "bg-gray-100" >
< div class = "bg-gray-100" >
< div class = "bg-gray-100 rounded mb-2" >
< div class = "bg-gray-100 rounded mb-2" >
< div class = "bg-white flex flex-col pt-3 pl-3" >
< div class = "bg-white flex flex-col pt-3 pl-3" >
< div class = "name mb-2 text-xs" > 缩略图 < / div >
< div class = "name mb-2 text-xs" > 缩略图 < / div >
< wd -upload :limit ="1" :file-list ="fileList" :action ="action" :formData ="formData" :header ="header"
< myUpload v-model ="model.pic_url" > < / myUpload >
@ success = "successImage" name = "image" : before - remove = "beforeRemove" > < / w d - u p l o a d >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
<!-- < div class = "bg-gray-100" >
< div class = "bg-gray-100" >
< div class = "bg-gray-100 rounded mb-2" >
< div class = "bg-gray-100 rounded mb-2" >
< div class = "bg-white flex flex-col pt-3 pl-3" >
< div class = "bg-white flex flex-col pt-3 pl-3" >
< div class = "name mb-2 text-xs" > 商品主图 < / div >
< div class = "name mb-2 text-xs" > 商品主图 < / div >
< wd -upload :file-list ="fileList" :action ="action" :formData ="formData" :header ="header"
< myUpload v-model ="model.pic_list" :size ="4" > < / myUpload >
@ change = "handleChange" name = "image" > < / w d - u p l o a d >
< / div >
< / div >
< / div >
< / div >
< / div > -- >
< / div >
< view class = "h-2 bg-gray-100" > < / view >
< view class = "h-2 bg-gray-100" > < / view >
< view class = " p-3 rounded mb-2" >
< view class = " p-3 rounded mb-2" >
< div class = "name mb-2 text-xs" > 商品名称 < / div >
< div class = "name mb-2 text-xs" > 商品名称 < / div >
< view class = "bg-white px-3 py-1 rounded" >
< view class = "bg-white px-3 py-1 rounded" >
< wd -textarea v -model = " model.value " auto -height / >
< wd -textarea v -model = " model.name " auto -height / >
< / view >
< / view >
< view class = "h-2 bg-gray-100" > < / view >
< view class = " p-3 rounded mb-2" >
< div class = "name mb-2 text-xs" > 商品分类 < / div >
< view class = "bg-white px-3 py-1 rounded" >
< wd -checkbox -group v-model ="model.classify_list" >
< view class = "flex overflow-auto flex-wrap" >
< div class = "grid grid-cols-3" >
< wd -checkbox style = "width: 100%;" shape = "button" v -for = " cat of classifyList "
: modelValue = "JSON.stringify(cat.parentIds)" >
{ { cat . name } }
< / w d - c h e c k b o x >
< / div >
< / view >
< / w d - c h e c k b o x - g r o u p >
< / view >
< / view >
< / view >
< / view >
@ -40,8 +57,7 @@
< div class = "p-2 bg-white" >
< div class = "p-2 bg-white" >
< div class = "name mb-2 text-xs" > 服务内容 < / div >
< div class = "name mb-2 text-xs" > 服务内容 < / div >
< view class = "bg-white px-3 py-1 rounded" >
< view class = "bg-white px-3 py-1 rounded" >
< wd -input type = "text" v -model = " value " placeholder = "例子: 正品保障,极速发货,7天退换货。多个请使用英文逗号“,”分隔"
< wd -input type = "text" v -model = " model.server_project " placeholder = "例子: 正品保障,极速发货,7天退换货。多个请使用英文逗号“,”分隔" / >
@ change = "handleChange" / >
< / view >
< / view >
< / div >
< / div >
< / view >
< / view >
@ -51,11 +67,12 @@
< view class = " p-3 rounded mb-2" >
< view class = " p-3 rounded mb-2" >
< div class = "name mb-2 text-xs" > 商品重量 < / div >
< div class = "name mb-2 text-xs" > 商品重量 < / div >
< view class = "bg-white px-3 py-2 rounded flex items-center mb-4" >
< view class = "bg-white px-3 py-2 rounded flex items-center mb-4" >
< wd -input -number v -model = " value" @change ="handleChange " / >
< wd -input -number v -model = " model.weight " / >
< view class = "text-xs from-neutral-300 ml-4" > 千克 < / view >
< view class = "text-xs from-neutral-300 ml-4" > 千克 < / view >
< / view >
< / view >
< wd -picker class = "w-full" :columns ="freightRules" label = "运费模板" v -model = " model.freight_id " / >
< wd -picker v -if = " freightRules.length " class = "w-full" :columns ="freightRules" label = "运费模板"
v - model = "model.freight_id" / >
< / view >
< / view >
@ -63,18 +80,33 @@
< view class = "p-3 rounded mb-2" >
< view class = "p-3 rounded mb-2" >
< div class = "name mb-2 text-xs" > 商品状态 < / div >
< div class = "name mb-2 text-xs" > 商品状态 < / div >
< view class = "bg-white px-3 py-2 rounded flex items-center mb-4" >
< view class = "bg-white px-3 py-2 rounded flex items-center" >
< wd -switch v -model = " model.status " / >
< wd -switch v -model = " model.status " :active-value ="1" :inactive-value ="0" / >
< / view >
< / view >
< view class = "h-2 bg-gray-100" > < / view >
< view class = "p-3 rounded mb-2" >
< div class = "name mb-2 text-xs" > 规格 < / div >
< view class = "bg-white px-3 py-2 rounded flex items-center" >
< wd -radio -group shape = "button" v-model ="model.use_sku" >
< wd -radio :value ="0" > 单规格 < / w d - r a d i o >
< wd -radio :value ="1" > 多规格 < / w d - r a d i o >
< / w d - r a d i o - g r o u p >
< / view >
< / view >
< / view >
< / view >
< view class = "h-2 bg-gray-100" > < / view >
< view class = "h-2 bg-gray-100" > < / view >
< skuEdit > < / skuEdit >
< skuEdit ref = "skuEditRef" :skuGroup ="skuGroup"
: Pdata = "{ skuDefault, skuLibrary, skuGroup, use_sku: model.use_sku }" >
< / skuEdit >
< / w d - c e l l - g r o u p >
< / w d - c e l l - g r o u p >
< view class = "footer mt-4" >
< view class = "footer mt-4" >
< wd -button type = "primary" size = "large" block > 保存 < / w d - b u t t o n >
< wd -button @click ="saveGoods" type = "primary" size = "large" block > 保存 < / w d - b u t t o n >
< / view >
< / view >
< / w d - f o r m >
< / w d - f o r m >
< / view >
< / view >
@ -82,10 +114,15 @@
< script setup >
< script setup >
import { ref } from 'vue'
import { ref } from 'vue'
import system from '@/api/modules/system.js'
import goods from '@/api/store/goods.js'
import { useToast , useMessage } from '@/uni_modules/wot-design-uni'
import { useToast , useMessage } from '@/uni_modules/wot-design-uni'
import goods from '@/api/store/goods.js'
import system from '@/api/modules/system.js'
import skuEdit from "./components/skuEdit.vue"
import skuEdit from "./components/skuEdit.vue"
import myUpload from "@/components/myUpload/index.vue"
import {
onLoad ,
onShow
} from "@dcloudio/uni-app" ;
const fileList = ref ( [ ] )
const fileList = ref ( [ ] )
@ -94,34 +131,18 @@ const beforeRemove = ({ file, resolve, index }) => {
resolve ( true )
resolve ( true )
}
}
const action = 'https://saasdemo.byin.vip/admin/system/uploadImage'
const token = uni . getStorageSync ( "token" ) ;
const header = {
Authorization : ` Bearer ${ token } `
}
const formData = {
parent _id : 0 ,
type : "image" ,
}
function successImage ( e ) {
fileList . value . push ( {
url : e . file . url
} )
}
const model = ref ( {
const model = ref ( {
classify _list : [ ] , / / 商 品 分 类 组
classify _list : [ ] , / / 商 品 分 类 组
name : "" , / / 商 品 名 称
name : "" , / / 商 品 名 称
keywords : "" , / / 商 品 关 键 词
keywords : "" , / / 商 品 关 键 词
sort : 1000 ,
sort : 1000 ,
status : 0 , / / 商 品 状 态
status : 0 , / / 商 品 状 态
freight _id : 0 , / / 运 费 规 则
freight _id : 99999999 , / / 运 费 规 则
weight : 0 , / / 商 品 重 量
weight : 0 , / / 商 品 重 量
pic _url : "" , / / 商 品 缩 略 图
pic _url : "" , / / 商 品 缩 略 图
pic _list : [ ] , / / 商 品 图 组
pic _list : [ ] , / / 商 品 图 组
video : "" , / / 商 品 视 频
video : "" , / / 商 品 视 频
detail : " ", / / 图 文 详 情
detail : "默认" , / / 图 文 详 情
use _sku : 0 , / / 是 否 使 用 规 格
use _sku : 0 , / / 是 否 使 用 规 格
sku _list : [ ] , / / 规 格 信 息
sku _list : [ ] , / / 规 格 信 息
is _discount : 0 , / / 是 否 有 折 扣
is _discount : 0 , / / 是 否 有 折 扣
@ -133,35 +154,199 @@ const model = ref({
check _price : 0 , / / 佣 金
check _price : 0 , / / 佣 金
} )
} )
const form = ref ( )
const load = ref ( false )
const skuGroup = ref ( [ ] )
const skuDefault = ref ( [ ] )
const skuLibrary = ref ( [ ] )
const skuEditRef = ref ( null )
const freightRules = ref ( [ {
label : "默认" ,
value : "99999999"
} ] )
onLoad ( async ( e ) => {
function handleSubmit1 ( ) {
const GetfreightRules = ( ) => {
form . value
goods . freightRules ( ) . then ( res => {
. validate ( )
. then ( ( { valid , errors } ) => {
freightRules . value = [
if ( valid ) {
... freightRules . value ,
showSuccess ( {
... res . data . rows . map ( item => {
msg : '校验通过'
return {
label : item . name ,
value : item . id
}
} )
} )
}
]
} )
}
GetfreightRules ( )
if ( e . id ) {
const res = await goods . goodsItem ( {
id : e . id
} )
model . value = res . data
model . value . pic _list = res . data . pic _list . map ( ( { pic _url } ) => pic _url ) ;
if ( ! model . value . freight _id ) {
model . value . freight _id = 99999999
}
model . value . classify _list = model . value . classify _list . map ( item => JSON . stringify ( item ) )
if ( res . data . use _sku == 0 ) {
skuDefault . value = res . data . goods _sku ;
} else {
skuLibrary . value = res . data . goods _sku ;
}
skuGroup . value = res . data . sku _group ? res . data . sku _group : [ ] ;
load . value = true
} else {
load . value = true
}
} )
/ / c o n s t f o r m = r e f ( )
const saveGoods = async ( ) => {
/ / 判 断 商 品 分 类 是 否 为 空
if ( model . value . classify _list . length === 0 ) {
return uni . showToast ( {
title : '请选择商品分类!' ,
icon : 'none'
} )
}
/ / 判 断 商 品 名 称 是 否 为 空
if ( model . value . name . trim ( ) === "" ) {
return uni . showToast ( {
title : '请输入商品名称!' ,
icon : 'none'
} )
}
/ / 判 断 商 品 关 键 词 是 否 为 空
/ / i f ( m o d e l . v a l u e . k e y w o r d s . t r i m ( ) = = = " " ) {
/ / r e t u r n u n i . s h o w T o a s t ( {
/ / t i t l e : ' 请 输 入 商 品 关 键 词 ! ' ,
/ / i c o n : ' n o n e '
/ / } )
/ / }
/ / 判 断 商 品 重 量 是 否 为 非 负 数
if ( model . value . weight < 0 ) {
return uni . showToast ( {
title : '请输入合法的商品重量!' ,
icon : 'none'
} )
}
/ / 判 断 商 品 缩 略 图 是 否 为 空
if ( String ( model . value . pic _url ) . trim ( ) === "" ) {
return uni . showToast ( {
title : '请上传商品缩略图!' ,
icon : 'none'
} )
}
/ / 判 断 商 品 图 组 是 否 为 空
if ( model . value . pic _list . length === 0 ) {
return uni . showToast ( {
title : '请上传商品图片组!' ,
icon : 'none'
} )
}
model . value . sku _group = [ ]
model . value . sku _list = [ ]
model . value . dist _price = Number . parseInt ( model . value . dist _price )
if ( model . value . use _sku == 1 ) {
model . value . sku _group = skuEditRef . value . skuGroup ;
model . value . sku _list = skuEditRef . value . skuLibrary ;
} else {
model . value . sku _list = skuEditRef . value . skuDefault ;
}
if ( ! model . value . sku _list . length ) {
uni . showToast ( {
title : '规格不完整,请调整!' ,
icon : 'none'
} )
} )
. catch ( ( error ) => {
}
console . log ( error , 'error' )
if ( ! model . value . sku _list . every ( item => Boolean ( item . price !== "" && item . stock !== "" && item . original _price !== "" ) ) ) {
uni . showToast ( {
title : '规格不完整,请调整!' ,
icon : 'none'
} )
} )
console . log ( "规格不完整,请调整!" ) ;
return
}
let freight _id = model . value . freight _id
if ( freight _id = 99999999 ) {
freight _id = 0
}
const pic _list = model . value . pic _list . map ( item => ( {
pic _url : item
} ) )
const classify _list = model . value . classify _list . map ( item => JSON . parse ( item ) )
const res = await goods . goodsEdit ( { ... model . value , pic _list , freight _id , classify _list } ) ;
console . log ( res ) ;
if ( res . code == 0 ) {
uni . showToast ( {
title : '商品信息保存成功!' ,
icon : 'success'
} )
}
}
}
const freightRules = ref ( [ ] )
const classifyList = ref ( [ ] )
const GetfreightRules = ( ) => {
const getClassify = ( ) => {
goods . freightRules ( ) . then ( res => {
function flattenCategories ( categories , parentIds = [ ] ) {
freightRules . value = res . data . rows . map ( item => {
let flatCategories = [ ] ;
return {
label : item . name ,
for ( const category of categories ) {
value : item . id
const categoryWithParents = {
... category ,
parentIds : [ ... parentIds , category . id ] ,
} ;
flatCategories . push ( categoryWithParents ) ;
if ( category . children && category . children . length > 0 ) {
flatCategories = flatCategories . concat ( flattenCategories ( category . children , [ ... parentIds , category . id ] ) ) ;
}
}
} )
}
return flatCategories ;
}
goods . classify . list ( ) . then ( res => {
classifyList . value = flattenCategories ( res . data )
console . log ( classifyList . value ) ;
} )
} )
}
}
GetfreightRules ( )
getClassify ( )
< / script >
< / script >
< style lang = "scss" > < / style >
< style lang = "scss" > < / style >