applyNew.uvue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. <template>
  2. <uni-navbar-lite :showRight=false title="物料申请"></uni-navbar-lite>
  3. <view class="page-container">
  4. <scroll-view class="page-content">
  5. <view class="section">
  6. <view class="search-bar">
  7. <view class="search-box">
  8. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  9. <input class="search-input" type="text" placeholder="请输入关键字查询" v-model="keyword" @input="handleSearch" />
  10. <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
  11. <text class="clear-btn-text">×</text>
  12. </view>
  13. <view class="search-btn" @tap="handleSearch">
  14. <text class="search-btn-text">搜索</text>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="status-tabs">
  19. <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false">
  20. <view
  21. v-for="(cat, idx) in categories"
  22. :key="idx"
  23. class="status-tab"
  24. :class="{ 'active': currentStatus === cat.id }"
  25. @click="switchStatus(cat.id)"
  26. >
  27. <text class="status-tab-text" :class="{ 'active-text': currentStatus === cat.id }">{{ cat.name }}</text>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <view class="section">
  33. <view class="section-header">
  34. <view class="section-header-left">
  35. <view class="section-indicator"></view>
  36. <text class="section-title">物料列表</text>
  37. </view>
  38. <view class="add-material-btn" @click="showAddMaterialModal = true">
  39. <text class="add-material-text">新物料</text>
  40. </view>
  41. </view>
  42. <view class="material-list">
  43. <view
  44. v-for="(item, index) in dataList"
  45. :key="item.itemId + '_' + page"
  46. class="list-item"
  47. @click="handleItemClick(item, index)"
  48. >
  49. <view class="item-header">
  50. <view class="item-info">
  51. <view class="item-name-row">
  52. <text class="item-name" :class="{'status-0': getAuditStatus(item) == 0, 'status-2': getAuditStatus(item) == 3}">{{ getItemName(item) }}</text>
  53. <text class="item-measure">{{ getMeasureName(item) }}</text>
  54. </view>
  55. <view class="item-sub-row">
  56. <text class="item-sub-title">{{ getItemTypeName(item) }}</text>
  57. <text class="item-stock">库存: {{ getStockNum(item) }}</text>
  58. </view>
  59. </view>
  60. <view class="item-actions">
  61. <view v-if="getAuditStatus(item) == 0 && !item.isSelected!" class="delete-btn" @click.stop="handleDeleteMaterial(item)">
  62. <text class="delete-icon">×</text>
  63. </view>
  64. <view v-if="item.isSelected" class="added-btn">
  65. <text class="added-icon">已选</text>
  66. </view>
  67. <view v-else-if="isItemDisabled(item)" class="add-btn disabled">
  68. <text class="add-icon">+</text>
  69. </view>
  70. <view v-else class="add-btn" @click.stop="addToSelected(item)">
  71. <text class="add-icon">+</text>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 手动分页 -->
  78. <view class="pagination">
  79. <view class="page-btn" :class="{disabled: page <= 1}" @click="prevPage">
  80. <text class="page-btn-text"><</text>
  81. </view>
  82. <text class="page-info">第{{ page }}页 / 共{{ totalPages }}页</text>
  83. <view class="page-btn" :class="{disabled: page >= totalPages}" @click="nextPage">
  84. <text class="page-btn-text">></text>
  85. </view>
  86. </view>
  87. </view>
  88. <view class="section">
  89. <view class="section-header">
  90. <view class="section-header-left">
  91. <view class="section-indicator"></view>
  92. <text class="section-title">已选列表</text>
  93. </view>
  94. </view>
  95. <view class="selected-list">
  96. <view v-if="selectedItems.length === 0" class="empty-tip">
  97. <text class="empty-tip-text">请选择物料</text>
  98. </view>
  99. <view
  100. v-else
  101. v-for="(selItem, selIndex) in selectedItems"
  102. :key="selIndex"
  103. class="selected-item"
  104. >
  105. <text class="selected-item-name">{{ selItem.itemName }}</text>
  106. <text class="selected-item-measure">{{ selItem.measureName }}</text>
  107. <view class="quantity-control">
  108. <view class="qty-btn" @click="decreaseQty(selIndex)">
  109. <text class="qty-btn-text">-</text>
  110. </view>
  111. <input
  112. class="quantity-input"
  113. type="digit"
  114. v-model="selItem.qty"
  115. placeholder="数量"
  116. />
  117. <view class="qty-btn" @click="increaseQty(selIndex)">
  118. <text class="qty-btn-text">+</text>
  119. </view>
  120. </view>
  121. <view class="delete-btn" @click="removeSelected(selIndex)">
  122. <text class="delete-icon">×</text>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. </scroll-view>
  128. <!-- 底部按钮 -->
  129. <view class="bottom-buttons">
  130. <view class="btn-row">
  131. <button class="save-btn" @click="saveApplication">保存</button>
  132. <button class="confirm-btn" @click="confirmApplication">确认申请</button>
  133. </view>
  134. </view>
  135. <!-- 新增物料弹窗 -->
  136. <view v-if="showAddMaterialModal" class="picker-modal">
  137. <view class="modal-mask" @click="showAddMaterialModal = false"></view>
  138. <view class="modal-content">
  139. <view class="modal-header">
  140. <text class="modal-title">新增物料</text>
  141. <text class="modal-close" @click="showAddMaterialModal = false">取消</text>
  142. </view>
  143. <view class="form-item-input">
  144. <text class="label-picker">物料名称</text>
  145. <view class="view-input-picker">
  146. <input class="input-picker" type="text" placeholder="请输入物料名称" v-model="newMaterial.itemName" />
  147. </view>
  148. </view>
  149. <view class="form-item-input">
  150. <text class="label-picker">规格型号</text>
  151. <view class="view-input-picker">
  152. <input class="input-picker" type="text" placeholder="请输入规格型号" v-model="newMaterial.specification" />
  153. </view>
  154. </view>
  155. <view class="form-item-input">
  156. <text class="label-picker">单位</text>
  157. <view class="view-input-picker measure-input-row">
  158. <input class="input-picker" type="text" placeholder="请输入或选择单位" v-model="newMaterial.measureName" />
  159. <view class="pick-btn" @click="showMeasurePicker = true">
  160. <text class="pick-btn-text">选择</text>
  161. </view>
  162. </view>
  163. </view>
  164. <view class="form-item-input">
  165. <text class="label-picker">产品链接</text>
  166. <view class="view-input-picker">
  167. <input class="input-picker" type="url" placeholder="请输入产品链接" v-model="newMaterial.productUrl" />
  168. </view>
  169. </view>
  170. <view class="form-item-input">
  171. <text class="label-picker">图片(最多3张)</text>
  172. <view class="upload-wrapper">
  173. <UploadImage
  174. :maxCount="3"
  175. :modelValue="newMaterial.imageUrls"
  176. businessType="material"
  177. @update:modelValue="handleImageUpdate"
  178. />
  179. </view>
  180. </view>
  181. <view class="form-item-btn">
  182. <button class="btn-primary" @click="handleAddMaterial">
  183. 保存
  184. </button>
  185. </view>
  186. </view>
  187. </view>
  188. <!-- 单位选择弹窗 -->
  189. <view v-if="showMeasurePicker" class="picker-modal">
  190. <view class="modal-mask" @click="showMeasurePicker = false"></view>
  191. <view class="modal-content">
  192. <view class="modal-header">
  193. <text class="modal-title">选择单位</text>
  194. <text class="modal-close" @click="showMeasurePicker = false">取消</text>
  195. </view>
  196. <scroll-view class="measure-list" :scroll-y="true">
  197. <view
  198. v-for="(item, index) in measureList"
  199. :key="index"
  200. class="measure-item"
  201. @click="selectMeasure(item)"
  202. >
  203. <text class="measure-name">{{ item['measureName'] }}</text>
  204. </view>
  205. <view v-if="measureList.length === 0" class="empty-tip">
  206. <text class="empty-tip-text">暂无单位数据</text>
  207. </view>
  208. </scroll-view>
  209. </view>
  210. </view>
  211. </view>
  212. </template>
  213. <script setup lang="uts">
  214. import { ref, computed, onBeforeUnmount, onMounted } from 'vue'
  215. import { getItemTypeListByParentId, getItemList, savePurchaseApply, confirmPurchaseApply, addMaterial, getMeasureList, deleteMaterial } from '../../api/apply/index'
  216. import UploadImage from '../../components/upload-image/upload-image.uvue'
  217. import type { UploadResponse } from '../../types/workbench'
  218. let searchTimer: number | null = null
  219. type CategoryItem = { id: string; name: string; code: string }
  220. type Item = {
  221. itemId: string;
  222. itemName: string;
  223. itemCode: string;
  224. itemTypeName: string;
  225. measureName: string;
  226. specification: string;
  227. imageUrls: string;
  228. productUrl: string;
  229. auditStatus: number;
  230. stockNum: number;
  231. isSelected?: boolean;
  232. }
  233. type SelectedItem = { itemId: string; itemName: string; itemTypeName: string; measureName: string; qty: string }
  234. const keyword = ref<string>("")
  235. const dataList = ref<Item[]>([])
  236. const selectedItems = ref<SelectedItem[]>([])
  237. const page = ref<number>(1)
  238. const pageSize: number = 10
  239. const total = ref<number>(0)
  240. const totalPages = computed((): number => {
  241. if (total.value <= 0) return 1
  242. return Math.ceil(total.value / pageSize)
  243. })
  244. const hasMore = ref<boolean>(true)
  245. const loading = ref<boolean>(false)
  246. const refreshing = ref<boolean>(false)
  247. const categories = ref<CategoryItem[]>([])
  248. const dealLoad = ref<boolean>(false)
  249. let currentStatus = ref<string>('')
  250. const isSearching = ref<boolean>(false)
  251. // 新增物料相关
  252. const showAddMaterialModal = ref<boolean>(false)
  253. const showMeasurePicker = ref<boolean>(false)
  254. const measureList = ref<UTSJSONObject[]>([])
  255. type NewMaterial = {
  256. itemName: string
  257. specification: string
  258. measureName: string
  259. imageUrls: UploadResponse[]
  260. productUrl: string
  261. }
  262. const newMaterial = ref<NewMaterial>({
  263. itemName: '',
  264. specification: '',
  265. measureName: '',
  266. imageUrls: [],
  267. productUrl: ''
  268. })
  269. // 加载单位列表
  270. const loadMeasureList = (): void => {
  271. getMeasureList().then((res: any) => {
  272. const data = res as UTSJSONObject
  273. const list = data['data']
  274. if (list != null) {
  275. measureList.value = list as UTSJSONObject[]
  276. }
  277. }).catch(() => {
  278. measureList.value = []
  279. })
  280. }
  281. // 选择单位
  282. const selectMeasure = (item: UTSJSONObject): void => {
  283. const measureName = item['measureName'] != null ? item['measureName'].toString() : ''
  284. newMaterial.value.measureName = measureName
  285. showMeasurePicker.value = false
  286. }
  287. // 获取当前选中的分类code
  288. const getCurrentCategoryCode = (): string => {
  289. const currentCat = categories.value.find((c: CategoryItem) => c.id === currentStatus.value)
  290. return currentCat != null ? currentCat.code : ''
  291. }
  292. // 加载物料列表
  293. const loadItems = (): void => {
  294. loading.value = true
  295. const itemTypeCode = getCurrentCategoryCode()
  296. getItemList(itemTypeCode, page.value, pageSize, keyword.value).then((res: any) => {
  297. const data = res as UTSJSONObject
  298. const rows = data['rows']
  299. const totalNum = data['total']
  300. if (totalNum != null) {
  301. total.value = totalNum as number
  302. }
  303. if (rows != null) {
  304. const listData = rows as UTSJSONObject[]
  305. if (listData.length > 0) {
  306. const arr: Item[] = []
  307. const selectedIds = selectedItems.value.map((s: SelectedItem) => s.itemId)
  308. listData.forEach((item: UTSJSONObject) => {
  309. const itemId = item['itemId'] != null ? item['itemId'].toString() : ''
  310. let auditStatus = -1
  311. const auditStatusVal = item['auditStatus']
  312. if (auditStatusVal != null) {
  313. if (typeof auditStatusVal === 'number') {
  314. auditStatus = auditStatusVal as number
  315. } else {
  316. auditStatus = parseInt(auditStatusVal.toString())
  317. }
  318. }
  319. let stockNum = 0
  320. const stockNumVal = item['stockNum']
  321. if (stockNumVal != null) {
  322. if (typeof stockNumVal === 'number') {
  323. stockNum = stockNumVal as number
  324. } else {
  325. stockNum = parseFloat(stockNumVal.toString())
  326. }
  327. }
  328. const it: Item = {
  329. itemId: itemId,
  330. itemName: item['itemName'] != null ? item['itemName'].toString() : '',
  331. itemCode: item['itemCode'] != null ? item['itemCode'].toString() : '',
  332. itemTypeName: item['itemTypeName'] != null ? item['itemTypeName'].toString() : '',
  333. measureName: item['measureName'] != null ? item['measureName'].toString() : '',
  334. specification: item['specification'] != null ? item['specification'].toString() : '',
  335. imageUrls: item['imageUrls'] != null ? item['imageUrls'].toString() : '',
  336. productUrl: item['productUrl'] != null ? item['productUrl'].toString() : '',
  337. isSelected: selectedIds.includes(itemId),
  338. auditStatus: auditStatus,
  339. stockNum: stockNum
  340. }
  341. arr.push(it)
  342. })
  343. dataList.value = arr
  344. loading.value = false
  345. return
  346. }
  347. }
  348. dataList.value = []
  349. loading.value = false
  350. }).catch(() => {
  351. dataList.value = []
  352. loading.value = false
  353. })
  354. }
  355. // 上一页
  356. const prevPage = (): void => {
  357. if (page.value > 1) {
  358. page.value--
  359. loadItems()
  360. }
  361. }
  362. // 下一页
  363. const nextPage = (): void => {
  364. if (page.value < totalPages.value) {
  365. page.value++
  366. loadItems()
  367. }
  368. }
  369. const loadCategories = (): void => {
  370. getItemTypeListByParentId(200).then((res: any) => {
  371. const data = res as UTSJSONObject
  372. const list = data['data']
  373. if (list != null) {
  374. const listData = list as UTSJSONObject[]
  375. if (listData.length > 0) {
  376. const arr: CategoryItem[] = []
  377. listData.forEach((item: UTSJSONObject) => {
  378. const idVal = item['itemTypeId']
  379. const nameVal = item['itemTypeName']
  380. const codeVal = item['itemTypeCode']
  381. const cat: CategoryItem = {
  382. id: idVal != null ? idVal.toString() : '',
  383. name: nameVal != null ? nameVal.toString() : '',
  384. code: codeVal != null ? codeVal.toString() : ''
  385. }
  386. arr.push(cat)
  387. })
  388. const allItem: CategoryItem = {id: '', name: '全部', code: ''}
  389. arr.unshift(allItem)
  390. categories.value = arr
  391. // 加载第一个分类的物料
  392. if (arr.length > 0) {
  393. currentStatus.value = arr[0].id
  394. loadItems()
  395. }
  396. return
  397. }
  398. }
  399. const defaultArr: CategoryItem[] = []
  400. const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
  401. defaultArr.push(defaultItem)
  402. categories.value = defaultArr
  403. }).catch(() => {
  404. const defaultArr: CategoryItem[] = []
  405. const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
  406. defaultArr.push(defaultItem)
  407. categories.value = defaultArr
  408. })
  409. }
  410. // 添加到已选列表
  411. const addToSelected = (item: any | null): void => {
  412. if (item == null) return
  413. const mdItem = item as Item
  414. // 检查审核状态
  415. if (mdItem.auditStatus != null && mdItem.auditStatus === 2) {
  416. uni.showToast({ title: '该物料已禁用,无法添加', icon: 'none'})
  417. return
  418. }
  419. // 检查是否已存在
  420. const exists = selectedItems.value.find((s: SelectedItem) => s.itemId === mdItem.itemId)
  421. if (exists != null) {
  422. uni.showToast({ title: '该物料已在选择列表中', icon: 'none'})
  423. return
  424. }
  425. const selItem: SelectedItem = {
  426. itemId: mdItem.itemId,
  427. itemName: mdItem.itemName,
  428. itemTypeName: mdItem.itemTypeName,
  429. measureName: mdItem.measureName,
  430. qty: '1'
  431. }
  432. selectedItems.value.push(selItem)
  433. // 更新 dataList 中的选中状态
  434. const idx = dataList.value.findIndex((d: Item) => d.itemId === mdItem.itemId)
  435. if (idx >= 0) {
  436. dataList.value[idx].isSelected = true
  437. }
  438. }
  439. // 删除已选
  440. const removeSelected = (index: number): void => {
  441. const removedItem = selectedItems.value[index]
  442. selectedItems.value.splice(index, 1)
  443. // 重新加载当前页数据以更新选中状态
  444. loadItems()
  445. }
  446. // 增加数量
  447. const increaseQty = (index: number): void => {
  448. const currentQty = parseInt(selectedItems.value[index].qty)
  449. selectedItems.value[index].qty = (currentQty + 1).toString()
  450. }
  451. // 减少数量
  452. const decreaseQty = (index: number): void => {
  453. const currentQty = parseInt(selectedItems.value[index].qty)
  454. if (currentQty > 1) {
  455. selectedItems.value[index].qty = (currentQty - 1).toString()
  456. }
  457. }
  458. const handleItemClick = (item: any | null, index: number): void => {
  459. if (item == null) return
  460. const mdItem = item as Item
  461. uni.navigateTo({
  462. url: `/pages/item/detail?id=${mdItem.itemId}`
  463. })
  464. }
  465. const getItemName = (item: any | null): string => {
  466. if (item == null) return ''
  467. const mdItem = item as Item
  468. return mdItem.itemName
  469. }
  470. const getItemTypeName = (item: any | null): string => {
  471. if (item == null) return ''
  472. const mdItem = item as Item
  473. return mdItem.itemTypeName
  474. }
  475. const getMeasureName = (item: any | null): string => {
  476. if (item == null) return ''
  477. const mdItem = item as Item
  478. return mdItem.measureName
  479. }
  480. const getStockNum = (item: any | null): string => {
  481. if (item == null) return '0'
  482. const mdItem = item as Item
  483. const stock = mdItem.stockNum != null ? mdItem.stockNum : 0
  484. return stock.toString()
  485. }
  486. const getAuditStatus = (item: any | null): number => {
  487. if (item == null) return -1
  488. const mdItem = item as Item
  489. return mdItem.auditStatus != null ? mdItem.auditStatus : -1
  490. }
  491. const isItemDisabled = (item: any | null): boolean => {
  492. if (item == null) return false
  493. const mdItem = item as Item
  494. const status = mdItem.auditStatus != null ? mdItem.auditStatus : -1
  495. return status == 3
  496. }
  497. // 检查物料是否已被选择
  498. const isItemSelected = (item: any | null): boolean => {
  499. if (item == null) return false
  500. const mdItem = item as Item
  501. return selectedItems.value.find((s: SelectedItem) => s.itemId === mdItem.itemId) != null
  502. }
  503. const handleSearch = (): void => {
  504. const timer = searchTimer
  505. if (timer != null) {
  506. clearTimeout(timer)
  507. }
  508. searchTimer = setTimeout(() => {
  509. page.value = 1
  510. loadItems()
  511. }, 300)
  512. }
  513. const clearKeyword = (): void => {
  514. keyword.value = ''
  515. page.value = 1
  516. loadItems()
  517. }
  518. const switchStatus = (status: string): void => {
  519. if (loading.value) {
  520. return;
  521. }
  522. if (isSearching.value) {
  523. return
  524. }
  525. isSearching.value = true
  526. currentStatus.value = status
  527. page.value = 1
  528. loadItems()
  529. setTimeout(() => {
  530. isSearching.value = false
  531. }, 100)
  532. }
  533. // 构建申请单数据
  534. const buildApplyData = (status: string): UTSJSONObject => {
  535. const applyLines: UTSJSONObject[] = []
  536. selectedItems.value.forEach((item: SelectedItem) => {
  537. const lineObj = new UTSJSONObject()
  538. lineObj['itemId'] = parseInt(item.itemId)
  539. lineObj['itemCode'] = ''
  540. lineObj['itemName'] = item.itemName
  541. lineObj['specification'] = ''
  542. lineObj['unitOfMeasure'] = ''
  543. lineObj['quantityApply'] = parseInt(item.qty)
  544. applyLines.push(lineObj)
  545. })
  546. const result = new UTSJSONObject()
  547. result['applyCode'] = ''
  548. result['applyName'] = '物料申请'
  549. result['status'] = status
  550. result['wmPurchaseApplyLineList'] = applyLines
  551. return result
  552. }
  553. // 来源页面
  554. const fromIndexPage = ref<boolean>(false)
  555. // 保存申请
  556. const saveApplication = (): void => {
  557. if (selectedItems.value.length === 0) {
  558. uni.showToast({ title: '请选择物料', icon: 'none'})
  559. return
  560. }
  561. // 构建申请单数据
  562. const applyData = buildApplyData('PREPARE')
  563. savePurchaseApply(applyData).then((res: any) => {
  564. uni.showToast({ title: '保存成功', icon: 'success'})
  565. // 清空已选列表
  566. selectedItems.value = []
  567. loadItems()
  568. // 如果从index.uvue跳转过来,返回index.uvue
  569. if (fromIndexPage.value) {
  570. setTimeout(() => {
  571. uni.navigateBack()
  572. }, 1000)
  573. }else{
  574. uni.navigateTo({
  575. url: `/pages/apply/index?from=new`
  576. })
  577. }
  578. }).catch((e) => {
  579. console.log(e)
  580. const error = e as UTSError
  581. const errMsg = error?.message
  582. uni.showToast({ title: errMsg.toString(), icon: 'none'})
  583. })
  584. }
  585. // 确认申请
  586. const confirmApplication = (): void => {
  587. if (selectedItems.value.length === 0) {
  588. uni.showToast({ title: '请选择物料', icon: 'none'})
  589. return
  590. }
  591. // 验证所有数量都大于0
  592. for (let i = 0; i < selectedItems.value.length; i++) {
  593. const qty = parseFloat(selectedItems.value[i].qty)
  594. if (qty <= 0) {
  595. uni.showToast({ title: '所有物料数量必须大于0', icon: 'none'})
  596. return
  597. }
  598. }
  599. // 构建申请单数据
  600. const applyData = buildApplyData('CONFIRMED')
  601. savePurchaseApply(applyData).then((res: any) => {
  602. uni.showToast({ title: '确认申请成功', icon: 'success'})
  603. // 清空已选列表
  604. selectedItems.value = []
  605. loadItems()
  606. // 如果从index.uvue跳转过来,返回index.uvue
  607. if (fromIndexPage.value) {
  608. setTimeout(() => {
  609. uni.navigateBack()
  610. }, 1000)
  611. }else{
  612. uni.navigateTo({
  613. url: `/pages/apply/index?from=new`
  614. })
  615. }
  616. }).catch((e) => {
  617. const error = e as UTSError
  618. const errMsg = error?.message
  619. uni.showToast({ title: errMsg.toString(), icon: 'none'})
  620. })
  621. }
  622. // 处理图片更新
  623. const handleImageUpdate = (value: UploadResponse[]): void => {
  624. newMaterial.value.imageUrls = value
  625. }
  626. // 处理新增物料
  627. const handleAddMaterial = async (): Promise<void> => {
  628. // 验证输入
  629. if (newMaterial.value.itemName.length == 0) {
  630. uni.showToast({ title: '请输入物料名称', icon: 'none'})
  631. return
  632. }
  633. if (newMaterial.value.measureName.length == 0) {
  634. uni.showToast({ title: '请输入单位', icon: 'none'})
  635. return
  636. }
  637. try {
  638. // 构建物料数据
  639. const materialData = new UTSJSONObject()
  640. materialData['itemShortName'] = newMaterial.value.itemName
  641. materialData['itemName'] = newMaterial.value.itemName + "("+newMaterial.value.specification+")"
  642. materialData['specification'] = newMaterial.value.specification
  643. materialData['measureName'] = newMaterial.value.measureName
  644. materialData['auditStatus'] = 0 // 审核状态为0
  645. // 从 UploadResponse 数组中提取 fileName 并拼接成逗号分隔的字符串
  646. const imageFileNames = newMaterial.value.imageUrls.map((item: UploadResponse) => item.fileName).join(',')
  647. materialData['imageUrls'] = imageFileNames
  648. materialData['productUrl'] = newMaterial.value.productUrl
  649. // 调用接口保存物料
  650. await addMaterial(materialData)
  651. // 保存成功
  652. uni.showToast({ title: '物料新增成功', icon: 'success'})
  653. // 关闭弹窗
  654. showAddMaterialModal.value = false
  655. // 清空表单
  656. newMaterial.value = {
  657. itemName: '',
  658. specification: '',
  659. measureName: '',
  660. imageUrls: [],
  661. productUrl: ''
  662. } as NewMaterial
  663. // 重新加载物料列表
  664. loadItems()
  665. } catch (e) {
  666. const error = e as UTSError
  667. const errMsg = error?.message
  668. uni.showToast({ title: errMsg.toString(), icon: 'none'})
  669. }
  670. }
  671. // 处理删除物料
  672. const handleDeleteMaterial = (item: Item): void => {
  673. uni.showModal({
  674. title: '确认删除',
  675. content: `确定要删除物料「${item.itemName}」吗?`,
  676. success: (res) => {
  677. if (res.confirm) {
  678. deleteMaterial(item.itemId).then(() => {
  679. uni.showToast({
  680. title: '删除成功',
  681. icon: 'success',
  682. })
  683. loadItems()
  684. }).catch((e) => {
  685. const error = e as UTSError
  686. const errMsg = error?.message
  687. uni.showModal({
  688. title: '删除失败',
  689. content: errMsg.toString(),
  690. showCancel: false,
  691. confirmText: '确定'
  692. })
  693. })
  694. }
  695. }
  696. })
  697. }
  698. onMounted(() => {
  699. loadCategories()
  700. loadMeasureList()
  701. // 获取页面参数,判断是否从index.uvue跳转过来
  702. const pages = getCurrentPages()
  703. const currentPage = pages[pages.length - 1]
  704. const options = currentPage.options
  705. if (options != null && options.from == 'index') {
  706. fromIndexPage.value = true
  707. }
  708. })
  709. </script>
  710. <style lang="scss">
  711. .page-container {
  712. flex: 1;
  713. background-color: #f5f8fe;
  714. padding-top: env(safe-area-inset-top);
  715. background-color: #e8f0f9;
  716. padding: 0rpx 20rpx 0rpx 20rpx;
  717. }
  718. .page-content {
  719. flex: 1;
  720. padding: 0rpx;
  721. padding-bottom: 150rpx;
  722. box-sizing: border-box;
  723. }
  724. .section {
  725. margin-top: 10rpx;
  726. padding: 0 10rpx 10rpx;
  727. background: #ffffff;
  728. border-radius: 16rpx;
  729. .section-header {
  730. flex-direction: row;
  731. align-items: center;
  732. justify-content: space-between;
  733. padding: 30rpx 10rpx 20rpx;
  734. }
  735. .section-header-left {
  736. flex-direction: row;
  737. align-items: center;
  738. }
  739. .add-material-btn {
  740. padding: 8rpx 16rpx;
  741. background-color: #007aff;
  742. border-radius: 8rpx;
  743. }
  744. .add-material-text {
  745. color: #ffffff;
  746. font-size: 24rpx;
  747. font-weight: bold;
  748. }
  749. &-indicator {
  750. width: 6rpx;
  751. height: 32rpx;
  752. background-color: #007aff;
  753. border-radius: 3rpx;
  754. margin-right: 12rpx;
  755. }
  756. &-title {
  757. font-size: 36rpx;
  758. color: #333333;
  759. font-weight: bold;
  760. }
  761. }
  762. .search-bar {
  763. padding: 10rpx 3rpx;
  764. }
  765. .search-box {
  766. flex-direction: row;
  767. align-items: center;
  768. height: 72rpx;
  769. padding: 0 24rpx;
  770. background-color: #f5f5f5;
  771. border-radius: 16rpx;
  772. .search-icon {
  773. width: 32rpx;
  774. height: 32rpx;
  775. margin-right: 12rpx;
  776. }
  777. .search-input {
  778. flex: 1;
  779. font-size: 28rpx;
  780. color: #333333;
  781. }
  782. .search-btn {
  783. padding: 10rpx 20rpx;
  784. background-color: #007aff;
  785. border-radius: 8rpx;
  786. margin-left: 10rpx;
  787. }
  788. .search-btn-text {
  789. color: #ffffff;
  790. font-size: 24rpx;
  791. }
  792. .clear-btn {
  793. width: 36rpx;
  794. height: 36rpx;
  795. border-radius: 18rpx;
  796. background-color: #cccccc;
  797. align-items: center;
  798. justify-content: center;
  799. margin-left: 10rpx;
  800. }
  801. .clear-btn-text {
  802. color: #ffffff;
  803. font-size: 24rpx;
  804. font-weight: bold;
  805. }
  806. }
  807. .status-tabs {
  808. padding: 20rpx 30rpx;
  809. background-color: #ffffff;
  810. border-bottom: 1rpx solid #eeeeee;
  811. }
  812. .scroll-view_H {
  813. width: 100%;
  814. flex-direction: row;
  815. }
  816. .status-tab {
  817. padding: 16rpx 24rpx;
  818. text-align: center;
  819. margin-right: 16rpx;
  820. border-radius: 8rpx;
  821. background-color: #f5f5f5;
  822. flex-shrink: 0;
  823. &:last-child {
  824. margin-right: 0;
  825. }
  826. &.active {
  827. background-color: #007aff;
  828. }
  829. .status-tab-text {
  830. font-size: 26rpx;
  831. color: #666666;
  832. &.active-text {
  833. color: #ffffff;
  834. font-weight: bold;
  835. }
  836. }
  837. }
  838. .list-item {
  839. margin: 3rpx;
  840. padding: 10rpx 10rpx 0rpx 10rpx;
  841. border-bottom: 1px solid #f9f9f9;
  842. }
  843. .item-header {
  844. flex-direction: row;
  845. align-items: center;
  846. justify-content: space-between;
  847. margin-bottom: 10rpx;
  848. }
  849. .item-actions {
  850. display: flex;
  851. align-items: center;
  852. gap: 10rpx;
  853. }
  854. .item-title {
  855. flex: 1;
  856. }
  857. .item-name {
  858. font-size: 28rpx;
  859. color: #333333;
  860. font-weight: bold;
  861. &.status-0 {
  862. color: #ff4d4f;
  863. }
  864. &.status-2 {
  865. color: #999999;
  866. }
  867. }
  868. .item-name-row {
  869. flex-direction: row;
  870. align-items: center;
  871. }
  872. .item-measure {
  873. font-size: 24rpx;
  874. color: #999999;
  875. margin-left: 10rpx;
  876. }
  877. .item-sub-title {
  878. flex: 1;
  879. font-size: 23rpx;
  880. color: #797979;
  881. margin-left: 10rpx;
  882. }
  883. .item-sub-row {
  884. flex-direction: row;
  885. align-items: center;
  886. }
  887. .item-stock {
  888. font-size: 23rpx;
  889. color: #52c41a;
  890. margin-left: 20rpx;
  891. }
  892. .item-measure {
  893. font-size: 23rpx;
  894. color: #999999;
  895. margin-left: 10rpx;
  896. }
  897. .add-btn {
  898. width: 44rpx;
  899. height: 44rpx;
  900. border-radius: 22rpx;
  901. background-color: #165DFF;
  902. color: #FFFFFF;
  903. align-items: center;
  904. justify-content: center;
  905. }
  906. .add-btn.disabled {
  907. background-color: #cccccc;
  908. }
  909. .added-btn {
  910. padding: 8rpx 16rpx;
  911. border-radius: 8rpx;
  912. align-items: center;
  913. justify-content: center;
  914. }
  915. .added-icon {
  916. color: #ff4d4f;
  917. font-size: 24rpx;
  918. }
  919. .detail-link {
  920. font-size: 21rpx;
  921. color: #999999;
  922. }
  923. .material-list {
  924. max-height: 720rpx;
  925. overflow-y: auto;
  926. }
  927. .pagination {
  928. flex-direction: row;
  929. display: flex;
  930. align-items: center;
  931. justify-content: center;
  932. padding: 20rpx;
  933. gap: 30rpx;
  934. }
  935. .page-btn {
  936. padding: 10rpx 20rpx;
  937. margin: 5px;
  938. background-color: #165DFF;
  939. border-radius: 8rpx;
  940. }
  941. .page-btn.disabled {
  942. background-color: #cccccc;
  943. }
  944. .page-btn-text {
  945. color: #FFFFFF;
  946. font-size: 26rpx;
  947. }
  948. .page-info {
  949. font-size: 26rpx;
  950. color: #666666;
  951. }
  952. .selected-list {
  953. padding: 20rpx;
  954. background-color: #ffffff;
  955. min-height: 150rpx;
  956. display: flex;
  957. flex-direction: column;
  958. gap: 15rpx;
  959. }
  960. .empty-tip {
  961. display: flex;
  962. align-items: center;
  963. justify-content: center;
  964. padding: 40rpx;
  965. }
  966. .empty-tip-text {
  967. color: #999999;
  968. font-size: 28rpx;
  969. }
  970. .selected-item {
  971. display: flex;
  972. flex-direction: row;
  973. align-items: center;
  974. background-color: #ffffff;
  975. border-radius: 10rpx;
  976. padding: 20rpx;
  977. border: 1rpx solid #e5e5e5;
  978. box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.05);
  979. white-space: nowrap;
  980. }
  981. .selected-item-name {
  982. font-size: 26rpx;
  983. color: #333333;
  984. margin-right: 20rpx;
  985. font-weight: 500;
  986. // white-space: nowrap;
  987. max-width: 180rpx;
  988. // overflow: hidden;
  989. // text-overflow: ellipsis;
  990. flex-shrink: 0;
  991. }
  992. .selected-item-measure {
  993. font-size: 24rpx;
  994. color: #999999;
  995. margin-right: 20rpx;
  996. flex-shrink: 0;
  997. }
  998. .quantity-control {
  999. display: flex;
  1000. flex-direction: row;
  1001. align-items: center;
  1002. margin-left: auto;
  1003. margin-right: 20rpx;
  1004. flex-shrink: 0;
  1005. }
  1006. .qty-btn {
  1007. width: 44rpx;
  1008. height: 44rpx;
  1009. background-color: #f5f5f5;
  1010. border-radius: 6rpx;
  1011. align-items: center;
  1012. justify-content: center;
  1013. border: 1rpx solid #e5e5e5;
  1014. }
  1015. .qty-btn-text {
  1016. color: #333333;
  1017. font-size: 28rpx;
  1018. font-weight: bold;
  1019. }
  1020. .quantity-input {
  1021. width: 160rpx;
  1022. height: 44rpx;
  1023. background-color: #f5f5f5;
  1024. border-radius: 6rpx;
  1025. font-size: 24rpx;
  1026. padding: 0 10rpx;
  1027. border: 1rpx solid #e5e5e5;
  1028. text-align: center;
  1029. margin: 0 10rpx;
  1030. }
  1031. .quantity-input:focus {
  1032. outline: none;
  1033. border-color: #007aff;
  1034. background-color: #ffffff;
  1035. }
  1036. .delete-btn {
  1037. width: 40rpx;
  1038. height: 40rpx;
  1039. border-radius: 20rpx;
  1040. background-color: #ff4d4f;
  1041. align-items: center;
  1042. justify-content: center;
  1043. display: flex;
  1044. flex-shrink: 0; // 防止删除按钮被压缩
  1045. }
  1046. .delete-icon {
  1047. color: #ffffff;
  1048. font-size: 30rpx;
  1049. font-weight: bold;
  1050. }
  1051. /* 底部按钮 */
  1052. .bottom-buttons {
  1053. padding: 20rpx;
  1054. background-color: #ffffff;
  1055. border-top: 1rpx solid #e5e5e5;
  1056. position: fixed;
  1057. bottom: 0;
  1058. left: 0;
  1059. right: 0;
  1060. z-index: 100;
  1061. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  1062. }
  1063. .btn-row {
  1064. flex-direction: row;
  1065. display: flex;
  1066. gap: 20rpx;
  1067. }
  1068. .save-btn {
  1069. width: 180rpx;
  1070. height: 80rpx;
  1071. background-color: #f5f5f5;
  1072. color: #333333;
  1073. font-size: 28rpx;
  1074. font-weight: 500;
  1075. border-radius: 20rpx;
  1076. border: 1rpx solid #e5e5e5;
  1077. }
  1078. .confirm-btn {
  1079. flex: 1;
  1080. height: 80rpx;
  1081. background-color: #007aff;
  1082. color: #ffffff;
  1083. font-size: 28rpx;
  1084. font-weight: 600;
  1085. border-radius: 20rpx;
  1086. margin-left: 10rpx;
  1087. border: none;
  1088. box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
  1089. }
  1090. /* 新增物料弹窗样式 */
  1091. .picker-modal {
  1092. position: fixed;
  1093. top: 0;
  1094. left: 0;
  1095. right: 0;
  1096. bottom: 0;
  1097. z-index: 1000;
  1098. display: flex;
  1099. align-items: center;
  1100. justify-content: center;
  1101. }
  1102. .modal-mask {
  1103. position: absolute;
  1104. top: 0;
  1105. left: 0;
  1106. right: 0;
  1107. bottom: 0;
  1108. background-color: rgba(0, 0, 0, 0.5);
  1109. }
  1110. .modal-content {
  1111. position: relative;
  1112. width: 90%;
  1113. // max-width: 500rpx;
  1114. background-color: #ffffff;
  1115. border-radius: 16rpx;
  1116. padding: 30rpx;
  1117. box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
  1118. }
  1119. .modal-header {
  1120. display: flex;
  1121. flex-direction: row;
  1122. justify-content: space-between;
  1123. align-items: center;
  1124. margin-bottom: 30rpx;
  1125. padding-bottom: 20rpx;
  1126. border-bottom: 1rpx solid #e5e5e5;
  1127. }
  1128. .modal-title {
  1129. font-size: 32rpx;
  1130. font-weight: bold;
  1131. color: #333333;
  1132. }
  1133. .modal-close {
  1134. font-size: 28rpx;
  1135. color: #999999;
  1136. padding: 8rpx 16rpx;
  1137. border-radius: 8rpx;
  1138. background-color: #f5f5f5;
  1139. }
  1140. .form-item-input {
  1141. display: flex;
  1142. flex-direction: column;
  1143. margin-bottom: 24rpx;
  1144. }
  1145. .label-picker {
  1146. font-size: 28rpx;
  1147. color: #333333;
  1148. margin-bottom: 12rpx;
  1149. font-weight: 500;
  1150. }
  1151. .view-input-picker {
  1152. position: relative;
  1153. width: 100%;
  1154. }
  1155. .input-picker {
  1156. width: 100%;
  1157. height: 80rpx;
  1158. padding: 0 24rpx;
  1159. background-color: #f5f5f5;
  1160. border-radius: 12rpx;
  1161. font-size: 28rpx;
  1162. color: #333333;
  1163. border: 1rpx solid #e5e5e5;
  1164. }
  1165. .input-picker:focus {
  1166. outline: none;
  1167. border-color: #007aff;
  1168. background-color: #ffffff;
  1169. }
  1170. .form-item-btn {
  1171. margin-top: 30rpx;
  1172. display: flex;
  1173. justify-content: center;
  1174. }
  1175. .btn-primary {
  1176. width: 100%;
  1177. height: 80rpx;
  1178. background-color: #007aff;
  1179. color: #ffffff;
  1180. font-size: 28rpx;
  1181. font-weight: 600;
  1182. border-radius: 12rpx;
  1183. border: none;
  1184. box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
  1185. }
  1186. .add-icon{
  1187. color: #ffffff;
  1188. }
  1189. .measure-list {
  1190. max-height: 500rpx;
  1191. overflow-y: auto;
  1192. }
  1193. .measure-item {
  1194. padding: 24rpx;
  1195. border-bottom: 1rpx solid #f0f0f0;
  1196. }
  1197. .measure-name {
  1198. font-size: 28rpx;
  1199. color: #333333;
  1200. }
  1201. .measure-input-row {
  1202. flex-direction: row;
  1203. align-items: center;
  1204. }
  1205. .measure-input-row .input-picker {
  1206. flex: 1;
  1207. margin-right: 16rpx;
  1208. }
  1209. .pick-btn {
  1210. padding: 16rpx 24rpx;
  1211. background-color: #007aff;
  1212. border-radius: 8rpx;
  1213. }
  1214. .pick-btn-text {
  1215. color: #ffffff;
  1216. font-size: 26rpx;
  1217. }
  1218. /* 图片上传样式 */
  1219. .image-upload-container {
  1220. display: flex;
  1221. flex-direction: row;
  1222. flex-wrap: wrap;
  1223. gap: 16rpx;
  1224. margin-top: 12rpx;
  1225. }
  1226. .uploaded-image {
  1227. position: relative;
  1228. width: 160rpx;
  1229. height: 160rpx;
  1230. border-radius: 8rpx;
  1231. overflow: hidden;
  1232. border: 1rpx solid #e5e5e5;
  1233. }
  1234. .uploaded-image-item {
  1235. width: 100%;
  1236. height: 100%;
  1237. }
  1238. .image-delete-btn {
  1239. position: absolute;
  1240. top: 8rpx;
  1241. right: 8rpx;
  1242. width: 36rpx;
  1243. height: 36rpx;
  1244. border-radius: 18rpx;
  1245. background-color: rgba(0, 0, 0, 0.6);
  1246. display: flex;
  1247. align-items: center;
  1248. justify-content: center;
  1249. }
  1250. .image-delete-icon {
  1251. color: #ffffff;
  1252. font-size: 28rpx;
  1253. font-weight: bold;
  1254. }
  1255. .upload-btn {
  1256. width: 160rpx;
  1257. height: 160rpx;
  1258. border-radius: 8rpx;
  1259. border: 2rpx dashed #e5e5e5;
  1260. display: flex;
  1261. flex-direction: column;
  1262. align-items: center;
  1263. justify-content: center;
  1264. background-color: #fafafa;
  1265. }
  1266. .upload-btn-icon {
  1267. font-size: 48rpx;
  1268. color: #999999;
  1269. margin-bottom: 8rpx;
  1270. }
  1271. .upload-btn-text {
  1272. font-size: 24rpx;
  1273. color: #999999;
  1274. }
  1275. </style>