WareHouseUpdateForm.vue 41 KB

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