TblBiddingShenqForm.vue 9.5 KB
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <a-input v-model="model.productName" placeholder="请输入品名" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specifications">
              <a-input v-model="model.specifications" placeholder="请输入规格" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input-number
                v-model="model.num"
                placeholder="请输入数量"
                style="width: 100%"
                :disabled="isBianhaoDisabled"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="danwei">
              <a-input v-model="model.danwei" placeholder="请输入单位" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wuType">
              <a-input v-model="model.wuType" placeholder="请输入物料类别" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作令" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workOrder">
              <a-input v-model="model.workOrder" placeholder="请输入工作令" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用途" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purpose">
              <a-input v-model="model.purpose" placeholder="请输入用途" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="当前库存" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ku">
              <a-input v-model="model.ku" placeholder="请输入当前库存" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sqTime">
              <j-date v-model="model.sqTime" placeholder="请输入申请日期" :disabled="isBianhaoDisabled" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryTime">
              <j-date v-model="model.deliveryTime" placeholder="请输入使用日期" :disabled="isBianhaoDisabled" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="brand">
              <a-input v-model="model.brand" placeholder="请输入品牌" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">
              <a-input v-model="model.notes" placeholder="请输入备注" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicant">
              <a-input v-model="model.applicant" placeholder="请输入申请人" :disabled="isBianhaoDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <!-- <a-form-model-item label="一级审批人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spOne">
              
            </a-form-model-item> -->
            <a-form-model-item
              label="一级审批"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="spOne"
              v-if="userInfo().username === 'admin'"
            >
              <a-radio-group v-model="model.spOne" @change="handleSpChange('spOne')">
                <a-radio value="同意">同意</a-radio>
                <a-radio value="不同意">不同意</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="二级审批人"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="spTwo"
              v-if="userInfo().username === 'admin'"
            >
              <a-radio-group v-model="model.spTwo" @change="handleSpChange('spTwo')">
                <a-radio value="同意">同意</a-radio>
                <a-radio value="不同意">不同意</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="不同意备注"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="noNotes"
              v-if="
                (model.spOne === '不同意' && userInfo().username === 'admin') ||
                (model.spTwo === '不同意' && userInfo().username === 'admin')
              "
            >
              <a-input v-model="model.noNotes" placeholder="请输入不同意备注"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script >
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { mapGetters } from 'vuex'
export default {
  name: 'TblBiddingShenqForm',

  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      isBianhaoDisabled: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        productName: [{ required: true, message: '请输入品名!' }],
        specifications: [{ required: true, message: '请输入规格!' }],
        num: [{ required: true, message: '请输入数量!' }],
        danwei: [{ required: true, message: '请输入单位!' }],
        wuType: [{ required: true, message: '请输入物料类别!' }],
        workOrder: [{ required: true, message: '请输入工作令!' }],
        purpose: [{ required: true, message: '请输入用途!' }],
        ku: [{ required: true, message: '请输入当前库存!' }],
        sqTime: [{ required: true, message: '请输入申请日期!' }],
        deliveryTime: [{ required: true, message: '请输入使用日期!' }],
        brand: [{ required: true, message: '请输入品牌!' }],
        notes: [{ required: true, message: '请输入备注!' }],
        applicant: [{ required: true, message: '请输入申请人!' }],
      },
      url: {
        add: '/trad/tblBiddingShenq/add',
        edit: '/trad/tblBiddingShenq/edit',
        queryById: '/trad/tblBiddingShenq/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    handleSpChange(type) {
      if (type === 'spOne' && this.model.spOne === '同意') {
        this.model.noNotes = ''
      } else if (type === 'spTwo' && this.model.spTwo === '同意') {
        this.model.noNotes = ''
      }
    },
    add() {
      this.edit(this.modelDefault)
      this.isBianhaoDisabled = false
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
      if (this.userInfo().username === 'admin') {
        this.isBianhaoDisabled = true
      } else {
        this.isBianhaoDisabled = false
      }
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              console.log(this.nickname())
              console.log(this.userInfo().username)
            })
        }
      })
    },
  },
}
</script>