qushaowei
2024-07-25 52190152691bc217844d4f87b700274c297b104e
src/views/eam/modules/repairorder/moudles/RepairOrderActualMaterialReport.vue
@@ -19,6 +19,30 @@
        slot-scope='text, record, index'
      >
        <div :key="col.dataIndex">
          <a-input
            :value="text"
            v-if="col.dataIndex == 'sparePartId'"
            auto-size
            placeholder="请输入物料名称"
            @change="(e)=>handleChange(e, record.key, col, index)"
            :disabled="record.disabled"
          />
          <a-input
            :value="text"
            v-if="col.dataIndex == 'repairOrderAmUda1'"
            auto-size
            placeholder="请输入单位"
            @change="(e)=>handleChange(e, record.key, col, index)"
            :disabled="record.disabled"
          />
          <j-dict-select-tag
            :value='text'
            v-if="col.dataIndex == 'outboundOrderId'"
            dictCode="material_type"
            :disabled="false"
            style="width: 100%;"
            @change='(e)=>handleChange(e, record.key, col, index)'
          />
          <a-input-number
            :value="text"
            v-if="col.dataIndex == 'actualQuantity'"
@@ -31,6 +55,15 @@
        </div>
      </template>
      <span
        slot='action'
        slot-scope='text, record,index'
      >
        <a
          :disabled="mainId.status=='4'"
          @click='handleDelete(index)'
        >删除</a>
      </span>
      <!-- <span
        slot='action'
        slot-scope='text, record'
      >
@@ -56,34 +89,37 @@
        >
          <a v-if="record.isLock=='no'&&mainId.status=='3'">删除</a>
        </a-popconfirm>
      </span>
      </span> -->
    </a-table>
    <a-button
      style="width: 100%; margin-top: 16px; margin-bottom: 8px"
      type="dashed"
      icon="plus"
      @click="addMaterial"
      :disabled="mainId.status=='4'"
      :disabled="mainId.status!='3'"
    >添加实际用料</a-button>
    <!-- :disabled="mainId.status!='3'||( mainId.repairOrderUda1!='needPart'&&mainId.repairOrderUda1!='needSpare')" -->
    <div :style="{width: '100%',border: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',}">
      <a-row :style="{textAlign:'right'}">
        <!-- <a-button
        <a-button
          :style="{marginRight: '8px'}"
          @click="handleCancel"
          @click='handleCancel'
        >
          取消
        </a-button> -->
        </a-button>
        <!-- <a-button
          @click="handleOk(1)"
          type="primary"
          @click='handleOk(1)'
          type='primary'
          :style="{marginRight: '8px'}"
          :disabled="specialyMaintenanceOrderStatus!='4'"
        >暂存</a-button>
          :disabled="this.repairOrderStatus=='4' || this.repairOrderStatus=='2'"
        >暂存
        </a-button> -->
        <a-button
          @click="handleOk(0)"
          type="primary"
          :disabled="specialyMaintenanceOrderStatus!='4'"
        >保存</a-button> -->
          @click='handleOk(0)'
          type='primary'
          :disabled="this.mainId.status=='4' || this.mainId.status=='2'"
        >保存
        </a-button>
      </a-row>
      <!-- :disabled="false" -->
    </div>
