xsh 3 år sedan
förälder
incheckning
c7f72831de
3 ändrade filer med 101 tillägg och 72 borttagningar
  1. 32 43
      src/components/HeaderElement.vue
  2. 23 0
      src/views/SystemAdmin/FarmAdmin.vue
  3. 46 29
      src/views/SystemAdmin/UserAdmin.vue

+ 32 - 43
src/components/HeaderElement.vue

@@ -9,14 +9,14 @@
       </el-col>
       <el-col :span="10" :offset="9" style="height: 100%">
         <div class="flex">
-<!--          <div class="user" style="width: 180px;">-->
-<!--            <div>-->
-<!--              <el-select @change="onChange" size="mini" v-model="farmId">-->
-<!--                <el-option v-for="item in farmList" :key="item.id" :label="item.farmName" :value="item.id"></el-option>-->
-<!--              </el-select>-->
-<!--            </div>-->
-<!--          </div>-->
-<!--          <el-divider direction="vertical"></el-divider>-->
+          <div class="user" style="width: 180px;">
+            <div>
+              <el-select @change="onChange" size="mini" v-model="farmId">
+                <el-option v-for="item in getFarmList" :key="item.id" :label="item.farmName" :value="item.id"></el-option>
+              </el-select>
+            </div>
+          </div>
+          <el-divider direction="vertical"></el-divider>
           <div class="user" style="width: 250px;">
             <div>
               <el-switch
@@ -96,7 +96,7 @@
 
 <script>
 import { mapState, mapActions } from 'vuex'
-import { findUpdate } from '../utils/api';
+import { findUpdate, getFarmId } from '../utils/api';
 import { Chrome } from 'vue-color';
 import { Debounce } from "../utils";
 
@@ -109,42 +109,24 @@ export default {
     // 'slider-picker': Slider,
     'chrome-picker': Chrome
   },
