文件
mashangyoujiu/Public/Retail/js/goods-unit/manage-goods-unit.js

210 行
9.3 KiB
JavaScript
可执行文件

Vue.component('manage-goods-unit', {
template: `<div>
<div style="display: flex;padding-bottom: 10px;flex-wrap: wrap;">
<el-input v-model="searchForm.name" clearable
@keydown.enter.exact.native.prevent="searchData"
style="width:200px;margin-right: 10px" size="small"
placeholder="单位名称"></el-input>
<el-button type="primary" @click="searchData" size="small">查询</el-button>
<el-button v-if="operate.addUnit"
type="primary" plain
@click="showAddUnitLibrary=true"
size="small">新增
</el-button>
</div>
<div>
<template>
<el-table :data="dataList" :header-cell-style="{background:'#F5F7FA',color:'#606266'}"
:highlight-current-row="true"
border size="small" max-height="500">
<el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
<el-table-column prop="name" align="center" label="单位名称" min-width="150"
show-overflow-tooltip></el-table-column>
<el-table-column prop="add_time" align="center" label="添加时间" show-overflow-tooltip
min-width="150"></el-table-column>
<el-table-column label="操作" width="100" align="center">
<template slot-scope="scope">
<el-button type="text" size="mini"
v-if="operate.deleteUnit&&scope.row.merchant_id!=0"
style="color:#999"
@click="delUnitLibrary(scope.row)">删除
</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="sizeChange"
@current-change="currentChange"
layout="total, sizes, prev, pager, next, jumper"
:current-page="searchForm.page"
:pager-count="5"
:page-sizes="[10,20,30,40,50,60,70,80,90]"
:page-size="10"
:total="count">
</el-pagination>
</template>
</div>
<el-dialog title="新增单位" :append-to-body="true"
:visible.sync="showAddUnitLibrary" :before-close="closeEditUnitLibrary"
width="400px">
<el-form size="small" label-width="80px" ref="ruleForm" :rules="rules" :model="ruleForm" @submit.native.prevent>
<el-form-item label="单位名称" prop="name">
<el-input v-model="ruleForm.name" placeholder="请输入单位名称" maxLength="20"></el-input>
</el-form-item>
</el-form>
<div style="text-align: center;margin-top: 50px">
<el-button type="primary" size="medium" @click="saveUnitLibrary">保存</el-button>
</div>
</el-dialog>
</div>`,
props: {
'operateType': {
type: Number,
required: true,
},//1商户 2门店
},
data() {
return {
dataList: [], // 数据
searchForm: {
name: '',
page: 1, // 分页
limit: 10, // 每页显示条数
},//搜索表单
count: 0, // 总条数
showAddUnitLibrary: false, //是否显示添加
operate: {}, //权限
ruleForm: {
id: 0,
name: '',
},//新增、编辑表单
rules: {
name: [{message: '请输入单位名称', required: true, trigger: 'change'}],
},
requestUrl: {
addUnit: '/index.php/Retail/UnitLibrary/' + (this.operateType == 1 ? 'addMerchantUnit' : 'addStoreUnit'),
deleteUnit: '/index.php/Retail/UnitLibrary/' + (this.operateType == 1 ? 'deleteMerchantUnit' : 'deleteStoreUnit'),
},
};
},
methods: {
closeEditUnitLibrary() {
this.$refs.ruleForm.resetFields();
this.ruleForm.id = '';
this.showAddUnitLibrary = false;
},
/* 获取数据 */
getUnitLibraryList() {
this.dataList = [];
this.loading = true;
this.sendRequest('Retail/UnitLibrary/getUnitList',{
data: {
...this.searchForm,
type: this.operateType,
},
success: (res) => {
this.loading = false;
if (res.status == 1) {
this.count = res.data.count;
this.dataList = res.data.list;
}else{
this.$message.error(res.message);
}
},
})
},
//查询
searchData() {
this.searchForm.page = 1;
this.getUnitLibraryList();
},
/* 切换每页数量 */
sizeChange(val) {
this.searchForm.limit = val;
this.searchForm.page = 1;
this.getUnitLibraryList();
},
/* 切换页数 */
currentChange(val) {
this.searchForm.page = val;
this.getUnitLibraryList();
},
//保存单位
saveUnitLibrary() {
this.$refs.ruleForm.validate((valid) => {
if (!valid) {
return false;
}
this.$confirm("确认要保存该单位吗?", "温馨提示", {
confirmButtonText: '保存',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.$loading({
lock: true,
text: '保存中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
this.sendRequest(this.requestUrl.addUnit, {
data: {
...this.ruleForm
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.closeEditUnitLibrary();
this.$message.success(res.message);
this.getUnitLibraryList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
})
},
//删除单位
delUnitLibrary(item) {
this.$confirm("删除后不影响已使用该单位的商品,确认要删除该单位吗?", "温馨提示", {
confirmButtonText: '删除',
cancelButtonText: '取消',
type: 'info'
}).then(() => {
this.$loading({
lock: true,
text: '删除中,请等待',
spinner: 'el-icon-loading',
background: 'rgba(255, 255, 255, 0.7)'
});
this.sendRequest(this.requestUrl.deleteUnit, {
data: {
id: item.id,
name: item.name,
},
success: (res) => {
this.$loading().close();
if (res.status == 1) {
this.$message.success(res.message);
this.getUnitLibraryList();
} else {
this.$message.error(res.message)
}
},
})
}).catch(() => {
})
},
},
created() {
this.getUnitLibraryList();
this.checkOperateAuth(this.requestUrl, (data) => {
this.operate = data;
})
},
});