LR 2 years ago
parent
commit
eca88fd0ac

+ 1 - 1
.eslintrc.js

@@ -230,7 +230,7 @@ module.exports = {
       }
     ],
     'space-before-blocks': [2, 'always'],
-    'space-before-function-paren': [2, 'never'],
+    'space-before-function-paren': 0,
     'space-in-parens': [2, 'never'],
     'space-infix-ops': 2,
     'space-unary-ops': [

+ 7 - 0
src/api/marterial/index.js

@@ -12,3 +12,10 @@ export const fetchRestMaterial = (processId) =>
     method: 'get',
     params: { processId }
   })
+
+export const fetchDispatchedMaterial = (processId) =>
+  request({
+    url: '/tofly-flow/tfprojectmaterialw/page',
+    method: 'get',
+    params: { processId, materialTypeList: 2, current: 1, size: 9999 }
+  })

+ 1 - 0
src/views/zhpt/projectManager/newInstall/common/mixins/index.js

@@ -2,3 +2,4 @@ export { default as InputMixin } from './input'
 export { default as DetailMixin } from './detail'
 export { default as PageMixin } from './page'
 export { default as ProjectSelectorMixin } from './projectSelector'
+export { default as MaterialTableMixin } from './materialTable'

+ 14 - 8
src/views/zhpt/projectManager/newInstall/common/mixins/input.js

@@ -1,12 +1,11 @@
 import NodeHandle from '@/components/projectCom/nodeHandle/index.vue'
 import InputLegend from '@/components/projectCom/legend/index.vue'
 import InputForm from '@/components/projectCom/inputForm/index.vue'
