| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504 |
- <template>
- <uni-navbar-lite :showRight=false title="物料申请"></uni-navbar-lite>
- <view class="page-container">
- <scroll-view class="page-content">
- <view class="section">
- <view class="search-bar">
- <view class="search-box">
- <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
- <input class="search-input" type="text" placeholder="请输入关键字查询" v-model="keyword" @input="handleSearch" />
- <view v-if="keyword.length > 0" class="clear-btn" @tap="clearKeyword">
- <text class="clear-btn-text">×</text>
- </view>
- <view class="search-btn" @tap="handleSearch">
- <text class="search-btn-text">搜索</text>
- </view>
- </view>
- </view>
-
- <view class="status-tabs">
- <scroll-view class="scroll-view_H" direction="horizontal" :show-scrollbar="false">
- <view
- v-for="(cat, idx) in categories"
- :key="idx"
- class="status-tab"
- :class="{ 'active': currentStatus === cat.id }"
- @click="switchStatus(cat.id)"
- >
- <text class="status-tab-text" :class="{ 'active-text': currentStatus === cat.id }">{{ cat.name }}</text>
- </view>
- </scroll-view>
- </view>
- </view>
- <view class="section">
- <view class="section-header">
- <view class="section-header-left">
- <view class="section-indicator"></view>
- <text class="section-title">物料列表</text>
- </view>
- <view class="add-material-btn" @click="showAddMaterialModal = true">
- <text class="add-material-text">新物料</text>
- </view>
- </view>
- <view class="material-list">
- <view
- v-for="(item, index) in dataList"
- :key="item.itemId + '_' + page"
- class="list-item"
- @click="handleItemClick(item, index)"
- >
- <view class="item-header">
- <view class="item-info">
- <view class="item-name-row">
- <text class="item-name" :class="{'status-0': getAuditStatus(item) == 0, 'status-2': getAuditStatus(item) == 3}">{{ getItemName(item) }}</text>
- <text class="item-measure">{{ getMeasureName(item) }}</text>
- </view>
- <view class="item-sub-row">
- <text class="item-sub-title">{{ getItemTypeName(item) }}</text>
- <text class="item-stock">库存: {{ getStockNum(item) }}</text>
- </view>
- </view>
- <view class="item-actions">
- <view v-if="getAuditStatus(item) == 0 && !item.isSelected!" class="delete-btn" @click.stop="handleDeleteMaterial(item)">
- <text class="delete-icon">×</text>
- </view>
- <view v-if="item.isSelected" class="added-btn">
- <text class="added-icon">已选</text>
- </view>
- <view v-else-if="isItemDisabled(item)" class="add-btn disabled">
- <text class="add-icon">+</text>
- </view>
- <view v-else class="add-btn" @click.stop="addToSelected(item)">
- <text class="add-icon">+</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 手动分页 -->
- <view class="pagination">
- <view class="page-btn" :class="{disabled: page <= 1}" @click="prevPage">
- <text class="page-btn-text"><</text>
- </view>
- <text class="page-info">第{{ page }}页 / 共{{ totalPages }}页</text>
- <view class="page-btn" :class="{disabled: page >= totalPages}" @click="nextPage">
- <text class="page-btn-text">></text>
- </view>
- </view>
- </view>
- <view class="section">
- <view class="section-header">
- <view class="section-header-left">
- <view class="section-indicator"></view>
- <text class="section-title">已选列表</text>
- </view>
- </view>
- <view class="selected-list">
- <view v-if="selectedItems.length === 0" class="empty-tip">
- <text class="empty-tip-text">请选择物料</text>
- </view>
- <view
- v-else
- v-for="(selItem, selIndex) in selectedItems"
- :key="selIndex"
- class="selected-item"
- >
- <text class="selected-item-name">{{ selItem.itemName }}</text>
- <text class="selected-item-measure">{{ selItem.measureName }}</text>
- <view class="quantity-control">
- <view class="qty-btn" @click="decreaseQty(selIndex)">
- <text class="qty-btn-text">-</text>
- </view>
- <input
- class="quantity-input"
- type="digit"
- v-model="selItem.qty"
- placeholder="数量"
- />
- <view class="qty-btn" @click="increaseQty(selIndex)">
- <text class="qty-btn-text">+</text>
- </view>
- </view>
- <view class="delete-btn" @click="removeSelected(selIndex)">
- <text class="delete-icon">×</text>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
-
- <!-- 底部按钮 -->
- <view class="bottom-buttons">
- <view class="btn-row">
- <button class="save-btn" @click="saveApplication">保存</button>
- <button class="confirm-btn" @click="confirmApplication">确认申请</button>
- </view>
- </view>
-
- <!-- 新增物料弹窗 -->
- <view v-if="showAddMaterialModal" class="picker-modal">
- <view class="modal-mask" @click="showAddMaterialModal = false"></view>
- <view class="modal-content">
- <view class="modal-header">
- <text class="modal-title">新增物料</text>
- <text class="modal-close" @click="showAddMaterialModal = false">取消</text>
- </view>
- <view class="form-item-input">
- <text class="label-picker">物料名称</text>
- <view class="view-input-picker">
- <input class="input-picker" type="text" placeholder="请输入物料名称" v-model="newMaterial.itemName" />
- </view>
- </view>
- <view class="form-item-input">
- <text class="label-picker">规格型号</text>
- <view class="view-input-picker">
- <input class="input-picker" type="text" placeholder="请输入规格型号" v-model="newMaterial.specification" />
- </view>
- </view>
- <view class="form-item-input">
- <text class="label-picker">单位</text>
- <view class="view-input-picker measure-input-row">
- <input class="input-picker" type="text" placeholder="请输入或选择单位" v-model="newMaterial.measureName" />
- <view class="pick-btn" @click="showMeasurePicker = true">
- <text class="pick-btn-text">选择</text>
- </view>
- </view>
- </view>
- <view class="form-item-input">
- <text class="label-picker">产品链接</text>
- <view class="view-input-picker">
- <input class="input-picker" type="url" placeholder="请输入产品链接" v-model="newMaterial.productUrl" />
- </view>
- </view>
- <view class="form-item-input">
- <text class="label-picker">图片(最多3张)</text>
- <view class="upload-wrapper">
- <UploadImage
- :maxCount="3"
- :modelValue="newMaterial.imageUrls"
- businessType="material"
- @update:modelValue="handleImageUpdate"
- @delete="handleImageDelete"
- />
- </view>
- </view>
- <view class="form-item-btn">
- <button class="btn-primary" @click="handleAddMaterial">
- 保存
- </button>
- </view>
- </view>
- </view>
-
- <!-- 单位选择弹窗 -->
- <view v-if="showMeasurePicker" class="picker-modal">
- <view class="modal-mask" @click="showMeasurePicker = false"></view>
- <view class="modal-content">
- <view class="modal-header">
- <text class="modal-title">选择单位</text>
- <text class="modal-close" @click="showMeasurePicker = false">取消</text>
- </view>
- <scroll-view class="measure-list" :scroll-y="true">
- <view
- v-for="(item, index) in measureList"
- :key="index"
- class="measure-item"
- @click="selectMeasure(item)"
- >
- <text class="measure-name">{{ item['measureName'] }}</text>
- </view>
- <view v-if="measureList.length === 0" class="empty-tip">
- <text class="empty-tip-text">暂无单位数据</text>
- </view>
- </scroll-view>
- </view>
- </view>
-
- <!-- 删除确认弹窗 -->
- <view v-if="showDeleteConfirm" class="delete-confirm-modal">
- <view class="delete-confirm-mask" @click="showDeleteConfirm = false"></view>
- <view class="delete-confirm-content">
- <text class="delete-confirm-title">确认删除</text>
- <text class="delete-confirm-text">确定要删除这张图片吗?</text>
- <view class="delete-confirm-btns">
- <view class="delete-confirm-cancel" @click="showDeleteConfirm = false">
- <text class="delete-confirm-cancel-text">取消</text>
- </view>
- <view class="delete-confirm-ok" @click="confirmDeleteImage">
- <text class="delete-confirm-ok-text">确定</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script setup lang="uts">
- import { ref, computed, onBeforeUnmount, onMounted } from 'vue'
- import { getItemTypeListByParentId, getItemList, savePurchaseApply, confirmPurchaseApply, addMaterial, getMeasureList, deleteMaterial } from '../../api/apply/index'
- import UploadImage from '../../components/upload-image/upload-image.uvue'
- import type { UploadResponse } from '../../types/workbench'
- let searchTimer: number | null = null
-
- type CategoryItem = { id: string; name: string; code: string }
- type Item = {
- itemId: string;
- itemName: string;
- itemCode: string;
- itemTypeName: string;
- measureName: string;
- specification: string;
- imageUrls: string;
- productUrl: string;
- auditStatus: number;
- stockNum: number;
- isSelected?: boolean;
- }
- type SelectedItem = { itemId: string; itemName: string; itemTypeName: string; measureName: string; qty: string }
-
- const keyword = ref<string>("")
-
- const dataList = ref<Item[]>([])
- const selectedItems = ref<SelectedItem[]>([])
- const page = ref<number>(1)
- const pageSize: number = 10
- const total = ref<number>(0)
- const totalPages = computed((): number => {
- if (total.value <= 0) return 1
- return Math.ceil(total.value / pageSize)
- })
- const hasMore = ref<boolean>(true)
- const loading = ref<boolean>(false)
- const refreshing = ref<boolean>(false)
-
- const categories = ref<CategoryItem[]>([])
-
- const dealLoad = ref<boolean>(false)
- let currentStatus = ref<string>('')
- const isSearching = ref<boolean>(false)
- // 新增物料相关
- const showAddMaterialModal = ref<boolean>(false)
- const showMeasurePicker = ref<boolean>(false)
- const measureList = ref<UTSJSONObject[]>([])
- const showDeleteConfirm = ref<boolean>(false)
- const deleteImageIndex = ref<number>(0)
- type NewMaterial = {
- itemName: string
- specification: string
- measureName: string
- imageUrls: UploadResponse[]
- productUrl: string
- }
- const newMaterial = ref<NewMaterial>({
- itemName: '',
- specification: '',
- measureName: '',
- imageUrls: [],
- productUrl: ''
- })
- // 加载单位列表
- const loadMeasureList = (): void => {
- getMeasureList().then((res: any) => {
- const data = res as UTSJSONObject
- const list = data['data']
- if (list != null) {
- measureList.value = list as UTSJSONObject[]
- }
- }).catch(() => {
- measureList.value = []
- })
- }
- // 选择单位
- const selectMeasure = (item: UTSJSONObject): void => {
- const measureName = item['measureName'] != null ? item['measureName'].toString() : ''
- newMaterial.value.measureName = measureName
- showMeasurePicker.value = false
- }
-
- // 获取当前选中的分类code
- const getCurrentCategoryCode = (): string => {
- const currentCat = categories.value.find((c: CategoryItem) => c.id === currentStatus.value)
- return currentCat != null ? currentCat.code : ''
- }
-
- // 加载物料列表
- const loadItems = (): void => {
- loading.value = true
- const itemTypeCode = getCurrentCategoryCode()
- getItemList(itemTypeCode, page.value, pageSize, keyword.value).then((res: any) => {
- const data = res as UTSJSONObject
- const rows = data['rows']
- const totalNum = data['total']
- if (totalNum != null) {
- total.value = totalNum as number
- }
- if (rows != null) {
- const listData = rows as UTSJSONObject[]
- if (listData.length > 0) {
- const arr: Item[] = []
- const selectedIds = selectedItems.value.map((s: SelectedItem) => s.itemId)
- listData.forEach((item: UTSJSONObject) => {
- const itemId = item['itemId'] != null ? item['itemId'].toString() : ''
- let auditStatus = -1
- const auditStatusVal = item['auditStatus']
- if (auditStatusVal != null) {
- if (typeof auditStatusVal === 'number') {
- auditStatus = auditStatusVal as number
- } else {
- auditStatus = parseInt(auditStatusVal.toString())
- }
- }
- let stockNum = 0
- const stockNumVal = item['stockNum']
- if (stockNumVal != null) {
- if (typeof stockNumVal === 'number') {
- stockNum = stockNumVal as number
- } else {
- stockNum = parseFloat(stockNumVal.toString())
- }
- }
- const it: Item = {
- itemId: itemId,
- itemName: item['itemName'] != null ? item['itemName'].toString() : '',
- itemCode: item['itemCode'] != null ? item['itemCode'].toString() : '',
- itemTypeName: item['itemTypeName'] != null ? item['itemTypeName'].toString() : '',
- measureName: item['measureName'] != null ? item['measureName'].toString() : '',
- specification: item['specification'] != null ? item['specification'].toString() : '',
- imageUrls: item['imageUrls'] != null ? item['imageUrls'].toString() : '',
- productUrl: item['productUrl'] != null ? item['productUrl'].toString() : '',
- isSelected: selectedIds.includes(itemId),
- auditStatus: auditStatus,
- stockNum: stockNum
- }
- arr.push(it)
- })
- dataList.value = arr
- loading.value = false
- return
- }
- }
- dataList.value = []
- loading.value = false
- }).catch(() => {
- dataList.value = []
- loading.value = false
- })
- }
-
- // 上一页
- const prevPage = (): void => {
- if (page.value > 1) {
- page.value--
- loadItems()
- }
- }
-
- // 下一页
- const nextPage = (): void => {
- if (page.value < totalPages.value) {
- page.value++
- loadItems()
- }
- }
-
- const loadCategories = (): void => {
- getItemTypeListByParentId(200).then((res: any) => {
- const data = res as UTSJSONObject
- const list = data['data']
- if (list != null) {
- const listData = list as UTSJSONObject[]
- if (listData.length > 0) {
- const arr: CategoryItem[] = []
- listData.forEach((item: UTSJSONObject) => {
- const idVal = item['itemTypeId']
- const nameVal = item['itemTypeName']
- const codeVal = item['itemTypeCode']
- const cat: CategoryItem = {
- id: idVal != null ? idVal.toString() : '',
- name: nameVal != null ? nameVal.toString() : '',
- code: codeVal != null ? codeVal.toString() : ''
- }
- arr.push(cat)
- })
- const allItem: CategoryItem = {id: '', name: '全部', code: ''}
- arr.unshift(allItem)
- categories.value = arr
- // 加载第一个分类的物料
- if (arr.length > 0) {
- currentStatus.value = arr[0].id
- loadItems()
- }
- return
- }
- }
- const defaultArr: CategoryItem[] = []
- const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
- defaultArr.push(defaultItem)
- categories.value = defaultArr
- }).catch(() => {
- const defaultArr: CategoryItem[] = []
- const defaultItem: CategoryItem = {id: '', name: '全部', code: ''}
- defaultArr.push(defaultItem)
- categories.value = defaultArr
- })
- }
-
- // 添加到已选列表
- const addToSelected = (item: any | null): void => {
- if (item == null) return
- const mdItem = item as Item
- // 检查审核状态
- if (mdItem.auditStatus != null && mdItem.auditStatus === 2) {
- uni.showToast({ title: '该物料已禁用,无法添加', icon: 'none'})
- return
- }
- // 检查是否已存在
- const exists = selectedItems.value.find((s: SelectedItem) => s.itemId === mdItem.itemId)
- if (exists != null) {
- uni.showToast({ title: '该物料已在选择列表中', icon: 'none'})
- return
- }
- const selItem: SelectedItem = {
- itemId: mdItem.itemId,
- itemName: mdItem.itemName,
- itemTypeName: mdItem.itemTypeName,
- measureName: mdItem.measureName,
- qty: '1'
- }
- selectedItems.value.push(selItem)
- // 更新 dataList 中的选中状态
- const idx = dataList.value.findIndex((d: Item) => d.itemId === mdItem.itemId)
- if (idx >= 0) {
- dataList.value[idx].isSelected = true
- }
- }
-
- // 删除已选
- const removeSelected = (index: number): void => {
- const removedItem = selectedItems.value[index]
- selectedItems.value.splice(index, 1)
- // 重新加载当前页数据以更新选中状态
- loadItems()
- }
-
- // 增加数量
- const increaseQty = (index: number): void => {
- const currentQty = parseInt(selectedItems.value[index].qty)
- selectedItems.value[index].qty = (currentQty + 1).toString()
- }
-
- // 减少数量
- const decreaseQty = (index: number): void => {
- const currentQty = parseInt(selectedItems.value[index].qty)
- if (currentQty > 1) {
- selectedItems.value[index].qty = (currentQty - 1).toString()
- }
- }
-
- const handleItemClick = (item: any | null, index: number): void => {
- if (item == null) return
- const mdItem = item as Item
- uni.navigateTo({
- url: `/pages/item/detail?id=${mdItem.itemId}`
- })
- }
- const getItemName = (item: any | null): string => {
- if (item == null) return ''
- const mdItem = item as Item
- return mdItem.itemName
- }
- const getItemTypeName = (item: any | null): string => {
- if (item == null) return ''
- const mdItem = item as Item
- return mdItem.itemTypeName
- }
- const getMeasureName = (item: any | null): string => {
- if (item == null) return ''
- const mdItem = item as Item
- return mdItem.measureName
- }
-
- const getStockNum = (item: any | null): string => {
- if (item == null) return '0'
- const mdItem = item as Item
- const stock = mdItem.stockNum != null ? mdItem.stockNum : 0
- return stock.toString()
- }
-
- const getAuditStatus = (item: any | null): number => {
- if (item == null) return -1
- const mdItem = item as Item
- return mdItem.auditStatus != null ? mdItem.auditStatus : -1
- }
-
- const isItemDisabled = (item: any | null): boolean => {
- if (item == null) return false
- const mdItem = item as Item
- const status = mdItem.auditStatus != null ? mdItem.auditStatus : -1
- return status == 3
- }
-
- // 检查物料是否已被选择
- const isItemSelected = (item: any | null): boolean => {
- if (item == null) return false
- const mdItem = item as Item
- return selectedItems.value.find((s: SelectedItem) => s.itemId === mdItem.itemId) != null
- }
- const handleSearch = (): void => {
- const timer = searchTimer
- if (timer != null) {
- clearTimeout(timer)
- }
- searchTimer = setTimeout(() => {
- page.value = 1
- loadItems()
- }, 300)
- }
-
- const clearKeyword = (): void => {
- keyword.value = ''
- page.value = 1
- loadItems()
- }
-
- const switchStatus = (status: string): void => {
- if (loading.value) {
- return;
- }
- if (isSearching.value) {
- return
- }
- isSearching.value = true
- currentStatus.value = status
- page.value = 1
- loadItems()
- setTimeout(() => {
- isSearching.value = false
- }, 100)
- }
- // 构建申请单数据
- const buildApplyData = (status: string): UTSJSONObject => {
- const applyLines: UTSJSONObject[] = []
- selectedItems.value.forEach((item: SelectedItem) => {
- const lineObj = new UTSJSONObject()
- lineObj['itemId'] = parseInt(item.itemId)
- lineObj['itemCode'] = ''
- lineObj['itemName'] = item.itemName
- lineObj['specification'] = ''
- lineObj['unitOfMeasure'] = ''
- lineObj['quantityApply'] = parseInt(item.qty)
- applyLines.push(lineObj)
- })
- const result = new UTSJSONObject()
- result['applyCode'] = ''
- result['applyName'] = '物料申请'
- result['status'] = status
- result['wmPurchaseApplyLineList'] = applyLines
- return result
- }
- // 来源页面
- const fromIndexPage = ref<boolean>(false)
- // 保存申请
- const saveApplication = (): void => {
- if (selectedItems.value.length === 0) {
- uni.showToast({ title: '请选择物料', icon: 'none'})
- return
- }
- // 构建申请单数据
- const applyData = buildApplyData('PREPARE')
- savePurchaseApply(applyData).then((res: any) => {
- uni.showToast({ title: '保存成功', icon: 'success'})
- // 清空已选列表
- selectedItems.value = []
- loadItems()
- // 如果从index.uvue跳转过来,返回index.uvue
- if (fromIndexPage.value) {
- setTimeout(() => {
- uni.navigateBack()
- }, 1000)
- }else{
- uni.navigateTo({
- url: `/pages/apply/index?from=new`
- })
- }
- }).catch((e) => {
- console.log(e)
- const error = e as UTSError
- const errMsg = error?.message
- uni.showToast({ title: errMsg.toString(), icon: 'none'})
- })
- }
- // 确认申请
- const confirmApplication = (): void => {
- if (selectedItems.value.length === 0) {
- uni.showToast({ title: '请选择物料', icon: 'none'})
- return
- }
- // 验证所有数量都大于0
- for (let i = 0; i < selectedItems.value.length; i++) {
- const qty = parseFloat(selectedItems.value[i].qty)
- if (qty <= 0) {
- uni.showToast({ title: '所有物料数量必须大于0', icon: 'none'})
- return
- }
- }
- // 构建申请单数据
- const applyData = buildApplyData('CONFIRMED')
- savePurchaseApply(applyData).then((res: any) => {
- uni.showToast({ title: '确认申请成功', icon: 'success'})
- // 清空已选列表
- selectedItems.value = []
- loadItems()
- // 如果从index.uvue跳转过来,返回index.uvue
- if (fromIndexPage.value) {
- setTimeout(() => {
- uni.navigateBack()
- }, 1000)
- }else{
- uni.navigateTo({
- url: `/pages/apply/index?from=new`
- })
- }
- }).catch((e) => {
- const error = e as UTSError
- const errMsg = error?.message
- uni.showToast({ title: errMsg.toString(), icon: 'none'})
- })
- }
-
- // 处理图片更新
- const handleImageUpdate = (value: UploadResponse[]): void => {
- newMaterial.value.imageUrls = value
- }
- // 处理图片删除
- const handleImageDelete = (index: number, currentList: UploadResponse[]): void => {
- deleteImageIndex.value = index
- showDeleteConfirm.value = true
- }
- const confirmDeleteImage = (): void => {
- newMaterial.value.imageUrls.splice(deleteImageIndex.value, 1)
- showDeleteConfirm.value = false
- }
- // 处理新增物料
- const handleAddMaterial = async (): Promise<void> => {
- // 验证输入
- if (newMaterial.value.itemName.length == 0) {
- uni.showToast({ title: '请输入物料名称', icon: 'none'})
- return
- }
- if (newMaterial.value.measureName.length == 0) {
- uni.showToast({ title: '请输入单位', icon: 'none'})
- return
- }
- try {
- // 构建物料数据
- const materialData = new UTSJSONObject()
- materialData['itemShortName'] = newMaterial.value.itemName
- materialData['itemName'] = newMaterial.value.itemName + "("+newMaterial.value.specification+")"
- materialData['specification'] = newMaterial.value.specification
- materialData['measureName'] = newMaterial.value.measureName
- materialData['auditStatus'] = 0 // 审核状态为0
- // 从 UploadResponse 数组中提取 fileName 并拼接成逗号分隔的字符串
- const imageFileNames = newMaterial.value.imageUrls.map((item: UploadResponse) => item.fileName).join(',')
- materialData['imageUrls'] = imageFileNames
- materialData['productUrl'] = newMaterial.value.productUrl
-
- // 调用接口保存物料
- await addMaterial(materialData)
-
- // 保存成功
- uni.showToast({ title: '物料新增成功', icon: 'success'})
-
- // 关闭弹窗
- showAddMaterialModal.value = false
-
- // 清空表单
- newMaterial.value = {
- itemName: '',
- specification: '',
- measureName: '',
- imageUrls: [],
- productUrl: ''
- } as NewMaterial
-
- // 重新加载物料列表
- loadItems()
- } catch (e) {
- const error = e as UTSError
- const errMsg = error?.message
- uni.showToast({ title: errMsg.toString(), icon: 'none'})
- }
- }
- // 处理删除物料
- const handleDeleteMaterial = (item: Item): void => {
- uni.showModal({
- title: '确认删除',
- content: `确定要删除物料「${item.itemName}」吗?`,
- success: (res) => {
- if (res.confirm) {
- deleteMaterial(item.itemId).then(() => {
- uni.showToast({
- title: '删除成功',
- icon: 'success',
- })
- loadItems()
- }).catch((e) => {
- const error = e as UTSError
- const errMsg = error?.message
- uni.showModal({
- title: '删除失败',
- content: errMsg.toString(),
- showCancel: false,
- confirmText: '确定'
- })
- })
- }
- }
- })
- }
- onMounted(() => {
- loadCategories()
- loadMeasureList()
- // 获取页面参数,判断是否从index.uvue跳转过来
- const pages = getCurrentPages()
- const currentPage = pages[pages.length - 1]
- const options = currentPage.options
- if (options != null && options.from == 'index') {
- fromIndexPage.value = true
- }
- })
- </script>
- <style lang="scss">
- .page-container {
- flex: 1;
- background-color: #f5f8fe;
- padding-top: env(safe-area-inset-top);
- background-color: #e8f0f9;
- padding: 0rpx 20rpx 0rpx 20rpx;
- }
- .page-content {
- flex: 1;
- padding: 0rpx;
- padding-bottom: 150rpx;
- box-sizing: border-box;
- }
- .section {
- margin-top: 10rpx;
- padding: 0 10rpx 10rpx;
-
- background: #ffffff;
- border-radius: 16rpx;
-
- .section-header {
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- padding: 30rpx 10rpx 20rpx;
- }
-
- .section-header-left {
- flex-direction: row;
- align-items: center;
- }
-
- .add-material-btn {
- padding: 8rpx 16rpx;
- background-color: #007aff;
- border-radius: 8rpx;
- }
-
- .add-material-text {
- color: #ffffff;
- font-size: 24rpx;
- font-weight: bold;
- }
-
- &-indicator {
- width: 6rpx;
- height: 32rpx;
- background-color: #007aff;
- border-radius: 3rpx;
- margin-right: 12rpx;
- }
-
- &-title {
- font-size: 36rpx;
- color: #333333;
- font-weight: bold;
- }
- }
- .search-bar {
- padding: 10rpx 3rpx;
- }
- .search-box {
- flex-direction: row;
- align-items: center;
- height: 72rpx;
- padding: 0 24rpx;
- background-color: #f5f5f5;
- border-radius: 16rpx;
-
- .search-icon {
- width: 32rpx;
- height: 32rpx;
- margin-right: 12rpx;
- }
-
- .search-input {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
- }
-
- .search-btn {
- padding: 10rpx 20rpx;
- background-color: #007aff;
- border-radius: 8rpx;
- margin-left: 10rpx;
- }
- .search-btn-text {
- color: #ffffff;
- font-size: 24rpx;
- }
- .clear-btn {
- width: 36rpx;
- height: 36rpx;
- border-radius: 18rpx;
- background-color: #cccccc;
- align-items: center;
- justify-content: center;
- margin-left: 10rpx;
- }
- .clear-btn-text {
- color: #ffffff;
- font-size: 24rpx;
- font-weight: bold;
- }
- }
- .status-tabs {
- padding: 20rpx 30rpx;
- background-color: #ffffff;
- border-bottom: 1rpx solid #eeeeee;
- }
- .scroll-view_H {
- width: 100%;
- flex-direction: row;
- }
- .status-tab {
- padding: 16rpx 24rpx;
- text-align: center;
- margin-right: 16rpx;
- border-radius: 8rpx;
- background-color: #f5f5f5;
- flex-shrink: 0;
- &:last-child {
- margin-right: 0;
- }
- &.active {
- background-color: #007aff;
- }
- .status-tab-text {
- font-size: 26rpx;
- color: #666666;
- &.active-text {
- color: #ffffff;
- font-weight: bold;
- }
- }
- }
- .list-item {
- margin: 3rpx;
- padding: 10rpx 10rpx 0rpx 10rpx;
- border-bottom: 1px solid #f9f9f9;
- }
- .item-header {
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 10rpx;
- }
- .item-actions {
- display: flex;
- align-items: center;
- gap: 10rpx;
- }
- .item-title {
- flex: 1;
- }
- .item-name {
- font-size: 28rpx;
- color: #333333;
- font-weight: bold;
-
- &.status-0 {
- color: #ff4d4f;
- }
-
- &.status-2 {
- color: #999999;
- }
- }
- .item-name-row {
- flex-direction: row;
- align-items: center;
- }
- .item-measure {
- font-size: 24rpx;
- color: #999999;
- margin-left: 10rpx;
- }
- .item-sub-title {
- flex: 1;
- font-size: 23rpx;
- color: #797979;
- margin-left: 10rpx;
- }
- .item-sub-row {
- flex-direction: row;
- align-items: center;
- }
- .item-stock {
- font-size: 23rpx;
- color: #52c41a;
- margin-left: 20rpx;
- }
- .item-measure {
- font-size: 23rpx;
- color: #999999;
- margin-left: 10rpx;
- }
- .add-btn {
- width: 44rpx;
- height: 44rpx;
- border-radius: 22rpx;
- background-color: #165DFF;
- color: #FFFFFF;
- align-items: center;
- justify-content: center;
- }
-
- .add-btn.disabled {
- background-color: #cccccc;
- }
-
- .added-btn {
- padding: 8rpx 16rpx;
- border-radius: 8rpx;
- align-items: center;
- justify-content: center;
- }
-
- .added-icon {
- color: #ff4d4f;
- font-size: 24rpx;
- }
-
- .detail-link {
- font-size: 21rpx;
- color: #999999;
- }
-
- .material-list {
- max-height: 720rpx;
- overflow-y: auto;
- }
-
- .pagination {
- flex-direction: row;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 20rpx;
- gap: 30rpx;
- }
-
- .page-btn {
- padding: 10rpx 20rpx;
- margin: 5px;
- background-color: #165DFF;
- border-radius: 8rpx;
- }
-
- .page-btn.disabled {
- background-color: #cccccc;
- }
-
- .page-btn-text {
- color: #FFFFFF;
- font-size: 26rpx;
- }
-
- .page-info {
- font-size: 26rpx;
- color: #666666;
- }
-
- .selected-list {
- padding: 20rpx;
- background-color: #ffffff;
- min-height: 150rpx;
- display: flex;
- flex-direction: column;
- gap: 15rpx;
- }
- .empty-tip {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 40rpx;
- }
- .empty-tip-text {
- color: #999999;
- font-size: 28rpx;
- }
- .selected-item {
- display: flex;
- flex-direction: row;
- align-items: center;
- background-color: #ffffff;
- border-radius: 10rpx;
- padding: 20rpx;
- border: 1rpx solid #e5e5e5;
- box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.05);
- white-space: nowrap;
- }
- .selected-item-name {
- font-size: 26rpx;
- color: #333333;
- margin-right: 20rpx;
- font-weight: 500;
- // white-space: nowrap;
- max-width: 180rpx;
- // overflow: hidden;
- // text-overflow: ellipsis;
- flex-shrink: 0;
- }
- .selected-item-measure {
- font-size: 24rpx;
- color: #999999;
- margin-right: 20rpx;
- flex-shrink: 0;
- }
- .quantity-control {
- display: flex;
- flex-direction: row;
- align-items: center;
- margin-left: auto;
- margin-right: 20rpx;
- flex-shrink: 0;
- }
- .qty-btn {
- width: 44rpx;
- height: 44rpx;
- background-color: #f5f5f5;
- border-radius: 6rpx;
- align-items: center;
- justify-content: center;
- border: 1rpx solid #e5e5e5;
- }
- .qty-btn-text {
- color: #333333;
- font-size: 28rpx;
- font-weight: bold;
- }
- .quantity-input {
- width: 160rpx;
- height: 44rpx;
- background-color: #f5f5f5;
- border-radius: 6rpx;
- font-size: 24rpx;
- padding: 0 10rpx;
- border: 1rpx solid #e5e5e5;
- text-align: center;
- margin: 0 10rpx;
- }
- .quantity-input:focus {
- outline: none;
- border-color: #007aff;
- background-color: #ffffff;
- }
- .delete-btn {
- width: 40rpx;
- height: 40rpx;
- border-radius: 20rpx;
- background-color: #ff4d4f;
- align-items: center;
- justify-content: center;
- display: flex;
- flex-shrink: 0; // 防止删除按钮被压缩
- }
- .delete-icon {
- color: #ffffff;
- font-size: 30rpx;
- font-weight: bold;
- }
- /* 底部按钮 */
- .bottom-buttons {
- padding: 20rpx;
- background-color: #ffffff;
- border-top: 1rpx solid #e5e5e5;
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- z-index: 100;
- box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
- }
- .btn-row {
- flex-direction: row;
- display: flex;
- gap: 20rpx;
- }
- .save-btn {
- width: 180rpx;
- height: 80rpx;
- background-color: #f5f5f5;
- color: #333333;
- font-size: 28rpx;
- font-weight: 500;
- border-radius: 20rpx;
- border: 1rpx solid #e5e5e5;
- }
- .confirm-btn {
- flex: 1;
- height: 80rpx;
- background-color: #007aff;
- color: #ffffff;
- font-size: 28rpx;
- font-weight: 600;
- border-radius: 20rpx;
- margin-left: 10rpx;
- border: none;
- box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
- }
- /* 新增物料弹窗样式 */
- .picker-modal {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 1000;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .modal-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- }
- .modal-content {
- position: relative;
- width: 90%;
- // max-width: 500rpx;
- background-color: #ffffff;
- border-radius: 16rpx;
- padding: 30rpx;
- box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
- }
- .modal-header {
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 30rpx;
- padding-bottom: 20rpx;
- border-bottom: 1rpx solid #e5e5e5;
- }
- .modal-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- }
- .modal-close {
- font-size: 28rpx;
- color: #999999;
- padding: 8rpx 16rpx;
- border-radius: 8rpx;
- background-color: #f5f5f5;
- }
- .form-item-input {
- display: flex;
- flex-direction: column;
- margin-bottom: 24rpx;
- }
- .label-picker {
- font-size: 28rpx;
- color: #333333;
- margin-bottom: 12rpx;
- font-weight: 500;
- }
- .view-input-picker {
- position: relative;
- width: 100%;
- }
- .input-picker {
- width: 100%;
- height: 80rpx;
- padding: 0 24rpx;
- background-color: #f5f5f5;
- border-radius: 12rpx;
- font-size: 28rpx;
- color: #333333;
- border: 1rpx solid #e5e5e5;
- }
- .input-picker:focus {
- outline: none;
- border-color: #007aff;
- background-color: #ffffff;
- }
- .form-item-btn {
- margin-top: 30rpx;
- display: flex;
- justify-content: center;
- }
- .btn-primary {
- width: 100%;
- height: 80rpx;
- background-color: #007aff;
- color: #ffffff;
- font-size: 28rpx;
- font-weight: 600;
- border-radius: 12rpx;
- border: none;
- box-shadow: 0 2rpx 8rpx rgba(0, 122, 255, 0.3);
- }
- .add-icon{
- color: #ffffff;
- }
-
- .measure-list {
- max-height: 500rpx;
- overflow-y: auto;
- }
-
- .measure-item {
- padding: 24rpx;
- border-bottom: 1rpx solid #f0f0f0;
- }
-
- .measure-name {
- font-size: 28rpx;
- color: #333333;
- }
-
- .measure-input-row {
- flex-direction: row;
- align-items: center;
- }
-
- .measure-input-row .input-picker {
- flex: 1;
- margin-right: 16rpx;
- }
-
- .pick-btn {
- padding: 16rpx 24rpx;
- background-color: #007aff;
- border-radius: 8rpx;
- }
-
- .pick-btn-text {
- color: #ffffff;
- font-size: 26rpx;
- }
- /* 图片上传样式 */
- .image-upload-container {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- gap: 16rpx;
- margin-top: 12rpx;
- }
- .uploaded-image {
- position: relative;
- width: 160rpx;
- height: 160rpx;
- border-radius: 8rpx;
- overflow: hidden;
- border: 1rpx solid #e5e5e5;
- }
- .uploaded-image-item {
- width: 100%;
- height: 100%;
- }
- .image-delete-btn {
- position: absolute;
- top: 8rpx;
- right: 8rpx;
- width: 36rpx;
- height: 36rpx;
- border-radius: 18rpx;
- background-color: rgba(0, 0, 0, 0.6);
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .image-delete-icon {
- color: #ffffff;
- font-size: 28rpx;
- font-weight: bold;
- }
- .upload-btn {
- width: 160rpx;
- height: 160rpx;
- border-radius: 8rpx;
- border: 2rpx dashed #e5e5e5;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- background-color: #fafafa;
- }
- .upload-btn-icon {
- font-size: 48rpx;
- color: #999999;
- margin-bottom: 8rpx;
- }
- .upload-btn-text {
- font-size: 24rpx;
- color: #999999;
- }
-
- /* 删除确认弹窗样式 */
- .delete-confirm-modal {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 10000;
- display: flex;
- align-items: center;
- justify-content: center;
- }
-
- .delete-confirm-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0.5);
- }
-
- .delete-confirm-content {
- position: relative;
- width: 600rpx;
- background-color: #ffffff;
- border-radius: 16rpx;
- padding: 40rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
-
- .delete-confirm-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 20rpx;
- }
-
- .delete-confirm-text {
- font-size: 28rpx;
- color: #666666;
- margin-bottom: 40rpx;
- }
-
- .delete-confirm-btns {
- display: flex;
- flex-direction: row;
- gap: 40rpx;
- }
-
- .delete-confirm-cancel {
- padding: 20rpx 60rpx;
- background-color: #f5f5f5;
- border-radius: 12rpx;
- }
-
- .delete-confirm-cancel-text {
- font-size: 28rpx;
- color: #666666;
- }
-
- .delete-confirm-ok {
- padding: 20rpx 60rpx;
- background-color: #ff4d4f;
- border-radius: 12rpx;
- }
-
- .delete-confirm-ok-text {
- font-size: 28rpx;
- color: #ffffff;
- }
- </style>
|