| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- <template>
- <view class="folder-select-page">
- <!-- 顶部导航栏 -->
- <view class="header-bg" :style="{ paddingTop: statusBarHeight + 'px' }">
- <view class="header-content">
- <view class="back-btn" @click="handleBack">
- <text class="back-icon">‹</text>
- </view>
- <text class="header-title">选择文件夹</text>
- <view class="placeholder"></view>
- </view>
- </view>
-
- <!-- 项目信息 -->
- <view class="project-info-bar">
- <text class="project-label">当前项目:</text>
- <text class="project-name">{{ projectName }}</text>
- </view>
-
- <!-- 选择表单 -->
- <view class="form-container">
- <view v-if="loading" class="loading-tip">
- <text class="loading-text">加载中...</text>
- </view>
-
- <view v-else class="form-content">
- <!-- 国家-中心联动选择 -->
- <view class="form-item">
- <view class="form-label">国家 - 中心:</view>
- <picker
- mode="multiSelector"
- :range="pickerRange"
- :value="[selectedCountryIndex, selectedCenterIndex]"
- @change="handleMultiPickerChange"
- @columnchange="handleColumnChange"
- >
- <view class="picker-display">
- <text class="picker-text" :class="{ placeholder: selectedCountryIndex === -1 || selectedCenterIndex === -1 }">
- {{ getDisplayText() }}
- </text>
- <text class="picker-arrow">›</text>
- </view>
- </picker>
- </view>
-
- <!-- 名称和生效日期合并 -->
- <view class="form-item highlight-item">
- <view class="form-label required">名称:</view>
- <view class="input-wrapper highlight">
- <input
- v-model="documentName"
- type="text"
- placeholder="请输入具体文档名"
- class="input-field"
- @input="handleDocumentNameInput"
- />
- </view>
- <view class="date-picker-wrapper">
- <picker
- mode="date"
- :value="effectiveDate"
- @change="handleDateChange"
- >
- <view class="picker-display">
- <text class="picker-text" :class="{ placeholder: !effectiveDate }">
- {{ effectiveDate || '请输入生效日期' }}
- </text>
- <text class="picker-arrow">›</text>
- </view>
- </picker>
- </view>
- <view class="final-name-preview">
- <text class="preview-label">完整名称预览:</text>
- <text class="preview-text">{{ getFinalName() }}</text>
- </view>
- </view>
-
- <!-- 提交按钮 -->
- <button
- class="confirm-btn"
- :disabled="selectedCountryIndex < 0 || selectedCenterIndex < 0 || !documentName.trim()"
- @click="handleSubmit"
- >
- 提交
- </button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getFolderList, uploadScanFile } from '@/apis/scan'
- export default {
- data() {
- return {
- statusBarHeight: 0,
- projectId: 0,
- projectName: '',
- projectCode: '',
- rawData: null,
- loading: false,
- showRawData: false,
-
- // 原始数据列表(用于查找独立的中心)
- allFolders: [],
-
- // 国家列表
- countryList: [],
- selectedCountryIndex: 0, // 默认选中第一个(NA)
-
- // 中心列表
- centerList: [],
- selectedCenterIndex: 0, // 默认选中第一个(NA)
-
- // 文档名称输入
- documentName: '',
-
- // 生效日期
- effectiveDate: ''
- }
- },
- computed: {
- // 构建选择器的 range 数据
- pickerRange() {
- // 第一列:国家名称数组
- const countryNames = this.countryList.map(item => item.name)
- // 第二列:中心显示名称数组
- const centerNames = this.centerList.map(item => item.displayName || item.name)
-
- return [countryNames, centerNames]
- }
- },
- onLoad(options) {
- this.projectId = parseInt(options.projectId) || 0
- this.projectName = decodeURIComponent(options.projectName || '')
- this.projectCode = decodeURIComponent(options.projectCode || '')
- },
- onReady() {
- // 获取系统信息
- const windowInfo = uni.getWindowInfo()
- this.statusBarHeight = windowInfo.statusBarHeight || 0
-
- // 加载数据
- if (this.projectId) {
- this.loadFolderList()
- } else {
- console.error('projectId 为空,无法加载文件夹列表')
- }
- },
- methods: {
- // 返回上一页
- handleBack() {
- uni.navigateBack()
- },
-
- // 加载文件夹列表
- async loadFolderList() {
- if (this.loading) return
-
- try {
- this.loading = true
-
- const response = await getFolderList({
- projectId: this.projectId
- })
-
- // 保存原始数据
- this.rawData = response
-
- // 解析数据
- if (response.code === 200 && response.data && Array.isArray(response.data)) {
- this.allFolders = response.data
- this.parseCountryList(response.data)
- }
-
- } catch (error) {
- console.error('加载失败:', error)
- uni.showToast({
- title: '加载失败',
- icon: 'none'
- })
- } finally {
- this.loading = false
- }
- },
-
- // 解析国家列表(type === 1 为国家)
- parseCountryList(data) {
- const countries = data.filter(item => {
- return item.type === 1 // 国家类型
- })
-
- // 在列表开头添加 NA 选项
- this.countryList = [
- { id: 'NA', name: 'NA', type: 1, children: [], displayName: 'NA' },
- ...countries
- ]
-
- // 初始化时加载第一个国家(NA)的中心列表
- if (this.countryList.length > 0) {
- this.loadCenterList(0)
- }
- },
-
- // 加载中心列表
- loadCenterList(countryIndex) {
- if (countryIndex >= 0 && this.countryList[countryIndex]) {
- const country = this.countryList[countryIndex]
-
- // 如果选择的是 NA(第一个选项)
- if (country.id === 'NA') {
- // 获取所有不属于任何国家的中心
- this.centerList = this.getIndependentCenters()
- } else {
- // 选择了具体国家,显示该国家下的所有中心(包括子中心)
- const allCenters = this.getAllCentersRecursive(country.children || [])
-
- // 在列表开头添加 NA 选项
- this.centerList = [
- { id: 'NA', name: 'NA', type: 2, displayName: 'NA' },
- ...allCenters
- ]
- }
- } else {
- this.centerList = [{ id: 'NA', name: 'NA', type: 2, displayName: 'NA' }]
- }
- },
-
- // 递归获取所有中心(包括子中心)
- getAllCentersRecursive(nodes, prefix = '') {
- let centers = []
-
- nodes.forEach(node => {
- // 如果是中心类型(type === 2)
- if (node.type === 2) {
- // 添加当前中心,名称带层级前缀
- const displayName = prefix ? `${prefix} > ${node.name}` : node.name
- centers.push({
- ...node,
- displayName: displayName, // 用于显示的名称
- originalName: node.name // 保留原始名称
- })
-
- // 如果有子节点,递归获取
- if (node.children && node.children.length > 0) {
- const subCenters = this.getAllCentersRecursive(node.children, displayName)
- centers = centers.concat(subCenters)
- }
- } else if (node.children && node.children.length > 0) {
- // 如果不是中心但有子节点,继续递归
- const subCenters = this.getAllCentersRecursive(node.children, prefix)
- centers = centers.concat(subCenters)
- }
- })
-
- return centers
- },
-
- // 多列选择器列变化
- handleColumnChange(e) {
- const column = e.detail.column // 哪一列变化了
- const value = e.detail.value // 变化后的值
-
- // 如果是第一列(国家)变化
- if (column === 0) {
- this.selectedCountryIndex = value
- // 重新加载中心列表
- this.loadCenterList(value)
- // 重置中心选择为第一个
- this.selectedCenterIndex = 0
- }
- },
-
- // 多列选择器确认
- handleMultiPickerChange(e) {
- const values = e.detail.value
- this.selectedCountryIndex = values[0]
- this.selectedCenterIndex = values[1]
- },
-
- // 获取显示文本
- getDisplayText() {
- if (this.selectedCountryIndex >= 0 && this.selectedCenterIndex >= 0) {
- const country = this.countryList[this.selectedCountryIndex]
- const center = this.centerList[this.selectedCenterIndex]
-
- if (country && center) {
- const centerName = center.displayName || center.name
- return `${country.name} - ${centerName}`
- }
- }
- return '请选择国家和中心'
- },
-
- // 日期选择变化
- handleDateChange(e) {
- this.effectiveDate = e.detail.value
- },
-
- // 处理文档名称输入,禁止输入 "-" 字符
- handleDocumentNameInput(e) {
- const value = e.detail.value
-
- // 检测是否包含 "-" 字符
- if (value.includes('-')) {
- // 移除所有 "-" 字符
- const filteredValue = value.replace(/-/g, '')
- this.documentName = filteredValue
-
- // 提示用户
- uni.showToast({
- title: '文档名称不能包含"-"字符',
- icon: 'none',
- duration: 1500
- })
- } else {
- this.documentName = value
- }
- },
-
- // 格式化日期为 YYYYMMDD 格式(用于显示)
- formatDate(dateStr) {
- if (!dateStr) return ''
- // 将 2026-01-21 转换为 20260121
- return dateStr.replace(/-/g, '')
- },
-
- // 格式化日期为 YYYY-MM-DD HH:mm:ss 格式(用于提交)
- formatDateTimeForSubmit(dateStr) {
- if (!dateStr) return ''
- // 将 2026-01-21 转换为 2026-01-21 00:00:00
- return `${dateStr} 00:00:00`
- },
-
- // 获取文件夹ID(folder参数的逻辑)
- getFolderId() {
- const selectedCountry = this.countryList[this.selectedCountryIndex]
- const selectedCenter = this.centerList[this.selectedCenterIndex]
-
- // 如果选择了中心(且不是NA),使用中心ID
- if (selectedCenter && selectedCenter.id !== 'NA') {
- return selectedCenter.id
- }
-
- // 如果选择了国家(且不是NA),使用国家ID
- if (selectedCountry && selectedCountry.id !== 'NA') {
- return selectedCountry.id
- }
-
- // 否则使用0
- return 0
- },
-
- // 获取完整名称(用于提交)
- // 格式:{项目编号}-{国家名/NA}-{中心号/NA}-[具体文档名]-[生效日期]
- getFullNameForSubmit() {
- const projectCode = this.projectCode || 'NA'
-
- const country = this.countryList[this.selectedCountryIndex]
- const countryName = country && country.id !== 'NA' ? country.name : 'NA'
-
- const center = this.centerList[this.selectedCenterIndex]
- const centerId = center && center.id !== 'NA' ? center.id : 'NA'
-
- const docName = this.documentName.trim() || '[请输入具体文档名]'
- const date = this.formatDate(this.effectiveDate) || '[请输入生效日期]'
-
- return `${projectCode}-${countryName}-${centerId}-${docName}-${date}`
- },
-
- // 获取显示名称(用于前端显示,NA时隐藏)
- // 格式:{项目编号}-[国家名(如果不是NA)]-[中心号(如果不是NA)]-[具体文档名]-[生效日期]
- getFinalName() {
- const projectCode = this.projectCode || 'NA'
-
- const country = this.countryList[this.selectedCountryIndex]
- const countryName = country && country.id !== 'NA' ? country.name : ''
-
- const center = this.centerList[this.selectedCenterIndex]
- const centerId = center && center.id !== 'NA' ? center.id : ''
-
- const docName = this.documentName.trim() || '[请输入具体文档名]'
- const date = this.formatDate(this.effectiveDate) || '[请输入生效日期]'
-
- // 构建名称数组,过滤掉空值
- const nameParts = [projectCode, countryName, centerId, docName, date].filter(part => part !== '')
-
- return nameParts.join('-')
- },
-
- // 获取所有不属于任何国家的中心
- getIndependentCenters() {
- // 收集所有国家下的中心ID
- const centerIdsInCountries = new Set()
-
- this.allFolders.forEach(folder => {
- if (folder.type === 1 && folder.children) { // 国家类型
- this.collectAllCenterIds(folder.children, centerIdsInCountries)
- }
- })
-
- // 找出所有不在国家下的中心(直接在根目录下的中心)
- const independentCenters = this.allFolders.filter(folder => {
- return folder.type === 2 && !centerIdsInCountries.has(folder.id)
- })
-
- // 递归获取这些独立中心及其子中心
- const allIndependentCenters = this.getAllCentersRecursive(independentCenters)
-
- // 在列表开头添加 NA 选项
- return [
- { id: 'NA', name: 'NA', type: 2, displayName: 'NA' },
- ...allIndependentCenters
- ]
- },
-
- // 收集所有中心ID(递归)
- collectAllCenterIds(nodes, centerIds) {
- nodes.forEach(node => {
- if (node.type === 2) {
- centerIds.add(node.id)
- }
- if (node.children && node.children.length > 0) {
- this.collectAllCenterIds(node.children, centerIds)
- }
- })
- },
-
- // 中心选择变化(保留以防需要)
- handleCenterChange(e) {
- const index = parseInt(e.detail.value)
- this.selectedCenterIndex = index
- },
-
- // 提交
- async handleSubmit() {
- if (this.selectedCountryIndex < 0) {
- uni.showToast({
- title: '请选择国家',
- icon: 'none'
- })
- return
- }
-
- if (this.selectedCenterIndex < 0) {
- uni.showToast({
- title: '请选择中心',
- icon: 'none'
- })
- return
- }
-
- if (!this.documentName.trim()) {
- uni.showToast({
- title: '请输入具体文档名',
- icon: 'none'
- })
- return
- }
-
- if (!this.effectiveDate) {
- uni.showToast({
- title: '请输入生效日期',
- icon: 'none'
- })
- return
- }
-
- const selectedCountry = this.countryList[this.selectedCountryIndex]
- const selectedCenter = this.centerList[this.selectedCenterIndex]
-
- // 从全局数据中获取扫描的fileBase64List
- const fileBase64List = getApp().globalData.scannedFileBase64List
-
- if (!fileBase64List || fileBase64List.length === 0) {
- uni.showToast({
- title: '未找到扫描文件',
- icon: 'none'
- })
- return
- }
-
- try {
- uni.showLoading({
- title: '提交中...',
- mask: true
- })
-
- // 构建请求参数
- const fullName = this.getFullNameForSubmit() // 完整名称用于提交
- const folderId = this.getFolderId()
-
- const params = {
- projectId: this.projectId,
- folder: folderId,
- specificName: this.documentName.trim(),
- name: fullName,
- effectiveDate: this.formatDateTimeForSubmit(this.effectiveDate),
- files: fileBase64List
- }
-
- // 调用上传接口
- const response = await uploadScanFile(params)
-
- uni.hideLoading()
-
- if (response.code === 200) {
- uni.showToast({
- title: '提交成功',
- icon: 'success',
- duration: 2000
- })
-
- // 清空全局数据
- getApp().globalData.scannedFileBase64List = []
-
- // 延迟返回首页
- setTimeout(() => {
- uni.reLaunch({
- url: '/pages/home/index'
- })
- }, 2000)
- } else {
- throw new Error(response.msg || '提交失败')
- }
-
- } catch (error) {
- uni.hideLoading()
- console.error('提交失败:', error)
- uni.showToast({
- title: error.message || '提交失败',
- icon: 'none'
- })
- }
- },
-
- // 确认选择(保留旧方法以防其他地方调用)
- handleConfirm() {
- this.handleSubmit()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .folder-select-page {
- width: 100%;
- height: 100vh;
- display: flex;
- flex-direction: column;
- background-color: #f5f5f5;
-
- // 顶部导航栏
- .header-bg {
- background: linear-gradient(180deg, #1ec9c9 0%, #1eb8b8 100%);
- position: relative;
- z-index: 100;
-
- .header-content {
- height: 88rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 24rpx;
-
- .back-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: flex-start;
-
- .back-icon {
- font-size: 56rpx;
- color: #ffffff;
- font-weight: 300;
- }
- }
-
- .header-title {
- flex: 1;
- text-align: center;
- font-size: 32rpx;
- font-weight: 600;
- color: #ffffff;
- }
-
- .placeholder {
- width: 60rpx;
- }
- }
- }
-
- // 项目信息栏
- .project-info-bar {
- padding: 24rpx;
- background: #ffffff;
- display: flex;
- align-items: center;
- border-bottom: 1rpx solid #f5f5f5;
-
- .project-label {
- font-size: 28rpx;
- color: #666666;
- margin-right: 8rpx;
- }
-
- .project-name {
- font-size: 28rpx;
- font-weight: 600;
- color: #1ec9c9;
- }
- }
-
- // 表单容器
- .form-container {
- flex: 1;
- overflow-y: auto;
- }
-
- .form-content {
- padding: 32rpx;
- }
-
- .form-item {
- margin-bottom: 32rpx;
-
- &.highlight-item {
- .form-label {
- font-size: 32rpx;
- color: #1ec9c9;
-
- &.required::after {
- content: ' *';
- color: #ff4444;
- }
- }
- }
-
- .form-label {
- font-size: 28rpx;
- color: #333333;
- font-weight: 600;
- margin-bottom: 16rpx;
- }
-
- .date-picker-wrapper {
- margin-top: 16rpx;
- }
-
- .final-name-preview {
- margin-top: 16rpx;
- padding: 20rpx 24rpx;
- background: #f5f5f5;
- border-radius: 12rpx;
- border: 2rpx dashed #cccccc;
-
- .preview-label {
- font-size: 24rpx;
- color: #666666;
- display: block;
- margin-bottom: 8rpx;
- }
-
- .preview-text {
- font-size: 26rpx;
- color: #333333;
- font-weight: 500;
- word-break: break-all;
- }
- }
-
- .input-wrapper {
- background: #ffffff;
- border: 2rpx solid #e0e0e0;
- border-radius: 12rpx;
- padding: 24rpx;
- transition: all 0.3s;
-
- &.highlight {
- border: 3rpx solid #1ec9c9;
- background: linear-gradient(135deg, #f0fffe 0%, #ffffff 100%);
- box-shadow: 0 4rpx 12rpx rgba(30, 201, 201, 0.15);
- padding: 28rpx;
- }
-
- &:focus-within {
- border-color: #1ec9c9;
- box-shadow: 0 0 0 4rpx rgba(30, 201, 201, 0.1);
- }
-
- .input-field {
- width: 100%;
- font-size: 28rpx;
- color: #333333;
-
- &::placeholder {
- color: #999999;
- }
- }
- }
-
- .picker-display {
- background: #ffffff;
- border: 2rpx solid #e0e0e0;
- border-radius: 12rpx;
- padding: 24rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- transition: all 0.3s;
-
- &.disabled {
- background: #f5f5f5;
- opacity: 0.6;
- }
-
- .picker-text {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
-
- &.placeholder {
- color: #999999;
- }
- }
-
- .picker-arrow {
- font-size: 40rpx;
- color: #999999;
- font-weight: 300;
- margin-left: 16rpx;
- }
- }
- }
-
- .confirm-btn {
- width: 100%;
- height: 88rpx;
- background: linear-gradient(135deg, #1ec9c9 0%, #1eb8b8 100%);
- color: #ffffff;
- font-size: 32rpx;
- font-weight: 600;
- border-radius: 16rpx;
- border: none;
- margin-top: 32rpx;
- transition: all 0.3s;
- box-shadow: 0 6rpx 20rpx rgba(30, 201, 201, 0.3);
-
- &:disabled {
- background: #cccccc;
- box-shadow: none;
- opacity: 0.6;
- }
-
- &:active:not(:disabled) {
- opacity: 0.9;
- transform: scale(0.98);
- }
-
- &::after {
- border: none;
- }
- }
-
- // 调试信息
- .debug-section {
- margin-top: 48rpx;
- padding: 24rpx;
- background: #fff3cd;
- border-radius: 12rpx;
- border: 1rpx solid #ffc107;
-
- .debug-title {
- font-size: 28rpx;
- font-weight: 600;
- color: #856404;
- margin-bottom: 12rpx;
- }
-
- .debug-item {
- font-size: 24rpx;
- color: #856404;
- line-height: 1.8;
- }
- }
-
- // 原始数据
- .raw-data-section {
- margin-top: 32rpx;
-
- .raw-data-title {
- font-size: 28rpx;
- font-weight: 600;
- color: #666666;
- padding: 16rpx;
- background: #f5f5f5;
- border-radius: 8rpx;
- cursor: pointer;
-
- &:active {
- background: #e0e0e0;
- }
- }
-
- .json-display {
- margin-top: 16rpx;
- background: #f5f5f5;
- padding: 24rpx;
- border-radius: 8rpx;
- font-size: 22rpx;
- color: #333333;
- font-family: 'Courier New', monospace;
- line-height: 1.6;
- word-break: break-all;
- white-space: pre-wrap;
- }
- }
-
- .loading-tip {
- padding: 200rpx 0;
- text-align: center;
-
- .loading-text {
- font-size: 28rpx;
- color: #999999;
- }
- }
- }
- </style>
|