|
|
@ -1,6 +1,31 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<a-button @click="handleSelectGoods">选择商品</a-button> |
|
|
|
<a-button @click="handleSelectGoods">选择商品</a-button> |
|
|
|
|
|
|
|
<a-table |
|
|
|
|
|
|
|
v-show="selectedItems.length" |
|
|
|
|
|
|
|
class="table-goodsList" |
|
|
|
|
|
|
|
rowKey="goods_id" |
|
|
|
|
|
|
|
:columns="columns" |
|
|
|
|
|
|
|
:dataSource="selectedItems" |
|
|
|
|
|
|
|
:pagination="false" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<!-- 商品信息 --> |
|
|
|
|
|
|
|
<template slot="item" slot-scope="item"> |
|
|
|
|
|
|
|
<GoodsItem |
|
|
|
|
|
|
|
:data="{ |
|
|
|
|
|
|
|
image: item.goods_image, |
|
|
|
|
|
|
|
imageAlt: '商品图片', |
|
|
|
|
|
|
|
title: item.goods_name, |
|
|
|
|
|
|
|
subtitle: `¥${item.goods_price_min}`, |
|
|
|
|
|
|
|
}" |
|
|
|
|
|
|
|
:subTitleColor="true" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
<!-- 操作项 --> |
|
|
|
|
|
|
|
<span slot="action" slot-scope="text, item, index"> |
|
|
|
|
|
|
|
<a v-action:delete @click="handleDeleteItem(index)">删除</a> |
|
|
|
|
|
|
|
</span> |
|
|
|
|
|
|
|
</a-table> |
|
|
|
<GoodsModal |
|
|
|
<GoodsModal |
|
|
|
ref="GoodsModal" |
|
|
|
ref="GoodsModal" |
|
|
|
:multiple="multiple" |
|
|
|
:multiple="multiple" |
|
|
@ -15,37 +40,39 @@ |
|
|
|
import PropTypes from 'ant-design-vue/es/_util/vue-types' |
|
|
|
import PropTypes from 'ant-design-vue/es/_util/vue-types' |
|
|
|
import cloneDeep from 'lodash.clonedeep' |
|
|
|
import cloneDeep from 'lodash.clonedeep' |
|
|
|
import { GoodsModal } from '@/components/Modal' |
|
|
|
import { GoodsModal } from '@/components/Modal' |
|
|
|
|
|
|
|
import { GoodsItem } from '@/components/Table' |
|
|
|
|
|
|
|
|
|
|
|
const columns = [ |
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: '商品ID', |
|
|
|
title: '商品ID', |
|
|
|
dataIndex: 'goods_id' |
|
|
|
dataIndex: 'goods_id', |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: '商品信息', |
|
|
|
title: '商品信息', |
|
|
|
scopedSlots: { customRender: 'item' } |
|
|
|
scopedSlots: { customRender: 'item' }, |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: '库存总量', |
|
|
|
title: '库存总量', |
|
|
|
dataIndex: 'stock_total' |
|
|
|
dataIndex: 'stock_total', |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
title: '操作', |
|
|
|
title: '操作', |
|
|
|
width: '180px', |
|
|
|
width: '180px', |
|
|
|
dataIndex: 'action', |
|
|
|
dataIndex: 'action', |
|
|
|
scopedSlots: { customRender: 'action' } |
|
|
|
scopedSlots: { customRender: 'action' }, |
|
|
|
} |
|
|
|
}, |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
// 商品选择器组件 |
|
|
|
// 商品选择器组件 |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: 'SelectGoods', |
|
|
|
name: 'SelectGoods', |
|
|
|
components: { |
|
|
|
components: { |
|
|
|
GoodsModal |
|
|
|
GoodsModal, |
|
|
|
|
|
|
|
GoodsItem, |
|
|
|
}, |
|
|
|
}, |
|
|
|
model: { |
|
|
|
model: { |
|
|
|
prop: 'value', |
|
|
|
prop: 'value', |
|
|
|
event: 'change' |
|
|
|
event: 'change', |
|
|
|
}, |
|
|
|
}, |
|
|
|
props: { |
|
|
|
props: { |
|
|
|
// 多选模式, 如果false为单选 |
|
|
|
// 多选模式, 如果false为单选 |
|
|
@ -53,15 +80,15 @@ export default { |
|
|
|
// 最大选择的数量限制, multiple模式下有效 |
|
|
|
// 最大选择的数量限制, multiple模式下有效 |
|
|
|
maxNum: PropTypes.integer.def(100), |
|
|
|
maxNum: PropTypes.integer.def(100), |
|
|
|
// 默认选中的商品 |
|
|
|
// 默认选中的商品 |
|
|
|
defaultList: PropTypes.array.def([]) |
|
|
|
defaultList: PropTypes.array.def([]), |
|
|
|
}, |
|
|
|
}, |
|
|
|
data () { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
columns, |
|
|
|
columns, |
|
|
|
// 已选择的商品列表 |
|
|
|
// 已选择的商品列表 |
|
|
|
selectedItems: [], |
|
|
|
selectedItems: [], |
|
|
|
// 已选择的商品ID集 |
|
|
|
// 已选择的商品ID集 |
|
|
|
selectedGoodsIds: [] |
|
|
|
selectedGoodsIds: [], |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
watch: { |
|
|
@ -69,24 +96,22 @@ export default { |
|
|
|
defaultList: { |
|
|
|
defaultList: { |
|
|
|
// 首次加载的时候执行函数 |
|
|
|
// 首次加载的时候执行函数 |
|
|
|
immediate: true, |
|
|
|
immediate: true, |
|
|
|
handler (val) { |
|
|
|
handler(val) { |
|
|
|
const { selectedItems } = this |
|
|
|
const { selectedItems } = this |
|
|
|
if (val.length && !selectedItems.length) { |
|
|
|
if (val.length && !selectedItems.length) { |
|
|
|
this.onUpdate(cloneDeep(val)) |
|
|
|
this.onUpdate(cloneDeep(val)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
created () { |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
created() {}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
|
|
|
|
|
|
|
|
// 更新数据 |
|
|
|
// 更新数据 |
|
|
|
onUpdate (selectedItems) { |
|
|
|
onUpdate(selectedItems) { |
|
|
|
if (this.multiple || !selectedItems.length) { |
|
|
|
if (this.multiple || !selectedItems.length) { |
|
|
|
// 多选模式 |
|
|
|
// 多选模式 |
|
|
|
this.selectedItems = selectedItems |
|
|
|
this.selectedItems = selectedItems |
|
|
|
this.selectedGoodsIds = selectedItems.map(item => item.goods_id) |
|
|
|
this.selectedGoodsIds = selectedItems.map((item) => item.goods_id) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 单选模式 |
|
|
|
// 单选模式 |
|
|
|
const single = selectedItems[selectedItems.length - 1] |
|
|
|
const single = selectedItems[selectedItems.length - 1] |
|
|
@ -97,32 +122,30 @@ export default { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 打开商品选择器 |
|
|
|
// 打开商品选择器 |
|
|
|
handleSelectGoods () { |
|
|
|
handleSelectGoods() { |
|
|
|
this.$refs.GoodsModal.handle() |
|
|
|
this.$refs.GoodsModal.handle() |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 商品库modal确认回调 |
|
|
|
// 商品库modal确认回调 |
|
|
|
handleSelectGoodsSubmit (result) { |
|
|
|
handleSelectGoodsSubmit(result) { |
|
|
|
const { selectedItems } = result |
|
|
|
const { selectedItems } = result |
|
|
|
this.onUpdate(cloneDeep(selectedItems)) |
|
|
|
this.onUpdate(cloneDeep(selectedItems)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 删除商品 |
|
|
|
// 删除商品 |
|
|
|
handleDeleteItem (index) { |
|
|
|
handleDeleteItem(index) { |
|
|
|
const { selectedItems } = this |
|
|
|
const { selectedItems } = this |
|
|
|
selectedItems.splice(index, 1) |
|
|
|
selectedItems.splice(index, 1) |
|
|
|
this.onUpdate(selectedItems) |
|
|
|
this.onUpdate(selectedItems) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 触发change事件 |
|
|
|
// 触发change事件 |
|
|
|
onChange () { |
|
|
|
onChange() { |
|
|
|
const { multiple, selectedGoodsIds } = this |
|
|
|
const { multiple, selectedGoodsIds } = this |
|
|
|
const sGoodsIds = multiple ? selectedGoodsIds : (selectedGoodsIds.length ? selectedGoodsIds[0] : undefined) |
|
|
|
const sGoodsIds = multiple ? selectedGoodsIds : selectedGoodsIds.length ? selectedGoodsIds[0] : undefined |
|
|
|
this.$emit('select', multiple ? this.selectedItems : this.selectedItems[0]) |
|
|
|
|
|
|
|
return this.$emit('change', sGoodsIds) |
|
|
|
return this.$emit('change', sGoodsIds) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|