cuijian
2023-10-24 7f98d8bf975e89b8ced554916d3a46739f5275d3
src/views/spare/modules/sparePartScrapRequirement/SparePartScrapRequirementForm.vue
@@ -1,38 +1,46 @@
<template>
  <a-spin :spinning='confirmLoading'>
    <j-form-container :disabled='formDisabled'>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref='form' :model='model' :rules='validatorRules' slot='detail'>
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span='12'>
            <a-form-model-item label='单据号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='num'>
              <a-input v-model='model.num' placeholder='请输入单据号'></a-input>
          <a-col :span="12">
            <a-form-model-item label="单据号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num">
              <a-input v-model="model.num" placeholder="将由系统自动生成" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='申请部门' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='departId'>
          <a-col :span="12">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
              <!--              <a-input v-model="model.departId" placeholder="请输入领用部门ID" ></a-input>-->
<!--              <j-dict-select-tag
                allow-clear
                :placeholder="'请选择申请部门'"
                v-model='model.departId'
                dictCode="sys_depart,depart_name,id,del_flag!='1'"
              />-->
              <a-select
                :placeholder="'请选择申请部门'"
                :options="this.departs"
              <!--              <j-dict-select-tag
                              allow-clear
                              :placeholder="'请选择申请部门'"
                              v-model='model.departId'
                              dictCode="sys_depart,depart_name,id,del_flag!='1'"
                            />-->
              <a-tree-select
                style="width: 100%"
                v-model='model.departId'
                :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                :tree-data="treeData"
                placeholder="请选择申请部门"
                tree-default-expand-all
                v-model="model.departId"
              />
              <!--              <a-select
                              :placeholder="'请选择申请部门'"
                              :options="this.departs"
                              style="width: 100%"
                              v-model='model.departId'
                            />-->
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='备注' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='remark'>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <!--              <a-input v-model="model.userId" placeholder="请输入领用人员ID" ></a-input>-->
              <a-textarea
                allow-clear
                :placeholder="'请输入备注'"
                v-model='model.remark'
                v-model="model.remark"
              />
            </a-form-model-item>
          </a-col>
@@ -41,24 +49,26 @@
      </a-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <a-tabs v-model='activeKey' @change='handleChangeTabs'>
      <a-tab-pane tab='备件报废明细表' :key='refKeys[0]' :forceRender='true'>
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="备件报废明细表" :key="refKeys[0]" :forceRender="true">
        <j-vxe-table
          keep-source
          :ref='refKeys[0]'
          :loading='sparesScrapRequirementDetailTable.loading'
          :columns='sparesScrapRequirementDetailTable.columns'
          :dataSource='sparesScrapRequirementDetailTable.dataSource'
          :maxHeight='300'
          :disabled='formDisabled'
          :rowNumber='true'
          :rowSelection='true'
          :toolbar='true'
          :toolbarConfig='toolbarConfig'
          :ref="refKeys[0]"
          :loading="sparesScrapRequirementDetailTable.loading"
          :columns="sparesScrapRequirementDetailTable.columns"
          :dataSource="sparesScrapRequirementDetailTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :alwaysEdit="true"
          :rowNumber="true"
          :bordered="bordered"
          :rowSelection="true"
          :toolbar="true"
          :toolbarConfig="toolbarConfig"
        >
          <template slot='toolbarPrefix'>
            <a-button type='primary' @click='selectEquipmentList' :disabled='formDisabled'>选择备件
          <template slot="toolbarPrefix">
            <a-button type="primary" @click="selectEquipmentList" :disabled="formDisabled">选择备件
            </a-button>
          </template>
          <!--          <template slot='toolbarPrefix'>
@@ -68,8 +78,7 @@
        </j-vxe-table>
      </a-tab-pane>
    </a-tabs>
    <spare-select-list ref='SparesSelectModal'></spare-select-list>
    <!--    <spare-requirement-select-modal ref='SpareRequirementSelecModal'></spare-requirement-select-modal>-->
    <spare-select-list ref="SparesSelectModal"></spare-select-list>
  </a-spin>
