| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021 |
- <template>
- <view>
- <cu-custom :backUrl="'/pages/index/index'" :isBack="true" bgColor="bg-gradual-blue">
- <block slot="content">入库修改</block>
- </cu-custom>
- <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules"
- ref="inputForm">
- <u-form-item label="入库编号" borderBottom prop="wareHouseNumber">
- <u--input placeholder="自动生成" v-model="inputForm.wareHouseNumber" disabled></u--input>
- </u-form-item>
- <u-form-item label="入库名称" borderBottom prop="wareHouseName" :required="true">
- <u--input placeholder="请填写入库名称" v-model="inputForm.wareHouseName" :disabled="nodeFlag"></u--input>
- </u-form-item>
- <u-form-item label="经办人" borderBottom prop="handledBy">
- <u--input v-model="inputForm.handledBy" disabled></u--input>
- </u-form-item>
- <u-form-item label="经办部门" borderBottom prop="handledByOfficeName">
- <u--input v-model="inputForm.handledByOfficeName" disabled></u--input>
- </u-form-item>
- <u-form-item label="入库时间" borderBottom prop="wareHouseDate" :required="true">
- <el-date-picker v-model="inputForm.wareHouseDate" type="date" placeholder="请选择入库时间" style="width:100%"
- placement="bottom-start" clearable :disabled="nodeFlag">
- </el-date-picker>
- </u-form-item>
- <purchase-selector :inputForm="inputForm" :disabled="nodeFlag" @selected="handlePurchaseSelected">
- </purchase-selector>
- <u-form-item label="备注" borderBottom prop="remarks">
- <u--textarea placeholder="请填写备注信息" :rows="4" :maxlength="500" v-model="inputForm.remarks"
- :disabled="nodeFlag"></u--textarea>
- </u-form-item>
- <view v-if="inputForm.purchaseNo" class="section-wrap">
- <view class="section-title">采购详情</view>
- <view v-for="(item, index) in inputForm.detailInfos" :key="item.id || index" class="detail-card">
- <view class="detail-card-title">采购明细 {{ index + 1 }}</view>
- <view class="detail-grid">
- <view class="detail-item">
- <text class="detail-label">采购人</text>
- <text class="detail-value">{{ item.purchaserAgent || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">采购部门</text>
- <text class="detail-value">{{ item.procurementOffice || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">采购类型</text>
- <text class="detail-value">{{ item.procurementType || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">商品名称</text>
- <text class="detail-value">{{ item.tradeName || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">供应商</text>
- <text class="detail-value">{{ item.supplierName || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">商品数量</text>
- <text class="detail-value">{{ item.tradeNumber || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">商品单价</text>
- <text class="detail-value">{{ item.tradePrice || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">商品总价</text>
- <text class="detail-value">{{ item.priceSum || '-' }}</text>
- </view>
- </view>
- </view>
- </view>
- <view class="section-wrap">
- <view class="section-title">入库修改详情</view>
- <view v-for="(item, index) in inputForm.wareHouse" :key="item.id || index"
- class="detail-card warehouse-card" :class="statusClass(item)">
- <view class="detail-card-head">
- <view class="detail-card-title">入库明细 {{ index + 1 }}</view>
- <view v-if="statusLabel(item)" class="status-badge" :class="statusBadgeClass(item)">
- {{ statusLabel(item) }}
- </view>
- </view>
- <u-form-item label="入库人" :prop="'wareHouse[' + index + '].wareHouseMan'" :required="true">
- <u--input v-model="inputForm.wareHouse[index].wareHouseMan" placeholder="请选择入库人"
- :disabled="nodeFlag" @focus="openUserPullForm(index)" clearable></u--input>
- </u-form-item>
- <u-form-item label="入库部门" :prop="'wareHouse[' + index + '].wareHouseManOffice'">
- <u--input v-model="inputForm.wareHouse[index].wareHouseManOffice" disabled></u--input>
- </u-form-item>
- <u-form-item label="入库类型" :prop="'wareHouse[' + index + '].wareHouseType'" :required="true">
- <u--input v-model="inputForm.wareHouse[index].wareHouseType" placeholder="请选择入库类型"
- :disabled="nodeFlag" @focus="openTypePicker(index)" clearable></u--input>
- </u-form-item>
- <ware-house-goods-selector :rowIndex="index" :inputForm="inputForm" :disabled="nodeFlag"
- @selected="handleGoodsSelected"></ware-house-goods-selector>
- <ware-house-supplier-selector :rowIndex="index" :inputForm="inputForm" :disabled="nodeFlag"
- @selected="handleSupplierSelected"></ware-house-supplier-selector>
- <u-form-item label="商品数量" :prop="'wareHouse[' + index + '].tradeNumber'" :required="true">
- <u--input v-model="inputForm.wareHouse[index].tradeNumber" placeholder="请输入商品数量"
- :disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
- </u-form-item>
- <u-form-item label="单位" :prop="'wareHouse[' + index + '].company'">
- <u--input v-model="inputForm.wareHouse[index].company" placeholder="请输入单位" :disabled="nodeFlag"
- @blur="markWareHouseModified(index)"></u--input>
- </u-form-item>
- <u-form-item label="包装规格" :prop="'wareHouse[' + index + '].spec'">
- <u--input v-model="inputForm.wareHouse[index].spec" placeholder="请输入包装规格" :disabled="nodeFlag"
- @blur="onRowInputBlur(index, 'spec')"></u--input>
- </u-form-item>
- <u-form-item label="商品单价(元)" :prop="'wareHouse[' + index + '].tradePrice'">
- <u--input v-model="inputForm.wareHouse[index].tradePrice" placeholder="请输入商品单价"
- :disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradePrice')"></u--input>
- </u-form-item>
- <u-form-item label="商品总价" :prop="'wareHouse[' + index + '].priceSum'">
- <u--input v-model="inputForm.wareHouse[index].priceSum" placeholder="自动计算" disabled></u--input>
- </u-form-item>
- <u-form-item label="生产日期" :prop="'wareHouse[' + index + '].produceDate'">
- <el-date-picker v-model="inputForm.wareHouse[index].produceDate" type="date"
- placeholder="请选择生产日期" style="width:100%" placement="bottom-start" clearable
- :disabled="nodeFlag" @change="markWareHouseModified(index)">
- </el-date-picker>
- </u-form-item>
- <u-form-item label="保质期" :prop="'wareHouse[' + index + '].shelfLife'">
- <view class="shelf-life-wrap">
- <u--input class="shelf-life-input" v-model="inputForm.wareHouse[index].shelfLife"
- placeholder="请输入保质期" :disabled="nodeFlag" @blur="markWareHouseModified(index)">
- </u--input>
- <jp-picker class="shelf-life-unit" placeholder="单位"
- v-model="inputForm.wareHouse[index].shelfLifeUnit" :disabled="nodeFlag" rangeKey="label"
- rangeValue="value" @change="markWareHouseModified(index)" :range="shelfLifeUnitOptions">
- </jp-picker>
- </view>
- </u-form-item>
- <u-form-item label="实际价格" :prop="'wareHouse[' + index + '].actualPrice'">
- <u--input v-model="inputForm.wareHouse[index].actualPrice" placeholder="请输入实际价格"
- :disabled="nodeFlag" @blur="onRowInputBlur(index, 'actualPrice')"></u--input>
- </u-form-item>
- <u-form-item label="备注" :prop="'wareHouse[' + index + '].remarks'">
- <u--input v-model="inputForm.wareHouse[index].remarks" placeholder="请输入备注" :disabled="nodeFlag"
- @blur="markWareHouseModified(index)"></u--input>
- </u-form-item>
- <u-form-item label="附件上传">
- <UploadComponent :uploadUrl="`${uploadUrl}/public-modules-server/oss/file/webUpload/upload`"
- @onRemove="(file, fileList, fileIndex) => handleRemove(file, fileList, index, fileIndex, 'detail')"
- @onSuccess="(file, fileList) => handleUploadSuccess(file, fileList, index, 'detail')"
- :fileList="inputForm.wareHouse[index].fileInfoLost" :limit="3" :isDelete="nodeFlag"
- :isUpload="nodeFlag">
- </UploadComponent>
- </u-form-item>
- <u-form-item label="" v-if="!nodeFlag">
- <view class="row-action-group">
- <el-button style="width: 100%" type="primary" plain @click="markWareHouseModified(index)">
- 标记修改
- </el-button>
- <el-button style="width: 100%" type="danger" plain @click="removeWareHouseRow(index)">
- 删除明细
- </el-button>
- </view>
- </u-form-item>
- </view>
- <u-form-item label="" v-if="!nodeFlag">
- <el-button style="width: 100%" type="primary" @click="addWareHouseRow()" plain>新增入库明细</el-button>
- </u-form-item>
- </view>
- <u-form-item label="修改原因" borderBottom prop="updateCause" :required="true">
- <u--textarea placeholder="请填写修改原因" :rows="5" :maxlength="500" v-model="inputForm.updateCause"
- :disabled="nodeFlag"></u--textarea>
- </u-form-item>
- <u-form-item label="附件">
- <UploadComponent :uploadUrl="`${uploadUrl}/public-modules-server/oss/file/webUpload/upload`"
- @onRemove="(file, fileList, fileIndex) => handleRemove(file, fileList, '', fileIndex, '')"
- @onSuccess="(file, fileList) => handleUploadSuccess(file, fileList, '', '')"
- :fileList="inputForm.files" :limit="3" :isDelete="nodeFlag" :isUpload="nodeFlag">
- </UploadComponent>
- </u-form-item>
- </u--form>
- <user-select ref="userPicker" @input="handleUserSelected"></user-select>
- <ba-tree-picker ref="treePicker" :multiple="false" @select-change="selectTypeChange" title="类型选择"
- :localdata="listData" valueKey="value" textKey="label" childrenKey="children" />
- </view>
- </template>
- <script>
- import { mapState } from 'vuex'
- import userSelect from '@/components/user-select/user-select-radio.vue'
- import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
- import UploadComponent from '@/pages/common/UploadComponent.vue'
- import upload from '@/utils/upload.js'
- import MaterialTypeService from '@/api/psi/MaterialTypeService'
- import MaterialManagementService from '@/api/psi/MaterialManagementService'
- import WareHouseService from '@/api/psi/WareHouseService'
- import CommonApi from '@/api/common/CommonApi'
- import PurchaseSelector from './PurchaseSelector.vue'
- import WareHouseGoodsSelector from './WareHouseGoodsSelector.vue'
- import WareHouseSupplierSelector from './WareHouseSupplierSelector.vue'
- export default {
- name: 'PsiWareHouseUpdateForm',
- components: {
- userSelect,
- baTreePicker,
- UploadComponent,
- PurchaseSelector,
- WareHouseGoodsSelector,
- WareHouseSupplierSelector
- },
- computed: mapState({
- userInfo: (state) => state.user.userInfo
- }),
- props: {
- businessId: {
- type: String,
- default: ''
- },
- formReadOnly: {
- type: Boolean,
- default: false
- },
- status: {
- type: String,
- default: ''
- },
- isCc: {
- type: Boolean,
- default: false
- },
- },
- data() {
- return {
- uploadUrl: upload.UPLOAD_URL,
- nodeFlag: false,
- loading: false,
- listData: [],
- materialList: [],
- currentTypeIndex: -1,
- inputForm: this.createInputForm(),
- rules: {
- wareHouseName: [
- {
- required: true,
- message: '入库名称不能为空',
- trigger: ['blur', 'change']
- }
- ],
- wareHouseDate: [
- {
- required: true,
- message: '入库时间不能为空',
- trigger: ['change']
- }
- ],
- purchaseNo: [
- {
- required: true,
- message: '采购编号不能为空',
- trigger: ['blur', 'change']
- }
- ],
- updateCause: [
- {
- required: true,
- message: '修改原因不能为空',
- trigger: ['blur', 'change']
- }
- ]
- },
- shelfLifeUnitOptions: [
- { label: '年', value: '年' },
- { label: '月', value: '月' },
- { label: '天', value: '天' }
- ]
- }
- },
- materialTypeService: null,
- materialManagementService: null,
- wareHouseService: null,
- commonApi: null,
- created() {
- this.ensureServices()
- this.loadMaterialTypes()
- this.fillUserInfo()
- },
- watch: {
- businessId: {
- handler() {
- if (this.businessId) {
- this.init(this.businessId)
- } else {
- this.resetForm()
- this.nodeFlag = false
- }
- },
- immediate: true,
- deep: false
- }
- },
- methods: {
- createInputForm() {
- return {
- id: '',
- procInsId: '',
- processDefinitionId: '',
- status: '',
- wareHouseTotalPrice: '',
- wareHouseActualPrice: '',
- tradeTotalPrice: '',
- fileInfoLost: [],
- purchaseNo: '',
- purchaseId: '',
- handledBy: '',
- handledById: '',
- handledByOffice: '',
- handledByOfficeName: '',
- wareHouseName: '',
- wareHouseNumber: '',
- userId: '',
- wareHouseDate: '',
- remarks: '',
- detailInfos: [],
- wareHouse: [],
- files: [],
- functionFlag: '',
- updateCause: ''
- }
- },
- ensureServices() {
- if (!this.materialTypeService) {
- this.materialTypeService = new MaterialTypeService()
- }
- if (!this.materialManagementService) {
- this.materialManagementService = new MaterialManagementService()
- }
- if (!this.wareHouseService) {
- this.wareHouseService = new WareHouseService()
- }
- if (!this.commonApi) {
- this.commonApi = new CommonApi()
- }
- },
- async loadMaterialTypes() {
- try {
- const data = await this.materialTypeService.cgList()
- this.materialList = data || []
- this.listData = this.buildTree(this.materialList)
- } catch (e) {
- this.materialList = []
- this.listData = []
- }
- },
- fillUserInfo() {
- if (!this.userInfo) {
- return
- }
- this.inputForm.handledBy = this.inputForm.handledBy || this.userInfo.name
- this.inputForm.handledById = this.inputForm.handledById || this.userInfo.id
- this.inputForm.userId = this.inputForm.userId || this.userInfo.id
- this.inputForm.handledByOffice = this.inputForm.handledByOffice || (this.userInfo.officeDTO && this.userInfo.officeDTO.id) || ''
- this.inputForm.handledByOfficeName = this.inputForm.handledByOfficeName || (this.userInfo.officeDTO && this.userInfo.officeDTO.name) || ''
- },
- resetForm() {
- this.inputForm = this.createInputForm()
- this.fillUserInfo()
- },
- async init(id) {
- this.ensureServices()
- this.resetForm()
- this.inputForm.id = id
- this.loading = true
- try {
- let data = await this.wareHouseService.findById(id, this.status)
- if (data && data.status === '5' && this.status === 'taskFormDetail') {
- try {
- data = await this.wareHouseService.findLastHiByid(id)
- } catch (e) {
- }
- }
- this.inputForm = this.normalizeFormData(this.recover(this.createInputForm(), data))
- this.fillUserInfo()
- this.nodeFlag = await this.resolveNodeFlag(data)
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- } catch (e) {
- this.nodeFlag = true
- } finally {
- this.loading = false
- }
- },
- async resolveNodeFlag(data) {
- if (this.formReadOnly || this.status === 'taskFormDetail' || this.status === 'testSee') {
- return true
- }
- try {
- const taskName = await this.commonApi.getTaskNameByProcInsId((data && data.procInsId) || this.inputForm.procInsId)
- if (this.isNotEmpty(taskName)) {
- return taskName !== '发起人重新发起申请'
- }
- } catch (e) {
- }
- return false
- },
- normalizeFormData(data) {
- const form = data || this.createInputForm()
- if (this.isNotEmpty(form.wareHouseDate)) {
- form.wareHouseDate = new Date(form.wareHouseDate)
- }
- form.detailInfos = (form.detailInfos || []).map(item => ({
- ...item,
- fileInfoLost: item.fileInfoLost || [],
- priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
- }))
- form.wareHouse = (form.wareHouse || []).map(item => ({
- ...item,
- fileInfoLost: item.fileInfoLost || [],
- upFlag: item.upFlag || '0',
- produceDate: this.isNotEmpty(item.produceDate) ? new Date(item.produceDate) : '',
- priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
- }))
- return form
- },
- buildTree(nodes, parentId = '0') {
- const tree = []
- for (const node of nodes || []) {
- if (node.parentId === parentId) {
- const children = this.buildTree(nodes, node.id)
- if (children.length) {
- node.children = children
- }
- tree.push(node)
- }
- }
- return tree
- },
- isEmpty(value) {
- if (value === null || value === undefined) {
- return true
- }
- if (typeof value === 'string' && value.trim() === '') {
- return true
- }
- if (Array.isArray(value) && value.length === 0) {
- return true
- }
- return false
- },
- isNotEmpty(value) {
- return !this.isEmpty(value)
- },
- computePriceSum(price, number) {
- if (this.isEmpty(price) || this.isEmpty(number)) {
- return ''
- }
- const amount = parseFloat(price || 0) * parseFloat(number || 0)
- if (Number.isNaN(amount)) {
- return ''
- }
- return amount.toFixed(2)
- },
- calculateDetailTotalPrice() {
- const total = (this.inputForm.detailInfos || []).reduce((sum, item) => {
- return sum + parseFloat(item.priceSum || 0)
- }, 0)
- this.inputForm.tradeTotalPrice = total ? total.toFixed(2) : ''
- },
- calculateWareHouseTotals() {
- const totalPrice = (this.inputForm.wareHouse || []).reduce((sum, item) => {
- return sum + parseFloat(item.priceSum || 0)
- }, 0)
- const totalActual = (this.inputForm.wareHouse || []).reduce((sum, item) => {
- return sum + parseFloat(item.actualPrice || 0)
- }, 0)
- this.inputForm.wareHouseTotalPrice = totalPrice ? totalPrice.toFixed(2) : ''
- this.inputForm.wareHouseActualPrice = totalActual ? totalActual.toFixed(2) : ''
- },
- openUserPullForm(index) {
- if (this.nodeFlag) {
- return
- }
- this.$refs.userPicker.open(index, 'wareHouse')
- },
- handleUserSelected(data, index, type) {
- if (type !== 'wareHouse') {
- return
- }
- this.patchWareHouseRow(index, {
- wareHouseManId: data.id,
- wareHouseMan: data.label,
- wareHouseManOffice: data.parentLabel,
- deptId: data.parentId
- })
- },
- openTypePicker(index) {
- if (this.nodeFlag) {
- return
- }
- this.currentTypeIndex = index
- this.$refs.treePicker._show(index)
- },
- selectTypeChange(ids, names, index) {
- this.patchWareHouseRow(index, {
- wareHouseType: names,
- wareHouseTypeId: ids[0],
- tradeName: '',
- supplierName: '',
- supplierId: '',
- isSupplier: '',
- tradePrice: '',
- tradeNumber: '',
- priceSum: '',
- company: '',
- spec: '',
- actualPrice: '',
- surplusNumber: ''
- })
- },
- async handlePurchaseSelected(row) {
- try {
- const data = await this.materialManagementService.findById(row.id)
- if (this.isNotEmpty(this.inputForm.purchaseNo) && this.inputForm.purchaseNo !== data.purchaseNo) {
- this.inputForm.wareHouse = []
- }
- this.inputForm.purchaseNo = data.purchaseNo || row.purchaseNo
- this.inputForm.purchaseId = row.id
- this.inputForm.detailInfos = (data.detailInfos || []).map(item => ({
- ...item,
- fileInfoLost: item.fileInfoLost || [],
- priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
- }))
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- } catch (e) {
- uni.showToast({
- title: '采购详情加载失败',
- icon: 'none'
- })
- }
- },
- handleGoodsSelected({ index, item }) {
- this.patchWareHouseRow(index, {
- tradeName: item.tradeName || ''
- })
- },
- handleSupplierSelected({ index, item }) {
- this.patchWareHouseRow(index, {
- supplierName: item.name || '',
- supplierId: item.id || '',
- isSupplier: '2'
- })
- },
- createWareHouseRow() {
- return {
- id: '',
- wareHouseManId: this.userInfo && this.userInfo.id,
- wareHouseMan: this.userInfo && this.userInfo.name,
- wareHouseManOffice: this.userInfo && this.userInfo.officeDTO && this.userInfo.officeDTO.name,
- deptId: this.userInfo && this.userInfo.officeDTO && this.userInfo.officeDTO.id,
- wareHouseType: '',
- wareHouseTypeId: '',
- tradeName: '',
- supplierName: '',
- supplierId: '',
- isSupplier: '',
- tradeNumber: '',
- company: '',
- spec: '',
- tradePrice: '',
- priceSum: '',
- produceDate: '',
- shelfLife: '',
- shelfLifeUnit: '',
- actualPrice: '',
- remarks: '',
- fileInfoLost: [],
- upFlag: '0',
- sourceId: ''
- }
- },
- addWareHouseRow() {
- this.inputForm.wareHouse.push(this.createWareHouseRow())
- this.calculateWareHouseTotals()
- },
- patchWareHouseRow(index, patch, markChanged = true) {
- const row = (this.inputForm.wareHouse || [])[index] || {}
- const nextRow = {
- ...row,
- ...patch
- }
- if (markChanged) {
- if (this.isNotEmpty(row.id) && this.isEmpty(row.sourceId)) {
- nextRow.upFlag = '1'
- } else {
- nextRow.upFlag = row.upFlag || '0'
- }
- }
- if (Object.prototype.hasOwnProperty.call(patch, 'tradePrice') || Object.prototype.hasOwnProperty.call(patch, 'tradeNumber')) {
- nextRow.priceSum = this.computePriceSum(nextRow.tradePrice, nextRow.tradeNumber)
- }
- this.$set(this.inputForm.wareHouse, index, nextRow)
- this.calculateWareHouseTotals()
- },
- markWareHouseModified(index) {
- const row = (this.inputForm.wareHouse || [])[index]
- if (!row) {
- return
- }
- if (this.isNotEmpty(row.id) && this.isEmpty(row.sourceId) && row.upFlag !== '1') {
- this.$set(this.inputForm.wareHouse[index], 'upFlag', '1')
- }
- },
- removeWareHouseRow(index) {
- this.inputForm.wareHouse.splice(index, 1)
- this.calculateWareHouseTotals()
- },
- onRowInputBlur(index, field) {
- const row = (this.inputForm.wareHouse || [])[index]
- if (!row) {
- return
- }
- let value = row[field]
- if (['tradeNumber', 'tradePrice', 'actualPrice'].includes(field)) {
- value = this.formatNumberInput(value)
- }
- if (field === 'spec') {
- value = this.formatIntegerInput(value)
- }
- this.patchWareHouseRow(index, {
- [field]: value
- })
- },
- formatNumberInput(inputValue, decimalLimit = 2) {
- if (this.isEmpty(inputValue)) {
- return ''
- }
- const valueText = String(inputValue)
- if (!/^\d*\.?\d*$/.test(valueText)) {
- return ''
- }
- let value = valueText.replace(/[^\d.]/g, '')
- const dotIndex = value.indexOf('.')
- if (dotIndex !== -1) {
- const substr = value.substr(dotIndex + 1)
- if (substr.indexOf('.') !== -1) {
- value = value.substr(0, dotIndex + 1) + substr.replace(/\./g, '')
- }
- }
- if (dotIndex !== -1) {
- const integerPart = value.substring(0, dotIndex)
- const decimalPart = value.substring(dotIndex + 1, dotIndex + 1 + decimalLimit)
- value = integerPart + '.' + decimalPart
- }
- return value
- },
- formatIntegerInput(inputValue) {
- if (this.isEmpty(inputValue)) {
- return ''
- }
- return String(inputValue).replace(/[^\d]/g, '')
- },
- handleUploadSuccess(file, fileList, index, type) {
- if (type === 'detail') {
- this.inputForm.wareHouse[index].fileInfoLost = fileList
- this.markWareHouseModified(index)
- } else {
- this.inputForm.files = fileList
- }
- },
- handleRemove(file, fileList, lineIndex, fileIndex, type) {
- if (type === 'detail') {
- this.inputForm.wareHouse[lineIndex].fileInfoLost.splice(fileIndex, 1)
- this.markWareHouseModified(lineIndex)
- } else {
- this.inputForm.files.splice(fileIndex, 1)
- }
- },
- formatDate(date) {
- if (this.isEmpty(date)) {
- return ''
- }
- const dateNew = new Date(date)
- if (Number.isNaN(dateNew.getTime())) {
- return ''
- }
- const year = dateNew.getFullYear()
- const month = `${dateNew.getMonth() + 1}`.padStart(2, '0')
- const day = `${dateNew.getDate()}`.padStart(2, '0')
- return `${year}-${month}-${day}`
- },
- toSubmitData() {
- const data = JSON.parse(JSON.stringify(this.inputForm))
- data.wareHouseDate = this.formatDate(this.inputForm.wareHouseDate)
- data.wareHouse = (this.inputForm.wareHouse || []).map(item => ({
- ...JSON.parse(JSON.stringify(item)),
- produceDate: this.formatDate(item.produceDate)
- }))
- return data
- },
- validateWareHouseRows() {
- if (this.isEmpty(this.inputForm.wareHouse)) {
- return true
- }
- const rows = this.inputForm.wareHouse
- for (let i = 0; i < rows.length; i++) {
- const row = rows[i]
- const lineNo = i + 1
- if (this.isEmpty(row.wareHouseMan)) {
- this.$message.error(`入库详情第${lineNo}行请选择入库人`)
- return false
- }
- if (this.isEmpty(row.wareHouseType)) {
- this.$message.error(`入库详情第${lineNo}行请选择入库类型`)
- return false
- }
- if (this.isEmpty(row.supplierName) || this.isEmpty(row.supplierId)) {
- this.$message.error(`入库详情第${lineNo}行请选择供应商`)
- return false
- }
- if (this.isEmpty(row.tradeName)) {
- this.$message.error(`入库详情第${lineNo}行请填写商品名称`)
- return false
- }
- if (this.isEmpty(row.tradeNumber)) {
- this.$message.error(`入库详情第${lineNo}行请填写商品数量`)
- return false
- }
- }
- for (let i = 0; i < rows.length; i++) {
- for (let j = i + 1; j < rows.length; j++) {
- if (rows[i].wareHouseTypeId === rows[j].wareHouseTypeId &&
- rows[i].tradeName === rows[j].tradeName &&
- rows[i].supplierId === rows[j].supplierId) {
- this.$message.warning('入库详情中,同种入库类型、同一供应商的商品名称只能输入一条')
- return false
- }
- }
- }
- return true
- },
- async saveForm(callback) {
- try {
- await this.$refs.inputForm.validate()
- if (!this.validateWareHouseRows()) {
- return
- }
- this.loading = true
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- const submitData = this.toSubmitData()
- submitData.status = '1'
- submitData.functionFlag = ''
- this.inputForm.status = '1'
- const data = await this.wareHouseService.save(submitData)
- callback(data.businessTable, data.businessId, submitData)
- } finally {
- this.loading = false
- }
- },
- async startForm(callback) {
- this.loading = true
- try {
- if (this.isNotEmpty(this.inputForm.id)) {
- const data = await this.wareHouseService.findById(this.inputForm.id)
- if (this.isNotEmpty(data.status) && !['0', '1', '3', '5'].includes(data.status)) {
- this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
- throw new Error('invalid status')
- }
- }
- await this.startFormTrue(callback)
- } finally {
- this.loading = false
- }
- },
- async startFormTrue(callback) {
- await this.$refs.inputForm.validate()
- if (!this.validateWareHouseRows()) {
- return
- }
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- const submitData = this.toSubmitData()
- submitData.status = '2'
- submitData.functionFlag = 'start'
- this.inputForm.status = '2'
- this.inputForm.functionFlag = 'start'
- const data = await this.wareHouseService.save(submitData)
- this.inputForm.id = data.businessId
- callback(data.businessTable, data.businessId, submitData)
- },
- async reapplyForm(callback) {
- this.loading = true
- try {
- const data = await this.wareHouseService.findById(this.inputForm.id)
- if (data.status !== '4') {
- this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
- throw new Error('invalid status')
- }
- await this.startFormTrue(callback)
- } finally {
- this.loading = false
- }
- },
- async agreeForm(callback) {
- this.loading = true
- try {
- await this.$refs.inputForm.validate()
- if (!this.validateWareHouseRows()) {
- return
- }
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- const submitData = this.toSubmitData()
- submitData.status = '5'
- submitData.functionFlag = 'agree'
- this.inputForm.status = '5'
- this.inputForm.functionFlag = 'agree'
- const data = await this.wareHouseService.save(submitData)
- callback(data.businessTable, data.businessId, submitData)
- } finally {
- this.loading = false
- }
- },
- async updateStatusById(type, callback) {
- this.loading = true
- try {
- if (type === 'reject' || type === 'reback') {
- const data = await this.wareHouseService.findById(this.inputForm.id)
- if (data.status !== '2') {
- this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
- throw new Error('invalid status')
- }
- const status = type === 'reject' ? '4' : '3'
- this.inputForm.status = status
- await this.wareHouseService.updateStatusById({
- status,
- id: this.inputForm.id
- })
- callback()
- } else if (type === 'hold') {
- const data = await this.wareHouseService.findById(this.inputForm.id)
- if (data.status !== '4') {
- this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
- throw new Error('invalid status')
- }
- await this.wareHouseService.backSourceData(this.inputForm.id)
- callback()
- }
- } finally {
- this.loading = false
- }
- },
- statusLabel(row) {
- if (row.upFlag === '1') {
- return '修改前'
- }
- if (row.upFlag === '2') {
- return '已删除'
- }
- if (row.upFlag === '0' && this.isNotEmpty(row.sourceId)) {
- return '修改后'
- }
- return ''
- },
- statusClass(row) {
- if (row.upFlag === '1') {
- return 'warehouse-card--before'
- }
- if (row.upFlag === '2') {
- return 'warehouse-card--deleted'
- }
- if (row.upFlag === '0' && this.isNotEmpty(row.sourceId)) {
- return 'warehouse-card--after'
- }
- return ''
- },
- statusBadgeClass(row) {
- if (row.upFlag === '1') {
- return 'status-badge--before'
- }
- if (row.upFlag === '2') {
- return 'status-badge--deleted'
- }
- if (row.upFlag === '0' && this.isNotEmpty(row.sourceId)) {
- return 'status-badge--after'
- }
- return ''
- }
- }
- }
- </script>
- <style scoped>
- .section-wrap {
- margin-top: 24rpx;
- }
- .section-title {
- margin-bottom: 16rpx;
- padding-left: 8rpx;
- font-size: 30rpx;
- font-weight: 700;
- color: #1f2937;
- border-left: 6rpx solid #2979ff;
- }
- .detail-card {
- margin-bottom: 20rpx;
- padding: 24rpx;
- background: #fff;
- border-radius: 20rpx;
- box-shadow: 0 10rpx 30rpx rgba(15, 23, 42, 0.05);
- }
- .detail-card-head {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 12rpx;
- }
- .detail-card-title {
- font-size: 28rpx;
- font-weight: 600;
- color: #0f172a;
- }
- .detail-grid {
- display: grid;
- grid-template-columns: repeat(2, minmax(0, 1fr));
- gap: 16rpx;
- }
- .detail-item {
- display: flex;
- flex-direction: column;
- padding: 18rpx 20rpx;
- background: #f8fafc;
- border-radius: 16rpx;
- }
- .detail-label {
- font-size: 22rpx;
- color: #64748b;
- }
- .detail-value {
- margin-top: 8rpx;
- font-size: 26rpx;
- line-height: 1.5;
- color: #0f172a;
- word-break: break-all;
- }
- .warehouse-card--before {
- background: #f3f4f6;
- }
- .warehouse-card--after {
- background: #f0fdf4;
- }
- .warehouse-card--deleted {
- background: #fef2f2;
- }
- .status-badge {
- padding: 8rpx 16rpx;
- border-radius: 999rpx;
- font-size: 22rpx;
- font-weight: 600;
- }
- .status-badge--before {
- color: #475569;
- background: #e2e8f0;
- }
- .status-badge--after {
- color: #166534;
- background: #dcfce7;
- }
- .status-badge--deleted {
- color: #b91c1c;
- background: #fee2e2;
- }
- .row-action-group {
- display: flex;
- gap: 16rpx;
- width: 100%;
- }
- .shelf-life-wrap {
- display: flex;
- width: 100%;
- gap: 16rpx;
- }
- .shelf-life-input {
- flex: 1;
- }
- .shelf-life-unit {
- width: 200rpx;
- }
- @media (max-width: 768px) {
- .detail-grid {
- grid-template-columns: repeat(1, minmax(0, 1fr));
- }
- }
- </style>
|