WareHouseUpdateForm.vue 36 KB

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