SuppilerForm.vue 7.02 KB
<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="submitForm"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form :form="form" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-item label="id" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-input placeholder="id" v-model="id" disabled=""></a-input>
              </a-form-item>
            </a-col>

            <a-col :span="24">
              <a-form-item label="供应商编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="suppiler_code">
                <!--                <a-input placeholder="请输入工作令号" v-model="queryParam.workNo" ></a-input>-->
                <j-popup v-model="suppiler_code" code="getPmaaucByT100" field="partnerid"
                         orgFields="partnerid,partnershortname"
                         destFields="partnerid,partnershortname" :multi="false" :trigger-change="true"
                         @callback="findCarNumberClick"/>
              </a-form-item>
            </a-col>

            <a-col :span="24">
              <a-form-item label="工艺合并" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isCell">
                <j-dict-select-tag v-model="isCell" placeholder="请选择是否合并"
                                   dictCode="yn"/>
              </a-form-item>
            </a-col>

            <a-col :span="24">
              <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <j-dict-select-tag v-model="unit" placeholder="请选择单位"
                                   dictCode="unit"/>
              </a-form-item>
            </a-col>

            <!--            <a-col :span="24">-->
            <!--              <a-form-item label="工艺编号" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
            <!--                &lt;!&ndash;                <a-input placeholder="请输入工作令号" v-model="queryParam.workNo"></a-input>&ndash;&gt;-->
            <!--                <j-popup v-model="craft" code="getT100Craft" field="partnerid"-->
            <!--                         orgFields="name,code"-->
            <!--                         destFields="name,code" :multi="true" :trigger-change="true"-->
            <!--                         @callback="findCraftNumberClick"/>-->
            <!--              </a-form-item>-->
            <!--            </a-col>-->

          </a-row>
        </a-form>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>

import {getAction, httpAction} from '@/api/manage'

export default {
  name: 'SuppilerForm',
  components: {},
  props: {
    //流程表单data
    formData: {
      type: Object,
      default: () => {
      },
      required: false
    },
    //表单模式:true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      form: this.$form.createForm(this),
      model: {},
      id: '',
      suppiler_code: "",
      suppiler_name: "",
      isCell: "",
      unit: "",
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      validatorRules: {
        suppiler_code: {
          rules: [
            {required: true, message: '请选择供应商'},
          ]
        },
        isCell: {
          rules: [
            {required: true, message: '请选择是否合并!'},
          ]
        },
      },
      url: {
        add: "/working/working/bindSuppiler",
        edit: "/working/working/bindSuppiler",
        queryById: "/working/working/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    //如果是流程中表单,则需要加载流程表单data
    this.showFlowData();
  },
  methods: {
    add() {
      this.edit({});
    },
    findCarNumberClick(row) {
      this.suppiler_name = row.partnershortname;
      this.suppiler_code = row.partnerid;
    },
    findCraftNumberClick(row) {

    },
    edit(ids) {
      this.id = '';
      this.id = ids;
      this.visible = true;
    },
    handleCancel() {

      this.visible = false;
    },
    handleOk() {
      this.visible = false;
    },
    //渲染流程表单数据

    showFlowData() {
      if (this.formBpm === true) {
        let params = {id: this.formData.dataId};
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result);
          }
        });
      }
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          httpurl += this.url.add;
          method = 'post';
          this.model.id = this.id;
          if (this.suppiler_code == '') {
            that.$message.error("请选择供应商!!");
            that.confirmLoading = false;
            return false;
          }
          if (this.isCell == undefined || this.isCell == '') {
            that.$message.error("请选择是否合并!!");
            that.confirmLoading = false;
            return false;
          }

          if (this.unit == undefined || this.isCell == '') {
            that.$message.error("请选择单位!!");
            that.confirmLoading = false;
            return false;
          }

          this.model.suppilerCode = this.suppiler_code;
          this.model.suppilerName = this.suppiler_name;
          this.model.isCell = this.isCell
          this.model.unit = this.unit
          let formData = Object.assign(this.model, values);
          console.log("表单提交数据", formData)
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              let formData = [];
              this.id = '';
              that.$emit('clearSelect');
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
              that.$emit('clearSelect');
            }
            this.visible = false;
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },

  }
}
</script>