TblOrderFormModal.vue 10.1 KB
<template>
  <j-modal :title="title" :width="width" :visible="visible" :confirmLoading="confirmLoading" :maskClosable="false"
    switchFullscreen @ok="handleOk" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订货单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderCompany" >
              <!-- <a-input v-model="model.orderCompany" placeholder="请输入订货单位"></a-input> -->
              <a-select  size="small"  v-model="model.orderCompany"  placeholder="请输入订货单位" allowClear show-search :filter-option="filterOption" mode="SECRET_COMBOBOX_MODE_DO_NOT_USE">
                <a-select-option v-for="(item,index) in orderCompanyList" :key="index" :value="item">{{ item }}</a-select-option>
              </a-select>
            </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="请输入工作令"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
              <!-- <a-input v-model="model.productName" placeholder="请输入产品名称"></a-input> -->
              <a-select  size="small"  v-model="model.productName"  placeholder="请输入产品名称" allowClear show-search :filter-option="filterOptionProductName" mode="SECRET_COMBOBOX_MODE_DO_NOT_USE">
                <a-select-option v-for="(item,index) in productNameList" :key="index" :value="item">{{ item }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productType">
              <a-select  size="small"  v-model="model.productType"  placeholder="请选择产品类型" allowClear>
                <a-select-option v-for="(item,index) in options" :key="index" :value="item.productTypeId">{{ item.productTypeName }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数量(套)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input v-model="model.quantity" placeholder="请输入数量(套)"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总工时" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input v-model="model.totalWorkingHours" placeholder="请输入总工时"></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="订单日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderDate">
              <j-date placeholder="请选择订单日期" v-model="model.orderDate" style="width: 100%"
                :disabled-date="disabledEndDate" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="派工日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dispatchDate">
              <j-date placeholder="请选择派工日期" v-model="model.dispatchDate" style="width: 100%"
                :disabled-date="disabledEndDate"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交货日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryDate">
              <j-date placeholder="请选择交货日期" v-model="model.deliveryDate" style="width: 100%"
                :disabled-date="disabledEndDate" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="主料图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pics">
              <j-image-upload isMultiple v-model="model.pics"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="主料图文件上传" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pics">
              <j-upload isMultiple v-model="model.files"></j-upload>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="文件上传" prop="files">
              <j-upload v-model="model.files"></j-upload>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>

import { httpAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { duplicateCheck } from '@/api/api'
import {listProductType,getOrderCompanyList,getProductNameList} from '@/api/ProductTpye'
import moment from 'moment'

export default {
  name: "TblOrderFormModal",
  components: {
  },
  data() {
    return {
      title: "操作",
      options:[],
      width: 800,
      visible: false,
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      validatorRules: {
        // orderId: [
        //   { required: true, message: '请输入主料号!' },
        //   { validator: this.validateBidNo }
        // ],
        orderCompany: [
          { required: true, message: '请输入订货单位!' },
        ],
        workOrder: [
          { required: true, message: '请输入工作令!' },
        ],
        productName: [
          { required: true, message: '请输入产品名称!' },
        ],
        productType: [
          { required: true, message: '请输入产品类型!' },
        ],
        quantity: [
          { required: true, message: '请输入数量!' },
        ],
        dispatchDate: [
          { required: true, message: '请输入派工日期!' },
        ],
        deliveryDate: [
          { required: true, message: '请输入交货日期!' },
        ],
      
      },
      url: {
        add: "/order_form/tblOrderForm/add",
        edit: "/order_form/tblOrderForm/edit",
      },
      productNameList:[],
        orderCompanyList:[]
    }
  },
  created() {
    // this.model.status = '未下单'
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
   
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
      this.loadTree()
      this.loadOrderCompanyList()
    this.loadProductNameList()
    },
    loadTree(){
        var that = this;
        listProductType().then((res)=>{
          if(res.success){
            // that.treeData = [];
            that.options = res.result
          }
        });
      },
      loadOrderCompanyList(){
        getOrderCompanyList().then((res)=>{
          if(res.success){
            this.orderCompanyList = res.result
            console.log('getOrderCompanyList',res)
          }
        });
      },
      loadProductNameList(){
        getProductNameList().then((res)=>{
          if(res.success){
            this.productNameList = res.result
            console.log('getProductNameList',res)
          }
        });
      },
      filterOption(input, option) {
        // console.log(input)
        // var temp = option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        // if(temp){
        //   return temp
        // }else{
        //   this.model.orderCompany = input
        // }
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      filterOptionProductName(input, option) {
        // console.log(input)
        // var temp = option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        // if(temp){
        //   return temp
        // }else{
        //   this.model.productName = input
        // }
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
    close() {
      this.$emit('close');
      this.visible = false;
      this.$refs.form.clearValidate();
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          //if(!this.model.pics && !this.model.files){
            //this.$message.warning("请上传主料图片或主料图文件!")
            //return
          //}
          // console.log(this.model)
          // return
          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;
            that.close();
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    validateBidNo(rule, value, callback) {
      var params = {
        tableName: 'tbl_order_form',
        fieldName: 'order_id',
        fieldVal: value,
        dataId: this.model.id,
      }
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback()
        } else {
          callback('编号已存在!')
        }
      })
    },
    disabledEndDate(val) {
      return val <= moment(new Date(), 'YYYY-MM-DD HH:mm:ss').subtract(1, 'minute').endOf('minute')
    },

  }
}
</script>