WareHouseUpdateForm.vue 44 KB

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