add.vue 22.1 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
<!-- 创建退货 -->
<template>
  <div class="addWrap" v-loading="loading">
    <div class="d2-container-content gl-form-min" style="padding: 10px 20px">
      <el-form :inline="true" size="small" :model="editRefundForm" ref="editRefundFormRef" :rules="formRules" class="demo-form-inline">
        <el-form-item label="退货仓库:" prop="yqMerchantId">
          <el-select v-model="editRefundForm.yqMerchantId" @change="changeYqMerchant(editRefundForm.yqMerchantId)" :disabled="isDisabled" style="width: 300px">
            <el-option v-for="item in yqMerchantIdList" :key="item.merchantNo" :label="item.merchantName" :value="item.merchantNo" />
          </el-select>
        </el-form-item>
        <el-form-item label="退货门店:" prop="merchantId">
          <el-select v-model="editRefundForm.merchantId" @change="changeMerchant(editRefundForm.merchantId)" :disabled="isDisabled" style="width: 300px">
            <el-option v-for="item in merchantList" :key="item.merchantId" :label="item.merchantName" :value="item.merchantId" />
          </el-select>
        </el-form-item>
        <el-form-item label="退货类型:" prop="refundType">
          <el-select v-model="editRefundForm.refundType" style="width: 300px">
            <el-option v-for="item in baseData.typeList" :key="item.confId" :label="item.confLabel" :value="item.confId" />
          </el-select>
        </el-form-item>
      </el-form>
      <div>
        <div class="containerDIV">
          <div class="title">退货列表</div>
          <div class="right">
            <div class="gl-form-min">
              <el-form ref="ruleForm" :model="searchForm" size="small" inline="true">
                <el-form-item label="退货:">
                  <el-input v-model="searchForm.upgradeGoodsNameOrSeries" style="width: 200px" placeholder="请输入产品名称/系列" maxlength="20" clearable />
                </el-form-item>

                <el-button @click="handleSearch" size="small" type="primary">查询</el-button>
              </el-form>
            </div>
          </div>
        </div>
        <GLTable ref="recordTable" :getListApi="getListApi" :searchForm="searchFormSearch" :tableParams="tableParams" :beforeSearchFn="beforeSearchFn" :pageConf="pageConf">
          <div slot="auth-button" slot-scope="scope">
            <el-button type="text" @click="refund(scope.scope)" :disabled="setDisabled(scope.scope)">退货</el-button>
          </div>
        </GLTable>
      </div>
    </div>
    <div class="d2-container-content">
      <p class="title">退货确认单</p>
      <GLTable ref="recordTable2" :tableData="chooseDataList" :tableParams="tableParams2" :hasPage="false">
        <template slot="profitAndLoss" slot-scope="scope">
          <span v-if="scope.scope.profitAndLoss || scope.scope.profitAndLoss == 0">
            <span v-if="parseFloat(scope.scope.profitAndLoss) > 0" style="color: blue">{{ '+' + parseFloat(scope.scope.profitAndLoss).toFixed(2) + (membraneTypeList.includes(scope.scope.goodsType) ? '米' : '件') }}</span>
            <span v-else-if="parseFloat(scope.scope.profitAndLoss) < 0" style="color: red">{{ parseFloat(scope.scope.profitAndLoss).toFixed(2) + (membraneTypeList.includes(scope.scope.goodsType) ? '米' : '件') }}</span>
            <span v-else>{{ parseFloat(scope.scope.profitAndLoss).toFixed(2) + (membraneTypeList.includes(scope.scope.goodsType) ? '米' : '件') }}</span>
          </span>
          <span v-else>-</span>
        </template>
        <div slot="auth-button" slot-scope="scope">
          <el-button type="text" @click="cancelRefund(scope.scope, scope.index)">取消</el-button>
        </div>
      </GLTable>
    </div>
    <div class="addRefundForm">
      <!-- <glsx-form ref="addRefundForm" :origin-data="editData" :form-list="editForm" form-ref="inveFormRef" :isShowBtn="false" @handleAddConfirm="handleAddConfirm" @handleClose="handleAddClose"></glsx-form> -->
      <glsx-form ref="addRefundForm" :origin-data="editData" :form-list="editForm" form-ref="inveFormRef" :isShowBtn="false"></glsx-form>
    </div>
    <div style="margin-top: 40px;text-align: center;">
      <el-button class="btn" @click="handleAddClose">
        取消
      </el-button>
      <el-button @click="beforeConfirm('save')" class="btn" type="primary" plain>
        保存
      </el-button>
      <el-button @click="beforeConfirm('invalid')" class="btn" type="primary" plain v-if="oprType == 'edit'">
        作废
      </el-button>
      <el-button @click="beforeConfirm('review')" type="primary" class="btn">
        提交审核
      </el-button>
    </div>
    <!-- 退货 -->
    <num-dialog :num-visible="numVisible" :record-info="recordInfo" v-if="numVisible" @dialogClose="dialogClose" />
  </div>
