applyNew.uvue 30 KB

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