rejectComp.vue 5.16 KB
<template>
  <h-dialog ref="myDialog" :title="title" :isVisible="isVisible" @confirm="handleSubmit" @cancel="handleCancel">
    <div class="formObj">
      <div class="cell">
        <div class="label">
          驳回节点
          <span class="require">*</span>
        </div>
        <van-radio-group v-model="rejectForm.rejectNode" direction="horizontal">
          <van-radio v-for="item in dynamicNodeList" :key="item.value" :name="item.value" icon-size="16px">
            {{ item.label }}
          </van-radio>
        </van-radio-group>
      </div>
      <div class="line-feed">
        <div class="label">
          驳回原因
          <span class="require">*</span>
        </div>
        <van-field class="textarea" v-model="rejectForm.rejectCause" rows="8" :autosize="{ maxHeight: 220 }" label="" type="textarea" maxlength="200" placeholder="请输入驳回原因" show-word-limit />
      </div>
      <div class="explain" v-if="staffType == 4">说明:驳回后,整个采购订单进行驳回,无法再重新进行发货操作。</div>
    </div>
  </h-dialog>
</template>

<script>
import hDialog from './dialog'
import { Toast } from 'vant'
import purchaseApi from '@/api/purchase'
export default {
  components: { hDialog },
  data() {
    return {
      name: this.$route.query.name,
      staffType: this.$route.query.staffType, //(2-运营审核 3-商务审核 4-采购发货审核)
      title: '驳回',
      rejectForm: {
        rejectNode: '',
        rejectCause: ''
      }
    }
  },

  props: {
    isVisible: {
      type: Boolean,
      default: false
    },
    infoData: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    /**
     * 根据 staffType 动态生成驳回节点列表
     */
    dynamicNodeList() {
      const baseOptions = [
        { label: '采购商户', value: '1' },
        { label: '运营审核', value: '2' },
        { label: '经理审核', value: '6' },
        { label: '商务审核', value: '3' }
      ]

      switch (this.staffType) {
        // 运营审核
        case '2':
          // 只返回采购审核
          return [baseOptions[0]]
        // 商务审核
        case '3':
          // 返回采购审核、运营审核
          return baseOptions.slice(0, 3)
        // 采购发货审核
        case '4':
          // 返回全部
          return baseOptions
        // 总监审核
        case '5':
          // 返回采购审核、运营审核
          return baseOptions.slice(0, 3)
        // 经理审核
        case '6':
          // 返回采购审核、运营审核
          return baseOptions.slice(0, 2)
        default:
          return [] // 默认无选项
      }
    }
  },
  methods: {
    validateRequiredFields() {
      let validators = {
        rejectNode: () => {
          Toast('请选择驳回节点')
        },
        rejectCause: () => {
          Toast('请输入驳回原因')
        }
      }
      for (let key in validators) {
        if (!this.rejectForm[key]) {
          validators[key]()
          return false
        }
      }
      return true
    },
    getRejectMethodByStaffType() {
      const methodMap = {
        2: 'operatorReject',
        3: 'businessReject',
        4: 'shipmentReject',
        5: 'directorReject',
        6: 'managerReject'
      }
      return methodMap[this.staffType]
    },
    async handleSubmit() {
      const isValid = this.validateRequiredFields()
      if (!isValid) return
      const methodName = this.getRejectMethodByStaffType()
      if (!methodName) {
        Toast('当前角色不支持此操作')
        return
      }
      try {
        this.$refs.myDialog.startLoading()

        const params = {
          orderCode: this.infoData.orderCode,
          operatorName: this.name,
          ...this.rejectForm
        }

        const result = await purchaseApi[methodName](params)

        if (result.code == 0) {
          Toast.success('操作成功')
          this.$refs.myDialog.stopLoading()
          this.handleCancel()
          this.$emit('success')
        } else {
          this.$refs.myDialog.stopLoading()
          Toast.fail(result.message || '请求失败')
        }
      } catch (error) {
        this.$refs.myDialog.stopLoading()
        Toast.fail('系统异常,请稍后再试')
        console.error(error)
      }
      // this.$refs.myDialog.stopLoading();
    },
    handleCancel() {
      this.$emit('cancel')
      //   this.isVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
.formObj {
  margin: 0 12px;
  font-size: 14px;
  .cell {
    display: flex;
    align-items: center;
    height: 52px;
    border-bottom: 1px solid #eff0f2;
  }
  .label {
    color: #333333;
    font-size: 14px;
    margin-right: 18px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    line-height: 20px;
    .require {
      color: #f24724;
      font-size: 14px;
      margin-left: 4px;
      line-height: 52px;
      margin-top: 5px;
    }
  }
  .line-feed {
    .label {
      line-height: 52px;
    }
    .textarea {
      border-radius: 8px;
      border: 1px solid #eff0f2;
      //   height: 220px;
    }
  }
  .explain {
    color: #999999;
    font-size: 14px;
    margin-top: 10px;
  }
}
</style>