approveComp.vue 5.47 KB
<template>
  <h-dialog ref="myDialog" :title="title" :isVisible="isVisible" @confirm="handleSubmit" @cancel="handleCancel">
    <div class="formObj">
      <div class="cell" @click="handleSelect" v-if="['2', '5', '6'].includes(staffType)">
        <div class="label">
          发货主体
          <span class="require">*</span>
        </div>
        <van-cell is-link :value="approveForm.sendOutMerchantName" />
      </div>
      <div class="line-feed">
        <div class="label">备注</div>
        <van-field class="textarea" v-model="approveForm.remark" rows="8" :autosize="{ maxHeight: 220 }" label="" type="textarea" maxlength="200" placeholder="请输入备注" show-word-limit />
      </div>
      <div class="explain" v-if="staffType == 2">说明:订单审核后自动流转至下一节点进行复审。</div>
      <div class="explain" v-if="staffType == 6">说明:订单审核后自动流转至下一节点进行复审。</div>
      <div class="explain" v-if="staffType == 3">说明:订单审核后会自动流转至供应商进行确认并发货。</div>
      <div class="explain" v-if="staffType == 5">说明:订单审核后自动流转至商务进行复审。</div>
    </div>
    <send-out-comp :isVisible="sendOutVisible" v-if="sendOutVisible" @cancel="handleSendCancel" @submit="handleSendSumit" :sendOutMerchantId="approveForm.sendOutMerchantId"></send-out-comp>
  </h-dialog>
</template>

<script>
import { Toast } from 'vant'
import hDialog from './dialog'
import sendOutComp from './sendOutComp'
import purchaseApi from '@/api/purchase'
export default {
  components: { hDialog, sendOutComp },
  data() {
    return {
      isSubmit: false,
      name: this.$route.query.name,
      staffType: this.$route.query.staffType,
      sendOutVisible: false,
      title: '通过',
      approveForm: {
        remark: '',
        sendOutMerchantId: '',
        sendOutMerchantName: ''
      }
    }
  },
  props: {
    isVisible: {
      type: Boolean,
      default: false
    },
    infoData: {
      type: Object,
      default: () => ({})
    }
  },
  watch: {
    infoData: {
      handler(val) {
        this.initData(val)
      },
      immediate: true,
      deep: true
    }
  },

  methods: {
    handleSendCancel() {
      this.sendOutVisible = false
    },
    handleSendSumit(data) {
      this.approveForm.sendOutMerchantName = data.shippingEntity
      this.approveForm.sendOutMerchantId = data.shippingEntityId
      this.handleSendCancel()
    },
    initData(val) {
      this.approveForm.sendOutMerchantName = val.sendOutMerchantName ? val.sendOutMerchantName : ''
      this.approveForm.sendOutMerchantId = val.sendOutMerchantId
    },
    handleSelect() {
      console.log('handleSelect')
      // this.$emit('handleSelect')
      this.sendOutVisible = true
    },
    validateRequiredFields() {
      let validators = {
        sendOutMerchantId: () => {
          Toast('请选择发货主体')
        }
      }
      for (let key in validators) {
        if (!this.approveForm[key]) {
          validators[key]()
          return false
        }
      }
      return true
    },
    getMethodByStaffType() {
      const methodMap = {
        2: 'operatorAudit',
        3: 'businessAudit',
        5: 'directorAudit',
        6: 'managerAudit'
      }
      return methodMap[this.staffType]
    },
    async handleSubmit() {
      const isValid = this.validateRequiredFields()
      if (!isValid) return
      const methodName = this.getMethodByStaffType()
      if (!methodName) {
        Toast('当前角色不支持此操作')
        return
      }
      try {
        this.isSubmit = true
        this.$refs.myDialog.startLoading()

        const params = {
          orderCode: this.infoData.orderCode,
          operatorName: this.name,
          ...this.approveForm
        }
        //运营审核有该字段,商户审核没有2-运营审核 3-商务审核
        if (this.staffType == 3) {
          delete params.sendOutMerchantName
          delete params.sendOutMerchantId
        }

        const result = await purchaseApi[methodName](params)

        if (result.code == 0) {
          Toast.success('操作成功')
          this.isSubmit = false
          this.$refs.myDialog.stopLoading()
          this.handleCancel()
          this.$emit('success')
        } else {
          this.$refs.myDialog.stopLoading()
          Toast.fail(result.message || '请求失败')
        }
      } catch (error) {
        this.isSubmit = false
        this.$refs.myDialog.stopLoading()
        Toast.fail('系统异常,请稍后再试')
        console.error(error)
      }
    },
    handleCancel() {
      this.$emit('cancel')
    }
  }
}
</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;
  }
  ::v-deep .van-cell__value--alone {
    text-align: right;
    color: #333333;
    font-size: 14px;
    width: 300px;
  }
}
</style>