index.vue 14.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
<!--  -->
<template>
  <div class="userStyle">
    <!-- 搜索 -->
    <div class="formSearch">
      <el-form>
        <el-form-item>
          <el-button v-if="authState==2" type="success" @click="add">添加</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="authState==1" type="success" @click="goAuthPageUrl">去授权</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="tableBox">
      <el-table
        ref="multipleTable"
        :data="tableData"
        border
        :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column prop="kfId" label="客服id" />
        <el-table-column prop="name" label="客服名称" />
        <el-table-column width="100" label="客服头像">
          <template slot-scope="scope">
            <img
              style="width: 40px; height: 40px"
              :src="scope.row.headImg"
              alt=""
            >
          </template>
        </el-table-column>
        <el-table-column prop="url" label="客服链接" />
        <!-- <el-table-column prop="name" label="接待人数量" /> -->
        <el-table-column label="操作" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="btnList">
              <el-button type="text" @click="edit(scope.row)">编辑</el-button>
              <el-button type="text" @click="del(scope.row)">删除</el-button>
              <el-button type="text" @click="reception(scope.row)">接待人员管理</el-button>
            </div>
          </template>
        </el-table-column>
        <template slot="empty">
          <div>
            {{ authState==1?'暂未授权':'暂无数据' }}
          </div>
        </template>
      </el-table>
    </div>

    <!-- *************对话框开始************* -->
    <el-dialog
      :title="userState ? '新增客服' : '修改客服'"
      :visible.sync="addFormDialog"
      width="30%"
      center
      :close-on-click-modal="false"
    >
      <!-- 新增用户 -->
      <div>
        <el-form
          ref="ruleForm"
          :model="addForm"
          label-width="80px"
          :rules="userRules"
        >
          <el-form-item label="客服头像" prop="headImg">
            <!-- 上传图片 -->
            <div class="uploadWidth">
              <el-upload
                class="avatar-uploader"
                list-type="picture-card"
                :headers="headers"
                :action="uploadUrl"
                :show-file-list="false"
                :on-success="handlePictureCardPreview"
              >
                <img
                  v-if="headImg"
                  :src="headImg"
                  class="avatar"
                >
                <i v-else class="el-icon-plus avatar-uploader-icon" />
              </el-upload>
            </div>
          </el-form-item>
          <el-form-item label="客服名称" prop="name">
            <el-input v-model="addForm.name" placeholder="请输入客服名称" />
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addFormDialog = false">取 消</el-button>
        <el-button type="primary" @click="addForm_enter('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 接待人员管理 -->
    <el-drawer
      title="接待人员管理"
      :visible.sync="servicePage"
      direction="rtl"
      class="serviceBox"
      size="60%"
    >
      <div class="userStyle">
        <el-form :inline="true">
          <el-form-item label="客服名称:">
            {{ serviceItem.name }}
          </el-form-item>
          <br>
          <el-form-item label="客服头像:">
            <img
              style="width: 60px; height: 60px"
              :src="serviceItem.headImg"
              alt=""
            >
          </el-form-item>
        </el-form>
        <el-form :inline="true" :model="ReceptionistForm">
          <el-form-item>
            <el-button type="success" plain @click="addReception">添加</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 表格 -->
      <div class="userStyle">
        <el-table
          ref="multipleTable"
          :data="serverData"
          border
          tooltip-effect="dark"
          style="width: 100%"
        >
          <el-table-column prop="name" label="名称" />
          <el-table-column prop="state" label="接待状态">
            <template slot-scope="scope">
              <span v-if="scope.row.state == 0">接待中</span>
              <span v-if="scope.row.state == 1">空闲</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="btnList">
                <el-button type="text" @click="deleteReceptionist(scope.row)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-drawer>
    <!-- 接待人弹窗 -->
    <el-dialog
      title="添加接待人"
      :visible.sync="addServerShow"
      width="30%"
      center
      :close-on-click-modal="false"
    >
      <el-form :inline="true" :model="CustomerForm" class="demo-form-inline">
        <el-form-item class="inputWide" label="部门">
          <el-select
            v-model="CustomerName"
            placeholder="请选择"
            @change="selDepartment"
          >
            <el-option
              v-for="item in DepartmentList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <!-- 表格 -->
      <div class="tableBox">
        <el-table
          ref="multipleTable"
          :data="CustomerData"
          border
          :header-cell-style="{ background: '#EEF3FF', color: '#333333' }"
          tooltip-effect="dark"
          style="width: 100%"
          max-height="400"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column
            prop="name"
            label="接待人昵称"
            show-overflow-tooltip
          />
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addServerShow = false">取 消</el-button>
        <el-button type="primary" @click="addReceptionSubmit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import 《组件名称》 from '《组件路径》';