@@ -96,14 +132,13 @@
import pick from 'lodash.pick'
import JEllipsis from '@/components/jeecg/JEllipsis'
import JSelectSparePartModal from './select/JSelectSparePartModal'
import RepairOrderActualMaterialReportModel   from './RepairOrderActualMaterialReportModel.vue'
// import RepairOrderActualMaterialReportModel from './RepairOrderActualMaterialReportModel.vue'
export default {
  name: 'RepairOrderActualMaterialReport',
  mixins: [JeecgListMixin],
  components: {
    JEllipsis,
    JSelectSparePartModal,
    RepairOrderActualMaterialReportModel
  },
  props: {
    mainId: {
@@ -159,73 +194,55 @@
      dataSource: [],
      columns: [
        {
          title: '领料出库单',
          dataIndex: 'num',
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          width: 150,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '备件编码',
          dataIndex: 'sparePartNum',
          title: '物料名称',
          dataIndex: 'sparePartId',
          scopedSlots: { customRender: 'sparePartId' },
          align: "center",
          // className: 'red',
          // width: 250,
        },
        {
          title: '备件名称',
          dataIndex: 'sparePartName',
          title: '物料种类',
          dataIndex: 'outboundOrderId',
          scopedSlots: { customRender: 'outboundOrderId' },
          align: "center",
        },
        {
          title: '规格',
          dataIndex: 'sparePartSpecification',
          align: "center",
        },
        {
          title: '型号',
          dataIndex: 'sparePartModel',
          align: "center",
        },
        {
          title: '制造商',
          dataIndex: 'constructorName',
          align: "center",
        },
        {
          title: '主单位',
          dataIndex: 'mainUnitName',
          align: "center",
        },
        {
          title: '主数量',
          align: 'center',
          dataIndex: 'mainQuantity'
        },
        {
          title: '可用数量',
          align: 'center',
          dataIndex: 'availableQuantity'
          // width: 250,
        },
        {
          title: '使用数量',
          dataIndex: 'actualQuantity',
          align: "center",
          scopedSlots: { customRender: 'actualQuantity' },
          className: 'red',
          // className: 'red',
        },
        {
          title: '单位',
          dataIndex: 'repairOrderAmUda1',
          scopedSlots: { customRender: 'repairOrderAmUda1' },
          align: "center",
          // className: 'red',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 250,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/eam/repairOrder/listRepairOrderActualMaterialByMainId',
        confirmMaterial: "/eam/repairOrderActualMaterial/add",
        list: '/eam/repairOrderActualMaterial/list',
        confirmMaterial: "/eam/repairOrderActualMaterial/addNew",
        delete: "/eam/repairOrderActualMaterial/delete",
        addInit: "/eam/repairOrderActualMaterial/addInit",
        lock: "/eam/repairOrderActualMaterial/lock",
@@ -237,6 +254,7 @@
  watch: {
    mainId: {
      immediate: true,
      deep: true,
      handler(val) {
        console.log(val)
        if (!this.mainId.id) {
@@ -249,24 +267,26 @@
      }
    }
  },
  created() {
    // this.queryParam['maintenanceOrderId'] = this.dailyMaintenanceOrderId;
    // this.queryParam['equipmentId'] = this.equipmentId
    // this.loadData(1);
    console.log("77777777",this.mainId)
  },
  // created() {
  // this.queryParam['maintenanceOrderId'] = this.dailyMaintenanceOrderId;
  // this.queryParam['equipmentId'] = this.equipmentId
  // this.loadData(1);
  // console.log("77777777", this.mainId)
  // },
  methods: {
    addMaterial() {
      let ids = [];
      for (let i = 0; i < this.dataSource.length; i++) {
        ids.push(this.dataSource[i].outboundOrderDetailId);
      }
      this.$refs.JSelectSparePartModal.showModals(ids);
      this.$refs.JSelectSparePartModal.title = '选择备件信息'
      this.$refs.JSelectSparePartModal.disableSubmit = false
      // let ids = [];
      // for (let i = 0; i < this.dataSource.length; i++) {
      //   ids.push(this.dataSource[i].outboundOrderDetailId);
      // }
      // this.$refs.JSelectSparePartModal.showModals(ids);
      // this.$refs.JSelectSparePartModal.title = '选择备件信息'
      // this.$refs.JSelectSparePartModal.disableSubmit = false
      // this.dataSource.push({ sparePartId: '', outboundOrderId: this.mainId.repairOrderUda1, repairOrderAmUda1: '', actualQuantity: '', repairOrderId: this.mainId.id })
      this.dataSource.push({ sparePartId: '', outboundOrderId: '', repairOrderAmUda1: '', actualQuantity: '', repairOrderId: this.mainId.id })
    },
    handleCancel() {
      this.$bus.$emit('close');
      this.$bus.$emit('closeDrawer')
    },
    close() {
      this.$emit('close');
@@ -281,27 +301,39 @@
      console.log(column)
      const temp = [...this.dataSource]
      const target = temp[index]
      let availableQuantity = target['availableQuantity']
      if (target) {
        if (value != undefined && value != null && value != '' && availableQuantity < value) {
          this.$message.error('使用数量不能大于可用数量!')
        } else {
        }
        target[column.dataIndex] = value
        this.dataSource = temp
      // let availableQuantity = target['availableQuantity']
      // if (target) {
      //   if (value != undefined && value != null && value != '' && availableQuantity < value) {
      //     this.$message.error('使用数量不能大于可用数量!')
      //   } else {
      //   }
      //   target[column.dataIndex] = value
      //   this.dataSource = temp
      // }
      if ('sparePartId' == column.dataIndex) {
        target['sparePartId'] = value.target.value
      }
      if ('repairOrderAmUda1' == column.dataIndex) {
        target['repairOrderAmUda1'] = value.target.value
      }
      if ('actualQuantity' == column.dataIndex) {
        target['actualQuantity'] = value
      }
      if ('outboundOrderId' == column.dataIndex) {
        target['outboundOrderId'] = value
      }
    },
    clearList() {
      this.dataSource = [];
      this.ipagination.current = 1
    },
    getUuiD(randomLength) {
      return Number(
        Math.random()
          .toString()
          .substr(2, randomLength) + Date.now()
      ).toString(36)
    },
    // getUuiD(randomLength) {
    //   return Number(
    //     Math.random()
    //       .toString()
    //       .substr(2, randomLength) + Date.now()
    //   ).toString(36)
    // },
    handleLock(record) {
      let that = this;
      if (record.actualQuantity == null || record.actualQuantity == undefined || record.actualQuantity == '') {
@@ -371,51 +403,98 @@
          this.loading = false
        })
    },
  },
  mounted() {
    let newActualMaterials = [];
    this.$bus.$on('selectionRows', (data) => {
      for (let i = 0; i < data.length; i++) {
        var actualMaterial
          =
        {
          id: this.getUuiD(16),
          num: data[i].num,
          outboundOrderDetailId: data[i].id,
          sparePartId: data[i].sparePartId,
          sparePartNum: data[i].spareNum,
          sparePartName: data[i].spareName,
          sparePartSpecification: data[i].specification,
          sparePartModel: data[i].model,
          constructorName: data[i].constructorName,
          constructorId: data[i].constructorId,
          mainUnitName: data[i].mainUnitName,
          mainUnitId: data[i].mainUnitId,
          mainQuantity: data[i].mainQuantity,
          useQuantity: data[i].useQuantity,
          availableQuantity: data[i].availableQuantity,
          repairOrderId: this.mainId.id,
          equipmentId: this.equipmentId,
          isLock: 'no'
    handleOk(saveStatus) {
      const that = this
      if (saveStatus == 0) {
        let workHoursDataSource = that.dataSource
        for (let i = 0; i < workHoursDataSource.length; i++) {
          if (workHoursDataSource[i].sparePartId == undefined || workHoursDataSource[i].sparePartId == null || workHoursDataSource[i].sparePartId == '') {
            that.$message.warning('请选择第' + (i + 1) + '行物料名称!')
            return false
          }
          if (workHoursDataSource[i].repairOrderAmUda1 == undefined || workHoursDataSource[i].repairOrderAmUda1 == null || workHoursDataSource[i].repairOrderAmUda1 == '') {
            that.$message.warning('请填写第' + (i + 1) + '行单位!')
            return false
          }
          if (workHoursDataSource[i].actualQuantity == undefined || workHoursDataSource[i].actualQuantity == null || workHoursDataSource[i].actualQuantity == '') {
            that.$message.warning('请填写第' + (i + 1) + '行使用数量!')
            return false
          }
          if (workHoursDataSource[i].outboundOrderId == undefined || workHoursDataSource[i].outboundOrderId == null || workHoursDataSource[i].outboundOrderId == '') {
            that.$message.warning('请填写第' + (i + 1) + '行物料种类!')
            return false
          }
        }
        newActualMaterials.push(actualMaterial);
      }
      let that = this
      let obj = obj = postAction(this.url.addInit, newActualMaterials)
      obj.then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
        } else {
          that.$message.warning(res.message)
      if (that.dataSource.length === 0) {
        that.$message.warning('请添加用料!')
        return
      }
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = that.dataSource;
          let obj = obj = postAction(this.url.confirmMaterial, formData)
          obj.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()
            that.loadData(1)
          })
        }
      }).finally(res => {
        that.loadData();
        newActualMaterials = []
      })
    })
    },
    handleDelete(index) {
      console.log(index)
      this.dataSource.splice(index, 1)
    },
  },
  // mounted() {
  //   let newActualMaterials = [];
  //   this.$bus.$on('selection3Rows', (data) => {
  //     for (let i = 0; i < data.length; i++) {
  //       newActualMaterials.push({
  //         // id: this.getUuiD(16),
  //         num: data[i].num,
  //         outboundOrderDetailId: data[i].id,
  //         sparePartId: data[i].sparePartId,
  //         // sparePartNum: data[i].spareNum,
  //         // sparePartName: data[i].spareName,
  //         // sparePartSpecification: data[i].specification,
  //         // sparePartModel: data[i].model,
  //         // constructorName: data[i].constructorName,
  //         // constructorId: data[i].constructorId,
  //         // mainUnitName: data[i].mainUnitName,
  //         // mainUnitId: data[i].mainUnitId,
  //         mainQuantity: data[i].mainQuantity,
  //         useQuantity: data[i].useQuantity,
  //         availableQuantity: data[i].availableQuantity,
  //         repairOrderId: this.mainId.id,
  //         equipmentId: this.equipmentId,
  //         isLock: 'no'
  //       })
  //     }
  //     let that = this
  //     postAction(this.url.addInit, newActualMaterials).then((res) => {
  //       if (res.success) {
  //         that.$message.success(res.message)
  //         newActualMaterials = []
  //         that.$emit('ok')
  //       } else {
  //         that.$message.warning(res.message)
  //       }
  //     }).finally(res => {
  //       that.loadData();
  //     })
  //   })
  // },
}
</script>