dispatch-task.vue 22.6 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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
<!-- 派件作业管理 -->
<template>
  <div
    class="dashboard-container dispatch-task customer-list-box"
    style="width: 100%"
  >
    <div class="app-container">
      <el-card
        class="search-card-box"
        shadow="never"
      >
        <el-form
          ref="operationalSearchFormData"
          :model="operationalSearchFormData"
          label-width="80px"
        >
          <div class="filter-container">
            <el-row :gutter="60">
              <el-col :span="8">
                <el-form-item
                  label="派件任务编号:"
                  style="margin-bottom: 0px"
                  label-width="110px"
                >
                  <el-input
                    v-model="operationalSearchFormData.id"
                    placeholder="请输入派件任务编号"
                    clearable
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="订单编号:"
                  style="margin-bottom: 0px"
                  label-width="110px"
                >
                  <el-input
                    v-model="operationalSearchFormData.orderId"
                    placeholder="请输入订单编号"
                    clearable
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="所属营业部:"
                  style="margin-bottom: 20px"
                  label-width="110px"
                >
                  <treeselect
                    v-model="operationalSearchFormData.agencyId"
                    :options="agencyOptions"
                    :normalizer="normalizer"
                    :searchable="true"
                    style="width: 100%"
                    placeholder="请选择所属营业部"
                    no-options-text="暂无数据"
                    no-results-text="暂无数据"
                    @select="selectAgency"
                    @open="open"
                    @close="close"
                  />
                  <img
                    ref="arrow"
                    src="../../../assets/pullDown.png"
                    style="position:absolute;width:18px;height:18px;right:9px;top:12px;cursor:pointer;pointer-events:none;transition-duration:0.3s"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="签收状态:"
                  style="margin-bottom: 15px"
                  label-width="110px"
                >
                  <el-select
                    v-model="operationalSearchFormData.signStatus"
                    clearable
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in signStatus"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="预计完成时间:"
                  style="margin-bottom: 20px"
                  label-width="110px"
                >
                  <el-date-picker
                    v-model="estimatedTime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetimerange"
                    placeholder="选择预计完成时间"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    @change="handleEstimatedTimeChange"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="实际完成时间:"
                  style="margin-bottom: 20px"
                  label-width="110px"
                >
                  <el-date-picker
                    v-model="actualTime"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetimerange"
                    placeholder="选择预计完成时间"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    @change="handleActualTimeChange"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="任务分配状态:"
                  style="margin-bottom: 20px"
                  label-width="110px"
                >
                  <el-select
                    v-model="operationalSearchFormData.assignedStatus"
                    clearable
                    placeholder="请选择任务分配状态"
                  >
                    <el-option
                      v-for="item in operationOptions"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-button
                  type="warning"
                  @click="handleFilter('查询')"
                >搜索</el-button>
                <el-button
                  class="reset-btn"
                  plain
                  @click="resetForm('operationalSearchFormData')"
                >重置</el-button>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </el-card>
      <TabChange
        :default-active-index="0"
        :is-show-num="false"
        :setting-list="[
          {
            key: 'all',
            value: 0,
            label: '全部',
            num: allNum
          },
          {
            key: 'able',
            value: 1,
            label: '新任务',
            num: newNum
          },
          {
            key: 'unable',
            value: 2,
            label: '已完成',
            num: doneNum
          }
        ]"
        @tabChange="tabChange"
      ></TabChange>
      <div
        v-loading="listLoading"
        :class="{ 'loading-box': listLoading }"
        element-loading-text="加载中"
        style="margin-top: 20px"
      >
        <el-card
          class="table-card-box"
          shadow="never"
        >
          <el-button
            class="customer-add-btn"
            @click="handleAddCourier(multipleSelection)"
          >人工分配</el-button>
          <el-table
            :key="tableKey"
            ref="multipleTable"
            :data="dataList"
            fit
            style="width: 100%"
            stripe
            :header-cell-style="{ background: 'rgba(250,252,255,1)',}"
            :header-cell-class-name="isTableDisabled?'disabled':'able'"
            @selection-change="handleSelectionChange"
          >
            <div
              v-show="(!dataList || dataList.length <= 0) && !listLoading && !searchkey"
              slot="empty"
            >
              <img
                src="@/icons/pic-kong.png"
                alt="img"
                style="margin-top: 20px;width: 25%;height: 25%;"
              >
              <p
                style="
                margin-top: -20px;
                padding-bottom: 0px;
                "
              >这里空空如也</p>

            </div>
            <el-card
              v-show="(!dataList || dataList.length <= 0) && !listLoading && searchkey"
              slot="empty"
              class="table-empty-box"
              shadow="never"
            >
              <empty></empty>
            </el-card>
            <el-table-column
              align="left"
              type="selection"
              width="60"
              fixed
              :selectable="selectEnable"
            />
            <el-table-column
              align="left"
              type="index"
              label="序号"
              width="80"
            >
              <template slot-scope="scope">
                <span>{{
                  scope.$index +
                    (operationalSearchFormData.page - 1) *
                    operationalSearchFormData.pageSize +
                    1
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="派件作业编号"
              min-width="160px"
              prop="id"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="订单编号"
              min-width="180"
              prop="orderId"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="所在营业部"
              min-width="180"
              prop="agencyName"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="任务分配状态"
              min-width="120"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.assignedStatus == 1">未分配</span>
                <span
                  v-else-if="scope.row.assignedStatus == 2"
                  class="tableColumn-status normal"
                >已分配</span>
                <span
                  v-else
                  class="tableColumn-status stop-use"
                >待人工分配</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="快递员姓名"
              min-width="120"
              prop="courierName"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="签收状态"
              min-width="80px"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.signStatus === 1">已签收</span>
                <span v-else-if="!scope.row.signStatus">未签收</span>
                <span v-else>拒收</span>
              </template>
            </el-table-column>

            <el-table-column
              align="left"
              label="签收人"
              min-width="100"
              prop="signRecipient"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.signRecipient === 1">本人</span>
                <span v-else>代收</span>
              </template>
            </el-table-column>

            <el-table-column
              align="left"
              label="预计开始时间"
              min-width="160"
              prop="estimatedStartTime"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="预计完成时间"
              min-width="160"
              prop="estimatedEndTime"
            >
            </el-table-column>
            <el-table-column
              v-if="![1,3].includes(operationalSearchFormData.status)"
              align="left"
              label="实际完成时间"
              min-width="160"
              prop="actualEndTime"
            >
            </el-table-column>
          </el-table>
          <!-- end -->
          <!-- 分页 -->
          <div
            class="pagination"
            style="margin-bottom:30px!important"
          >
            <div class="pages">
              <el-pagination
                :current-page="Number(operationalSearchFormData.page)"
                :total="Number(total)"
                :page-size="Number(operationalSearchFormData.pageSize)"
                :page-sizes="[10, 20, 30, 50]"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
          <!-- end -->
          <el-dialog
            class="add-form-dialog"
            :title="titleInfo.text"
            :visible.sync="dialogFormVisible"
            width="600px"
          >
            <el-form
              ref="dataForm"
            >
              <el-form-item
                label="选择快递员:"
                prop="courierName"
                :label-width="formLabelWidth"
              >
                <el-select
                  v-model="courierId"
                  value-key="item.userId"
                  placeholder="请选择"
                  clearable
                  filterable
                  @change="handleChange"
                >
                  <el-option
                    v-for="item in courierOptions"
                    :key="item.userId"
                    :label="item.name"
                    :value="item.userId"
                  />
                </el-select>
              </el-form-item>
            </el-form>
            <div
              slot="footer"
              class="dialog-footer"
              style="text-align: center"
            >
              <el-button
                type="primary"
                class="save-btn"
                @click="createData"
              >确定</el-button>
              <el-button
                class="cancel-btn"
                @click="cancelDisFn"
              >取消</el-button>
            </div>
          </el-dialog>
        </el-card>
      </div>
    </div>

  </div>
</template>

<script>
import { pickupTaskList, courierList, dispatchTaskForCourier } from '@/api/branch'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
import TabChange from '@/components/TabChange'
import { agencyList } from '@/api/institutions'
import { getNotNullParams } from '@/utils/index'
export default {
  components: {
    Treeselect,
    TabChange
  },
  data() {
    return {
      // 表头全选是否禁用
      isTableDisabled: false,
      allNum: 0,
      newNum: 0,
      doneNum: 0,
      courierId: '',
      formLabelWidth: '100px',
      multipleSelection: [],
      tableKey: 0,
      dataList: [],
      total: null,
      searchkey: false,
      provinceList: [],
      tableChecked: [],
      courierOptions: [],
      operationOptions: [{
        id: 2,
        name: '已分配'
      },
      {
        id: 3,
        name: '待人工分配'
      }],
      signStatus: [
        {
          id: 1,
          name: '已签收'
        },
        {
          id: 2,
          name: '拒收'
        }
      ],
      listLoading: true,
      alertText: '',
      dialogFormVisible: false,
      operationalSearchFormData: {
        page: 1,
        pageSize: 10,
        taskType: 2,
        status: 0,
        id: '',
        orderId: '',
        agencyId: '',
        minEstimatedEndTime: '',
        maxEstimatedEndTime: '',
        minActualEndTime: '',
        maxActualEndTime: '',
        assignedStatus: '',
        signStatus: ''
      },
      actualTime: [],
      estimatedTime: [],
      courierParams: {
        page: 1,
        pageSize: 1000,
        agentId: ''
      },
      titleInfo: {
        pageTitle: '',
        text: ''
      },
      selectedAgencyList: [],
      agencyOptions: [],
      normalizer(node) {
        return {
          id: node.id,
          label: node.name,
          children: node.children
        }
      }
    }
  },

  // 挂载结束
  mounted: function () {},
  // 创建完毕状态
  created() {
    this.getAgencyList()
    this.initialDate()
    // 键盘enter操作
    document.onkeydown = function (e) {
      var key = window.event.keyCode
      if (key === 13) {
        this.handleFilter(this.operationalSearchFormData)
      }
    }
  },
  // 组件更新
  updated: function () {},
  methods: {
    selectEnable(row) {
      if (row.assignedStatus === 2) {
        return false
      } else {
        return true
      }
    },
    // 获取起始/目的地机构列表数据
    async getAgencyList() {
      const { data: res } = await agencyList()
      // 获取数据给options
      this.agencyOptions = JSON.parse(res)
      // // // 递归处理树形数据结构并且修改可修改每一项的属性
      // const mapTree = (org) => {
      //   const haveChildren = Array.isArray(org.children) && org.children.length > 0

      //   return {
      //     ...org,
      //     isDisabled: org.name === '昌平沙河镇营业部',
      //     children: haveChildren ? org.children.map(child => mapTree(child)) : null
      //   }
      // }
      // this.agencyOptions = JSON.parse(res).map(org => mapTree(org))
    },
    tabChange(val) {
      this.operationalSearchFormData.status = val
      this.getList()
    },
    selectAgency(val) {
      this.operationalSearchFormData.agencyId = val.id
    },
    handleActualTimeChange(val) {
      this.actualTime = val
      this.operationalSearchFormData.minActualEndTime = val[0]
      this.operationalSearchFormData.maxActualEndTime = val[1]
    },
    handleEstimatedTimeChange(val) {
      this.estimatedTime = val
      this.operationalSearchFormData.minEstimatedEndTime = val[0]
      this.operationalSearchFormData.maxEstimatedEndTime = val[1]
    },
    // 获取快递员列表数据
    async getLineList() {
      const { data: res } = await courierList(this.courierParams)
      // 获取数据给options
      this.courierOptions = res.items
    },
    opens() {
      this.$refs.arrows.style.transform = 'rotate(-180deg)'
    },
    closes() {
      this.$refs.arrows.style.transform = 'rotate(0deg)'
    },
    open() {
      this.$refs.arrow.style.transform = 'rotate(-180deg)'
    },
    close() {
      this.$refs.arrow.style.transform = 'rotate(0deg)'
    },
    cancelDisFn() {
      this.$refs['dataForm'].resetFields()
      this.dialogFormVisible = false
    },
    // 初始数据
    initialDate() {
      // 读取数据
      this.getList()
    },

    handleSelectionChange(val) {
      this.multipleSelection = val.map((item) => item.id)
      this.selectedAgencyList = Array.from(new Set(val.map(item => item.agencyId)))
      if (!this.courierParams.agentId) {
        this.getLineList()
      }
      this.courierParams.agentId = this.selectedAgencyList[0]
    },
    // 获取列表数据
    async getList() {
      this.listLoading = true
      const params = getNotNullParams(this.operationalSearchFormData)
      // eslint-disable-next-line no-undef
      const { data: res } = await pickupTaskList(params)
      this.listLoading = false
      // 获取数据给dataList
      this.dataList = res.items
      // 当页全禁用时表头多选也禁用
      this.isTableDisabled = this.dataList.every(item => item.assignedStatus === 2)
      // 获取总条数
      this.total = res.counts
    },
    // 重置
    resetForm() {
      this.$refs['operationalSearchFormData'].resetFields()
      this.operationalSearchFormData.page = 1
      this.operationalSearchFormData.pageSize = 10
      this.operationalSearchFormData.taskType = 2
      this.operationalSearchFormData.id = ''
      this.operationalSearchFormData.orderId = ''
      this.operationalSearchFormData.agencyId = ''
      this.operationalSearchFormData.minEstimatedEndTime = ''
      this.searchkey = false
      this.operationalSearchFormData.maxEstimatedEndTime = ''
      this.operationalSearchFormData.minActualEndTime = ''
      this.operationalSearchFormData.maxActualEndTime = ''
      this.operationalSearchFormData.assignedStatus = ''
      this.operationalSearchFormData.signStatus = ''
      this.actualTime = []
      this.estimatedTime = []
      this.getList()
    },
    // 搜索信息
    handleFilter(opt) {
      // this.operationalSearchFormData = {
      //   ...this.operationalSearchFormData,
      //   page: opt === '查询' ? 1 : this.operationalSearchFormData.page
      // }
      this.operationalSearchFormData.page = 1
      const params = getNotNullParams(this.operationalSearchFormData)
      this.getList(params)
      this.searchkey = true
    },
    // 每页显示信息条数
    handleSizeChange(val) {
      this.operationalSearchFormData.pageSize = val
      if (this.operationalSearchFormData.page === 1) {
        this.getList(this.operationalSearchFormData)
      }
    },
    // 进入某一页
    handleCurrentChange(val) {
      this.operationalSearchFormData.page = val
      this.getList()
    },
    // 快递员下拉选择
    handleChange(val) {
      this.courierId = val
    },
    // 分配快递员
    handleAddCourier() {
      const length = this.multipleSelection.length
      if (length === 0) {
        this.$message({
          message: '选择要分配的作业!',
          type: 'error'
        })
        return
      }
      if (this.selectedAgencyList.length > 1) {
        this.$message({
          message: '请选择一个营业部下面的派件作业!',
          type: 'error'
        })
        return
      }
      this.dialogFormVisible = true
      this.titleInfo.text = '人工分配'
    },
    // 弹层隐藏
    dialogFormH() {
      this.dialogFormVisible = false
    },
    // 表单提交
    async createData() {
      if (!this.courierId) {
        return this.$message.error('请选择快递员')
      }
      this.dialogFormH()
      await dispatchTaskForCourier(
        {
          ids: this.multipleSelection,
          courierId: this.courierId
        }
      ).then((res) => {
        if (String(res.code) === '200') {
          this.$message.success('人工分配成功')
          this.getList(this.operationalSearchFormData)
          this.courierId = ''
          this.multipleSelection = []
          this.selectedAgencyList = []
        }
        this.$refs.multipleTable.clearSelection()
      }).catch((err) => {
        this.courierId = ''
        this.multipleSelection = []
        this.selectedAgencyList = []
        this.$refs.multipleTable.clearSelection()
        this.$message.error(err.msg || '人工分配失败')
      })
    },
    // 查看运单详情
    handleWayllDetail(id) {
      // eslint-disable-next-line object-curly-spacing
      this.$router.push({ path: '/business/waybill-detail', query: { id: id } })
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-card__body {
  padding-bottom: 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}
// 下拉框
/deep/ .el-select {
  width: 100%;
}
</style>

<style lang="scss" scoped>
/deep/ .el-card{
  overflow: initial;
}
/deep/ .vue-treeselect__menu-container{
  z-index: 9999!important;
}
/deep/ .el-table tr td:last-child .cell{
  text-align: inherit;
}
</style>