| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 | <template>	<section>		<!--工具条-->		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">			<el-form :inline="true" :model="filters">                <el-form-item>                    <el-input v-model="filters.keyName" placeholder="请输入工厂名称进行搜索" clearable></el-input>                </el-form-item>				<el-form-item>					<el-button type="primary" @click.native="getFactory">查询</el-button>				</el-form-item>				<el-form-item style="float:right;">					<el-button type="primary" @click.native="handleAdd">新增</el-button>				</el-form-item>			</el-form>		</el-col>		<!--列表-->		<el-table :data="list" highlight-current-row :height="tableHeight" v-loading="listLoading" style="width: 100%;">            <el-table-column type="index" width="60"></el-table-column>			<el-table-column prop="factoryName" label="工厂名称" width="300" sortable></el-table-column>            <el-table-column prop="factoryArea" label="工厂地址" sortable></el-table-column>			<el-table-column label="操作" width="150">				<template slot-scope="scope">					<el-button size="small" @click.native="handleEdit(scope.$index, scope.row)">编辑</el-button>					<el-button type="danger" size="small" @click.native.native="handleDel(scope.$index, scope.row)">删除</el-button>				</template>			</el-table-column>		</el-table>		<!--工具条-->		<el-col :span="24" class="toolbar">            <el-pagination                @size-change="handleSizeChange"                @current-change="handleCurrentChange"                :page-sizes="[20 , 50 , 80 , 100]"                :page-size="20"                layout="total, sizes, prev, pager, next"                :total="total"                style="float:right;">            </el-pagination>		</el-col>        <!--新增界面-->		<el-dialog title="新增工厂" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>			<el-form :model="addForm" label-width="100px" :rules="formRules" ref="addForm" :inline="true" class="demo-form-inline">				<el-form-item label="工厂名称" prop="factoryName">					<el-input v-model="addForm.factoryName" autocomplete="off" placeholder="请输入工厂名称"></el-input>				</el-form-item>                <el-form-item label="工厂地址" prop="factoryArea">					<el-input v-model="addForm.factoryArea" autocomplete="off" :change="changeFactoryArea('addContainer')" placeholder="请输入工厂地址"></el-input>				</el-form-item>                <div id="addContainer" class="formMap" v-if="addForm.factoryArea != ''"></div>			</el-form>			<div slot="footer" class="dialog-footer">				<el-button @click.native="addFormVisible = false">取消</el-button>				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>			</div>		</el-dialog>		<!--编辑界面-->		<el-dialog title="编辑工厂" v-if="editFormVisible" :visible.sync="editFormVisible" :close-on-click-modal="false" customClass='customWidth'>			<el-form :model="editForm" label-width="100px" :rules="formRules" ref="editForm" :inline="true" class="demo-form-inline">				<el-form-item label="工厂名称" prop="factoryName">					<el-input v-model="editForm.factoryName" autocomplete="off" placeholder="请输入工厂名称"></el-input>				</el-form-item>                <el-form-item label="工厂地址" prop="factoryArea">					<el-input v-model="editForm.factoryArea" autocomplete="off" :change="changeFactoryArea('editContainer')" placeholder="请输入工厂地址"></el-input>				</el-form-item>                <div id="editContainer" class="formMap" v-if="editForm.factoryArea != ''"></div>			</el-form>			<div slot="footer" class="dialog-footer">				<el-button @click.native="editFormVisible = false">取消</el-button>				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>			</div>		</el-dialog>	</section></template><script>	import util from '../../common/js/util'	export default {		data() {			return {				filters: {                    keyName: ''                },				list: [],				total: 0,                page: 1,                size: 20,                listLoading: false,                tableHeight: 0,                                noSub: false,                formRules: {					factoryName: [						{ required: true, message: '请输入公司名称', trigger: 'blur' }                    ],                    factoryArea: [                        { required: true, message: '请输入公司地址', trigger: 'blur' }                    ]                },                // 新增界面				addFormVisible: false,				addLoading: false,				addForm: {                    factoryName: '',                    factoryArea: '',                    yLng: 0,                    xLat: 0,                    flag: 0				},                                // 编辑界面				editFormVisible: false,				editLoading: false,				editForm: {					id: 0,					factoryName: '',                    factoryArea: '',                    yLng: 0,                    xLat: 0,                    flag: 1				}			}		},		methods: {            //  分页			handleCurrentChange(val) {				this.page = val;				this.getFactory();            },            handleSizeChange(val) {                this.size = val;				this.getFactory();            },			//获取用户列表			getFactory() {				this.listLoading = true;                this.http.post(this.port.base.factoryList, {                    keyName: this.filters.keyName,                    pageNum: this.page,                    pageSize: this.size                }, res => {                    this.listLoading = false;                    if (res.code == "ok") {                        this.list = res.data.list;                        this.total = res.data.total;                    } else {                        this.$message({                            message: res.msg,                            type: 'error'                        });                    }                }, error => {                    this.listLoading = false;                    this.$message({                        message: error,                        type: 'error'                    });                })            },                        //地址输入切换            changeFactoryArea(mapId) {                if(mapId == "addContainer"){                    this.markLocation(this.addForm.factoryArea, mapId);                } else {                    this.markLocation(this.editForm.factoryArea, mapId);                }                            },            //显示新增界面			handleAdd() {                this.addFormVisible = true;                this.noSub = false;				this.addForm = {                    factoryName: '',                    factoryArea: '',                    yLng: 0,                    xLat: 0,                    flag: 0				};            },            //新增			addSubmit() {				this.$refs.addForm.validate((valid) => {					if (valid) {                        if(this.noSub){                            this.$message({                                message: '定位失败!',                                type: 'error'                            });                        } else {                            this.addLoading = true;                            this.http.post(this.port.base.addFactory, this.addForm , res => {                                this.addLoading = false;                                this.addFormVisible = false;                                if (res.code == "ok") {                                    this.$message({                                        message: '创建成功',                                        type: 'success'                                    });                                    this.getFactory();                                } else {                                    this.$message({                                        message: res.msg,                                        type: 'error'                                    });                                }                            }, error => {                                this.addLoading = false;                                this.addFormVisible = false;                                this.$message({                                    message: error,                                    type: 'error'                                });                            })                        }					}				});            },            			//删除			handleDel(index, row) {				this.$confirm('确认删除该工厂吗?', '提示', {					type: 'warning'				}).then(() => {                    this.http.post(this.port.base.delFactory, {                        id: row.id                    }, res => {                        if (res.code == "ok") {                            this.$message({                                message: '删除成功',                                type: 'success'                            });                            this.getFactory();                        } else {                            this.$message({                                message: res.msg,                                type: 'error'                            });                        }                    }, error => {                        this.$message({                            message: error,                            type: 'error'                        });                    })				});            },            			//显示编辑界面			handleEdit: function (index, row) {                this.editFormVisible = true;                this.noSub = false;                this.editForm = {                    id: row.id,                    factoryName: row.factoryName,                    factoryArea: row.factoryArea,                    yLng: row.yLng,                    xLat: row.xLat,                    flag: 1				};            },            			//编辑			editSubmit: function () {				this.$refs.editForm.validate((valid) => {					if (valid) {                        if(this.noSub){                            this.$message({                                message: '定位失败!',                                type: 'error'                            });                        } else {                            this.editLoading = true;                            this.http.post(this.port.base.addFactory, this.editForm , res => {                                this.editLoading = false;                                this.editFormVisible = false;                                if (res.code == "ok") {                                    this.$message({                                        message: '修改成功',                                        type: 'success'                                    });                                    this.getFactory();                                } else {                                    this.$message({                                        message: res.msg,                                        type: 'error'                                    });                                }                            }, error => {                                this.editLoading = false;                                this.editFormVisible = false;                                this.$message({                                    message: error,                                    type: 'error'                                });                            })                        }					}				});            },            // 获取经纬度            markLocation: function(address,mapId) {                var _this = this;                AMap.plugin('AMap.Geocoder', function() {                    var geocoder = new AMap.Geocoder();                                geocoder.getLocation(address, function(status, result) {                        if (status === 'complete' && result.info === 'OK') {                            // 经纬度                                                  var lng = result.geocodes[0].location.lng;                            var lat = result.geocodes[0].location.lat;                                                        _this.noSub = false;                            if(mapId == "addContainer") {                                _this.addForm.yLng = lng;                                _this.addForm.xLat = lat;                            } else {                                _this.editForm.yLng = lng;                                _this.editForm.xLat = lat;                            }                                    // 地图实例                            var map = new AMap.Map(mapId, {                                resizeEnable: true, // 允许缩放                                center: [lng, lat], // 设置地图的中心点                                zoom: 15        // 设置地图的缩放级别,0 - 20                            });                                                        // 添加标记                            var marker = new AMap.Marker({                                map: map,                                position: new AMap.LngLat(lng, lat),   // 经纬度                            });                                                    } else {                            _this.noSub = true;                            //console.log('定位失败!');                        }                    });                });            }        },        created() {            let height = window.innerHeight;            this.tableHeight = height - 210;            const that = this;            window.onresize = function temp() {                that.tableHeight = window.innerHeight - 210;                };        },		mounted() {			this.getFactory();        }	}</script><style scoped>    .formMap {        height: 400px;    }</style>
 |