-import MaterialTable from '@/views/zhpt/projectManager/newInstall/components/MaterialTable.vue'
 import { pick, omit, isEmpty } from 'lodash'
 import { getProcesssById } from '@/api/flowInfo'
 import { findStepDatamap } from '@/views/zhpt/projectManager/newInstall/common/config'
 export default {
-  components: { NodeHandle, InputLegend, InputForm, MaterialTable },
+  components: { NodeHandle, InputLegend, InputForm },
   props: { inputData: { type: Object, default: () => ({}) } },
   inject: ['refetch'],
   data() {
@@ -23,26 +22,32 @@ export default {
       const { tenantId } = flowConfigInfo || {}
       return tenantId
     },
+
     configId() {
       const { flowConfigInfo } = this.inputData || {}
       const { id: configId } = flowConfigInfo || {}
       return configId
     },
+
     processId() {
       const { processId } = this.inputData.data || {}
       return processId
     },
+
     mainProcessId() {
       const { id } = this.inputData.data || {}
       return id
     },
+
     service() {
       const { currentserviceImpls } = this.inputData || {}
       return currentserviceImpls
     },
+
     savedData() {
       return findStepDatamap(this.detail, this.service, this.$route.name)
     },
+
     nodeHandleConfig() {
       const { annex } = this.savedData || {}
       return {
@@ -60,6 +65,7 @@ export default {
         return []
       }
     },
+
     getFileConfig(fileStr) {
       if (!fileStr) return []
       const files = this.parse(fileStr)
@@ -69,14 +75,15 @@ export default {
         uid: String(item.otherName || '').replace(/\D/g, '')
       }))
     },
+
     closePage() {
       this.$emit('input', false)
       this.refetch()
     },
+
     validate() {
       let validateResult = true
       for (const item in this.ruleFormList) {
-        console.log(item)
         if (this.ruleFormList[item] && this.ruleFormList[item].validate) {
           this.ruleFormList[item].validate((e) => {
             if (!e) validateResult = e
@@ -88,6 +95,7 @@ export default {
       }
       return validateResult
     },
+
     getFormData(extend = {}, isSign = false, mapExtend = {}, getMapData) {
       let formData = Object.keys(this.ruleFormList).reduce((acc, current) => {
         const { ruleForm } = this.ruleFormList[current] || {}
@@ -135,6 +143,7 @@ export default {
 
       return { files, dto: new Blob([JSON.stringify(formData)], { type: 'application/json' }) }
     },
+
     async fetchSaveData() {
       if (!this.processId) return
       this.fetchingDetail = true
@@ -146,6 +155,7 @@ export default {
       }
       this.fetchingDetail = false
     },
+
     getFormData1({
       extend = {},
       isNode = false,
@@ -243,12 +253,8 @@ export default {
       return [formData, data]
     }
   },
+
   created() {
     this.fetchSaveData()
-  },
-  watch: {
-    savedData(val) {
-      console.log(val)
-    }
   }
 }

+ 51 - 7
src/views/zhpt/projectManager/newInstall/common/mixins/materialTable.js

@@ -1,19 +1,63 @@
 import MaterialTable from '@/views/zhpt/projectManager/newInstall/components/MaterialTable.vue'
-import { fetchRestMaterial } from '@/api/marterial'
+import {
+  fetchRestMaterial
+  // fetchDispatchedMaterial
+} from '@/api/marterial'
+import { isEmpty } from 'lodash'
 
 export default {
   components: { MaterialTable },
   props: { inputData: { type: Object, default: () => ({}) } },
   inject: ['refetch'],
   data() {
-    return {}
-  },
-  computed: {
-    defaultMaterialData() {
-      return []
+    return {
+      fetchingRestOfMaterials: false,
+      // fetchingDispatchedMaterials: false,
+      restOfMaterials: []
+      // dispatchedMaterials: []
     }
   },
   methods: {
-    fetchRestMaterial(id)
+    async fetchRestMaterial(id) {
+      this.fetchingRestOfMaterials = true
+      try {
+        const { data } = await fetchRestMaterial(id)
+        if (isEmpty(data)) {
+          this.$message.warning('该工程未派工,不能领料')
+        }
+        this.restOfMaterials = data || []
+      } catch (error) {
+        console.log(error)
+      }
+      this.fetchingRestOfMaterials = false
+    }
+    // async fetchDispatchedMaterial(id) {
+    //   this.fetchingDispatchedMaterials = true
+    //   try {
+    //     const {
+    //       data: { records }
+    //     } = await fetchDispatchedMaterial(id)
+    //     if (isEmpty(records)) {
+    //       this.$message.warning('该工程未派工,不能领料')
+    //     }
+    //     this.dispatchedMaterials = records || []
+    //   } catch (error) {
+    //     console.log(error)
+    //   }
+    //   this.fetchingDispatchedMaterials = false
+    // }
+  },
+  watch: {
+    mainProcessId: {
+      handler(val) {
+        if (val) {
+          console.log('fetchRestMaterial: ', val)
+          // console.log('fetchDispatchedMaterial: ', val)
+          this.fetchRestMaterial(val)
+          // this.fetchDispatchedMaterial(val)
+        }
+      },
+      immediate: true
+    }
   }
 }

+ 14 - 0
src/views/zhpt/projectManager/newInstall/common/mixins/projectSelector.js

@@ -25,14 +25,17 @@ export default {
     onChooseProject() {
       this.dialogVisible = true
     },
+
     onProjectChange(data) {
       const { processId, ...rest } = data
       this.onProjectChoose({ id: processId, ...rest })
     },
+
     onProjectChoose(data) {
       this.currentMainProcess = data
       this.fetchMainProcessData(data.id)
     },
+
     async fetchMainProcessData(id) {
       if (!id) return
       this.fetchingMainProcessDetail = true
@@ -44,5 +47,16 @@ export default {
       }
       this.fetchingMainProcessDetail = false
     }
+  },
+  watch: {
+    mainProcessId: {
+      handler(val) {
+        if (val) {
+          console.log('fetchMainProcessData: ', val)
+          this.fetchMainProcessData(val)
+        }
+      },
+      immediate: true
+    }
   }
 }

+ 109 - 9
src/views/zhpt/projectManager/newInstall/components/MaterialTable.vue

@@ -1,13 +1,28 @@
 <template>
   <el-table size="mini" :data="data" style="width: 100%" border :header-cell-style="rowStyle">
     <el-table-column type="index" label="序号" align="center" width="50px" />
-    <el-table-column prop="matterP.matterTypeName" label="材料类型" align="center" />
-    <el-table-column prop="matterP.matterName" label="材料名称" align="center" />
-    <el-table-column prop="matterP.standards" label="规格" align="center" />
-    <el-table-column prop="matterP.unit" label="单位" align="center" />
-    <el-table-column prop="matterP.matterPrice.price" label="售价(元)" align="center" />
-    <el-table-column prop="matterP.matterPrice.installPrice" label="人工单价(元)" align="center" />
-    <el-table-column prop="quantity" :label="quantityName" align="center" />
+    <template v-for="{ max, align, ...col } in cols">
+      <el-table-column
+        :key="col.prop"
+        v-bind="col"
+        :align="align || 'center'"
+        :header-align="align || 'center'"
+        :show-overflow-tooltip="!inputKeys.includes(col.prop) || isDetail"
+      >
+        <template v-if="!isDetail && inputKeys.includes(col.prop)" v-slot:default="{ row }">
+          <el-input-number
+            v-if="col.prop === 'quantity'"
+            v-model="row.quantity"
+            size="small"
+            :min="1"
+            :max="max && max(row)"
+            style="width:100%"
+          />
+          <el-input v-else v-model="row.remark" size="small" style="width:100%" maxlength="255" />
+        </template>
+      </el-table-column>
+    </template>
+
     <template v-slot:empty>
       <el-empty :image="nullPng" />
     </template>
@@ -18,11 +33,96 @@
 import nullPng from '@/assets/icon/null.png'
 export default {
   name: 'MaterialTable',
-  props: { data: { type: Array, default: () => ({}) }, quantityName: { type: String, default: '预算量' } },
+  props: {
+    data: { type: Array, default: () => ({}) },
+    /** 物资类型 1预算;2开工;3领料;4补料;5退料;6其它;7验收申请 */
+    type: { type: Number, default: 0 },
+    isDetail: { type: Boolean, default: false }
+  },
   data() {
     return {
       nullPng,
-      rowStyle: { background: 'rgba(250,250,250)', color: 'rgb(50,59,65)', height: '39px', textAlign: 'center' }
+      rowStyle: { background: 'rgba(250,250,250)', color: 'rgb(50,59,65)', height: '39px' },
+      inputKeys: ['quantity', 'remark'],
+      tableData: []
+    }
+  },
+  computed: {
+    cols() {
+      const dynamicCols = (() => {
+        // quantityAll 预算量+补料量
+        // receivedNum 已领量
+        // supplyNum 补充量
+        // returnNums 退料量
+        switch (this.type) {
+          // 领料
+          case 3: {
+            return [
+              { prop: 'receivedNum', label: '已领取', width: '80px' },
+              {
+                prop: 'quantity',
+                label: '本次领取',
+                width: '150px',
+                max: ({ quantityAll, receivedNum, returnNums }) => +quantityAll - +receivedNum + +returnNums
+              }
+            ]
+          }
+          // 补料
+          case 4: {
+            return [
+              { prop: 'receivedNum', label: '已领取', width: '80px' },
+              { prop: 'quantity', label: '本次增加预算', max: () => 99999, width: '150px' }
+            ]
+          }
+          // 退料
+          case 5: {
+            return [
+              { prop: 'receivedNum', label: '已领取', width: '80px' },
+              {
+                prop: 'quantity',
+                label: '退料量',
+                width: '150px',
+                max: ({ receivedNum, returnNums }) => +receivedNum - +returnNums
+              },
+              {
+                prop: 'actual',
+                label: '实际使用量',
+                formater: ({ receivedNum, returnNums, quantity }) => +receivedNum - +returnNums - +quantity
+              }
+            ]
+          }
+
+          default: {
+            return []
+          }
+        }
+      })()
+      return [
+        { prop: 'categoryName', label: '材料类别', width: '90px' },
+        { prop: 'matterTypeName', label: '材料类型', width: '90px' },
+        { prop: 'matterName', label: '材料名称', minWidth: '120px', align: 'left' },
+        { prop: 'standards', label: '规格', width: '90px' },
+        { prop: 'unit', label: '单位', width: '90px' },
+        { prop: 'price', label: '售价(元)', width: '80px' },
+        { prop: 'installPrice', label: '人工单价(元)', width: '90px' },
+        { prop: 'quantityAll', label: '预算量', width: '80px' },
+        ...dynamicCols,
+        { prop: 'remark', label: '备注', width: '130px' }
+      ].filter((item) => {
+        if (item.prop === 'quantity') {
+          return !this.isDetail
+        }
+        return true
+      })
+    }
+  },
+  watch: {
+    data: {
+      handler(val) {
+        if (val) {
+          this.tableData = [...val]
+        }
+      }
     }
   }
 }

+ 12 - 29
src/views/zhpt/projectManager/newInstall/recieveMaterial/addProject/inputPage.vue

@@ -21,7 +21,7 @@
       </input-legend>
       <input-legend :label="'材料信息'" isopen="true">
         <div style="margin-bottom: 10px;">
-          <material-table ref="materialRef" :data="defaultMaterialData" />
+          <material-table ref="materialRef" :data="restOfMaterials" :type="3" />
         </div>
       </input-legend>
       <node-handle ref="nextNodeInfo" v-model="ruleFormList.form2" :input-data="inputData" :set-show="setShow" />
@@ -34,25 +34,26 @@
     <project-selector
       :id="39"
       :visible.sync="dialogVisible"
-      :query="{ tenantId, configId: MAIN_CONFIG_ID }"
+      :query="{ tenantId, configId: mainConfigId }"
       @choose="onProjectChoose"
     />
   </div>
 </template>
 
 <script>
-import ProjectSelector from '@/views/zhpt/projectManager/newInstall/components/ProjectSelector.vue'
-import { InputMixin, ProjectSelectorMixin } from '@/views/zhpt/projectManager/newInstall/common/mixins'
+import {
+  InputMixin,
+  ProjectSelectorMixin,
+  MaterialTableMixin
+} from '@/views/zhpt/projectManager/newInstall/common/mixins'
 import { addFlow } from '@/api/flowInfo.js'
 import { getAllUser } from '@/api/base'
-import { isEmpty } from 'lodash'
 import { MAIN_CONFIG_ID } from '@/views/zhpt/projectManager/newInstall/common/config'
 
 const DISPATCH_SERVICE_NAME = 'tfProjectDispatchWService'
 
 export default {
-  components: { ProjectSelector },
-  mixins: [InputMixin, ProjectSelectorMixin],
+  mixins: [InputMixin, ProjectSelectorMixin, MaterialTableMixin],
   data() {
     return {
       title: '工程领料',
@@ -69,6 +70,7 @@ export default {
           {
             group: [
               { field: 'dataTime', value: dataTime, label: '领料日期', type: 'date', required: true },
+
               {
                 field: 'adder',
                 value: adder,
@@ -79,7 +81,7 @@ export default {
                 config: {
                   multiple: false,
                   searchData: { depts: buildUnit },
-                  method: buildUnit ? getAllUser : () => [],
+                  method: buildUnit ? getAllUser : async () => [],
                   field: { id: 'realName', label: 'realName' }
                 }
               },
@@ -89,29 +91,9 @@ export default {
           }
         ]
       }
-    },
-
-    defaultMaterialData() {
-      const saved = this.savedData.dataMap
-      const transform = ({ quantity, matterP, id }) => ({ ...matterP, quantity, _id: id })
-      if (!isEmpty(saved)) {
-        return (Array.isArray(saved) ? saved : [saved]).map(transform)
-      }
-
-      const dispatch =
-        (this.mainProcessDetail.nodes || []).find((item) => {
-          const { dataMap } = item
-          return !!(dataMap || {})[DISPATCH_SERVICE_NAME]
-        }) || {}
-      const { [DISPATCH_SERVICE_NAME]: materialData } = dispatch.dataMap || {}
-      const { materialList } = (materialData || [])[0] || {}
-      if (Array.isArray(materialList)) {
-        return materialList.map(transform)
-      }
-
-      return []
     }
   },
+
   methods: {
     async onSubmit(save) {
       if (!this.mainProcessId) {
@@ -137,6 +119,7 @@ export default {
       )
       const formData = new FormData()
       formData.append('dto', dto)
+
       if (files) {
         const { addFile } = files
         if (addFile && addFile.length > 0) {