| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920 |
- <template>
- <view class="page-wrap">
- <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" value-format="yyyy-MM-dd"
- placeholder="请选择入库时间" style="width:100%" placement="bottom-start" clearable
- :disabled="nodeFlag">
- </el-date-picker>
- </u-form-item>
- <purchase-selector :inputForm="inputForm" :disabled="nodeFlag" :required="false"
- @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.supplierName || '-' }}</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.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 class="detail-item">
- <text class="detail-label">单位</text>
- <text class="detail-value">{{ item.company || '-' }}</text>
- </view>
- <view class="detail-item">
- <text class="detail-label">备注</text>
- <text class="detail-value">{{ item.remarks || '-' }}</text>
- </view>
- </view>
- <el-button v-if="!nodeFlag" style="width: 100%; margin-top: 16rpx;" type="primary" plain
- @click="wareHouseAdd(index)">
- 入库
- </el-button>
- </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">
- <view class="detail-card-title">入库明细 {{ index + 1 }}</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="calculateWareHouseTotals"></u--input>
- </u-form-item>
- <u-form-item label="包装规格" :prop="'wareHouse[' + index + '].spec'" :required="true">
- <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">
- </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">
- </u--input>
- <jp-picker class="shelf-life-unit" placeholder="单位"
- v-model="inputForm.wareHouse[index].shelfLifeUnit" :disabled="nodeFlag" rangeKey="label"
- rangeValue="value" :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">
- </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">
- <el-button style="width: 100%" type="danger" plain @click="removeWareHouseRow(index)">
- 删除入库明细 {{ index + 1 }}
- </el-button>
- </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="附件">
- <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>
- <view v-if="!nodeFlag" class="submit-bar">
- <el-button class="submit-button" type="primary" :loading="loading" @click="handlePageSubmit">
- 提交
- </el-button>
- </view>
- <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 PurchaseSelector from './PurchaseSelector.vue'
- import WareHouseGoodsSelector from './WareHouseGoodsSelector.vue'
- import WareHouseSupplierSelector from './WareHouseSupplierSelector.vue'
- export default {
- name: 'PsiWareHouseAddForm',
- 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']
- }
- ]
- },
- shelfLifeUnitOptions: [
- { label: '年', value: '年' },
- { label: '月', value: '月' },
- { label: '天', value: '天' }
- ]
- }
- },
- materialTypeService: null,
- materialManagementService: null,
- wareHouseService: null,
- created() {
- this.ensureServices()
- this.loadMaterialTypes()
- this.resetForm()
- },
- watch: {
- userInfo: {
- handler() {
- this.fillUserInfo()
- },
- immediate: true,
- deep: true
- }
- },
- onLoad(options = {}) {
- this.ensureServices()
- this.resetForm()
- if (options.purchaseId) {
- this.loadPurchaseById(options.purchaseId)
- } else if (options.id) {
- this.init('purchaseAdd', options.id)
- }
- },
- methods: {
- createInputForm() {
- return {
- id: '',
- procInsId: '',
- processDefinitionId: '',
- status: '',
- wareHouseTotalPrice: '',
- wareHouseActualPrice: '',
- tradeTotalPrice: '',
- fileInfoLost: [],
- purchaseNo: '',
- purchaseId: '',
- contractNo: '',
- handledBy: '',
- handledById: '',
- handledByOffice: '',
- handledByOfficeName: '',
- wareHouseName: '',
- wareHouseNumber: '',
- userId: '',
- wareHouseDate: '',
- remarks: '',
- detailInfos: [],
- wareHouse: [],
- files: [],
- functionFlag: ''
- }
- },
- ensureServices() {
- if (!this.materialTypeService) {
- this.materialTypeService = new MaterialTypeService()
- }
- if (!this.materialManagementService) {
- this.materialManagementService = new MaterialManagementService()
- }
- if (!this.wareHouseService) {
- this.wareHouseService = new WareHouseService()
- }
- },
- 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
- }
- const office = this.userInfo.officeDTO || this.userInfo.office || {}
- this.inputForm.handledBy = this.inputForm.handledBy || this.userInfo.name || this.userInfo.realname || ''
- this.inputForm.handledById = this.inputForm.handledById || this.userInfo.id || this.userInfo.userId || ''
- this.inputForm.userId = this.inputForm.userId || this.userInfo.id || this.userInfo.userId || ''
- this.inputForm.handledByOffice = this.inputForm.handledByOffice || office.id || this.userInfo.officeId || ''
- this.inputForm.handledByOfficeName = this.inputForm.handledByOfficeName || office.name || this.userInfo.officeName || ''
- },
- resetForm() {
- this.inputForm = this.createInputForm()
- this.fillUserInfo()
- this.nodeFlag = !!this.formReadOnly
- },
- init(method, id) {
- this.resetForm()
- if (method === 'purchaseAdd' && id) {
- this.loadPurchaseById(id)
- }
- },
- async loadPurchaseById(id) {
- try {
- const data = await this.materialManagementService.findById(id)
- this.applyPurchaseData(data, id)
- } catch (e) {
- uni.showToast({
- title: '采购详情加载失败',
- icon: 'none'
- })
- }
- },
- applyPurchaseData(data, id) {
- const purchase = data || {}
- this.inputForm.purchaseNo = purchase.purchaseNo || ''
- this.inputForm.purchaseId = id || purchase.id || ''
- this.inputForm.detailInfos = (purchase.detailInfos || []).map(item => ({
- ...item,
- fileInfoLost: item.fileInfoLost || [],
- priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
- }))
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- },
- buildTree(nodes, parentId = '0') {
- const tree = []
- for (const node of nodes || []) {
- if (node.parentId === parentId) {
- const treeNode = {
- ...node
- }
- const children = this.buildTree(nodes, node.id)
- if (children.length) {
- treeNode.children = children
- }
- tree.push(treeNode)
- }
- }
- 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.applyPurchaseData(data, row.id)
- } 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(row = {}) {
- const office = (this.userInfo && (this.userInfo.officeDTO || this.userInfo.office)) || {}
- return {
- id: '',
- wareHouseManId: this.userInfo && (this.userInfo.id || this.userInfo.userId),
- wareHouseMan: this.userInfo && (this.userInfo.name || this.userInfo.realname),
- wareHouseManOffice: office.name || (this.userInfo && this.userInfo.officeName),
- deptId: office.id || (this.userInfo && this.userInfo.officeId),
- wareHouseType: '',
- wareHouseTypeId: '',
- tradeName: '',
- supplierName: '',
- supplierId: '',
- isSupplier: '',
- tradeNumber: '',
- company: '',
- spec: '',
- tradePrice: '',
- priceSum: '',
- produceDate: '',
- shelfLife: '',
- shelfLifeUnit: '月',
- actualPrice: '',
- remarks: '',
- fileInfoLost: [],
- ...row
- }
- },
- addWareHouseRow(row) {
- this.inputForm.wareHouse.push(this.createWareHouseRow(row))
- this.calculateWareHouseTotals()
- },
- wareHouseAdd(index) {
- const detail = (this.inputForm.detailInfos || [])[index]
- if (!detail) {
- return
- }
- const row = {
- wareHouseTypeId: detail.procurementTypeId || '',
- wareHouseType: detail.procurementType || '',
- tradeName: detail.tradeName || '',
- tradeNumber: detail.tradeNumber || '',
- tradePrice: detail.tradePrice || '',
- company: detail.company || '',
- priceSum: this.computePriceSum(detail.tradePrice, detail.tradeNumber),
- supplierId: '',
- supplierName: '',
- isSupplier: '',
- spec: '',
- produceDate: '',
- shelfLife: '',
- shelfLifeUnit: '月'
- }
- if (this.isNotEmpty(detail.supplierId) && this.isNotEmpty(detail.isSupplier) && detail.isSupplier === '2') {
- row.supplierId = detail.supplierId
- row.supplierName = detail.supplierName
- row.isSupplier = detail.isSupplier
- }
- this.addWareHouseRow(row)
- },
- patchWareHouseRow(index, patch) {
- const row = (this.inputForm.wareHouse || [])[index] || {}
- const nextRow = {
- ...row,
- ...patch
- }
- 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()
- },
- 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)
- if (this.isNotEmpty(value) && parseInt(value, 10) <= 0) {
- value = ''
- this.$message.warning('请输入除0以外的正整数')
- }
- }
- 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, '')
- }
- 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
- } else {
- this.inputForm.files = fileList
- }
- },
- handleRemove(file, fileList, lineIndex, fileIndex, type) {
- if (type === 'detail') {
- this.inputForm.wareHouse[lineIndex].fileInfoLost.splice(fileIndex, 1)
- } 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.tradeTotalPrice = this.normalizeOptionalNumber(data.tradeTotalPrice)
- data.wareHouseTotalPrice = this.normalizeOptionalNumber(data.wareHouseTotalPrice)
- data.wareHouseActualPrice = this.normalizeOptionalNumber(data.wareHouseActualPrice)
- data.wareHouse = (this.inputForm.wareHouse || []).map(item => ({
- ...JSON.parse(JSON.stringify(item)),
- produceDate: this.formatDate(item.produceDate),
- priceSum: this.normalizeOptionalNumber(this.computePriceSum(item.tradePrice, item.tradeNumber)),
- tradeTotalPrice: this.normalizeOptionalNumber(item.tradeTotalPrice),
- actualPrice: this.normalizeOptionalNumber(item.actualPrice)
- }))
- return data
- },
- normalizeOptionalNumber(value) {
- if (this.isEmpty(value)) {
- return null
- }
- return value
- },
- validateBaseForm() {
- if (this.isEmpty(this.inputForm.wareHouseDate)) {
- this.$message.error('入库时间不能为空')
- return false
- }
- return true
- },
- validateWareHouseRows() {
- if (this.isEmpty(this.inputForm.wareHouse)) {
- this.$message.error('至少填写一条入库详情信息')
- return false
- }
- 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
- }
- if (this.isEmpty(row.spec)) {
- 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
- },
- confirmShelfLifeRows() {
- const rows = this.inputForm.wareHouse || []
- const index = rows.findIndex(row => {
- return (this.isEmpty(row.produceDate) && this.isNotEmpty(row.shelfLife)) ||
- (this.isNotEmpty(row.produceDate) && this.isEmpty(row.shelfLife))
- })
- if (index === -1) {
- return Promise.resolve(true)
- }
- const row = rows[index]
- return new Promise(resolve => {
- uni.showModal({
- title: '提示',
- content: `入库详情第${index + 1}行的${row.tradeName || '商品'}的生产日期或保质期未填写,是否继续提交?`,
- success: res => {
- resolve(!!res.confirm)
- },
- fail: () => {
- resolve(false)
- }
- })
- })
- },
- async submitWithStatus(status, functionFlag, callback) {
- this.fillUserInfo()
- await this.$refs.inputForm.validate()
- if (!this.validateBaseForm()) {
- return
- }
- if (!this.validateWareHouseRows()) {
- return
- }
- const confirmed = await this.confirmShelfLifeRows()
- if (!confirmed) {
- return
- }
- this.loading = true
- try {
- this.calculateDetailTotalPrice()
- this.calculateWareHouseTotals()
- const submitData = this.toSubmitData()
- submitData.status = status
- submitData.functionFlag = functionFlag
- this.inputForm.status = status
- this.inputForm.functionFlag = functionFlag
- const data = await this.wareHouseService.save(submitData)
- this.inputForm.id = data.businessId
- if (callback) {
- callback(data.businessTable, data.businessId, submitData)
- }
- return data
- } finally {
- this.loading = false
- }
- },
- saveForm(callback) {
- return this.submitWithStatus('1', '', callback)
- },
- async handlePageSubmit() {
- const data = await this.submitWithStatus('0', '')
- if (!data) {
- return
- }
- uni.showToast({
- title: '提交成功',
- icon: 'success'
- })
- setTimeout(() => {
- uni.navigateBack()
- }, 800)
- },
- startForm(callback) {
- return this.startFormTrue(callback)
- },
- startFormTrue(callback) {
- return this.submitWithStatus('2', 'start', callback)
- },
- reapplyForm(callback) {
- return this.startFormTrue(callback)
- },
- agreeForm(callback) {
- return this.submitWithStatus('5', 'agree', callback)
- }
- }
- }
- </script>
- <style scoped>
- .page-wrap {
- padding-bottom: 120rpx;
- }
- .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);
- }
- .warehouse-card {
- padding-bottom: 16rpx;
- }
- .detail-card-title {
- margin-bottom: 12rpx;
- 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;
- }
- .shelf-life-wrap {
- display: flex;
- width: 100%;
- gap: 16rpx;
- }
- .shelf-life-input {
- flex: 1;
- min-width: 0;
- }
- .shelf-life-unit {
- flex: 0 0 128rpx;
- width: 128rpx;
- }
- .submit-bar {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 20;
- padding: 18rpx 28rpx calc(18rpx + env(safe-area-inset-bottom));
- background: #fff;
- box-shadow: 0 -8rpx 24rpx rgba(15, 23, 42, 0.08);
- }
- .submit-button {
- width: 100%;
- }
- @media (max-width: 768px) {
- .detail-grid {
- grid-template-columns: repeat(1, minmax(0, 1fr));
- }
- }
- </style>
|