+  watch: {
+    farmList: {
+      handler(newVal) {
+        if(newVal.length > 0) {
+          this.getFarmList = []
+          newVal.forEach(item => {
+            if(item.rowStatus) {
+              this.getFarmList.push(item)
+            }
+          })
+        }
+      },
+      deep: true
+    }
+  },
   data() {
     return {
-      colorList: [
-        {
-          id: 1,
-          color: '#31C3A6'
-        },
-        {
-          id: 2,
-          color: '#3498DB'
-        },
-        {
-          id: 3,
-          color: '#ED6E4D'
-        },
-        {
-          id: 4,
-          color: '#FABB3D'
-        },
-        {
-          id: 5,
-          color: '#AA7AB3'
-        },
-        {
-          id: 6,
-          color: '#9AD0B9'
-        },
-        {
-          id: 7,
-          color: '#EA94BE'
-        },
-        {
-          id: 8,
-          color: '#C1374A'
-        },
-      ],
+      getFarmList: [],
     }
   },
   methods: {
@@ -178,6 +160,12 @@ export default {
     },
     // 拿到farmid
     init() {
+      getFarmId().then(res => {
+        if(res.code === 10000) {
+          this.setFarmIdAsync(res.data);
+          localStorage.setItem('lastFarmId', res.data);
+        }
+      })
     },
     // 选择牧场
     onChange(val) {
@@ -198,6 +186,7 @@ export default {
   mounted() {
     this.init();
     this.GetFarm()
+    console.log(this.farmId)
   }
 }
 </script>

+ 23 - 0
src/views/SystemAdmin/FarmAdmin.vue

@@ -1,6 +1,9 @@
 <template>
   <div style="box-sizing: border-box; padding: 20px;">
     <new-table :height="600" :title="title" :listData="farmList" :tableItems="tableItems" :shows="tableShows" @selectionChange="selectionChange">
+      <template #rowStatus="scope">
+        <el-switch v-model="scope.row.rowStatus"  @change="handleSwitch($event, scope.row)"></el-switch>
+      </template>
       <template #right>
         <el-button  size="mini" type="primary" v-if="hasPerm('farmAdmin:add')" style="margin-right: 10px" @click="addFarm">添加牧场</el-button>
         <el-button size="mini" type="danger" v-if="hasPerm('farmAdmin:del')" style="margin-right: 10px" @click="delAll">批量删除</el-button>
@@ -74,6 +77,12 @@ export default {
           slotName: 'frontLocation'
         },
         {
+          prop: 'rowStatus',
+          label: '是否启用',
+          minWidth: '100',
+          slotName: 'rowStatus'
+        },
+        {
           label: '操作',
           minWidth: '100',
           slotName: 'handler'
@@ -218,6 +227,20 @@ export default {
       }
       this.loc = ''
     },
+    handleSwitch(val, data) {
+      let params = {
+        id: data.id,
+        rowStatus: val
+      }
+      editFarm(params).then(res => {
+        this.reset();
+        if(res.code === 10000) {
+          this.$message.success(res.message)
+        } else {
+          this.$message.error(res.message);
+        }
+      })
+    },
     // 获取地址
     getlocation () {
       var loc = [];

+ 46 - 29
src/views/SystemAdmin/UserAdmin.vue

@@ -68,25 +68,32 @@
           </el-table-column>
           <el-table-column label="操作">
             <template slot-scope="scope">
-              <el-button type="primary" v-if="hasPerm('user:edit')" size="mini" style="margin-right: 10px;" @click="edit(scope.row)">编辑</el-button>
-              <el-dropdown>
-                <span class="el-dropdown-link">
-                  操作<i class="el-icon-arrow-down el-icon--right"></i>
-                </span>
-                <el-dropdown-menu slot="dropdown">
-                  <el-dropdown-item>
-                    <el-popconfirm
-                        title=" 确定要删除这个用户吗?"
-                        @confirm="del(scope.row)"
-                    >
-                      <el-button type="text" v-if="hasPerm('user:del')" size="mini" slot="reference">删除</el-button>
-                    </el-popconfirm>
-                  </el-dropdown-item>
-                  <el-dropdown-item>
-                    <el-button type="text" @click="handleFarm(scope.row)" size="mini" >分配牧场</el-button>
-                  </el-dropdown-item>
-                </el-dropdown-menu>
-              </el-dropdown>
+              <el-button type="primary" v-if="hasPerm('user:edit')" size="mini" @click="edit(scope.row)">编辑</el-button>
+              <el-button type="success" style="margin-right: 5px" @click="handleFarm(scope.row)" size="mini" >分配牧场</el-button>
+              <el-popconfirm
+                  title=" 确定要删除这个用户吗?"
+                  @confirm="del(scope.row)"
+              >
+                <el-button type="danger" v-if="hasPerm('user:del')" size="mini" slot="reference">删除</el-button>
+              </el-popconfirm>
+<!--              <el-dropdown>-->
+<!--                <span class="el-dropdown-link">-->
+<!--                  操作<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
+<!--                </span>-->
+<!--                <el-dropdown-menu slot="dropdown">-->
+<!--                  <el-dropdown-item>-->
+<!--                    <el-popconfirm-->
+<!--                        title=" 确定要删除这个用户吗?"-->
+<!--                        @confirm="del(scope.row)"-->
+<!--                    >-->
+<!--                      <el-button type="text" v-if="hasPerm('user:del')" size="mini" slot="reference">删除</el-button>-->
+<!--                    </el-popconfirm>-->
+<!--                  </el-dropdown-item>-->
+<!--                  <el-dropdown-item>-->
+<!--                    <el-button type="text" @click="handleFarm(scope.row)" size="mini" >分配牧场</el-button>-->
+<!--                  </el-dropdown-item>-->
+<!--                </el-dropdown-menu>-->
+<!--              </el-dropdown>-->
             </template>
           </el-table-column>
         </el-table>
@@ -148,7 +155,7 @@
         width="50%">
       <div>
         <el-table
-            :data="farmList"
+            :data="getFarmList"
             ref="multipleTable"
             tooltip-effect="dark"
             @selection-change="handleFarmChange">
@@ -177,7 +184,7 @@
 <script>
 import TableFooter from '../../components/TableFooter';
 import {getUserList, addUser, editUser, isUser, delUser,} from '../../utils/api';
-import { mapState } from 'vuex';
+import { mapState, mapActions } from 'vuex';
 export default {
   name: "UserAdmin",
   components: {
@@ -217,11 +224,28 @@ export default {
       // farmList: [],
       // 选中牧场的id
       selectFarm: '',
+      getFarmList: [],
     };
   },
   created() {
   },
+  watch: {
+    farmList: {
+      handler(newVal) {
+        if(newVal.length > 0) {
+          this.getFarmList = []
+          newVal.forEach(item => {
+            if(item.rowStatus) {
+              this.getFarmList.push(item)
+            }
+          })
+        }
+      },
+      deep: true
+    }
+  },
   methods: {
+    ...mapActions(['GetFarm']),
     // 搜索
     search() {
       this.init();
@@ -253,14 +277,6 @@ export default {
             }
           })
     },
-    // getFarm() {
-    //   getFarm().then(res => {
-    //     console.log(res)
-    //     if(res.code === 10000) {
-    //       this.farmList = res.data;
-    //     }
-    //   })
-    // },
     // 添加用户
     addUser() {
       this.dialogVisible = true;
@@ -477,6 +493,7 @@ export default {
   },
   mounted() {
     this.init();
+    this.GetFarm();
     // 获取牧场列表
     // this.getFarm();
   }