wang hou sheng 10 months ago
parent e5ec947c5a
commit 086f458e09
  1. 141
      src/common/model/goods/Index.js
  2. 7
      src/views/goods/Create.vue
  3. 23
      src/views/goods/Index.vue
  4. 17
      src/views/goods/Update.vue

@ -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 }
}
},
}

@ -71,7 +71,12 @@
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否怕抓" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-radio-group v-decorator="['is_grab', { initialValue: 0, rules: [{ required: true }] }]">
<a-radio :value="0"></a-radio>
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="商品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input placeholder="请输入商品编码" v-decorator="['goods_no']" />
</a-form-item>

@ -34,6 +34,13 @@
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="是否怕抓">
<a-select @change="getGrab" placeholder="请选择">
<a-select-option :value="item.id" v-for="item in grabList" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item class="search-btn">
<a-button type="primary" icon="search" html-type="submit">搜索</a-button>
</a-form-item>
@ -99,6 +106,9 @@
>{{ text == 10 ? '上架' : '下架' }}</a-tag
>
</span>
<span slot="grab" slot-scope="text">
<a-tag class="cur-p" :color="text == 0 ? 'green' : 'red'">{{ text == 0 ? '否' : '是' }}</a-tag>
</span>
<!-- 操作项 -->
<div class="actions" slot="action" slot-scope="text, item">
<router-link v-if="$auth('/goods/update')" :to="{ path: '/goods/update', query: { goodsId: item.goods_id } }"
@ -175,6 +185,11 @@ const columns = [
dataIndex: 'status',
scopedSlots: { customRender: 'status' },
},
{
title: '是否怕抓',
dataIndex: 'is_grab',
scopedSlots: { customRender: 'grab' },
},
{
title: '排序',
dataIndex: 'sort',
@ -211,7 +226,12 @@ export default {
listType: 'all',
spec_type: '',
channel: '',
is_grab: '',
},
grabList: [
{ id: '0', name: '否' },
{ id: '1', name: '是' },
],
//
isLoading: false,
//
@ -268,6 +288,9 @@ export default {
getChannel(val) {
this.queryParam.channel = val
},
getGrab(val) {
this.queryParam.is_grab = val
},
getDataList() {
return GoodsApi.getDataList().then((result) => {
const obj = result.data

@ -60,7 +60,12 @@
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否怕抓" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-radio-group v-decorator="['is_grab', { initialValue: 0, rules: [{ required: true }] }]">
<a-radio :value="0"></a-radio>
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否新品首发" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-radio-group v-decorator="['is_new', { initialValue: 0, rules: [{ required: true }] }]">
<a-radio :value="0"></a-radio>
@ -529,7 +534,7 @@ export default {
Ueditor,
InputNumberGroup,
MultiSpec,
AreasModal
AreasModal,
},
data() {
return {
@ -650,7 +655,8 @@ export default {
e.preventDefault()
//
const {
form: { validateFields },ruleList
form: { validateFields },
ruleList,
} = this
validateFields((errors, values) => {
// tab
@ -725,8 +731,8 @@ export default {
})
.finally(() => (this.isLoading = false))
},
//
handleAdd() {
//
handleAdd() {
const index = this.ruleList.length
const newItem = { ...defaultItem, key: index }
// id(id)
@ -792,4 +798,3 @@ export default {
<style lang="less" scoped>
@import './style.less';
</style>

Loading…
Cancel
Save