import {
  getAllList,
  delService,
  AddService,
  UpService,
  getAllReceptionist,
  getDepartmentList,
  getExternalUserList,
  saveReceptionist,
  deleteReceptionist,
  checkAuthState
} from '@/api/server';
import { QYuploadUrl } from '@/utils/request';
import { getToken } from '@/utils/auth';
export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      uploadUrl: QYuploadUrl,
      headers: {
        'Authorization-business': getToken()
      },
      formInline: {
        page: 1, // 当前页
        pageSize: 10, // 每页记录数
      },
      total: 1,
      tableData: [],
      userState: 1,
      addForm: {
        headImg: '',
        name: '',
      },
      addFormDialog: false,
      userRules: {
        name: [{ required: true, message: '请输入客服名称', trigger: 'blur' }],
        // headImg: [{ required: true, message: '请上传头像', trigger: 'blur' }],
      },
      servicePage: false,
      serviceItem: {},
      serverData: [],
      addServerShow: false,
      CustomerForm: {
        dates: [], // 成为客户时间数组
        lastTimes: [], // 上次消费时间
        phone: '', // 手机号
        page: 1, // 当前页
        pageSize: 10, // 每页数
        labelId: null,
      },
      CustomerData: [],
      DepartmentList: [],
      CustomerName: '',
      ReceptionistForm: {
        name: '',
        state: null,
        openKfId: '',
        userIdList: [],
      },
      headImg: '',
      authState: null,
      authPageUrl: ''
    };
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成(可以访问当前this实例)
  created() {},
  // 生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {
    this.getAll(this.formInline);
    this.getAuthState()
  },
  // 方法集合
  methods: {
    getAuthState() {
      checkAuthState().then(res => {
        console.log(res)
        // 授权状态 1-未授权 2-已授权 3-获取授权链接异常
        this.authState = res.data.state
        this.authPageUrl = res.data.authPageUrl
      })
    },
    goAuthPageUrl() {
      if (this.authPageUrl) {
        window.open(this.authPageUrl)
      }
    },
    // 上传
    handlePictureCardPreview(file) {
      this.headImg = file.data.url;
      this.addForm.headImg = file.data.mediaId;
    },
    // 分页管理
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.getAll(this.formInline);
    },
    handleCurrentChange(val) {
      this.formInline.page = val;
      this.getAll(this.formInline);
    },
    // 新增用户
    add() {
      if (this.tableData.length < 10) {
        this.userState = 1;
        this.addFormDialog = true;
        this.addForm = {
          name: '', //
          headImg: '', //
          openKfId: '',
        };
        this.headImg = ''
      } else {
        this.$message.warning('最多添加10个客服');
      }
    },
    // 编辑用户
    edit(row) {
      this.userState = 0;
      this.addFormDialog = true;
      const item = Object.assign({}, row)
      this.addForm = item;
      this.headImg = this.addForm.headImg
    },
    // 确认新增用户
    addForm_enter(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          if (this.userState === 1) {
            AddService(this.addForm).then((res) => {
              console.log(res);
              if (res.code === '') {
                this.$message({
                  message: '新增成功',
                  type: 'success',
                });
              }
              this.getAll(this.formInline);
              this.addFormDialog = false;
            });
          } else {
            UpService(this.addForm).then((res) => {
              console.log(res);
              if (res.code === '') {
                this.$message({
                  message: '修改成功',
                  type: 'success',
                });
              }
              this.getAll(this.formInline);
              this.addFormDialog = false;
            });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 删除用户
    async del(row) {
      this.$confirm('此操作将永久删除该客服, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          delService({ openKfId: row.openKfId }).then((res) => {
            if (res.code === '') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
            }
            this.getAll(this.formInline);
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          });
        });
    },
    // 初始化查询所有数据
    async getAll(formInline) {
      const res = await getAllList(formInline);
      this.tableData = res.data;
      // this.total = res.data.total
    },
    reception(row) {
      console.log(row, 123456789);
      this.serviceItem = row;
      this.ReceptionistForm.openKfId = row.openKfId;
      this.servicePage = true;
      this.getAllReceptionist();
    },
    // 获取客服下的接待人员
    getAllReceptionist() {
      getAllReceptionist(this.ReceptionistForm).then((res) => {
        this.serverData = res.data;
      });
    },
    clear() {
      this.ReceptionistForm.name = '';
      this.ReceptionistForm.state = null;
      this.getAllReceptionist();
    },
    // 添加接待人
    addReception() {
      this.addServerShow = true;
      this.getDepartmentList();
    },
    // 获取客户列表数据
    async getDepartmentList() {
      const res = await getDepartmentList();
      this.DepartmentList = res.data;
      const pid = this.DepartmentList[0].id;
      this.CustomerName = this.DepartmentList[0].name;
      this.getCustomerAll(pid);
    },
    selDepartment(e) {
      console.log(e);
      this.getCustomerAll(e);
    },
    getCustomerAll(pid) {
      getExternalUserList({ id: pid }).then((res) => {
        this.CustomerData = res.data;
      });
    },
    // 选中接待人员
    handleSelectionChange(val) {
      this.ReceptionistForm.userIdList = val.map((el) => {
        return el.userId;
      });
      console.log(this.ReceptionistForm.userIdList);
    },
    // 确认添加
    addReceptionSubmit() {
      saveReceptionist(this.ReceptionistForm).then((res) => {
        this.addServerShow = false;
        this.$message.success('添加成功');
        this.getAllReceptionist();
      });
    },
    // 删除接待员
    deleteReceptionist(row) {
      this.ReceptionistForm = row;
      this.$confirm('此操作将永久删除该接待员, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          deleteReceptionist(this.ReceptionistForm).then((res) => {
            if (res.code === '') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
            }
            this.getAllReceptionist();
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          });
        });
    },
  },
};
</script>
<style lang='scss' scoped>
.userStyle {
  padding: 20px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 140px;
  height: 140px;
  line-height: 140px;
  text-align: center;
}
.avatar {
  width: 100%;
  height: 100%;
  display: block;
}
</style>