WareHouseUpdateForm.vue 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. <template>
  2. <view>
  3. <cu-custom :backUrl="'/pages/index/index'" :isBack="true" bgColor="bg-gradual-blue">
  4. <block slot="content">入库修改</block>
  5. </cu-custom>
  6. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules"
  7. ref="inputForm">
  8. <u-form-item label="入库编号" borderBottom prop="wareHouseNumber">
  9. <u--input placeholder="自动生成" v-model="inputForm.wareHouseNumber" disabled></u--input>
  10. </u-form-item>
  11. <u-form-item label="入库名称" borderBottom prop="wareHouseName" :required="true">
  12. <u--input placeholder="请填写入库名称" v-model="inputForm.wareHouseName" :disabled="nodeFlag"></u--input>
  13. </u-form-item>
  14. <u-form-item label="经办人" borderBottom prop="handledBy">
  15. <u--input v-model="inputForm.handledBy" disabled></u--input>
  16. </u-form-item>
  17. <u-form-item label="经办部门" borderBottom prop="handledByOfficeName">
  18. <u--input v-model="inputForm.handledByOfficeName" disabled></u--input>
  19. </u-form-item>
  20. <u-form-item label="入库时间" borderBottom prop="wareHouseDate" :required="true">
  21. <el-date-picker v-model="inputForm.wareHouseDate" type="date" value-format="yyyy-MM-dd"
  22. placeholder="请选择入库时间" style="width:100%" placement="bottom-start" clearable :disabled="nodeFlag">
  23. </el-date-picker>
  24. </u-form-item>
  25. <purchase-selector :inputForm="inputForm" :disabled="nodeFlag" @selected="handlePurchaseSelected">
  26. </purchase-selector>
  27. <u-form-item label="备注" borderBottom prop="remarks">
  28. <u--textarea placeholder="请填写备注信息" :rows="4" :maxlength="500" v-model="inputForm.remarks"
  29. :disabled="nodeFlag"></u--textarea>
  30. </u-form-item>
  31. <view v-if="inputForm.purchaseNo" class="section-wrap">
  32. <view class="section-title">采购详情</view>
  33. <view v-for="(item, index) in inputForm.detailInfos" :key="item.id || index" class="detail-card">
  34. <view class="detail-card-title">采购明细 {{ index + 1 }}</view>
  35. <view class="detail-grid">
  36. <!-- <view class="detail-item">
  37. <text class="detail-label">采购人</text>
  38. <text class="detail-value">{{ item.purchaserAgent || '-' }}</text>
  39. </view>
  40. <view class="detail-item">
  41. <text class="detail-label">采购部门</text>
  42. <text class="detail-value">{{ item.procurementOffice || '-' }}</text>
  43. </view> -->
  44. <view class="detail-item">
  45. <text class="detail-label">商品名称</text>
  46. <text class="detail-value">{{ item.procurementType || '-' }}</text>
  47. </view>
  48. <!-- <view class="detail-item">
  49. <text class="detail-label">商品名称</text>
  50. <text class="detail-value">{{ item.tradeName || '-' }}</text>
  51. </view> -->
  52. <view class="detail-item">
  53. <text class="detail-label">品牌</text>
  54. <text class="detail-value">{{ item.brand || '-' }}</text>
  55. </view>
  56. <view class="detail-item">
  57. <text class="detail-label">规格</text>
  58. <text class="detail-value">{{ item.specification || '-' }}</text>
  59. </view>
  60. <view class="detail-item">
  61. <text class="detail-label">单位</text>
  62. <text class="detail-value">{{ item.company || '-' }}</text>
  63. </view>
  64. <view class="detail-item">
  65. <text class="detail-label">商品数量</text>
  66. <text class="detail-value">{{ item.tradeNumber || '-' }}</text>
  67. </view>
  68. <!-- <view class="detail-item">
  69. <text class="detail-label">商品单价</text>
  70. <text class="detail-value">{{ item.tradePrice || '-' }}</text>
  71. </view>
  72. <view class="detail-item">
  73. <text class="detail-label">商品总价</text>
  74. <text class="detail-value">{{ item.priceSum || '-' }}</text>
  75. </view> -->
  76. </view>
  77. </view>
  78. </view>
  79. <view class="section-wrap">
  80. <view class="section-title">入库详情</view>
  81. <view v-for="(item, index) in inputForm.wareHouse" :key="item.id || index" class="detail-card">
  82. <view class="detail-card-head">
  83. <view class="detail-card-title">入库明细 {{ index + 1 }}</view>
  84. </view>
  85. <!-- <u-form-item label="入库人" :prop="'wareHouse[' + index + '].wareHouseMan'" :required="true">
  86. <u--input v-model="inputForm.wareHouse[index].wareHouseMan" placeholder="请选择入库人"
  87. :disabled="nodeFlag" @focus="openUserPullForm(index)" clearable></u--input>
  88. </u-form-item>
  89. <u-form-item label="入库部门" :prop="'wareHouse[' + index + '].wareHouseManOffice'">
  90. <u--input v-model="inputForm.wareHouse[index].wareHouseManOffice" disabled></u--input>
  91. </u-form-item> -->
  92. <ware-house-goods-selector :rowIndex="index" :inputForm="inputForm" :disabled="nodeFlag"
  93. @selected="handleGoodsSelected"></ware-house-goods-selector>
  94. <u-form-item label="品牌" :prop="'wareHouse[' + index + '].brand'">
  95. <u--input v-model="inputForm.wareHouse[index].brand" disabled></u--input>
  96. </u-form-item>
  97. <u-form-item label="规格" :prop="'wareHouse[' + index + '].specification'">
  98. <u--input v-model="inputForm.wareHouse[index].specification" disabled></u--input>
  99. </u-form-item>
  100. <u-form-item label="单位" :prop="'wareHouse[' + index + '].company'">
  101. <u--input v-model="inputForm.wareHouse[index].company" placeholder="请输入单位" disabled
  102. @blur="markWareHouseModified(index)"></u--input>
  103. </u-form-item>
  104. <u-form-item label="商品数量" :prop="'wareHouse[' + index + '].tradeNumber'" :required="true">
  105. <u--input v-model="inputForm.wareHouse[index].tradeNumber" placeholder="请输入商品数量"
  106. :disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradeNumber')"></u--input>
  107. </u-form-item>
  108. <!-- <u-form-item label="包装规格" :prop="'wareHouse[' + index + '].spec'">
  109. <u--input v-model="inputForm.wareHouse[index].spec" placeholder="请输入包装规格" :disabled="nodeFlag"
  110. @blur="onRowInputBlur(index, 'spec')"></u--input>
  111. </u-form-item> -->
  112. <!-- <u-form-item label="商品单价(元)" :prop="'wareHouse[' + index + '].tradePrice'">
  113. <u--input v-model="inputForm.wareHouse[index].tradePrice" placeholder="请输入商品单价"
  114. :disabled="nodeFlag" @blur="onRowInputBlur(index, 'tradePrice')"></u--input>
  115. </u-form-item>
  116. <u-form-item label="商品总价" :prop="'wareHouse[' + index + '].priceSum'">
  117. <u--input v-model="inputForm.wareHouse[index].priceSum" placeholder="自动计算" disabled></u--input>
  118. </u-form-item>
  119. <u-form-item label="生产日期" :prop="'wareHouse[' + index + '].produceDate'">
  120. <el-date-picker v-model="inputForm.wareHouse[index].produceDate" type="date"
  121. placeholder="请选择生产日期" style="width:100%" placement="bottom-start" clearable
  122. :disabled="nodeFlag" @change="markWareHouseModified(index)">
  123. </el-date-picker>
  124. </u-form-item>
  125. <u-form-item label="保质期" :prop="'wareHouse[' + index + '].shelfLife'">
  126. <view class="shelf-life-wrap">
  127. <u--input class="shelf-life-input" v-model="inputForm.wareHouse[index].shelfLife"
  128. placeholder="请输入保质期" :disabled="nodeFlag" @blur="markWareHouseModified(index)">
  129. </u--input>
  130. <jp-picker class="shelf-life-unit" placeholder="单位"
  131. v-model="inputForm.wareHouse[index].shelfLifeUnit" :disabled="nodeFlag" rangeKey="label"
  132. rangeValue="value" @change="markWareHouseModified(index)" :range="shelfLifeUnitOptions">
  133. </jp-picker>
  134. </view>
  135. </u-form-item>
  136. <u-form-item label="实际价格" :prop="'wareHouse[' + index + '].actualPrice'">
  137. <u--input v-model="inputForm.wareHouse[index].actualPrice" placeholder="请输入实际价格"
  138. :disabled="nodeFlag" @blur="onRowInputBlur(index, 'actualPrice')"></u--input>
  139. </u-form-item> -->
  140. <u-form-item label="备注" :prop="'wareHouse[' + index + '].remarks'">
  141. <u--input v-model="inputForm.wareHouse[index].remarks" placeholder="请输入备注" :disabled="nodeFlag"
  142. @blur="markWareHouseModified(index)"></u--input>
  143. </u-form-item>
  144. <u-form-item label="附件上传">
  145. <UploadComponent :uploadUrl="`${uploadUrl}/public-modules-server/oss/file/webUpload/upload`"
  146. @onRemove="(file, fileList, fileIndex) => handleRemove(file, fileList, index, fileIndex, 'detail')"
  147. @onSuccess="(file, fileList) => handleUploadSuccess(file, fileList, index, 'detail')"
  148. :fileList="inputForm.wareHouse[index].fileInfoLost" :limit="3" :isDelete="nodeFlag"
  149. :isUpload="nodeFlag">
  150. </UploadComponent>
  151. </u-form-item>
  152. <u-form-item label="" v-if="!nodeFlag">
  153. <view class="row-action-group">
  154. <el-button style="width: 100%" type="danger" plain @click="removeWareHouseRow(index)">
  155. 删除明细
  156. </el-button>
  157. </view>
  158. </u-form-item>
  159. </view>
  160. <u-form-item label="" v-if="!nodeFlag">
  161. <el-button style="width: 100%" type="primary" @click="addWareHouseRow()" plain>新增入库明细</el-button>
  162. </u-form-item>
  163. </view>
  164. <u-form-item label="修改原因" borderBottom prop="updateCause" :required="true">
  165. <u--textarea placeholder="请填写修改原因" :rows="5" :maxlength="500" v-model="inputForm.updateCause"
  166. :disabled="nodeFlag"></u--textarea>
  167. </u-form-item>
  168. <u-form-item label="附件">
  169. <UploadComponent :uploadUrl="`${uploadUrl}/public-modules-server/oss/file/webUpload/upload`"
  170. @onRemove="(file, fileList, fileIndex) => handleRemove(file, fileList, '', fileIndex, '')"
  171. @onSuccess="(file, fileList) => handleUploadSuccess(file, fileList, '', '')"
  172. :fileList="inputForm.files" :limit="3" :isDelete="nodeFlag" :isUpload="nodeFlag">
  173. </UploadComponent>
  174. </u-form-item>
  175. </u--form>
  176. <user-select ref="userPicker" @input="handleUserSelected"></user-select>
  177. <ba-tree-picker ref="treePicker" :multiple="false" @select-change="selectTypeChange" title="类型选择"
  178. :localdata="listData" valueKey="value" textKey="label" childrenKey="children" />
  179. </view>
  180. </template>
  181. <script>
  182. import { mapState } from 'vuex'
  183. import userSelect from '@/components/user-select/user-select-radio.vue'
  184. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  185. import UploadComponent from '@/pages/common/UploadComponent.vue'
  186. import upload from '@/utils/upload.js'
  187. import MaterialTypeService from '@/api/psi/MaterialTypeService'
  188. import MaterialManagementService from '@/api/psi/MaterialManagementService'
  189. import WareHouseService from '@/api/psi/WareHouseService'
  190. import CommonApi from '@/api/common/CommonApi'
  191. import PurchaseSelector from './PurchaseSelector.vue'
  192. import WareHouseGoodsSelector from './WareHouseGoodsSelector.vue'
  193. export default {
  194. name: 'PsiWareHouseUpdateForm',
  195. components: {
  196. userSelect,
  197. baTreePicker,
  198. UploadComponent,
  199. PurchaseSelector,
  200. WareHouseGoodsSelector
  201. },
  202. computed: mapState({
  203. userInfo: (state) => state.user.userInfo
  204. }),
  205. props: {
  206. businessId: {
  207. type: String,
  208. default: ''
  209. },
  210. formReadOnly: {
  211. type: Boolean,
  212. default: false
  213. },
  214. status: {
  215. type: String,
  216. default: ''
  217. },
  218. isCc: {
  219. type: Boolean,
  220. default: false
  221. },
  222. },
  223. data() {
  224. return {
  225. uploadUrl: upload.UPLOAD_URL,
  226. nodeFlag: false,
  227. loading: false,
  228. listData: [],
  229. materialList: [],
  230. currentTypeIndex: -1,
  231. originalWareHouseRows: [],
  232. inputForm: this.createInputForm(),
  233. rules: {
  234. wareHouseName: [
  235. {
  236. required: true,
  237. message: '入库名称不能为空',
  238. trigger: ['blur', 'change']
  239. }
  240. ],
  241. updateCause: [
  242. {
  243. required: true,
  244. message: '修改原因不能为空',
  245. trigger: ['blur', 'change']
  246. }
  247. ]
  248. },
  249. shelfLifeUnitOptions: [
  250. { label: '年', value: '年' },
  251. { label: '月', value: '月' },
  252. { label: '天', value: '天' }
  253. ]
  254. }
  255. },
  256. materialTypeService: null,
  257. materialManagementService: null,
  258. wareHouseService: null,
  259. commonApi: null,
  260. created() {
  261. this.ensureServices()
  262. this.loadMaterialTypes()
  263. this.fillUserInfo()
  264. },
  265. watch: {
  266. businessId: {
  267. handler() {
  268. if (this.businessId) {
  269. this.init(this.businessId)
  270. } else {
  271. this.resetForm()
  272. this.nodeFlag = false
  273. }
  274. },
  275. immediate: true,
  276. deep: false
  277. }
  278. },
  279. async onLoad(options = {}) {
  280. const id = options.id || options.businessId || ''
  281. if (!id) {
  282. return
  283. }
  284. await this.init(id)
  285. if (options.readOnly === 'true' || options.method === 'view') {
  286. this.nodeFlag = true
  287. }
  288. },
  289. methods: {
  290. createInputForm() {
  291. return {
  292. id: '',
  293. procInsId: '',
  294. processDefinitionId: '',
  295. status: '',
  296. wareHouseTotalPrice: '',
  297. wareHouseActualPrice: '',
  298. tradeTotalPrice: '',
  299. fileInfoLost: [],
  300. purchaseNo: '',
  301. purchaseId: '',
  302. handledBy: '',
  303. handledById: '',
  304. handledByOffice: '',
  305. handledByOfficeName: '',
  306. wareHouseName: '',
  307. wareHouseNumber: '',
  308. userId: '',
  309. wareHouseDate: '',
  310. remarks: '',
  311. detailInfos: [],
  312. wareHouse: [],
  313. files: [],
  314. functionFlag: '',
  315. updateCause: ''
  316. }
  317. },
  318. ensureServices() {
  319. if (!this.materialTypeService) {
  320. this.materialTypeService = new MaterialTypeService()
  321. }
  322. if (!this.materialManagementService) {
  323. this.materialManagementService = new MaterialManagementService()
  324. }
  325. if (!this.wareHouseService) {
  326. this.wareHouseService = new WareHouseService()
  327. }
  328. if (!this.commonApi) {
  329. this.commonApi = new CommonApi()
  330. }
  331. },
  332. async loadMaterialTypes() {
  333. try {
  334. const data = await this.materialTypeService.cgList()
  335. this.materialList = data || []
  336. this.listData = this.buildTree(this.materialList)
  337. } catch (e) {
  338. this.materialList = []
  339. this.listData = []
  340. }
  341. },
  342. fillUserInfo() {
  343. if (!this.userInfo) {
  344. return
  345. }
  346. this.inputForm.handledBy = this.inputForm.handledBy || this.userInfo.name
  347. this.inputForm.handledById = this.inputForm.handledById || this.userInfo.id
  348. this.inputForm.userId = this.inputForm.userId || this.userInfo.id
  349. this.inputForm.handledByOffice = this.inputForm.handledByOffice || (this.userInfo.officeDTO && this.userInfo.officeDTO.id) || ''
  350. this.inputForm.handledByOfficeName = this.inputForm.handledByOfficeName || (this.userInfo.officeDTO && this.userInfo.officeDTO.name) || ''
  351. },
  352. resetForm() {
  353. this.inputForm = this.createInputForm()
  354. this.originalWareHouseRows = []
  355. this.fillUserInfo()
  356. },
  357. async init(id) {
  358. this.ensureServices()
  359. this.resetForm()
  360. this.inputForm.id = id
  361. this.loading = true
  362. try {
  363. let data = await this.wareHouseService.findById(id, this.status)
  364. if (data && data.status === '5' && this.status === 'taskFormDetail') {
  365. try {
  366. data = await this.wareHouseService.findLastHiByid(id)
  367. } catch (e) {
  368. }
  369. }
  370. this.inputForm = this.normalizeFormData(this.recover(this.createInputForm(), data))
  371. if (this.isEmpty(this.inputForm.id)) {
  372. this.inputForm.id = id
  373. }
  374. this.originalWareHouseRows = this.cloneRows(this.inputForm.wareHouse)
  375. this.fillUserInfo()
  376. this.nodeFlag = await this.resolveNodeFlag(data)
  377. this.calculateDetailTotalPrice()
  378. this.calculateWareHouseTotals()
  379. } catch (e) {
  380. this.nodeFlag = true
  381. } finally {
  382. this.loading = false
  383. }
  384. },
  385. async resolveNodeFlag(data) {
  386. if (this.formReadOnly || this.status === 'taskFormDetail' || this.status === 'testSee') {
  387. return true
  388. }
  389. try {
  390. const taskName = await this.commonApi.getTaskNameByProcInsId((data && data.procInsId) || this.inputForm.procInsId)
  391. if (this.isNotEmpty(taskName)) {
  392. return taskName !== '发起人重新发起申请'
  393. }
  394. } catch (e) {
  395. }
  396. return false
  397. },
  398. normalizeFormData(data) {
  399. const form = data || this.createInputForm()
  400. if (this.isNotEmpty(form.wareHouseDate)) {
  401. form.wareHouseDate = this.formatDate(form.wareHouseDate)
  402. }
  403. form.detailInfos = (form.detailInfos || []).map(item => ({
  404. ...item,
  405. fileInfoLost: item.fileInfoLost || [],
  406. priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
  407. }))
  408. form.wareHouse = (form.wareHouse || [])
  409. .filter(item => item.upFlag !== '1' && item.upFlag !== '2')
  410. .map(item => ({
  411. ...item,
  412. fileInfoLost: item.fileInfoLost || [],
  413. upFlag: item.upFlag || '0',
  414. produceDate: this.isNotEmpty(item.produceDate) ? new Date(item.produceDate) : '',
  415. priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
  416. }))
  417. return form
  418. },
  419. cloneRows(rows) {
  420. return JSON.parse(JSON.stringify(rows || []))
  421. },
  422. buildTree(nodes, parentId = '0') {
  423. const tree = []
  424. for (const node of nodes || []) {
  425. if (String(node.infoType || node.info_type || '') === '1') {
  426. continue
  427. }
  428. if (node.parentId === parentId) {
  429. const children = this.buildTree(nodes, node.id)
  430. if (children.length) {
  431. node.children = children
  432. }
  433. tree.push(node)
  434. }
  435. }
  436. return tree
  437. },
  438. isEmpty(value) {
  439. if (value === null || value === undefined) {
  440. return true
  441. }
  442. if (typeof value === 'string' && value.trim() === '') {
  443. return true
  444. }
  445. if (Array.isArray(value) && value.length === 0) {
  446. return true
  447. }
  448. return false
  449. },
  450. isNotEmpty(value) {
  451. return !this.isEmpty(value)
  452. },
  453. resolveBusinessId() {
  454. return this.inputForm.id || this.businessId || ''
  455. },
  456. ensureBusinessId() {
  457. const id = this.resolveBusinessId()
  458. if (this.isNotEmpty(id) && this.isEmpty(this.inputForm.id)) {
  459. this.inputForm.id = id
  460. }
  461. return id
  462. },
  463. computePriceSum(price, number) {
  464. if (this.isEmpty(price) || this.isEmpty(number)) {
  465. return ''
  466. }
  467. const amount = parseFloat(price || 0) * parseFloat(number || 0)
  468. if (Number.isNaN(amount)) {
  469. return ''
  470. }
  471. return amount.toFixed(2)
  472. },
  473. calculateDetailTotalPrice() {
  474. const total = (this.inputForm.detailInfos || []).reduce((sum, item) => {
  475. return sum + parseFloat(item.priceSum || 0)
  476. }, 0)
  477. this.inputForm.tradeTotalPrice = total ? total.toFixed(2) : ''
  478. },
  479. calculateWareHouseTotals() {
  480. const totalPrice = (this.inputForm.wareHouse || []).reduce((sum, item) => {
  481. return sum + parseFloat(item.priceSum || 0)
  482. }, 0)
  483. const totalActual = (this.inputForm.wareHouse || []).reduce((sum, item) => {
  484. return sum + parseFloat(item.actualPrice || 0)
  485. }, 0)
  486. this.inputForm.wareHouseTotalPrice = totalPrice ? totalPrice.toFixed(2) : ''
  487. this.inputForm.wareHouseActualPrice = totalActual ? totalActual.toFixed(2) : ''
  488. },
  489. getOriginalWareHouseRow(row) {
  490. const rowId = row && row.id
  491. if (this.isEmpty(rowId)) {
  492. return null
  493. }
  494. return (this.originalWareHouseRows || []).find(item => item.id === rowId) || null
  495. },
  496. isWareHouseRowChanged(row, originalRow) {
  497. if (!row || !originalRow) {
  498. return false
  499. }
  500. const fields = [
  501. 'wareHouseManId',
  502. 'wareHouseMan',
  503. 'deptId',
  504. 'wareHouseManOffice',
  505. 'wareHouseTypeId',
  506. 'wareHouseType',
  507. 'tradeName',
  508. 'tradeNumber',
  509. 'company',
  510. 'brand',
  511. 'specification',
  512. 'spec',
  513. 'tradePrice',
  514. 'actualPrice',
  515. 'produceDate',
  516. 'shelfLife',
  517. 'shelfLifeUnit',
  518. 'remarks'
  519. ]
  520. return fields.some(field => {
  521. let nextValue = row[field]
  522. let oldValue = originalRow[field]
  523. if (field === 'produceDate') {
  524. nextValue = this.formatDate(nextValue)
  525. oldValue = this.formatDate(oldValue)
  526. }
  527. return String(nextValue || '') !== String(oldValue || '')
  528. })
  529. },
  530. markChangedRowsForSubmit() {
  531. ;(this.inputForm.wareHouse || []).forEach((row, index) => {
  532. if (this.isEmpty(row.id) || this.isNotEmpty(row.sourceId)) {
  533. return
  534. }
  535. const originalRow = this.getOriginalWareHouseRow(row)
  536. if (this.isWareHouseRowChanged(row, originalRow)) {
  537. this.$set(this.inputForm.wareHouse[index], 'upFlag', '1')
  538. }
  539. })
  540. },
  541. normalizeWareHouseAmounts() {
  542. ;(this.inputForm.wareHouse || []).forEach((row, index) => {
  543. this.$set(this.inputForm.wareHouse[index], 'priceSum', this.computePriceSum(row.tradePrice, row.tradeNumber))
  544. })
  545. this.calculateWareHouseTotals()
  546. },
  547. openUserPullForm(index) {
  548. if (this.nodeFlag) {
  549. return
  550. }
  551. this.$refs.userPicker.open(index, 'wareHouse')
  552. },
  553. handleUserSelected(data, index, type) {
  554. if (type !== 'wareHouse') {
  555. return
  556. }
  557. this.patchWareHouseRow(index, {
  558. wareHouseManId: data.id,
  559. wareHouseMan: data.label,
  560. wareHouseManOffice: data.parentLabel,
  561. deptId: data.parentId
  562. })
  563. },
  564. openTypePicker(index) {
  565. if (this.nodeFlag) {
  566. return
  567. }
  568. this.currentTypeIndex = index
  569. this.$refs.treePicker._show(index)
  570. },
  571. selectTypeChange(ids, names, index) {
  572. this.patchWareHouseRow(index, {
  573. wareHouseType: names,
  574. wareHouseTypeId: ids[0],
  575. tradeName: '',
  576. tradePrice: '',
  577. tradeNumber: '',
  578. priceSum: '',
  579. company: '',
  580. brand: '',
  581. specification: '',
  582. spec: '1',
  583. actualPrice: '',
  584. surplusNumber: ''
  585. })
  586. },
  587. async handlePurchaseSelected(row) {
  588. try {
  589. const data = await this.materialManagementService.findById(row.id)
  590. if (this.isNotEmpty(this.inputForm.purchaseNo) && this.inputForm.purchaseNo !== data.purchaseNo) {
  591. this.inputForm.wareHouse = []
  592. }
  593. this.inputForm.purchaseNo = data.purchaseNo || row.purchaseNo
  594. this.inputForm.purchaseId = row.id
  595. this.inputForm.detailInfos = (data.detailInfos || []).map(item => ({
  596. ...item,
  597. fileInfoLost: item.fileInfoLost || [],
  598. priceSum: this.computePriceSum(item.tradePrice, item.tradeNumber)
  599. }))
  600. this.calculateDetailTotalPrice()
  601. this.calculateWareHouseTotals()
  602. } catch (e) {
  603. uni.showToast({
  604. title: '采购详情加载失败',
  605. icon: 'none'
  606. })
  607. }
  608. },
  609. handleGoodsSelected({ index, item }) {
  610. const tradeName = item.tradeName || item.name || ''
  611. this.patchWareHouseRow(index, {
  612. wareHouseType: tradeName,
  613. wareHouseTypeId: item.id || '',
  614. tradeName,
  615. goodsName: tradeName,
  616. brand: item.brand || '',
  617. specification: item.specification || '',
  618. company: item.company || '',
  619. spec: '1'
  620. })
  621. },
  622. createWareHouseRow() {
  623. return {
  624. id: '',
  625. wareHouseManId: this.userInfo && this.userInfo.id,
  626. wareHouseMan: this.userInfo && this.userInfo.name,
  627. wareHouseManOffice: this.userInfo && this.userInfo.officeDTO && this.userInfo.officeDTO.name,
  628. deptId: this.userInfo && this.userInfo.officeDTO && this.userInfo.officeDTO.id,
  629. wareHouseType: '',
  630. wareHouseTypeId: '',
  631. tradeName: '',
  632. tradeNumber: '',
  633. company: '',
  634. brand: '',
  635. specification: '',
  636. spec: '1',
  637. tradePrice: '',
  638. priceSum: '',
  639. produceDate: '',
  640. shelfLife: '',
  641. shelfLifeUnit: '',
  642. actualPrice: '',
  643. remarks: '',
  644. fileInfoLost: [],
  645. upFlag: '0',
  646. sourceId: ''
  647. }
  648. },
  649. addWareHouseRow() {
  650. this.inputForm.wareHouse.push(this.createWareHouseRow())
  651. this.calculateWareHouseTotals()
  652. },
  653. patchWareHouseRow(index, patch, markChanged = true) {
  654. const row = (this.inputForm.wareHouse || [])[index] || {}
  655. const nextRow = {
  656. ...row,
  657. ...patch
  658. }
  659. if (markChanged) {
  660. if (this.isNotEmpty(row.id) && this.isEmpty(row.sourceId)) {
  661. nextRow.upFlag = '1'
  662. } else {
  663. nextRow.upFlag = row.upFlag || '0'
  664. }
  665. }
  666. if (Object.prototype.hasOwnProperty.call(patch, 'tradePrice') || Object.prototype.hasOwnProperty.call(patch, 'tradeNumber')) {
  667. nextRow.priceSum = this.computePriceSum(nextRow.tradePrice, nextRow.tradeNumber)
  668. }
  669. this.$set(this.inputForm.wareHouse, index, nextRow)
  670. this.calculateWareHouseTotals()
  671. },
  672. markWareHouseModified(index) {
  673. const row = (this.inputForm.wareHouse || [])[index]
  674. if (!row) {
  675. return
  676. }
  677. if (this.isNotEmpty(row.id) && this.isEmpty(row.sourceId) && row.upFlag !== '1') {
  678. this.$set(this.inputForm.wareHouse[index], 'upFlag', '1')
  679. }
  680. },
  681. removeWareHouseRow(index) {
  682. this.inputForm.wareHouse.splice(index, 1)
  683. this.calculateWareHouseTotals()
  684. },
  685. onRowInputBlur(index, field) {
  686. const row = (this.inputForm.wareHouse || [])[index]
  687. if (!row) {
  688. return
  689. }
  690. let value = row[field]
  691. if (['tradeNumber', 'tradePrice', 'actualPrice'].includes(field)) {
  692. value = this.formatNumberInput(value)
  693. }
  694. if (field === 'spec') {
  695. value = this.formatIntegerInput(value)
  696. }
  697. this.patchWareHouseRow(index, {
  698. [field]: value
  699. })
  700. },
  701. formatNumberInput(inputValue, decimalLimit = 2) {
  702. if (this.isEmpty(inputValue)) {
  703. return ''
  704. }
  705. const valueText = String(inputValue)
  706. if (!/^\d*\.?\d*$/.test(valueText)) {
  707. return ''
  708. }
  709. let value = valueText.replace(/[^\d.]/g, '')
  710. const dotIndex = value.indexOf('.')
  711. if (dotIndex !== -1) {
  712. const substr = value.substr(dotIndex + 1)
  713. if (substr.indexOf('.') !== -1) {
  714. value = value.substr(0, dotIndex + 1) + substr.replace(/\./g, '')
  715. }
  716. }
  717. if (dotIndex !== -1) {
  718. const integerPart = value.substring(0, dotIndex)
  719. const decimalPart = value.substring(dotIndex + 1, dotIndex + 1 + decimalLimit)
  720. value = integerPart + '.' + decimalPart
  721. }
  722. return value
  723. },
  724. formatIntegerInput(inputValue) {
  725. if (this.isEmpty(inputValue)) {
  726. return ''
  727. }
  728. return String(inputValue).replace(/[^\d]/g, '')
  729. },
  730. handleUploadSuccess(file, fileList, index, type) {
  731. if (type === 'detail') {
  732. this.inputForm.wareHouse[index].fileInfoLost = fileList
  733. this.markWareHouseModified(index)
  734. } else {
  735. this.inputForm.files = fileList
  736. }
  737. },
  738. handleRemove(file, fileList, lineIndex, fileIndex, type) {
  739. if (type === 'detail') {
  740. this.inputForm.wareHouse[lineIndex].fileInfoLost.splice(fileIndex, 1)
  741. this.markWareHouseModified(lineIndex)
  742. } else {
  743. this.inputForm.files.splice(fileIndex, 1)
  744. }
  745. },
  746. formatDate(date) {
  747. if (this.isEmpty(date)) {
  748. return ''
  749. }
  750. const dateNew = new Date(date)
  751. if (Number.isNaN(dateNew.getTime())) {
  752. return ''
  753. }
  754. const year = dateNew.getFullYear()
  755. const month = `${dateNew.getMonth() + 1}`.padStart(2, '0')
  756. const day = `${dateNew.getDate()}`.padStart(2, '0')
  757. return `${year}-${month}-${day}`
  758. },
  759. toSubmitData() {
  760. const businessId = this.ensureBusinessId()
  761. this.normalizeWareHouseAmounts()
  762. this.markChangedRowsForSubmit()
  763. const data = JSON.parse(JSON.stringify(this.inputForm))
  764. data.id = data.id || businessId
  765. data.wareHouseDate = this.formatDate(this.inputForm.wareHouseDate)
  766. data.tradeTotalPrice = this.normalizeOptionalNumber(data.tradeTotalPrice)
  767. data.wareHouseTotalPrice = this.normalizeOptionalNumber(data.wareHouseTotalPrice)
  768. data.wareHouseActualPrice = this.normalizeOptionalNumber(data.wareHouseActualPrice)
  769. data.wareHouse = (this.inputForm.wareHouse || []).map(item => ({
  770. ...JSON.parse(JSON.stringify(item)),
  771. produceDate: this.formatDate(item.produceDate),
  772. priceSum: this.normalizeOptionalNumber(this.computePriceSum(item.tradePrice, item.tradeNumber)),
  773. tradeTotalPrice: this.normalizeOptionalNumber(item.tradeTotalPrice),
  774. actualPrice: this.normalizeOptionalNumber(item.actualPrice)
  775. }))
  776. return data
  777. },
  778. normalizeOptionalNumber(value) {
  779. if (this.isEmpty(value)) {
  780. return null
  781. }
  782. return value
  783. },
  784. validateBaseForm() {
  785. if (this.isEmpty(this.inputForm.wareHouseDate)) {
  786. this.$message.error('入库时间不能为空')
  787. return false
  788. }
  789. return true
  790. },
  791. validateBusinessId() {
  792. if (this.isEmpty(this.ensureBusinessId())) {
  793. this.$message.error('入库数据ID为空,请返回列表重新进入')
  794. return false
  795. }
  796. return true
  797. },
  798. validateWareHouseRows() {
  799. if (this.isEmpty(this.inputForm.wareHouse)) {
  800. return true
  801. }
  802. const rows = this.inputForm.wareHouse
  803. for (let i = 0; i < rows.length; i++) {
  804. const row = rows[i]
  805. const lineNo = i + 1
  806. if (this.isEmpty(row.wareHouseMan)) {
  807. this.$message.error(`入库详情第${lineNo}行请选择入库人`)
  808. return false
  809. }
  810. if (this.isEmpty(row.wareHouseType)) {
  811. this.$message.error(`入库详情第${lineNo}行请选择入库类型`)
  812. return false
  813. }
  814. if (this.isEmpty(row.tradeName)) {
  815. this.$message.error(`入库详情第${lineNo}行请填写商品名称`)
  816. return false
  817. }
  818. if (this.isEmpty(row.tradeNumber)) {
  819. this.$message.error(`入库详情第${lineNo}行请填写商品数量`)
  820. return false
  821. }
  822. }
  823. for (let i = 0; i < rows.length; i++) {
  824. for (let j = i + 1; j < rows.length; j++) {
  825. if (rows[i].wareHouseTypeId === rows[j].wareHouseTypeId &&
  826. rows[i].tradeName === rows[j].tradeName) {
  827. this.$message.warning('入库详情中,同种入库类型的商品名称只能输入一条')
  828. return false
  829. }
  830. }
  831. }
  832. return true
  833. },
  834. async saveForm(callback) {
  835. try {
  836. if (!this.validateBaseForm()) {
  837. return
  838. }
  839. if (!this.validateBusinessId()) {
  840. return
  841. }
  842. await this.$refs.inputForm.validate()
  843. if (!this.validateWareHouseRows()) {
  844. return
  845. }
  846. this.loading = true
  847. this.calculateDetailTotalPrice()
  848. this.calculateWareHouseTotals()
  849. const submitData = this.toSubmitData()
  850. submitData.status = '1'
  851. submitData.functionFlag = ''
  852. this.inputForm.status = '1'
  853. const data = await this.wareHouseService.save(submitData)
  854. callback(data.businessTable, data.businessId, submitData)
  855. } finally {
  856. this.loading = false
  857. }
  858. },
  859. async startForm(callback) {
  860. this.loading = true
  861. try {
  862. const id = this.ensureBusinessId()
  863. if (this.isNotEmpty(id)) {
  864. const data = await this.wareHouseService.findById(id)
  865. if (this.isNotEmpty(data.status) && !['0', '1', '3', '5'].includes(data.status)) {
  866. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  867. throw new Error('invalid status')
  868. }
  869. }
  870. await this.startFormTrue(callback)
  871. } finally {
  872. this.loading = false
  873. }
  874. },
  875. async startFormTrue(callback) {
  876. if (!this.validateBaseForm()) {
  877. return
  878. }
  879. if (!this.validateBusinessId()) {
  880. return
  881. }
  882. await this.$refs.inputForm.validate()
  883. if (!this.validateWareHouseRows()) {
  884. return
  885. }
  886. this.calculateDetailTotalPrice()
  887. this.calculateWareHouseTotals()
  888. const submitData = this.toSubmitData()
  889. submitData.status = '2'
  890. submitData.functionFlag = 'start'
  891. this.inputForm.status = '2'
  892. this.inputForm.functionFlag = 'start'
  893. const data = await this.wareHouseService.save(submitData)
  894. this.inputForm.id = data.businessId
  895. callback(data.businessTable, data.businessId, submitData)
  896. },
  897. async reapplyForm(callback) {
  898. this.loading = true
  899. try {
  900. const id = this.ensureBusinessId()
  901. if (this.isEmpty(id)) {
  902. this.$message.error('入库数据ID为空,请返回列表重新进入')
  903. throw new Error('missing business id')
  904. }
  905. const data = await this.wareHouseService.findById(id)
  906. if (data.status !== '4') {
  907. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  908. throw new Error('invalid status')
  909. }
  910. await this.startFormTrue(callback)
  911. } finally {
  912. this.loading = false
  913. }
  914. },
  915. async agreeForm(callback) {
  916. this.loading = true
  917. try {
  918. if (!this.validateBaseForm()) {
  919. return
  920. }
  921. if (!this.validateBusinessId()) {
  922. return
  923. }
  924. await this.$refs.inputForm.validate()
  925. if (!this.validateWareHouseRows()) {
  926. return
  927. }
  928. this.calculateDetailTotalPrice()
  929. this.calculateWareHouseTotals()
  930. const submitData = this.toSubmitData()
  931. submitData.status = '5'
  932. submitData.functionFlag = 'agree'
  933. this.inputForm.status = '5'
  934. this.inputForm.functionFlag = 'agree'
  935. const data = await this.wareHouseService.save(submitData)
  936. callback(data.businessTable, data.businessId, submitData)
  937. } finally {
  938. this.loading = false
  939. }
  940. },
  941. async updateStatusById(type, callback) {
  942. this.loading = true
  943. try {
  944. const id = this.ensureBusinessId()
  945. if (this.isEmpty(id)) {
  946. this.$message.error('入库数据ID为空,请返回列表重新进入')
  947. throw new Error('missing business id')
  948. }
  949. if (type === 'reject' || type === 'reback') {
  950. const data = await this.wareHouseService.findById(id)
  951. if (data.status !== '2') {
  952. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  953. throw new Error('invalid status')
  954. }
  955. const status = type === 'reject' ? '4' : '3'
  956. this.inputForm.status = status
  957. await this.wareHouseService.updateStatusById({
  958. status,
  959. id
  960. })
  961. callback()
  962. } else if (type === 'hold') {
  963. const data = await this.wareHouseService.findById(id)
  964. if (data.status !== '4') {
  965. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  966. throw new Error('invalid status')
  967. }
  968. await this.wareHouseService.backSourceData(id)
  969. callback()
  970. }
  971. } finally {
  972. this.loading = false
  973. }
  974. }
  975. }
  976. }
  977. </script>
  978. <style scoped>
  979. .section-wrap {
  980. margin-top: 24rpx;
  981. }
  982. .section-title {
  983. margin-bottom: 16rpx;
  984. padding-left: 8rpx;
  985. font-size: 30rpx;
  986. font-weight: 700;
  987. color: #1f2937;
  988. border-left: 6rpx solid #2979ff;
  989. }
  990. .detail-card {
  991. margin-bottom: 20rpx;
  992. padding: 24rpx;
  993. background: #fff;
  994. border-radius: 20rpx;
  995. box-shadow: 0 10rpx 30rpx rgba(15, 23, 42, 0.05);
  996. }
  997. .detail-card-head {
  998. display: flex;
  999. align-items: center;
  1000. justify-content: space-between;
  1001. margin-bottom: 12rpx;
  1002. }
  1003. .detail-card-title {
  1004. font-size: 28rpx;
  1005. font-weight: 600;
  1006. color: #0f172a;
  1007. }
  1008. .detail-grid {
  1009. display: grid;
  1010. grid-template-columns: repeat(2, minmax(0, 1fr));
  1011. gap: 16rpx;
  1012. }
  1013. .detail-item {
  1014. display: flex;
  1015. flex-direction: column;
  1016. padding: 18rpx 20rpx;
  1017. background: #f8fafc;
  1018. border-radius: 16rpx;
  1019. }
  1020. .detail-label {
  1021. font-size: 22rpx;
  1022. color: #64748b;
  1023. }
  1024. .detail-value {
  1025. margin-top: 8rpx;
  1026. font-size: 26rpx;
  1027. line-height: 1.5;
  1028. color: #0f172a;
  1029. word-break: break-all;
  1030. }
  1031. .row-action-group {
  1032. display: flex;
  1033. gap: 16rpx;
  1034. width: 100%;
  1035. }
  1036. .shelf-life-wrap {
  1037. display: flex;
  1038. width: 100%;
  1039. gap: 16rpx;
  1040. }
  1041. .shelf-life-input {
  1042. flex: 1;
  1043. min-width: 0;
  1044. }
  1045. .shelf-life-unit {
  1046. flex: 0 0 128rpx;
  1047. width: 128rpx;
  1048. }
  1049. @media (max-width: 768px) {
  1050. .detail-grid {
  1051. grid-template-columns: repeat(1, minmax(0, 1fr));
  1052. }
  1053. }
  1054. </style>