</template>

<script>
import numDialog from './numDialog'
// import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'RefundList',
  components: {
    numDialog
  },
  data() {
    return {
      oprType: 'add',
      routeInfo: {},
      loading: false,
      isDisabled: false,
      // 编辑首次进
      editFirst: false,
      editMerFirst: false,
      membraneTypeList: this.$membraneTypeList,
      searchForm: {
        upgradeGoodsNameOrSeries: ''
      },
      searchFormSearch: {},
      searchSelectObj: {},
      // getListApi: this.$apis.stockManage.stockRemainPage,
      getListApi: null,
      tableData: [],
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '产品名称',
            prop: 'upgradeGoodsName'
          },
          {
            label: '规格',
            prop: 'specificationData',
            width: 180,
            line: 1
          },
          {
            label: '产品编码',
            prop: 'productCode',
            width: '250px'
          },
          {
            label: '系列',
            prop: 'goodsSeries'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName'
          },
          {
            label: '库存',
            prop: 'stock',
            formatter: cellValue => {
              return cellValue.stock || cellValue.stock == 0 ? parseFloat(cellValue.stock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '所属仓库',
            prop: 'yqMerchantName'
          },
          {
            label: '所属门店',
            prop: 'merchantName'
          },
          {
            label: '膜卷号',
            prop: 'filmRollNo'
          }
        ]
      },
      tableParams2: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '产品名称',
            prop: 'upgradeGoodsName'
          },
          {
            label: '规格',
            prop: 'specificationData',
            width: 180,
            line: 1
          },
          {
            label: '产品编码',
            prop: 'type',
            width: '250px'
          },
          {
            label: '系列',
            prop: 'goodsName'
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName'
          },
          {
            label: '系统库存',
            prop: 'stock',
            formatter: cellValue => {
              return cellValue.stock || cellValue.stock == 0 ? parseFloat(cellValue.stock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '退货库存',
            prop: 'refundStock',
            formatter: cellValue => {
              return cellValue.refundStock || cellValue.refundStock == 0 ? parseFloat(cellValue.refundStock).toFixed(2) + (this.$membraneTypeList.includes(cellValue.goodsType) ? '米' : '件') : '-'
            }
          },
          {
            label: '所属仓库',
            prop: 'yqMerchantName'
          },
          {
            label: '所属门店',
            prop: 'merchantName'
          },
          {
            label: '膜卷号',
            prop: 'filmRollNo'
          }
        ]
      },
      baseData: {
        typeList: [
          {
            confId: 1,
            confLabel: '不良退货'
          },
          {
            confId: 2,
            confLabel: '呆滞退货'
          }
        ]
      },

      editData: {
        thumbUrlList: [],
        remark: ''
      },
      editForm: [
        {
          formBlock: [
            {
              name: 'thumbUrlList',
              label: '凭证图片',
              type: 'photo',
              tips: ['请上传小于2M的图片'],
              maxPhotoNum: 1
            },
            {
              name: 'remark',
              label: '备注说明',
              width: '432px',
              type: 'textarea',
              rows: 5,
              maxlength: 100
            }
          ]
        }
      ],
      numVisible: false,
      recordInfo: null,
      chooseDataList: [],
      editRefundForm: {
        yqMerchantId: '',
        merchantId: '',
        refundType: ''
      },
      formRules: {
        yqMerchantId: [
          {
            required: true,
            message: '请选择退货仓库',
            trigger: 'change'
          }
        ],
        merchantId: [
          {
            required: true,
            message: '请选择退货门店',
            trigger: 'change'
          }
        ],
        refundType: [
          {
            required: true,
            message: '请选择退货类型',
            trigger: 'change'
          }
        ]
      },
      yqMerchantIdList: [], //退货仓库
      merchantList: [], //退货门店
      oldyqMerchantId: '', //之前选择的仓库
      oldMerchantId: '', //之前选择的门店
      //保存/作废/提交审核,弹窗提示和状态值适配
      btnTypeMap: {
        save: {
          title: '提示',
          confirmMsg: '退货单保存后,系统自动按照退货实际库存进行库存更新;是否确定保存?',
          refundStatus: 1
        },
        invalid: {
          title: '退货申请作废确定',
          confirmMsg: '作废后无法恢复退货单,是否确认作废?',
          refundStatus: 5
        },
        review: {
          title: '提交确定',
          confirmMsg: '退货申请单,确认提交申请?',
          refundStatus: 2
        }
      }
    }
  },

  watch: {
    'editRefundForm.yqMerchantId'(val, oldval) {
      // console.log(val, oldval, '监听yqMerchantId')
      // this.getListApi = this.$apis.stockManage.stockRemainPage
      if (this.yqMerchantIdList.length == 1) {
        //当只有一个选项时不弹提示框
        // this.$refs.recordTable.refreshTable()
      } else {
        if (val != this.oldyqMerchantId) {
          //与之前的选项不一样
          if (!this.editFirst) {
            this.editRefundForm.merchantId = ''
            this.switchData(val, oldval, 'yqMerchant')
          }
          this.editFirst = false
        }
      }
    },

    'editRefundForm.merchantId'(val, oldval2) {
      // console.log(val, oldval2, '监听merchantId')
      this.getListApi = this.$apis.stockManage.stockRemainPage
      if (this.merchantList.length == 1) {
        this.$refs.recordTable.refreshTable()
      } else {
        if (val != this.oldMerchantId) {
          //与之前的选项不一样
          if (!this.editMerFirst) {
            this.switchData(val, oldval2, 'merchant')
          }
          this.editMerFirst = false
        }
      }
    }
  },

  mounted() {
    this.routeInfo = this.$route.query?.row || {}
    if (this.routeInfo?.refundCode) {
      this.oprType = 'edit'
      this.editFirst = true
      this.editMerFirst = true
      this.isDisabled = true
      this.getDetail()
    }
    // 获取当前登录账号可见的园区店列表
    this.$apis.stockManage.getyqMerchantList({ mainPartnerMerchant: true }).then(res => {
      this.yqMerchantIdList = res
      if (this.yqMerchantIdList && this.yqMerchantIdList.length == 1 && this.oprType == 'add') {
        this.editRefundForm.yqMerchantId = this.yqMerchantIdList[0].merchantNo
        this.getServicemerchantrefList(this.editRefundForm.yqMerchantId)
      }
    })
  },

  methods: {
    changeYqMerchant(merchantId) {
      // this.switchData(merchantId, 'yqMerchant')
    },

    changeMerchant(merchantId) {
      // this.switchData(merchantId, 'merchant')
    },

    getDetail() {
      this.$apis.stockManage
        .refundDetail({
          refundCode: this.routeInfo.refundCode
        })
        .then(res => {
          this.editRefundForm = res
          this.editRefundForm.yqMerchantId = this.editRefundForm.yqMerchantId + ''
          this.chooseDataList = res.stockRefundDetailList
          this.getListApi = this.$apis.stockManage.stockRemainPage
          this.$refs.recordTable.refreshTable()
          this.chooseDataList.forEach((item, idx) => {
            this.chooseDataList[idx].id = item.merchantShopGoodsStockPageResponse.id
            this.chooseDataList[idx].productCode = item.merchantShopGoodsStockPageResponse.productCode
            this.chooseDataList[idx].yqMerchantId = item.merchantShopGoodsStockPageResponse.yqMerchantId
            this.chooseDataList[idx].yqMerchantName = item.merchantShopGoodsStockPageResponse.yqMerchantName
            this.chooseDataList[idx].merchantId = item.merchantShopGoodsStockPageResponse.merchantId
            this.chooseDataList[idx].merchantName = item.merchantShopGoodsStockPageResponse.merchantName
            this.chooseDataList[idx].filmRollNo = item.merchantShopGoodsStockPageResponse.filmRollNo
            this.chooseDataList[idx].stock = item.merchantShopGoodsStockPageResponse.stock
            this.setDisabled(item)
          })
          if (res.voucherPic) {
            this.editData.thumbUrlList = [{ content: res.voucherPic }]
          }
          this.editData.remark = res.remark || ''
          console.log(this.editData, 'this.editData')
          this.getServicemerchantrefList(this.editRefundForm.yqMerchantId)
        })
    },

    // 获取仓库门店
    getServicemerchantrefList(merchantId) {
      this.$apis.stockManage
        .getServicemerchantrefList({
          yqMerchantId: merchantId
        })
        .then(res => {
          this.merchantList = res || []
          //总店
          let _headOffice = this.yqMerchantIdList.find(item => item.merchantNo === merchantId) || {}
          _headOffice.merchantId = _headOffice?.merchantNo
          //门店选项中加入总店
          this.merchantList.push(_headOffice)
          if (this.merchantList && this.merchantList.length == 1 && this.oprType == 'add') {
            this.editRefundForm.merchantId = this.merchantList[0].merchantId
          }
        })
    },

    switchData(val, oldval, type) {
      if (this.chooseDataList && this.chooseDataList.length > 0) {
        //当退货确认单有数据时提示
        this.$confirm('切换退货仓库和退货门店,自动重置已退货内容;是否确定切换?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            if (type == 'yqMerchant') {
              this.getServicemerchantrefList(val)
            } else {
              //选择门店以后才更新退货数据
              this.$refs.recordTable.refreshTable()
            }
            //清空退货确认单数据
            this.chooseDataList = []
          })
          .catch(err => {
            console.log(err)
            if (type == 'yqMerchant') {
              this.editRefundForm.yqMerchantId = oldval
              this.oldyqMerchantId = oldval
            } else if (type == 'merchant') {
              this.editRefundForm.merchantId = oldval
              this.oldMerchantId = oldval
            }
          })
      } else {
        if (type == 'yqMerchant') {
          this.getServicemerchantrefList(val)
        } else {
          //选择门店以后才更新退货数据
          this.$refs.recordTable.refreshTable()
        }
      }
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        let _form = {
          ...this.searchForm,
          ...this.editRefundForm
        }
        _form.stockFlag = true
        this.searchFormSearch = this.$common.utils.deepClone(_form)
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },

    handleSearch() {
      console.log(this.searchFormSearch)

      if (this.searchFormSearch.yqMerchantId && this.searchFormSearch.merchantId) {
        this.getListApi = this.$apis.stockManage.stockRemainPage
        this.$refs.recordTable.refreshTable()
      } else {
        this.$message({
          type: 'error',
          message: '请选择仓库和门店再查询数据'
        })
      }
    },

    // 退货
    refund(row) {
      this.recordInfo = row
      this.numVisible = true
    },

    // 设置禁选
    setDisabled(row) {
      const index = this.chooseDataList.findIndex(item => item.id == row.id)
      if (index == -1) {
        return false
      } else {
        return true
      }
    },

    dialogClose(chooseData) {
      this.numVisible = !this.numVisible
      console.log('chooseData', chooseData)
      if (chooseData) {
        chooseData = this.fieldConvert(chooseData)
        this.chooseDataList.push(chooseData)
      }
    },

    //选择的数据与提交数据之间的字段转换
    fieldConvert(obj) {
      obj.goodsName = obj.goodsSeries
      obj.type = obj.productCode
      return obj
    },

    // 取消
    cancelRefund(row, index) {
      console.log(row, index)
      this.chooseDataList = this.chooseDataList.filter(item => item.id != row.id)
    },

    /** 保存/作废/提交申请之前,表单校验等
     * 按钮类型 - 单据状态
     * 保存按钮(save) - 1:待提交
     * 提交审核按钮(review) - 2:待总部审核
     * 作废按钮(invalid) - 5:作废
     **/
    beforeConfirm(btnType = 'save') {
      this.$refs.editRefundFormRef.validate(valid => {
        if (valid) {
          if (this.chooseDataList.length == 0) {
            this.$notify({
              type: 'warning',
              title: '请选择退货商品'
            })
            return
          }
          const data = this.$refs.addRefundForm.formData
          console.log(data)
          var params = {}
          params = {
            ...params,
            ...this.editRefundForm
          }
          params.stockRefundDetailList = this.chooseDataList
          params.voucherPic = data.thumbUrlList.length > 0 ? data.thumbUrlList[0].content : ''
          params.remark = data.remark || ''
          console.log(params, 'params')
          // 调不同按钮的方法
          this.handleConfirm(params, btnType)
        }
      })
    },

    /** 保存/作废/审核提交,弹窗提示不一样
     * 按钮类型 - 单据状态
     * 保存按钮(save) - 创建 - 1:待提交;编辑 - 传详情里面的refundStatus状态
     * 提交审核按钮(review) - 2:待总部审核
     * 作废按钮(invalid) - 5:作废
     **/
    handleConfirm(params, btnType = 'save') {
      if (this.loading) {
        return true
      }
      const tipTxtObj = {
        save: '单据保存成功',
        review: '提交审核成功',
        invalid: '作废成功'
      }
      const btnObj = this.btnTypeMap[btnType]
      // eslint-disable-next-line prettier/prettier
      params.refundStatus = (this.oprType == 'edit' && btnType == 'save') ? this.editRefundForm.refundStatus : btnObj.refundStatus
      this.$confirm(btnObj.confirmMsg, btnObj.title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = true
          this.$apis.stockManage.refundSave(params).then(res => {
            this.$notify({
              type: res.code == 0 ? 'success' : 'error',
              title: res.code == 0 ? (tipTxtObj[btnType] || '操作成功') : res.message
            })
            if (res.code == 0) {
              if (btnType == 'save') {
                this.routeInfo.refundCode = res.data.refundCode
                this.oprType = 'edit'
                this.editFirst = true
                this.editMerFirst = true
                this.isDisabled = true
                this.getDetail()
              } else {
                this.handleAddClose()
              }
            }
          })
        })
        .catch(err => {
          console.log(err)
        }).finally(() => {
          this.loading = false
        })
    },
    handleAddClose(isRefresh = false) {
      this.$router.go(-1)
    }
  }
}
</script>
<style lang="scss" scoped>
.d2-container-content {
  background: #fff;
  padding: 20px;
  margin-bottom: 20px;
}

.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}

.title {
  font-weight: 600;
  font-size: 16px;
  color: #333333;
  padding: 17px 0;
}

.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}

.containerDIV {
  display: flex;
  justify-content: space-between; /* 关键:两端对齐 */
  /* align-items: flex-start; */
  /* width: 100%; */
}
/deep/.d2-container-content {
  padding-top: 0px;
}
.addRefundForm {
  /deep/.d2-container-content {
    padding: 0px;
  }
  /deep/.d2-form .d2-form-block {
    border-bottom: none !important;
    padding: 20px 0px 0px;
  }
}
.btn {
  height: 32px;
  border-radius: 4px;
  padding: 7.5px 18px;
}
</style>