From 088df43a09e89a36fa4d520dde0aa8d5a2cdc209 Mon Sep 17 00:00:00 2001
From: IvyXia123 <ivyHsia@126.com>
Date: Wed, 28 Aug 2019 10:31:22 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AE=A1=E7=90=86=E6=96=B0?=
 =?UTF-8?q?=E5=A2=9E=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/components/salesLevel/index.vue | 69 ++++++++++-------------------
 src/components/system/staff.vue     | 33 +++++++++++---
 src/service/api.js                  |  2 +-
 3 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/src/components/salesLevel/index.vue b/src/components/salesLevel/index.vue
index 16b498af..2f232b3d 100644
--- a/src/components/salesLevel/index.vue
+++ b/src/components/salesLevel/index.vue
@@ -31,7 +31,7 @@
         </div>
         <div class="" v-if="subcompanyList.length === 0" style="color: #000; font-size: 13px;text-align: center;padding-top: 20px;">暂无数据</div>
         <div style="text-align: right;padding-top: 30px; padding-right: 30px;">
-          <el-button type="primary" size="small" @click="changeRecord(1, 10)">变更记录</el-button>
+          <el-button type="primary" size="small" @click="staffCountClick('', 1, 10)">变更记录</el-button>
           <el-button type="primary" size="small" @click="newAdd">新增</el-button>
           <el-button type="primary" size="small" @click="preservation">保存</el-button>
         </div>
@@ -53,7 +53,7 @@
                 <td>{{ item.in_at }}</td>
                 <td>{{ item.base_salary }}</td>
                 <td>
-                  <router-link :to="{path:'/staff', query:{}}" target="_blank">
+                  <router-link :to="{name: 'staff', params:{ model: item.mobile }}">
                     <el-button size="mini" type="primary">修改</el-button>
                   </router-link>
                 </td>
@@ -70,16 +70,16 @@
             </tr>
           </tbody>
           </table>
+        <div style="padding-top: 20px;">
+          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
+                         :page-sizes="[5, 10, 20, 30, 40, 50, 60, 80, 100]"
+                         :page-size="limit"
+                         :current-page.sync="pageIndex"
+                         layout="total, sizes, prev, pager, next, jumper"
+                         :total="total" style="text-align: center;">
+          </el-pagination>
+        </div>
 
-        <!--<page v-if="staffContent.length != 0" :total="total" :limit="limit" @pageChange="onPageChange" @sizeChange="onSizeChange"/>-->
-
-        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
-          :page-sizes="[5, 10, 20, 30, 40, 50, 60, 80, 100]"
-          :page-size="limit"
-          :current-page.sync="pageIndex"
-          layout="total, sizes, prev, pager, next, jumper"
-          :total="total" style="text-align: center;">
-        </el-pagination>
       </el-dialog>
     </el-card>
   </div>
@@ -157,10 +157,11 @@
         // 获取新增的数据
         let subcompanyListArr = this.subcompanyList.slice(-this.saleLevelNum);
         if(JSON.stringify(subcompanyListArr).indexOf('""') !== -1){
-          this.$message({ message: '保存数据不能为空', type: 'warning' });
+          this.$message({ message: '没有新增的信息', type: 'warning' });
         }else {
           addConfigApi({ params: JSON.stringify(subcompanyListArr) }).then((res) => {
             this.getLevelListFn()
+            this.$message({ message: '数据保存成功', type: 'warning' });
           });
         }
       },
