WareHouseUpdateForm.vue 37 KB

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