approveComp.vue 6.52 KB

<template>
  <h-dialog ref="myDialog" :title="title" :isVisible="isVisible" @confirm="handleSubmit" @cancel="handleCancel">
    <div class="formObj">
      <div class="cell" @click="handleSelect(2)" v-if="['3'].includes(staffType)">
        <div class="label">
          调出仓库
          <span class="require">*</span>
        </div>
        <van-cell is-link :value="approveForm.callOutYqMerchantName" />
      </div>
      <div class="cell" @click="handleSelect(1)" v-if="['3'].includes(staffType)">
        <div class="label">
          调出门店
          <span class="require">*</span>
        </div>
        <van-cell is-link :value="approveForm.callOutMerchantName" />
      </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">说明:订单审核后自动流转至下一节点进行复审</div>
    </div>
    <!-- 先选仓库再选门店  -->
    <send-out-comp :isVisible="sendOutVisible" :isYq="isYq" v-if="sendOutVisible" @cancel="handleSendCancel" @submit="handleSendSumit" :sendOutMerchantId="isYq == 1?approveForm.callOutMerchantId:approveForm.callOutYqMerchantId" :yqMerchantId="approveForm.callOutYqMerchantId" :yqMerchantName="approveForm.callOutYqMerchantName"></send-out-comp>
  </h-dialog>
</template>

<script>
import { Toast } from 'vant'
import hDialog from './dialog'
import sendOutComp from './sendOutComp'
import allocateApi from '@/api/allocate'
export default {
  components: { hDialog, sendOutComp },
  data() {
    return {
      isYq:1, //1-门店 2-仓库
        isSubmit:false,
      name: this.$route.query.name,
      staffType: this.$route.query.staffType,
      sendOutVisible: false,
      title: '通过',
      approveForm: {
        remark: '',
        callOutYqMerchantId: '',
        callOutYqMerchantName: '',
        callOutMerchantId:'',
        callOutMerchantName:'',
      }
    }
  },
  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.handleSendCancel()
      //门店
      if(data.isYq==1){
        this.approveForm.callOutMerchantName = data.merchantName?data.merchantName:''
      this.approveForm.callOutMerchantId = data.merchantId
      }else{
        //仓库
        if(data.merchantNo ==  this.approveForm.callOutYqMerchantId) return 
         this.approveForm.callOutYqMerchantName = data.merchantName?data.merchantName:''
         this.approveForm.callOutYqMerchantId = data.merchantNo
         this.approveForm.callOutMerchantName =''
         this.approveForm.callOutMerchantId =''
      }
    
     
    },
    initData(val) {
      this.approveForm.callOutYqMerchantName = val.callOutYqMerchantName? val.callOutYqMerchantName:''
      this.approveForm.callOutYqMerchantId = val.callOutYqMerchantId
      this.approveForm.callOutMerchantName = val.callOutMerchantName? val.callOutMerchantName:''
      this.approveForm.callOutMerchantId = val.callOutMerchantId
    },
    handleSelect(val) {
      console.log('handleSelect')
      // this.$emit('handleSelect')
      this.isYq = val
      if(this.isYq  ==2&&!this.approveForm.callOutYqMerchantId){
        Toast('请先选择调出仓库')
        return 
      }
      this.sendOutVisible = true
    },
    validateRequiredFields() {
      let validators = {
        callOutYqMerchantId: () => {
          Toast('请选择调出仓库')
        },
        callOutMerchantId: () => {
          Toast('请选择调出门店')
        }
      }
      for (let key in validators) {
        if (!this.approveForm[key]) {
          validators[key]()
          return false
        }
      }
      return true
    },
    getMethodByStaffType() {
      const methodMap = {
        2: 'operatorAudit',
        3: 'businessAudit'
      }
      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 = {
          allocateCode: this.infoData.allocateCode,
          updatedBy: this.name,
          ...this.approveForm
        }
        //运营审核没有该字段,商户审核有 2-运营审核 3-商务审核
        if (this.staffType == 2) {
          delete params.callOutYqMerchantName
          delete params.callOutYqMerchantId
          delete params.callOutMerchantName
          delete params.callOutMerchantId
        }

        const result = await allocateApi[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>