@@ -195,7 +196,7 @@
         }
       },
       /**
-       * 级别渲染
+       * 级别渲染 + 变更记录
        * @param id   {String}
        * @param page {Number}
        * @param limit {Number}
@@ -204,55 +205,33 @@
         this.staffId = id;  // 获取id
         this.infoLoadingDialog = true
         this.pageIndex = page
-        getStaffApi(id, { page: page, limit: limit }).then(res => {
-          if(res.list.length > 0) {
-            this.staffTitle   = STAFF;
+        this.limit     = limit
+        let api = id ? getStaffApi : getRecordApi
+        api({ page: page, limit: limit }, id).then(res => {
+          let listDdata = id ? res.list : res.page_data
+          if(listDdata.length > 0) {
+            this.staffTitle   = id ? STAFF : recordList;
             this.total        = res.total;
-            this.staffContent = res.list;
+            this.staffContent = listDdata;
             this.salesLevelDialog = true
           }else {
             this.$message({ message: '暂无数据', type: 'warning' });
           }
-          this.infoLoadingDialog  = false
+          this.infoLoadingDialog = false
         })
       },
-      /**
-       * 变更记录
-       * @param page  {Number}
-       * @param limit {Number}
-       */
-      changeRecord(page, limit) {
-        this.pageIndex = page
-        this.infoLoadingDialog = true
-        this.staffId = ''; // id 变为空
-        getRecordApi({ page: page, limit: limit }).then(res => {
-          this.infoLoadingDialog  = false
-          this.staffTitle   = recordList;
-          this.total        = res.total;
-          this.staffContent = res.page_data;
-          this.salesLevelDialog = true
-        });
-      },
       /**
        * 分页
        * @param val
        */
       handleCurrentChange(val) {
         this.pageIndex = val
-        if(this.staffId) {
-          this.staffCountClick(this.staffId , val, this.limit)
-        }else {
-          this.changeRecord(val, this.limit)
-        }
+        this.staffCountClick(this.staffId , val, this.limit)
       },
       handleSizeChange(val) {
         this.pageIndex = 1
         this.limit = val
-        if(this.staffId) {
-          this.staffCountClick(this.staffId , 1, val)
-        }else {
-          this.changeRecord(val, this.limit)
-        }
+        this.staffCountClick(this.staffId , 1, val)
       }
     },
     mounted() {
diff --git a/src/components/system/staff.vue b/src/components/system/staff.vue
index b2c7d8f1..840b0957 100644
--- a/src/components/system/staff.vue
+++ b/src/components/system/staff.vue
@@ -114,7 +114,16 @@
             v-model="dialog.form.over_at" type="date" value-format="yyyy-MM-dd" :clearable="true" placeholder="选择日期">
           </el-date-picker>
         </el-form-item>
-
+        <el-form-item label="级别名称:" prop="sale_level_id">
+          <el-select v-model="dialog.form.sale_level_id" placeholder="请选择">
+            <el-option
+              v-for="item in levelNameArr"
+              :key="item.id"
+              :label="item.level_name"
+              :value="item.id">
+            </el-option>
+          </el-select>
+        </el-form-item>
       </el-form>
 
       <span slot="footer" class="dialog-footer">
@@ -126,7 +135,7 @@
 </template>
 
 <script>
-  import {getStaffListApi, postStaffListApi, putStaffListApi} from "../../service/api";
+  import {getStaffListApi, postStaffListApi, putStaffListApi, getLevelListApi} from "../../service/api";
   import page from '../framework/page'
   import {STAFF_TYPE} from '@/util/wordbook'
 
@@ -142,10 +151,11 @@
           type: '',
           status: '',
           start_in: '',
-          over_in: ''
+          over_in: '',
         },
         startTime: [],
         tableData: [],
+        levelNameArr: [],
         dialog: {
           title: '',
           show: false,
@@ -157,12 +167,14 @@
             type: '',
             in_at: '',
             over_at: '',
+            sale_level_id: '',
             rules: {
               name: [{required: true, message: '请输入', trigger: 'blur'}],
               mobile: [{required: true, message: '请输入', trigger: 'blur'}],
               id_card: [{required: true, message: '请输入', trigger: 'blur'}],
               type: [{required: true, message: '请选择', trigger: 'change'}],
               in_at: [{required: true, message: '请选择', trigger: 'change'}],
+              sale_level_id: [{required: true, message: '请选择', trigger: 'change'}],
             },
           }
         },
@@ -192,6 +204,7 @@
     },
     components: { page },
     mounted() {
+      console.log(this.dialog);
       this.getData()
     },
     methods: {
@@ -225,7 +238,8 @@
               mobile: this.dialog.form.mobile,
               id_card: this.dialog.form.id_card,
               type: this.dialog.form.type,
-              in_at: this.dialog.form.in_at
+              in_at: this.dialog.form.in_at,
+              sale_level_id: this.dialog.form.sale_level_id
             };
             if (this.dialog.form.id) { // 编辑
               json.id = this.dialog.form.id;
@@ -267,11 +281,19 @@
         this.searchFrom.id_card?json.id_card = this.searchFrom.id_card:'';
         this.searchFrom.type?json.type = this.searchFrom.type:'';
         this.searchFrom.status?json.status = this.searchFrom.status:'';
-
+        if(this.$route.params.model) {
+          json = Object.assign({}, json, { mobile: this.$route.params.model })
+          this.searchFrom.mobile = this.$route.params.model
+        }
         getStaffListApi(json).then(res => {
           this.tableData = res.list;
           this.total = res.total
+          this.$route.query.model = ''
         });
+        let data = { page: 1, limit: 100 }
+        getLevelListApi(data).then(res => {
+          this.levelNameArr = res.list
+        })
       },
 
       onAdd() {
@@ -293,6 +315,7 @@
           this.dialog.form.id_card = item.id_card;
           this.dialog.form.type = item.type;
           this.dialog.form.in_at = item.in_at;
+          this.dialog.form.sale_level_id = item.sale_level_id
           if (item.status == 1) { // 离职
             this.dialog.form.over_at = item.over_at;
           } else {
diff --git a/src/service/api.js b/src/service/api.js
index c20f90a0..6a8468ad 100644
--- a/src/service/api.js
+++ b/src/service/api.js
@@ -162,7 +162,7 @@ export const getLevelListApi = function (json) {
 };
 
 //所属级别员工列表
-export const getStaffApi = function (data, json) {
+export const getStaffApi = function (json, data) {
   return Vue.prototype.$fetch(`${_baseUrl}api/admin/sale/level/staff/${data}`, json)
 };
 
-- 
2.21.0