263 行
12 KiB
JavaScript
可执行文件
263 行
12 KiB
JavaScript
可执行文件
/**
|
|
* @m-choose-goods 选择商品
|
|
* @m-show-choose-goods 显示已选中的商品列表
|
|
*/
|
|
Vue.component('m-choose-goods', {
|
|
template: `<el-dialog :append-to-body="true" :title="needChoose?'选择商品':'查看商品'"
|
|
:visible.sync="showChooseGoods"
|
|
width="80%" :top="'50px'"
|
|
:before-close="closeDialog"
|
|
custom-class="customer-el-dialog__body"
|
|
:close-on-click-modal="false">
|
|
<el-scrollbar style="height: calc(100vh - 240px);padding-right: 8px">
|
|
<div style="padding:5px 0 15px 0px">
|
|
<el-input size="small" style="width: 190px;margin-bottom: 5px"
|
|
@keydown.enter.exact.native.prevent="pageChange(1)"
|
|
clearable
|
|
v-model="searchForm.search_info"
|
|
placeholder="商品名称/货号/条码"></el-input>
|
|
<choose-goods-class :store-id="storeId"
|
|
:is-disabled="!needChoose"
|
|
:user-type="2"
|
|
:selected-data="selectedClassId"
|
|
@choose-class="chooseSearchClass"></choose-goods-class>
|
|
<el-button type="primary" @click="pageChange(1)" size="small">搜索</el-button>
|
|
</div>
|
|
<template>
|
|
<el-table border :data="dataList" size="small" height="400" :header-cell-style="{background:'#F5F7FA',color:'#606266'}">
|
|
<el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
|
|
<el-table-column align="center" label="图片" min-width="66">
|
|
<template slot-scope="scope">
|
|
<el-image style="width: 40px;max-height: 40px;max-width: 40px;"
|
|
:src="scope.row.goods_img">
|
|
<div slot="error" class="image-slot">
|
|
<i class="el-icon-picture-outline"></i>
|
|
</div>
|
|
</el-image>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column align="center" prop="goods_name" label="商品名称" min-width="120"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="goods_number" label="货号" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="goods_code" label="条码" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="sku_name" label="规格" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column label="操作" v-if="needChoose" fixed="right" width="60" align="center">
|
|
<template slot-scope="scope">
|
|
<template v-if="!refresh">
|
|
<el-button size="mini" v-if="verifyUsed(scope.row)"
|
|
type="text" style="color: #aaaaaa">已选</el-button>
|
|
<el-button size="mini" :disabled="chooseIdList.length==20?true:false"
|
|
v-else type="text" @click="chooseIt(scope.row)">选择</el-button>
|
|
</template>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<el-pagination
|
|
@size-change="limitChange"
|
|
@current-change="pageChange"
|
|
:current-page="searchForm.page"
|
|
:page-size="searchForm.limit"
|
|
:total="currentLen"
|
|
:pager-count="5"
|
|
:page-sizes="[10,20,30,40,50,60,70,80,90,100]"
|
|
layout="total, sizes, prev, pager, next, jumper">
|
|
</el-pagination>
|
|
</template>
|
|
</el-scrollbar>
|
|
<div style="text-align: center;padding-top: 10px;border-top: 1px solid #DCDFE6;" v-if="needChoose">
|
|
<p style="font-size: 12px;color: #aaaaaa">已选 {{chooseIdList.length}}/20</p>
|
|
<el-button type="primary" size="medium" @click="closeDialog(1)">确定</el-button>
|
|
</div>
|
|
</el-dialog>`,
|
|
props: {
|
|
'showChooseGoods': {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
'needChoose': {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
'usedIdList': {
|
|
type: Array,
|
|
default: () => {
|
|
return []
|
|
},
|
|
},//已选ID列表
|
|
'selectedClassId': {
|
|
type: Array,
|
|
default: () => {
|
|
return []
|
|
},
|
|
},//已指定分类ID列表
|
|
'storeId': {
|
|
type: String,
|
|
default: '',
|
|
},//门店ID
|
|
},
|
|
data() {
|
|
return {
|
|
searchForm: {
|
|
exists_class_id_arr: '',
|
|
search_info: '',
|
|
person1: '',
|
|
person2: '',
|
|
person3: '',
|
|
store_id: '',
|
|
page: 1,
|
|
limit: 10,
|
|
},
|
|
currentLen: 0,
|
|
dataList: [],
|
|
chooseList: [],//本次已选商品列表
|
|
chooseIdList: [],//本次已选商品ID列表
|
|
refresh: false,
|
|
}
|
|
},
|
|
methods: {
|
|
closeDialog(type) {
|
|
this.$emit('close', type === 1 ? this.chooseList : []);
|
|
},
|
|
verifyUsed(item) {
|
|
let key = item.id;
|
|
if (item.attribute_state == 2) {
|
|
key += '_' + item.sku_id;
|
|
}
|
|
return this.chooseIdList.indexOf(key) >= 0 ? true : false;
|
|
},
|
|
chooseSearchClass(item) {
|
|
this.searchForm.person1 = item.data[0] ? item.data[0] : '';
|
|
this.searchForm.person2 = item.data[1] ? item.data[1] : '';
|
|
this.searchForm.person3 = item.data[2] ? item.data[2] : '';
|
|
},
|
|
chooseIt(item) {
|
|
this.chooseList.push(item);
|
|
let key = item.id;
|
|
if (item.attribute_state == 2) {
|
|
key += '_' + item.sku_id;
|
|
}
|
|
this.chooseIdList.push(key);
|
|
this.refresh = true;
|
|
this.$nextTick(() => {
|
|
this.refresh = false;
|
|
})
|
|
},
|
|
// 切换记录每页数量
|
|
limitChange(val) {
|
|
this.searchForm.limit = val;
|
|
this.searchForm.page = 1;
|
|
this.getGoodsList();
|
|
},
|
|
// 切换记录页数
|
|
pageChange(val) {
|
|
this.searchForm.page = val;
|
|
this.getGoodsList();
|
|
},
|
|
// 商品列表
|
|
getGoodsList() {
|
|
$.ajax({
|
|
url: '/index.php/Retail/Mcoupon/appointGoods',
|
|
type: "post",
|
|
data: this.searchForm,
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.dataList = res.data.list;
|
|
this.currentLen = res.data.count * 1;
|
|
} else {
|
|
this.dataList = [];
|
|
this.currentLen = 0;
|
|
}
|
|
}
|
|
})
|
|
},
|
|
},
|
|
watch: {
|
|
showChooseGoods(n, o) {
|
|
if (n) {
|
|
this.searchForm.store_id = this.storeId;
|
|
if (this.selectedClassId.length) {
|
|
this.searchForm.person1 = this.selectedClassId[0] ? this.selectedClassId[0] : '';
|
|
this.searchForm.person2 = this.selectedClassId[1] ? this.selectedClassId[1] : '';
|
|
this.searchForm.person3 = this.selectedClassId[2] ? this.selectedClassId[2] : '';
|
|
}
|
|
this.$nextTick(() => {
|
|
this.searchForm.exists_id_arr = this.chooseIdList.join(',');
|
|
this.pageChange(1);
|
|
})
|
|
} else {
|
|
this.searchForm = {
|
|
exists_id_arr: '',
|
|
search_info: '',
|
|
person1: '',
|
|
person2: '',
|
|
person3: '',
|
|
store_id: '',
|
|
page: 1,
|
|
limit: 10,
|
|
};
|
|
this.currentLen = 0;
|
|
this.dataList = [];
|
|
this.chooseList = [];//本次已选分类列表
|
|
this.chooseIdList = [];//本次已选分类ID列表
|
|
this.refresh = false;
|
|
}
|
|
},
|
|
usedIdList(n) {
|
|
this.chooseIdList = JSON.parse(JSON.stringify(n));
|
|
},
|
|
},
|
|
});
|
|
|
|
Vue.component('m-show-choose-goods', {
|
|
template: `<el-table :data="goodsList" border size="small" :header-cell-style="{background:'#F5F7FA',color:'#606266'}">
|
|
<el-table-column type="index" label="序号" align="center"></el-table-column>
|
|
<el-table-column align="center" label="图片" min-width="66">
|
|
<template slot-scope="scope">
|
|
<el-image style="width: 40px;max-height: 40px;max-width: 40px;"
|
|
:src="scope.row.goods_img">
|
|
<div slot="error" class="image-slot">
|
|
<i class="el-icon-picture-outline"></i>
|
|
</div>
|
|
</el-image>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column align="center" prop="goods_name" label="商品名称" min-width="120"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="goods_number" label="货号" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="goods_code" label="条码" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="sku_name" label="规格" min-width="80"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column label="操作" v-if="operateState" fixed="right" align="center" width="60">
|
|
<template slot-scope="scope">
|
|
<el-button type="text" @click="removeGoods(scope.$index,scope.row.goods_id)">删除</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>`,
|
|
props: {
|
|
'goodsList': {
|
|
type: Array,
|
|
default: () => {
|
|
return [];
|
|
},
|
|
},
|
|
'operateState': {
|
|
type: Boolean,
|
|
default: false,
|
|
},//操作的权限
|
|
},
|
|
methods: {
|
|
//移除已选商品
|
|
removeGoods(index, goods_id) {
|
|
this.goodsList.splice(index, 1);
|
|
this.$nextTick(() => {
|
|
this.$emit('del', goods_id);
|
|
});
|
|
},
|
|
}
|
|
});
|