index.vue 17.3 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
<template>
  <div class="purchase ">
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="showFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="table-header">
        <h2>调拨列表</h2>
        <div>
          <GLButton type="primary" plain size="small" @click="handleAdd" fn="创建调拨">创建调拨</GLButton>
          <!-- <el-button type="primary" size="small" @click="handleAdd">创建调拨</el-button> -->
          <el-button size="small" @click="exportExcel">导出</el-button>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="allocationRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <template slot="billStatus" slot-scope="scope">
          <div>
            <span :class="(billStatusObj[scope.scope.billStatus] || {}).class || ''"></span>
            <span>{{ scope.scope.billStatusName }}</span>
          </div>
        </template>
        <template slot="deliveryStatus" slot-scope="scope">
          <div>
            <span :class="(deliveryStatusObj[scope.scope.deliveryStatus] || {}).class || ''"></span>
            <span>{{ scope.scope.deliveryStatusName }}</span>
          </div>
        </template>
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <!-- <el-button type="text" @click="handleDetail(scope.scope)">查看</el-button> -->
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
    <!-- 查看 -->
    <allocation-detail-dialog :allocation-detail-visible="allocationDetailVisible" :allocationInfo="allocationInfo" v-if="allocationDetailVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import constData from './constant/data.js'
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
import allocationDetailDialog from './allocationDetailDialog'
export default {
  name: 'warehousing',
  components: {
    allocationDetailDialog
  },
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        queryCallInMerchant: true,
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: '',
        billStatusList: '',
        deliveryStatus: ''
      },
      tableSearchForm: {},
      allocationInfo: {},
      allocationDetailVisible: false,
      billStatusObj: constData.billStatusObj,
      deliveryStatusObj: {
        1: {
          class: 'ashSpot',
          name: '待发货'
        },
        2: {
          class: 'greenSpot',
          name: '全部发货'
        },
        3: {
          class: 'yellowSpot',
          name: '部分发货'
        }
      },
      showFormData: [
        {
          label: '调拨单号',
          name: 'allocateCode',
          type: 'input',
          maxlength: '20',
          isClear: true
        },
        {
          label: '调拨时间',
          name: 'allocateTime',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '调出仓库',
          name: 'callOutYqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqRelatedMerchantList',
          changeAttr: (value, targetItem) => {
            value ? this.getServicemerchantrefList(value, 'out') : (this.baseData.outMerchantList = [])
            this.searchForm.callOutMerchantId = ''
            this.getOptionsList('showFormData')
          }
        },
        {
          label: '调出门店',
          name: 'callOutMerchantId',
          type: 'select',
          noDataText: '请先选择调出仓库',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'outMerchantList'
        },
        {
          label: '调入仓库',
          name: 'callInYqMerchantId',
          type: 'select',
          optionList: [],
          optionId: 'merchantNo',
          optionLabel: 'merchantName',
          optionsName: 'yqRelatedMerchantList',
          changeAttr: (value, targetItem) => {
            value ? this.getServicemerchantrefList(value, 'in') : (this.baseData.inMerchantList = [])
            this.searchForm.callInMerchantId = ''
            this.getOptionsList('showFormData')
          }
        },
        {
          label: '调入门店',
          name: 'callInMerchantId',
          type: 'select',
          noDataText: '请先选择调入仓库',
          optionList: [],
          optionId: 'merchantId',
          optionLabel: 'merchantName',
          optionsName: 'inMerchantList'
        },
        {
          label: '单据状态',
          name: 'billStatusList',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confLabel',
          optionsName: 'billStatusList'
        },
        {
          label: '发货状态',
          name: 'deliveryStatus',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confLabel',
          optionsName: 'deliveryStatusList'
        },
        {
          label: '产品ID',
          name: 'commodityCode',
          type: 'input',
          isClear: true,
          maxlength: 20
        }
      ],
      // 表格
      getListApi: this.$apis.stockManage.stockAllocatePage,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '调拨单号',
            prop: 'allocateCode',
            width: 111
          },
          {
            label: '单据时间',
            prop: 'submitTime',
            width: 112
          },
          {
            label: '单据状态',
            prop: 'billStatusName',
            addHtml: 'billStatus',
            width: 130
          },
          {
            label: '调拨时间',
            prop: 'allocateTime',
            width: 112,
            formatter: cellValue => {
              return cellValue.allocateTime ? dayjs(cellValue.allocateTime).format('YYYY-MM-DD HH:mm:ss') : '--'
            }
          },
          {
            label: '调拨人',
            prop: 'operator',
            width: 100
          },
          {
            label: '调出仓库',
            prop: 'callOutYqMerchantName',
            width: 150
          },
          {
            label: '调出门店',
            prop: 'callOutMerchantName',
            width: 150
          },
          {
            label: '调入仓库',
            prop: 'callInYqMerchantName',
            width: 150
          },
          {
            label: '调入门店',
            prop: 'callInMerchantName',
            width: 150
          },
          {
            label: '承运单号',
            prop: 'deliveryNumber',
            width: 150,
            line: 1
          },
          {
            label: '承运公司',
            prop: 'deliveryCompany',
            width: 150,
            line: 1
          },
          {
            label: '发货状态',
            prop: 'deliveryStatusName',
            addHtml: 'deliveryStatus',
            width: 130
          },
          {
            label: '备注',
            prop: 'remark',
            width: 200,
            line: 1
          },
          {
            label: '收货人',
            prop: 'receiver',
            width: 200,
            line: 1
          },
          {
            label: '收货人电话',
            prop: 'phone',
            width: 140
          },
          {
            label: '收货地址',
            prop: 'address',
            width: 200,
            line: 1
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          condition: row => {
            return [0].includes(row.billStatus)
          },
          listeners: {
            click: row => this.handleEdit(row)
          }
        },
        {
          type: 'GLButton',
          name: '提交审核',
          attrs: {
            type: 'text',
            fn: '提交审核'
          },
          condition: row => {
            return [0].includes(row.billStatus)
          },
          listeners: {
            click: row => {
              this.$confirm('调拨申请单,确认提交申请?', '提交确定', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              })
                .then(() => {
                  console.log(row)
                  this.updateStatus(row, 1, '提交审核成功')
                })
                .catch(() => {})
            }
          }
        },
        {
          type: 'el-button',
          name: '查看',
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.handleDetail(row)
          }
        },
        {
          type: 'GLButton',
          name: '作废',
          attrs: {
            type: 'text',
            fn: '作废'
          },
          condition: row => {
            return [0].includes(row.billStatus)
          },
          listeners: {
            click: row => {
              this.$confirm('作废后无法恢复调拨单,是否确认作废?', '调拨申请作废确定', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              })
                .then(() => {
                  console.log(row)
                  this.updateStatus(row, '-1', '作废成功')
                })
                .catch(() => {})
            }
          }
        }
      ],
      // 基本数据
      baseData: {
        yqRelatedMerchantList: [],
        outMerchantList: [], //调出门店
        inMerchantList: [], //调入门店
        billStatusList: constData.billStatusList,
        deliveryStatusList: [
          { confId: 1, confLabel: '未发货' },
          { confId: 3, confLabel: '部分发货' },
          { confId: 2, confLabel: '全部发货' }
        ]
      },
      imgVisible: false,
      previewImgUrl: ''
    }
  },

  mounted() {
    //调入门店
    // this.$apis.stockManage.yqRelatedList({}).then(res => {
    //   this.baseData.yqRelatedMerchantList = res
    //   this.getOptionsList('showFormData')
    // })
    this.$apis.stockManage.getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.baseData.yqRelatedMerchantList = res
      this.getOptionsList('showFormData')
    })
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.allocateTime) {
        params.allocateTimeStart = new Date(this.searchForm.allocateTime[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.allocateTimeEnd = new Date(this.searchForm.allocateTime[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.allocateTime

      if (this.searchForm.billStatusList !== '' && this.searchForm.billStatusList !== null && this.searchForm.billStatusList !== undefined) {
        if (String(this.searchForm.billStatusList).indexOf(',') !== -1) {
          params.billStatusList = this.searchForm.billStatusList.split(',').map(item => Number(item))
        } else {
          params.billStatusList = [Number(this.searchForm.billStatusList)]
        }
      } else {
        delete params.billStatusList
      }

      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    // 获取仓库门店
    getServicemerchantrefList(merchantId, type) {
      this.$apis.stockManage
        .getServicemerchantrefList({
          yqMerchantId: merchantId
        })
        .then(res => {
          let _headOffice = {}
          if (type == 'out') {
            //调出门店
            this.baseData.outMerchantList = res || []
            //总店
            _headOffice = this.baseData.yqRelatedMerchantList.find(item => item.merchantNo === merchantId)
            _headOffice.merchantId = _headOffice.merchantNo
            //门店选项中加入总店
            this.baseData.outMerchantList.push(_headOffice)
          } else if (type == 'in') {
            //调入门店
            this.baseData.inMerchantList = res || []
            //总店
            _headOffice = this.baseData.yqRelatedMerchantList.find(item => item.merchantNo === merchantId)
            _headOffice.merchantId = _headOffice.merchantNo
            //门店选项中加入总店
            this.baseData.inMerchantList.push(_headOffice)
          }
          this.getOptionsList('showFormData')
        })
    },

    // 查看详情
    handleDetail(row) {
      this.allocationInfo = row
      this.allocationDetailVisible = true
      console.log(this.allocationDetailVisible)
    },
    updateStatus(row, billStatus, okMessage = '提交成功') {
      this.$apis.stockManage
        .updateStockAllocateStatus({
          id: row.id,
          billStatus
        })
        .then(res => {
          this.$notify({
            message: res.code == '0' ? okMessage : res.message,
            type: res.code == '0' ? 'success' : 'error'
          })
          this.$refs.allocationRef.refreshTable()
        })
    },
    handleAdd() {
      this.$router.push({
        path: '/allocation/add',
        query: {
          $title: '创建调拨'
        }
      })
    },
    handleEdit(row) {
      this.$router.push({
        path: '/allocation/add',
        query: {
          $title: '编辑调拨',
          row: row
        }
      })
    },
    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.allocationRef.data.length ? (this.$refs.allocationRef.tableHeightValues = '') : this.$refs.allocationRef.setTableHeightFun()
    },
    exportExcel() {
      var params = this.getParams()
      this.$apis.stockManage.exportaAllocateExcel(params).then(res => {
        window.location.href = res
      })
    },
    handleSearch() {
      this.$refs.allocationRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        allocateTime: '',
        allocateCode: '',
        callOutYqMerchantId: '',
        callInYqMerchantId: '',
        callOutMerchantId: '',
        callInMerchantId: '',
        billStatusList: '',
        deliveryStatus: '',
        queryCallInMerchant: true
      }
      this.showFormData[this.findFormIdx('callOutMerchantId')].optionList = []
      this.showFormData[this.findFormIdx('callInMerchantId')].optionList = []
      this.handleSearch()
    },

    findFormIdx(name) {
      return this.showFormData.findIndex(item => item.name === name)
    },

    handleEnlargeImg(url) {
      if (url) {
        this.previewImgUrl = url
        this.imgVisible = !this.imgVisible
      }
    },
    handleCloseImg() {
      this.imgVisible = !this.imgVisible
    },
    dialogClose() {
      this.allocationDetailVisible = !this.allocationDetailVisible
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/css/mixin.scss';
.purchase {
  .table-header {
    @include space-between_center;
    margin-bottom: 10px;
    h2 {
      font-weight: 600;
      font-size: 16px;
      color: #333;
    }
  }

  .greenSpot {
    @include dot;
    background: $color-green;
  }

  .yellowSpot {
    @include dot;
    background: $color-yellow;
  }

  .ashSpot {
    @include dot;
    background: $color-gray;
  }

  .redSpot {
    @include dot;
    background: $color-red;
  }
}
</style>