2020-09-22 14:50:10 +08:00

258 lines
6.4 KiB
Vue

<template>
<div>
<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
<el-form-item label="类型" >
<el-select v-model="specReq.typeId" :disabled="departmentReaderOnly" @change="changeDepartment(1)">
<el-option
v-for="item in types"
:key="item.id"
:label="item.type"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="品牌">
<el-input v-model="specReq.brand" placeholder="品牌信息" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="getData()">查询</el-button>
</el-form-item>
<el-form-item>
<el-button type="success" @click="addNewSpec()">新增品牌</el-button>
</el-form-item>
</el-form>
<el-table v-loading="dataListLoading" :data="data" style="width: 100%" @row-click="rowClick">
<el-table-column prop="id" header-align="center" align="center" label="ID"></el-table-column>
<el-table-column prop="typeName" header-align="center" align="center" label="类型"></el-table-column>
<el-table-column prop="brand" header-align="center" align="center" label="品牌"></el-table-column>
<el-table-column prop="rank" header-align="center" align="center" label="排序"></el-table-column>
<el-table-column fixed="right" header-align="center" align="center" width="180" label="操作">
<template slot-scope="scope">
<el-button
type="text"
size="mini"
@click="handleAddOrUpdate(scope.row)"
>编辑
</el-button>
<el-button
type="text"
size="mini"
@click="handleDelete(scope.row)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="specReq.page"
:page-sizes="[10, 20, 50, 100]"
:page-size="specReq.rows"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper"
></el-pagination>
<device-brand-detail v-if="isShowDetail" ref="deviceBrandDetail" @refreshDataList="getData"></device-brand-detail>
</div>
</template>
<script>
import { apiGetDeviceBrandList, apiDelDeviceBrands } from "@/api/api_equipment";
import DeviceBrandDetail from './device-brand-detail.vue'
export default {
components: {
DeviceBrandDetail
},
data() {
return {
isShowSearch: true,
data: [],
types: [],
name: "",
categorys: "",
input: "",
dataListLoading: false,
typeIndex: 0, //0现在是1级 1二级2三级
showHeader: false,
totalPage: 1,
departmentReaderOnly: false,
specReq: {
page: 1,
rows: 10,
sort: null,
order: null,
id: null,
isDelete: 0,
gmtCreate: null,
gmtModified: null,
brand: null,
typeId: null,
rank: null, //排序
},
isShowDetail: false
};
},
created() {
// this.handleGetImgCaptcha()
},
mounted() {
this.getData();
},
methods: {
addNewSpec(){
//id, typeId, type, brandId, brand, specs, skus, rank, used, remark, types, brands
setTimeout(() => {
var val = {id: null, typeId: null, brand: null, rank: 0}
this.$refs.deviceBrandDetail.init(val, this.types)
}, 500)
this.isShowDetail = true
},
changeDepartment(type) {
this.specReq.page = 1
this.getData()
},
sizeChangeHandle(val) {
this.specReq.page = 1
this.specReq.rows = val
this.getData();
},
currentChangeHandle(val) {
this.specReq.page = val
this.getData();
},
// 新增 / 编辑
handleAddOrUpdate (val) {
console.log(val)
//id, typeId, type, brandId, brand, specs, skus, rank, used, remark, types, brands
setTimeout(() => {
console.log(val)
this.$refs.deviceBrandDetail.init(val, this.types)
}, 500)
this.isShowDetail = true
},
// 删除
handleDelete (val) {
this.$confirm('确定删除“' + val.brand + '”吗?删除后该品牌将无法使用', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.delDeviceSpecs(val.id)
}).catch(() => {
})
},
delDeviceSpecs(id){
apiDelDeviceBrands({page: 1,
rows: 10,
sort: null,
order: null,
id: id,
isDelete: 0,
gmtCreate: null,
gmtModified: null,
brand: null,
typeId: null,
rank: null,
}).then((data) => {
console.log(data);
if (data && data.code === 0) {
this.$message('删除成功')
this.getData()
} else {
this.$message.error('删除失败' + data.msg)
}
this.dataListLoading = false;
});
},
getData() {
console.log("获取数据")
console.log(this.name)
console.log(this.categorys)
this.dataListLoading = true
apiGetDeviceBrandList(this.specReq).then((data) => {
console.log(data);
if (data && data.code === 0) {
this.data = data.rows;
this.totalPage = data.total
this.types = data.types
} else {
this.data = [];
}
this.dataListLoading = false;
});
},
btnSearch() {
this.specReq.page = 1
this.getData();
},
rowClick(row, event, column) {},
},
};
</script>
<style>
.el-row {
margin-bottom: 20px;
}
.el-col {
border-radius: 10px;
}
.bg-purple-dark {
background: #99a9bf;
}
.bg-purple {
background: #d3dce6;
}
.bg-purple-light {
background: #e5f2f1;
}
.grid-content {
border-radius: 4px;
min-height: 36px;
}
.row-bg {
padding: 10px 0;
background-color: #f9fafc;
}
.div_height {
height: 38px;
}
.div_width {
width: 100%;
}
.width_100 {
width: 100px;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 1em;
}
.flex {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
border: 1px solid;
}
.flex_son {
width: 100%;
height: 100%;
border: 0x solid;
}
</style>