|
|
|
@ -10,7 +10,6 @@ import * as DeliveryApi from '@/api/setting/delivery' |
|
|
|
|
* GoodsModel |
|
|
|
|
*/ |
|
|
|
|
export default { |
|
|
|
|
|
|
|
|
|
// 当前商品ID
|
|
|
|
|
goodsId: null, |
|
|
|
|
|
|
|
|
@ -33,22 +32,22 @@ export default { |
|
|
|
|
levelList: [ |
|
|
|
|
{ |
|
|
|
|
name: '一级佣金', |
|
|
|
|
value: 'first_money' |
|
|
|
|
value: 'first_money', |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: '二级佣金', |
|
|
|
|
value: 'second_money' |
|
|
|
|
value: 'second_money', |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: '三级佣金', |
|
|
|
|
value: 'third_money' |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
value: 'third_money', |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取form所需的数据
|
|
|
|
|
getFromData (goodsId = null) { |
|
|
|
|
getFromData(goodsId = null) { |
|
|
|
|
// 记录商品ID (编辑时)
|
|
|
|
|
this.goodsId = goodsId |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
@ -62,7 +61,7 @@ export default { |
|
|
|
|
// 获取服务与承诺
|
|
|
|
|
this.getServiceList(), |
|
|
|
|
// 获取会员等级列表
|
|
|
|
|
this.getUserGradeList() |
|
|
|
|
this.getUserGradeList(), |
|
|
|
|
]).then(() => { |
|
|
|
|
// 设置默认数据
|
|
|
|
|
this.setDefaultData() |
|
|
|
@ -72,30 +71,51 @@ export default { |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取商品详情
|
|
|
|
|
getGoodsDetail (goodsId = null) { |
|
|
|
|
getGoodsDetail(goodsId = null) { |
|
|
|
|
if (!goodsId) return false |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
GoodsApi.detail({ goodsId }) |
|
|
|
|
.then(result => { |
|
|
|
|
this.formData.goods = result.data.goodsInfo |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
GoodsApi.detail({ goodsId }).then((result) => { |
|
|
|
|
this.formData.goods = result.data.goodsInfo |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取表单默认值(用于form.setFieldsValue的数据)
|
|
|
|
|
getFieldsValue () { |
|
|
|
|
getFieldsValue() { |
|
|
|
|
// 商品详情信息
|
|
|
|
|
const goodsInfo = this.formData.goods |
|
|
|
|
// 格式化categoryIds
|
|
|
|
|
goodsInfo.categorys = this.formatCategoryIds(goodsInfo.categoryIds) |
|
|
|
|
// 商品基本数据
|
|
|
|
|
const goodsFormData = _.pick(goodsInfo, [ |
|
|
|
|
'goods_type', 'goods_name', 'categorys', 'goods_no', 'sort','is_brand','is_new','paihang','remaizhishu', |
|
|
|
|
'status', 'spec_type', 'deduct_stock_type', 'is_restrict', 'content', |
|
|
|
|
'selling_point', 'serviceIds', 'sales_initial', 'is_points_gift', |
|
|
|
|
'is_points_discount', 'is_enable_grade', 'is_alone_grade', 'is_ind_dealer', |
|
|
|
|
'dealer_money_type', 'first_money', 'second_money', 'third_money' |
|
|
|
|
'goods_type', |
|
|
|
|
'goods_name', |
|
|
|
|
'categorys', |
|
|
|
|
'goods_no', |
|
|
|
|
'sort', |
|
|
|
|
'is_brand', |
|
|
|
|
'is_new', |
|
|
|
|
'paihang', |
|
|
|
|
'remaizhishu', |
|
|
|
|
'status', |
|
|
|
|
'spec_type', |
|
|
|
|
'deduct_stock_type', |
|
|
|
|
'is_restrict', |
|
|
|
|
'content', |
|
|
|
|
'selling_point', |
|
|
|
|
'serviceIds', |
|
|
|
|
'sales_initial', |
|
|
|
|
'is_points_gift', |
|
|
|
|
'is_points_discount', |
|
|
|
|
'is_enable_grade', |
|
|
|
|
'is_alone_grade', |
|
|
|
|
'is_ind_dealer', |
|
|
|
|
'dealer_money_type', |
|
|
|
|
'first_money', |
|
|
|
|
'second_money', |
|
|
|
|
'third_money', |
|
|
|
|
'is_grab', |
|
|
|
|
]) |
|
|
|
|
return { |
|
|
|
|
...goodsFormData, |
|
|
|
@ -103,7 +123,7 @@ export default { |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 第二次赋值 (适用于动态渲染的form-item)
|
|
|
|
|
getFieldsValue2 () { |
|
|
|
|
getFieldsValue2() { |
|
|
|
|
const goodsInfo = this.formData.goods |
|
|
|
|
let goodsFormData = {} |
|
|
|
|
// 运费模板 (仅实物商品存在运费模板和配送设置)
|
|
|
|
@ -114,7 +134,13 @@ export default { |
|
|
|
|
} |
|
|
|
|
// 单规格数据
|
|
|
|
|
if (goodsInfo.spec_type == 10) { |
|
|
|
|
const skuOne = _.pick(goodsInfo.skuList[0], ['goods_price', 'line_price', 'cost_price', 'stock_num', 'goods_weight']) |
|
|
|
|
const skuOne = _.pick(goodsInfo.skuList[0], [ |
|
|
|
|
'goods_price', |
|
|
|
|
'line_price', |
|
|
|
|
'cost_price', |
|
|
|
|
'stock_num', |
|
|
|
|
'goods_weight', |
|
|
|
|
]) |
|
|
|
|
goodsFormData = { ...goodsFormData, ...skuOne } |
|
|
|
|
} |
|
|
|
|
// 商品限购数据
|
|
|
|
@ -129,56 +155,54 @@ export default { |
|
|
|
|
* 格式化categoryIds (用于表单元素选中) |
|
|
|
|
* @param {*} categoryIds |
|
|
|
|
*/ |
|
|
|
|
formatCategoryIds (categoryIds) { |
|
|
|
|
return categoryIds.map(id => { return { value: id } }) |
|
|
|
|
formatCategoryIds(categoryIds) { |
|
|
|
|
return categoryIds.map((id) => { |
|
|
|
|
return { value: id } |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取分类列表
|
|
|
|
|
getCategoryList () { |
|
|
|
|
getCategoryList() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
CategoryModel.getCategoryTreeSelect() |
|
|
|
|
.then(list => { |
|
|
|
|
this.formData.categoryList = list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
CategoryModel.getCategoryTreeSelect().then((list) => { |
|
|
|
|
this.formData.categoryList = list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取运费模板列表
|
|
|
|
|
getDeliveryList () { |
|
|
|
|
getDeliveryList() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
DeliveryApi.all() |
|
|
|
|
.then(result => { |
|
|
|
|
this.formData.deliveryList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
DeliveryApi.all().then((result) => { |
|
|
|
|
this.formData.deliveryList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取服务与承诺
|
|
|
|
|
getServiceList () { |
|
|
|
|
getServiceList() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
ServiceApi.all() |
|
|
|
|
.then(result => { |
|
|
|
|
this.formData.serviceList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
ServiceApi.all().then((result) => { |
|
|
|
|
this.formData.serviceList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 获取会员等级列表
|
|
|
|
|
getUserGradeList () { |
|
|
|
|
getUserGradeList() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
GradeApi.all({ status: 1 }) |
|
|
|
|
.then(result => { |
|
|
|
|
this.formData.userGradeList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
GradeApi.all({ status: 1 }).then((result) => { |
|
|
|
|
this.formData.userGradeList = result.data.list |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 设置默认的数据(无法用于form.setFieldsValue的数据)
|
|
|
|
|
setDefaultData () { |
|
|
|
|
setDefaultData() { |
|
|
|
|
// 默认的商品服务与承诺
|
|
|
|
|
this.setDefaultServiceIds() |
|
|
|
|
// 默认的等级折扣
|
|
|
|
@ -186,29 +210,28 @@ export default { |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 默认的商品服务与承诺
|
|
|
|
|
setDefaultServiceIds () { |
|
|
|
|
setDefaultServiceIds() { |
|
|
|
|
// 服务与承诺列表
|
|
|
|
|
const serviceList = this.formData.serviceList |
|
|
|
|
if (!this.goodsId) { |
|
|
|
|
// 默认选中的id集
|
|
|
|
|
const defaultServiceItems = serviceList.filter(item => item.is_default) |
|
|
|
|
this.formData.defaultServiceIds = defaultServiceItems.map(item => item.service_id) |
|
|
|
|
const defaultServiceItems = serviceList.filter((item) => item.is_default) |
|
|
|
|
this.formData.defaultServiceIds = defaultServiceItems.map((item) => item.service_id) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// 默认的等级折扣
|
|
|
|
|
setDefaultUserGradeValue () { |
|
|
|
|
setDefaultUserGradeValue() { |
|
|
|
|
// 会员等级列表
|
|
|
|
|
const userGradeList = this.formData.userGradeList |
|
|
|
|
// 单独设置折扣的配置 (已保存的)
|
|
|
|
|
const aloneGradeEquity = (this.goodsId && this.formData.goods.alone_grade_equity) |
|
|
|
|
? this.formData.goods.alone_grade_equity : {} |
|
|
|
|
const aloneGradeEquity = |
|
|
|
|
this.goodsId && this.formData.goods.alone_grade_equity ? this.formData.goods.alone_grade_equity : {} |
|
|
|
|
// 生成的默认数据
|
|
|
|
|
const defaultData = {} |
|
|
|
|
userGradeList.forEach(item => { |
|
|
|
|
userGradeList.forEach((item) => { |
|
|
|
|
defaultData[item.grade_id] = aloneGradeEquity[item.grade_id] || item.equity.discount |
|
|
|
|
}) |
|
|
|
|
this.formData.defaultUserGradeValue = { ...defaultData } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|