| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- <template>
- <div>
- <Toptitle>
- <template #left>
- <Button type="primary" @click="is_open = !is_open">{{
- is_open ? "收缩" : "展开"
- }}</Button>
- </template>
- <template #right>
- <Dropdown style="margin-left: 20px" @on-click="handleClick">
- <Button type="primary">
- 操作
- <Icon type="ios-arrow-down"></Icon>
- </Button>
- <DropdownMenu slot="list">
- <DropdownItem :name="1">新增</DropdownItem>
- <DropdownItem :name="2">批量删除</DropdownItem>
- <DropdownItem :name="3">导出</DropdownItem>
- </DropdownMenu>
- </Dropdown>
- </template>
- </Toptitle>
- <div
- :style="
- is_open
- ? 'max-height:200px;transition: all .5s;'
- : 'max-height:0px;overflow: hidden;transition: all .5s;'
- "
- >
- <Form :label-width="120" style="display: flex; flex-wrap: wrap">
- <FormItem label="管理员">
- <Select
- v-model="searchData.employee_id"
- filterable
- clearable
- transfer
- style="width: 200px"
- >
- <Option
- v-for="item in employeeList"
- :key="item.id"
- :value="item.id"
- :label="item.emp_name"
- />
- </Select>
- </FormItem>
- <FormItem label="仓库名称">
- <Input
- v-model="searchData.title"
- clearable
- style="width: 200px"
- placeholder="请输入"
- />
- </FormItem>
- <FormItem :label-width="30">
- <Button type="primary" @click="handleSearch">查询</Button>
- </FormItem>
- </Form>
- </div>
- <div style="max-height: calc(100% - 150px); border: 1px solid #fff">
- <vxe-grid
- v-bind="gridOptions"
- @checkbox-change="handleSelect"
- @checkbox-all="handleSelectAll"
- >
- <template #set="{ row }">
- <a style="margin-right: 10px" @click="handleEdit(row)">编辑</a>
- <a @click="handleDel(row)">删除</a>
- </template>
- </vxe-grid>
- </div>
- <div style="text-align: center; margin-top: 10px">
- <Page
- show-elevator
- :page-size-opts="[10, 20, 30, 40, 100, 1000]"
- @on-page-size-change="changeSize"
- @on-change="changePage"
- :current="pageIndex"
- show-total
- :total="total"
- show-sizer
- :page-size="pageSize"
- />
- </div>
- <Modal
- draggable
- title="新增"
- width="80"
- :closable="false"
- :mask-closable="false"
- v-model="is_show"
- >
- <div style="max-height: 450px; overflow: auto">
- <Form
- :label-width="100"
- v-for="(item, index) in modalData"
- :key="index"
- style="display: flex"
- >
- <FormItem label="管理员" style="width: 30%">
- <Select v-model="item.employee_id" filterable clearable transfer>
- <Option
- v-for="_item in employeeList"
- :key="_item.id"
- :value="_item.id"
- :label="_item.emp_name"
- />
- </Select>
- </FormItem>
- <FormItem label="仓库名称" style="width: 30%">
- <Input clearable placeholder="请输入" v-model="item.title" />
- </FormItem>
- <FormItem label="关联集团">
- <Select v-model="item.company" filterable clearable transfer>
- <Option
- v-for="_item in companyList"
- :key="_item.id"
- :value="_item.id"
- :label="_item.title"
- />
- </Select>
- </FormItem>
- <FormItem :label-width="40" style="width: 20%">
- <div class="icon">
- <Icon
- :size="20"
- type="ios-add-circle-outline"
- style="margin-right: 10px; cursor: pointer"
- @click="handleModalAdd(index)"
- />
- <Icon
- :size="20"
- type="ios-remove-circle-outline"
- style="cursor: pointer"
- @click="handleModalRemove(index)"
- />
- </div>
- </FormItem>
- </Form>
- </div>
- <div slot="footer">
- <Button style="margin-right: 10px" @click="is_show = false"
- >取消</Button
- >
- <Button type="primary" @click="handleSure">确认</Button>
- </div>
- </Modal>
- <Modal
- draggable
- title="编辑"
- width="40"
- :closable="false"
- :mask-closable="false"
- v-model="is_edit"
- >
- <Form :label-width="100">
- <FormItem label="管理员">
- <Select v-model="editData.employee_id" filterable clearable transfer>
- <Option
- v-for="_item in employeeList"
- :key="_item.id"
- :value="_item.id"
- :label="_item.emp_name"
- />
- </Select>
- </FormItem>
- <FormItem label="仓库名称">
- <Input clearable placeholder="请输入" v-model="editData.title" />
- </FormItem>
- <FormItem label="关联集团">
- <Select v-model="editData.company" filterable clearable transfer>
- <Option
- v-for="_item in companyList"
- :key="_item.id"
- :value="_item.id"
- :label="_item.title"
- />
- </Select>
- </FormItem>
- </Form>
- <div slot="footer">
- <Button style="margin-right: 10px" @click="is_edit = false"
- >取消</Button
- >
- <Button type="primary" @click="handleSureEdit">确认</Button>
- </div>
- </Modal>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- pageSize: 10,
- pageIndex: 1,
- total: 0,
- searchData: {
- employee_id: '',
- title: ""
- },
- is_edit: false,
- is_open: false,
- editData: {},
- proxyData: {},
- modalData: [],
- companyList:[],
- is_show: false,
- selectData: [],
- gridOptions: {
- maxHeight: 'auto',
- border: true,
- showOverflow: true,
- rowId: 'id',
- rowConfig: {
- isHover: true
- },
- columnConfig: {
- resizable: true
- },
- data: [],
- columns: [
- { type: 'checkbox', width: 80 },
- { title: '操作', slots: { default: 'set' }, width: 150, align: 'center' },
- { field: 'emp_name', title: '管理员', width: 220 },
- { field: 'title', title: '仓库名称' },
- { field: 'company_name', title: '关联集团' },
- ]
- },
- employeeList: [],
- }
- },
- created() {
- //获取人员列表
- this.axios.post('/api/employeeList').then(res => {
- this.employeeList = res.data.data;
- })
- //获取集团列表
- this.axios.post('/api/companyList').then(res=>{
- this.companyList = res.data.data;
- })
- },
- mounted() {
- this.initData();
- },
- methods: {
- changeSize(e) {
- this.pageSize = e;
- this.pageIndex = 1;
- this.initData(this.proxyData)
- },
- changePage(e) {
- this.pageIndex = e;
- this.initData(this.proxyData);
- },
- async handleClick(name) {
- if (name == 1) {
- this.handleAdd();
- } else if(name == 2){
- this.handleDel();
- }else {
- if(this.selectData.length==0){
- return this.$Message.warning('请选择需要导出的数据!')
- }
- let id = this.selectData.map(v=>v.id);
- const res = await this.axios.post('/api/exportFile',{type:18,id})
- if(res.code === 200){
- let url = `${this.$store.state.ip}/api/getExport/${res.data.file}`
- location.href = url
- }
- }
- },
- handleSearch() {
- this.proxyData = JSON.parse(JSON.stringify(this.searchData));
- this.pageIndex = 1;
- this.initData(this.proxyData);
- },
- handleModalAdd(index) {
- this.modalData.splice(index + 1, 0, { employee_id: '', title: "" })
- },
- handleModalRemove(index) {
- this.modalData.splice(index, 1)
- },
- handleSure() {
- let data = JSON.parse(JSON.stringify(this.modalData))
- data.forEach(v=>{
- v.company = [v.company]
- })
- this.axios.post('/api/storehouseAdd', { data }).then(res => {
- if (res.code == 200) {
- this.$Message.success(res.msg);
- this.initData(this.proxyData);
- this.is_show = false;
- }
- })
- },
- handleSureEdit() {
- let id = this.editData.id;
- let data = [{ employee_id: this.editData.employee_id, title: this.editData.title ,company:[this.editData.company]}]
- this.axios.post('/api/storehouseEdit', { id, data }).then(res => {
- if (res.code == 200) {
- this.$Message.success(res.msg);
- this.initData(this.proxyData);
- this.is_edit = false;
- }
- })
- },
- handleSelectAll(e) {
- this.selectData = e.records;
- },
- handleSelect(e) {
- this.selectData = e.records;
- },
- initData(row) {
- this.axios.post('/api/storehouseList', { ...row, page_index: this.pageIndex, page_size: this.pageSize }).then(res => {
- this.gridOptions.data = res.data.data;
- this.total = res.data.total;
- })
- },
- handleEdit(row) {
- this.is_edit = true;
- this.editData = JSON.parse(JSON.stringify(row));
- this.editData.company = this.editData.company_id.length==1?this.editData.company_id[0]:'';
- },
- handleAdd() {
- // if (type == 1) {//新增
- this.modalData = [
- {
- employee_id: '',
- title: ''
- }
- ]
- this.is_show = true;
- // }
- // else {//编辑
- // if (this.getBol(this.selectData)) {
- // this.is_show = true;
- // } else {
- // return this.$Message.warning('请选择一个子集团!')
- // }
- // let data = this.getData(this.selectData);
- // this.modalData = { id: data.id, employee_id: data.employee_id, title: data.title }
- // }
- },
- // getData(arr) {
- // let obj = {};
- // arr.forEach(v => {
- // if (v.children.length == 0) {
- // obj = v;
- // } else {
- // obj = this.getData(v.children);
- // }
- // })
- // return obj;
- // },
- // getBol(arr) {
- // let bol = true;
- // let ids = arr.map(v => v.id);
- // let fid = [this.selectData[0].id, ...this.getChildren(this.selectData[0].children)];
- // let length = arr.map(v => v.employee_id.length);
- // let setLength = Array.from(new Set(length));
- // if (length.length == setLength.length) {
- // ids.forEach(v => {
- // if (fid.indexOf(v) == -1) {
- // return bol = false
- // }
- // })
- // } else {
- // bol = false;
- // }
- // return bol
- // },
- // getChildren(arr) {
- // let id = [];
- // arr.forEach(v => {
- // id.push(v.id);
- // if (v.children.length != 0) {
- // id = [id, ...this.getChildren(v.children)];
- // }
- // })
- // return id;
- // },
- handleDel(row) {
- let id = [];
- if (row) {
- id = [row.id];
- } else {
- if (this.selectData.length == 0) {
- return this.$Message.warning('请选择数据!');
- }
- id = this.selectData.map(v => (v.id));
- }
- this.$Modal.confirm({
- title: '删除',
- content: '确认删除嘛?',
- onOk: () => {
- this.axios.post('/api/storehouseDel', {id}).then(res => {
- if (res.code == 200) {
- this.$Message.success(res.msg);
- if (this.pageIndex != 1 && !(this.gridOptions.data.length - id.length)) {
- this.pageIndex--;
- }
- this.selectData = [];
- this.initData(this.proxyData)
- }
- })
- }
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .icon {
- display: flex;
- width: 80px;
- justify-content: space-between;
- align-items: center;
- height: 44px;
- }
- </style>
|