文件
mashangyoujiu/Public/Retail/js/goods-label/band-label-link-goods.js

375 行
19 KiB
JavaScript
可执行文件

Vue.component('band-label-link-goods', {
template: `<el-dialog title="绑定商品"
:visible.sync="show"
:append-to-body="true"
:top="'65px'"
:before-close="closeBand"
:width="'calc(100vw - 160px)'"
:custom-class="'max-dialog-content'"
:close-on-press-escape="false"
:close-on-click-modal="false">
<div class="choose-store-goods-box">
<div class="chooseGoods" style="height: calc(100vh - 282px)">
<div class="chooseGoodsTables">
<el-form :inline="true" size="small">
<el-form-item label="关键词搜索">
<el-input :placeholder="'请输入'+(searchForm.search_type==1?'货号':(searchForm.search_type==2?'条码':'名称'))"
v-model="searchForm.search_text"
oninput="value=this.value.trim(' ')"
type="text"
clearable
style="width: 300px"
@keydown.enter.exact.native.prevent="handleCurrentChange(1)"
class="input-with-select">
<el-select v-model="searchForm.search_type"
style="width: 80px"
background slot="prepend">
<el-option label="货号" :value="1"></el-option>
<el-option label="条码" :value="2"></el-option>
<el-option label="名称" :value="3"></el-option>
</el-select>
</el-input>
</el-form-item>
<el-form-item>
<select-goods-category :user-type="operateType"
:store-id="storeId"
:category-id1.sync="searchForm.firstClass"
:category-id2.sync="searchForm.secondClass"
:category-id3.sync="searchForm.thirdClass"></select-goods-category>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleCurrentChange(1)" plain>搜索</el-button>
</el-form-item>
</el-form>
<template>
<el-table :data="goodsList"
:header-cell-style="{background:'#F5F7FA',color:'#606266'}"
border size="mini">
<el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
<el-table-column align="center" prop="goods_name" show-overflow-tooltip
label="商品名称" min-width="120px"></el-table-column>
<el-table-column align="center" label="图片" width="60px">
<template slot-scope="scope">
<el-image class="goods-img" :src="scope.row.goods_image?scope.row.goods_image:''">
<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="specifications" min-width="100" label="规格"></el-table-column>
<el-table-column align="center" prop="goods_number" min-width="100" label="货号"></el-table-column>
<el-table-column align="center" prop="goods_code" min-width="140" label="条码"></el-table-column>
<el-table-column align="center" label="操作" width="80px">
<template slot-scope="scope">
<el-button type="text"
size="mini"
:disabled="chooseGoodsList.length>=100?true:false"
@click="chooseGoods(scope.row)"
v-if="checkGoods(scope.row.id)">选择
</el-button>
<el-button v-else type="text" style="color: #666;" size="mini">已选</el-button>
</template>
</el-table-column>
<div slot="empty" v-if="!loading">暂无数据</div>
<div slot="empty" v-else><span class="el-icon-loading"></span></div>
</el-table>
<el-pagination @size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="searchForm.page"
:page-sizes="[10]"
:page-size="searchForm.limit"
layout="total, sizes, prev, pager, next, jumper"
:total="currentLen">
</el-pagination>
</template>
</div>
<div class="chooseGoodsTables">
<el-form :inline="true" class="demo-form-inline" size="small">
<el-form-item label="已选商品">
<el-input v-model="select_keyword"
clearable
@input="goodsNull"
@keydown.enter.exact.native.prevent="searchChooseGoods"
placeholder="请输入商品名称"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="searchChooseGoods" plain>搜索</el-button>
<el-button v-if="chooseGoodsList.length" @click="toClearChoose">清空已选</el-button>
</el-form-item>
</el-form>
<div class="selected-goods">
<el-table :data="showChooseGoodsList"
border size="mini"
:header-cell-style="{background:'#F5F7FA',color:'#606266'}"
height="calc(100vh - 286px)">
<el-table-column type="index" label="序号" align="center" width="50"></el-table-column>
<el-table-column align="center" prop="goods_name" show-overflow-tooltip
label="商品名称" min-width="120px"></el-table-column>
<el-table-column align="center" label="图片" width="60px">
<template slot-scope="scope">
<el-image class="goods-img" :src="scope.row.goods_image?scope.row.goods_image:''">
<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="specifications" min-width="100" label="规格"></el-table-column>
<el-table-column align="center" prop="goods_number" min-width="100" label="货号"></el-table-column>
<el-table-column align="center" prop="goods_code" min-width="140" label="条码"></el-table-column>
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button type="text" size="mini" @click="deleteSelected(scope.$index)">
删除
</el-button>
</template>
</el-table-column>
<div slot="empty" v-if="!loading">未选择商品</div>
</el-table>
</div>
</div>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="primary" round
@click="sureChooseGoods"
:disabled="chooseGoodsList.length==0||subLoading?true:false"
size="small">
<span>确定选择({{chooseGoodsList.length}}/100)</span>
<i v-if="subLoading" class="el-icon-loading"></i>
</el-button>
</div>
</el-dialog>`,
props: {
'show': {
type: Boolean,
default: false,
},
'operateType': {
type: Number,
default: 2,
},//1商户 2门店
'labelId': {
type: String,
required: true,
},
'storeId': {
type: String,
default: '',
},
'requestUrl': {
type: Object,
default() {
return {}
}
},//请求地址
},
data() {
return {
searchForm: {
search_type: 2,
search_text: '',
firstClass: '',
secondClass: '',
thirdClass: '',
page: 1,
limit: 10,
},//待选商品列表搜索选项
currentLen: 0,//待选商品总数量
loading: false,
goodsList: [],//待选商品列表
chooseGoodsList: [],//已选商品列表
showChooseGoodsList: [],//展示的已选商品列表
select_keyword: '',
chooseGoodsObj: {},//已选商品id对象
subLoading: false,
}
},
methods: {
//关闭弹框
closeBand() {
this.searchForm = {
search_type: 2,
search_text: '',
firstClass: '',
secondClass: '',
thirdClass: '',
page: 1,
limit: 10,
};
this.chooseGoodsList = [];
this.showChooseGoodsList = [];
this.chooseGoodsObj = {};
this.select_keyword = '';
this.$nextTick(() => {
this.$emit('close');
})
},
//即将清空已选
toClearChoose() {
this.$confirm("确认清空已选商品列表?", "关闭提示", {
confirmButtonText: '清空',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.chooseGoodsList = [];
this.showChooseGoodsList = [];
this.chooseGoodsObj = {};
var goodsList = JSON.parse(JSON.stringify(this.goodsList));
this.goodsList = [];
this.$nextTick(() => {
this.goodsList = goodsList;
})
}).catch(() => {
})
},
//确认选择商品
sureChooseGoods() {
this.$confirm("确认把已选商品与该标签绑定?", "温馨提示", {
confirmButtonText: '确认',
cancelButtonText: '取消',
}).then(() => {
let ids = [];
this.chooseGoodsList.forEach((item) => {
ids.push(item.id);
});
this.sendRequest(this.requestUrl.bandGoods,{
data: {
ids: ids.join(','),
label_id: this.labelId,
operate_type: this.operateType,
},
success: res => {
if (res.status == 1) {
this.$message.success(res.message);
this.closeBand();
} else {
this.$message.error(res.message);
}
}
});
}).catch(() => {
})
},
//清空已选搜索关键词
goodsNull(e) {
if (!e) {
this.showChooseGoodsList = this.chooseGoodsList
}
},
//判断商品是否可选
checkGoods(goods_id) {
return !this.chooseGoodsObj[goods_id];
},
//点击了选择商品
chooseGoods(item) {
item = JSON.parse(JSON.stringify(item));
this.chooseGoodsObj[item.id] = true;
this.chooseGoodsList.unshift(item);
if (this.select_keyword) {
if (this.fuzzySearch(item.goods_name, this.select_keyword)) {
this.showChooseGoodsList.unshift(item);
}
} else {
this.showChooseGoodsList.unshift(item);
}
var goodsList = JSON.parse(JSON.stringify(this.goodsList));
this.goodsList = [];
this.goodsList = goodsList;
},
//删除已选商品
deleteSelected(index) {
let goods_id = this.showChooseGoodsList[index].id;
delete this.chooseGoodsObj[goods_id];
this.showChooseGoodsList.splice(index, 1);
for (var i in this.chooseGoodsList) {
if (this.chooseGoodsList[i].id == goods_id) {
this.chooseGoodsList.splice(i, 1);
break;
}
}
delete goods_id;
var goodsList = JSON.parse(JSON.stringify(this.goodsList));
this.goodsList = [];
this.goodsList = goodsList;
},
//已选列表搜索
searchChooseGoods() {
this.showChooseGoodsList = [];
if (this.select_keyword == '') {
this.showChooseGoodsList = this.chooseGoodsList;
} else {
for (let i = 0; i < this.chooseGoodsList.length; i++) {
if (this.fuzzySearch(this.chooseGoodsList[i].goods_name, this.select_keyword)) {
this.showChooseGoodsList.push(this.chooseGoodsList[i]);
}
}
}
},
//模糊搜索商品名称
fuzzySearch(name, keyword) {
if (keyword === '' || keyword === undefined) {
return true;
}
let len = 0;
let arr = String(keyword).split('');
for (let i in arr) {
if (name.indexOf(arr[i]) != -1) {
len++;
}
}
if (len == arr.length) {
return true;
} else {
return false;
}
},
//切换每页数量
handleSizeChange(val) {
this.searchForm.limit = val;
this.searchForm.page = 1;
this.getData();
},
//切换页数
handleCurrentChange(val) {
this.searchForm.page = val;
this.getData();
},
//获取商品列表
getData() {
this.goodsList = [];
this.loading = true;
this.sendRequest('Retail/LabelInventory/getGoodsList',{
data: {
label_id: this.labelId,
operate_type: this.operateType,
...this.searchForm,
},
success: (res) => {
this.loading = false;
if (res.status == 1) {
this.goodsList = res.data.list;
this.currentLen = res.data.count;
}
},
})
},
},
watch: {
show(n, o) {
//监听show的变化,重新渲染列表
if (n) {
this.getData();
}
}
},
created() {
// console.log('created');
// this.getData();
},
})