</template>
@@ -81,7 +90,6 @@
import JFormContainer from '@comp/jeecg/JFormContainer'
import SpareSelectList from './SpareSelectList'
import { getAction } from '@api/manage'
/*import SpareRequirementSelectModal from './SpareRequirementSelectModal'*/
export default {
  name: 'SparePartScrapRequirementForm',
  mixins: [JVxeTableModelMixin],
@@ -92,6 +100,8 @@
  },
  data() {
    return {
      treeData: [],
      bordered: true,
      departs: [],
      labelCol: {
        xs: { span: 24 },
@@ -133,6 +143,7 @@
            title: '备件编码',
            key: 'spareNum',
            fixed: 'left',
            align: 'center',
            type: JVXETypes.normal,
            width: '200px',
            placeholder: '请输入${title}',
@@ -141,6 +152,7 @@
          {
            title: '备件名称',
            key: 'spareName',
            align: 'center',
            fixed: 'left',
            type: JVXETypes.normal,
            width: '200px',
@@ -151,6 +163,7 @@
            title: '型号',
            key: 'model',
            type: JVXETypes.normal,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
@@ -159,61 +172,69 @@
            title: '规格',
            key: 'specification',
            type: JVXETypes.normal,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '主单位',
            title: '单位',
            key: 'mainUnitIdName',
            type: JVXETypes.normal,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '主单位',
            title: '单位',
            key: 'mainUnitId',
            type: JVXETypes.hidden,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '辅单位',
            key: 'auxiliaryUnitIdName',
            type: JVXETypes.normal,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '辅单位',
            key: 'auxiliaryUnitId',
            type: JVXETypes.hidden,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          /*  {
             title: '辅单位',
             key: 'auxiliaryUnitIdName',
             align:'center',
             type: JVXETypes.normal,
             width: '200px',
             placeholder: '请输入${title}',
             defaultValue: ''
           },
           {
             title: '辅单位',
             key: 'auxiliaryUnitId',
             type: JVXETypes.hidden,
             align:'center',
             width: '200px',
             placeholder: '请输入${title}',
             defaultValue: ''
           }, */
          {
            title: '主数量',
            key: 'mainQuantity',
            type: JVXETypes.inputNumber,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: 0,
            formatter({ cellValue, row, column }) {
            /*             Function({cellValue, row, column}){
                          console.log(cellValue)
                          console.log(row)
                          console.log(column)
                          if (cellValue != null) {
                            let conversionRatio = row.conversionRatio
                            console.log(conversionRatio)
                            row.auxiliaryQuantity = Math.abs(cellValue * conversionRatio)
              if (cellValue != null) {
                let conversionRatio = row.conversionRatio
                row.auxiliaryQuantity = Math.abs(cellValue * conversionRatio)
              }
              return cellValue
            },
                          }
                          console.log(cellValue)
                          return cellValue
                        }, */
            validateRules: [
              {
                required: true,
@@ -231,18 +252,20 @@
            ]
          },
          {
            title: '辅数量',
            key: 'auxiliaryQuantity',
            type: JVXETypes.normal,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: 0
          },
          /*  {
             title: '辅数量',
             key: 'auxiliaryQuantity',
             type: JVXETypes.normal,
             width: '200px',
             align:'center',
             placeholder: '请输入${title}',
             defaultValue: 0
           }, */
          {
            title: '备件id',
            key: 'sparePartId',
            type: JVXETypes.hidden,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
@@ -251,6 +274,7 @@
            title: '换算比例',
            key: 'conversionRatio',
            type: JVXETypes.hidden,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
@@ -260,6 +284,7 @@
            title: '需求日期',
            key: 'requirementTime',
            type: JVXETypes.date,
            align: 'center',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
@@ -277,7 +302,9 @@
        add: '/spare/sparePartRequirement/add',
        edit: '/spare/sparePartRequirement/edit',
        queryById: '/spare/sparePartRequirement/queryById',
        getSysDeparts: "/eam/equipment/getSysDeparts",
        loadOptions: '/sys/sysDepart/loadDepartTreeOptions',
        getSysDeparts: '/eam/equipment/getSysDeparts',
        getNum: '/eam/sysIdentity/getNumNew',
        sparesScrapRequirementDetail: {
          list: '/spare/sparePartRequirement/querySparesScrapRequirementDetailByMainId'
        }
@@ -310,9 +337,69 @@
    })
  },
  created() {
    this.getSysDeparts()
    this.initOptions()
    this.initNum()
  },
  methods: {
    /*     edit(record) {
          this.form.resetFields();
          this.model = Object.assign({}, record);
          this.visible = true;
          this.disableSubmit = false;
          this.auxiliaryUnits = record.auxiliaryUnits
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.model,
              'num',
              'name',
              'specification',
              'model',
              'constructorId',
              'mainUnitId',
              'auxiliaryUnitId',
              'conversionRatio',
              'validityPeriod',
              'validityPeriodUnitId',
              'inventoryUpperLimit',
              'inventoryLowerLimit',
              'economicOrderQuantity',
              'purchaseLeadTime',
              'inventoryWarnLimit',
              'remark'));
          });
          if (record.id) {
            this.codeDisable = true;
          } else {
            this.codeDisable = false;
            this.$nextTick(() => {
              getAction(this.url.getNum, { type: 'SparePart', length: '4' }).then((res) => {
                if (res.success) {
                  this.form.setFieldsValue({ num: res.message });
                }
              })
            });
          }
        }, */
    initNum() {
      getAction(this.url.getNum, { type: 'SparePartRequirement', length: '4' }).then((res) => {
        if (res.success) {
          this.model.num = res.message
          /* this.model.setFieldsValue({ num: res.message }); */
        }
      })
    },
    initOptions() {
      getAction(this.url.loadOptions).then(res => {
        if (res.success) {
          this.treeData = res.result
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    getSysDeparts() {
      getAction(this.url.getSysDeparts).then((res) => {
        if (res.success) {
@@ -359,8 +446,6 @@
            auxiliaryUnitId: data[i].auxiliaryUnitId,
            mainUnitIdName: data[i].mainUnitId_dictText,
            auxiliaryUnitIdName: data[i].auxiliaryUnitId_dictText,
            mainQuantity: data[i].mainQuantity,
            auxiliaryQuantity: data[i].auxiliaryQuantity,
            requirementTime: data[i].requirementTime,
            conversionRatio: data[i].conversionRatio
@@ -391,8 +476,8 @@
    //校验所有一对一子表表单
    validateSubForm(allValues) {
      let tableData = this.$refs.sparesScrapRequirementDetail.getTableData()
      if(tableData.length == 0){
        this.$message.warning("请添加加报废明细!");
      if (tableData.length == 0) {
        this.$message.warning('请添加加报废明细!')
        return
      }
      return new Promise((resolve, reject) => {
@@ -424,6 +509,13 @@
      this.$emit('close')
      this.$refs.form.clearValidate()
    }
    /*     changeAuxiliaryQuantity(target){
          console.log(target.columnIndex)
          let num=target.columnIndex
          if (target.columnIndex ===num){
            target.row.auxiliaryQuantity=Math.abs(target.row.conversionRatio*target.row.mainQuantity)
          }
        } */
  }
}
</script>