| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <style>
- .el-table th>.cell {
- color: #333;
- font-weight: bold;
- font-size: 14px;
- }
- .table1 .el-table__footer-wrapper,
- .table1 .el-table__header-wrapper {
- border-bottom: 1.4px solid #D6D6D6;
- }
- .user_img{
- position: relative;
- margin-right: 8px;
- /* height: 50px;
- width: 50px; */
- }
- .default-avatar{
- width: 50px;
- height: 50px;
- border-radius: 50%;
- margin-right: 8px;
- }
- .uer-nickname {
- flex: 1;
- }
- </style>
- <div id="app">
- <div class="table-body" style="min-width: 1000px;">
- <div slot="header" class="clearfix" style="height: 20px;">
- <span>大区管理</span>
- <el-button style="float: right; padding: 3px 12px;margin-left: 20px;height: 32px;" type="primary" @click="onCreate">添加大区</el-button>
- </div>
- <div slot="header" class="clearfix" style="margin-top: 20px;">
- <div class="demo-input-suffix" style="margin-top: 20px;margin-bottom: 10px;">
- <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="请输入大区名称/ID" v-model="search.keyword" clearable></el-input>
- <el-input size="small" style="width:300px;margin-right: 20px;" placeholder="输入管辖区域名称" v-model="search.address" clearable></el-input>
- <el-button type="primary" size="small" @click="toSearch">搜索</el-button>
- </div>
- </div>
- <template>
- <el-table :data="list" stripe style="width: 100%" v-loading="listLoading" class="table1">
- <el-table-column prop="id" label="ID" align="center" width="160"></el-table-column>
- <el-table-column label="大区名称" prop="regional_name" width="200"></el-table-column>
- <el-table-column label="管辖区域" prop="area" align="left">
- <template slot-scope="scope">
- {{scope.row.area}}
- </template>
- </el-table-column>
- <el-table-column label="启用" align="center" width="80">
- <template slot-scope="scope">
- <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0"
- @change="onChangeStatus(scope.row)"></el-switch>
- </template>
- </el-table-column>
- <el-table-column label="添加时间" width="180" align="center">
- <template slot-scope="scope">
- {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
- </template>
- </el-table-column>
- <el-table-column label="操作" width="120" align="center">
- <template slot-scope="scope">
- <el-button @click="onEditRow(scope.row, scope.$index)" type="text" size="mini">编辑</el-button>
- <el-popconfirm @confirm="onDelete(scope.row, scope.$index)" title="您真的要删除当前大区吗?">
- <el-button type="text" slot="reference" style="color: #F56C6C">删除</el-button>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- <div flex="main:right cross:center" style="margin-top: 20px;">
- <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize"
- style="display: inline-block;float: right;" background @current-change="pageChange"
- layout="prev, pager, next" :total="pagination.totalCount">
- </el-pagination>
- </div>
- </template>
- <el-dialog :visible.sync="createDialogShow" width="600px" title="添加/修改大区" center>
- <div v-loading="loading">
- <el-form ref="form" :model="form" size="small" label-width="120px">
- <el-form-item label="大区名称" prop="regional_name" :rules="[{required: true, message: '大区名称不能为空'}]">
- <el-input v-model="form.regional_name" placeholder="请输入大区名称" clearable></el-input>
- </el-form-item>
- <el-form-item label="添加省份" prop="province_ids" :rules="[{required: true, message: '所辖省份不能为空'}]">
- <el-select v-model="selectDistrict" multiple placeholder="请选择大区所辖省份" filterable clearable style="width: 100%;" @change="handleChangeProvice">
- <el-option v-for="item in district" :key="item.id" :label="item.name" :value="item.id" :disabled="existProvinces.indexOf(item.id) != -1"></el-option>
- </el-select>
- </el-form-item>
- </el-form>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button @click="onCancel" type="default" size="small">取消</el-button>
- <el-button type="primary" :loading="btnLoading" style="margin-bottom: 10px;" size="small"
- @click="onSubmit">保存</el-button>
- </span>
- </el-dialog>
- </div>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- btnLoading: false,
- createDialogShow: false,
- listLoading: false,
- list: [],
- pagination: {
- total: 0
- },
- loading: false,
- LoadDataType: -1, //默认显示全部数据
- dialogFormVisible: false, //默认不显示弹窗
- dialogLoading:false,
- level_map:null,
- selectDistrict: [],
- search: {
- page: 1,
- limit:10,
- keyword: '',
- address: '',
- },
- levelList:[
- ],
- show: false,
- level: {
- show: false,
- area: null,
- },
- current_area:null,
- form: {
- id: 0,
- regional_name: '',
- province_ids: '',
- area: ''
- },
- district: [],
- existProvinces: [],
- address: null,
- props: {
- value: 'id',
- label: 'name',
- children: 'list',
- },
- mapDialogShow: false
- }
- },
- methods: {
- //状态按钮的点击事件
- toSearch() {
- this.search.page = 1;
- this.loadData();
- },
- toSearchActivity() {
- this.loadData()
- },
- update(row) {
- this.$confirm('删除该区域代理, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.loading = true;
- request({
- params: {
- r: 'area/default/delete',
- },
- method: 'post',
- data: {
- id: row.id,
- }
- }).then(e => {
- let res = e.data;
- this.listLoading = false;
- if (res.code === 0) {
- this.$message.success(res.msg);
- this.loadData();
- } else {
- this.$message.error(res.msg);
- }
- }).catch(e => {});
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '系统错误'
- });
- });
- },
- pageChange(page) {
- this.search.page = page;
- this.loadData();
- },
- loadData() {
- this.listLoading = true;
- let params = {
- r: 'area/regional/index'
- };
- params = Object.assign(params, this.search);
- request({
- params: params,
- method: 'get',
- }).then(e => {
- let res = e.data;
- this.listLoading = false;
- if (res.code === 0) {
- this.list = res.data.list;
- this.level_map = res.data.level_map;
- this.pagination = res.data.pagination; //拿到关于页码页容量的数据
- } else {
- this.$message.error(res.msg);
- }
- }).catch(e => {});
- },
- onCancel() {
- this.createDialogShow = false
- },
- onCreate() {
- this.form = {
- id: 0,
- regional_name: '',
- province_ids: '',
- area: ''
- }
- this.selectDistrict = []
- this.createDialogShow = true
- this.getExist();
- this.getDistrict();
- },
- addressChange(e) {
- },
- // 获取省市区列表
- getDistrict() {
- request({
- params: {
- r: 'area/default/district',
- level: 1
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.district = e.data.data.district;
- }
- }).catch(e => { });
- },
- getExist() {
- request({
- params: {
- r: 'area/regional/exist'
- },
- }).then(e => {
- if (e.data.code == 0) {
- if (this.selectDistrict.length > 0) {
- this.existProvinces = e.data.data.filter(item => !this.selectDistrict.includes(item));
- }else {
- this.existProvinces = e.data.data;
- }
- }
- }).catch(e => { });
- },
- onSubmit() {
- this.$refs['form'].validate((valid) => {
- if (valid) {
- this.loading = true
- request({
- method: 'post',
- params: {
- r: 'area/regional/save',
- },
- data: this.form
- }).then(e => {
- this.loading = false;
- if (e.data.code === 0) {
- this.createDialogShow = false
- this.search.page = 1;
- this.loadData()
- this.$message.success(e.data.msg);
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- this.loading = false;
- });
- } else {
- console.log(valid)
- }
- })
- },
- onDelete(item, index) {
- request({
- method: 'post',
- params: {
- r: 'area/regional/delete',
- },
- data: {id: item.id}
- }).then(e => {
- this.loading = false;
- if (e.data.code === 0) {
- this.$message.success(e.data.msg);
- this.list.splice(index, 1)
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- },
- onChangeStatus(item) {
- request({
- method: 'post',
- params: {
- r: 'area/regional/status',
- },
- data: {id: item.id, status: item.status}
- }).then(e => {
- this.loading = false;
- if (e.data.code === 0) {
- this.$message.success(e.data.msg);
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- },
- onEditRow(item, index) {
- this.onCreate()
- this.form = JSON.parse(JSON.stringify(item))
- this.selectDistrict = (item.province_ids + '').split(',').map(Number)
- console.log(this.selectDistrict)
- },
- handleChangeProvice(e) {
- let provinceSelected = [];
- let areaSelected = [];
- for(let i=0; i<e.length; i++){
- this.district.find(item => { //这里的options就是数据源
- if(item.id == e[i]){
- provinceSelected.push(item.id)
- areaSelected.push(item.name)
- }
- })
- }
- this.form.province_ids = provinceSelected.join(',')
- this.form.area = areaSelected.join(',');
- }
- },
- // 加载的时候获取到列表页
- mounted() {
- // 数据初始化
- this.LoadDataType = -1;
- this.loadData();
- }
- })
- </script>
|