Commit e8f5dac4fea940d6714db9dea1dc475c2472b581

Authored by 刘淇
1 parent 53e7aa96

三级联动

components/grouped-picker/grouped-picker.vue
... ... @@ -23,9 +23,27 @@
23 23  
24 24 <!-- 第 1 层:顶部 tab。原型是 3 个 tab 均分,所以 ≤4 个时不滚动(均分),
25 25 真实物料有 6 个 material_type,均分会把长名字挤掉,这时才转成横向滚动 -->
26   - <up-tabs v-if="!isSearching && tabList.length > 1" :list="tabList" :scrollable="tabScrollable"
27   - v-model:current="tabIdx" @change="onTabChange" :lineWidth="30" :lineHeight="4"
28   - activeColor="#2979ff" lineColor="#2979ff" inactiveColor="#606266"></up-tabs>
  26 + <!-- 第1层:顶部 tab。原型是 3 个 tab 均分,所以 ≤4 个时不滚动(均分),
  27 + 真实物料有 6 个 material_type,均分会把长名字挤掉,这时才转成横向滚动 -->
  28 +<!-- 删掉 ref="tabWrapRef",width 绑定 props.containerWidth -->
  29 +<view :style="{ width: containerWidth + 'px' }">
  30 + <up-tabs
  31 + v-if="!isSearching && tabList.length > 1"
  32 + :list="tabList"
  33 + :scrollable="tabScrollable"
  34 + v-model:current="tabIdx"
  35 + @change="onTabChange"
  36 + :lineWidth="30"
  37 + :lineHeight="4"
  38 + activeColor="#2979ff"
  39 + lineColor="#2979ff"
  40 + inactiveColor="#606266"
  41 + >
  42 + </up-tabs>
  43 +</view>
  44 +
  45 +
  46 +
29 47  
30 48 <view class="gp-body">
31 49 <!-- 最后一层:左侧竖排侧栏(1 层字段时它就是唯一的一层,此时上面没有 tab) -->
... ... @@ -111,7 +129,12 @@ const props = defineProps({
111 129 // 单选传字符串、多选传数组
112 130 value: { type: [String, Array], default: '' },
113 131 // { 选项值: 数量 }
114   - quantities: { type: Object, default: () => ({}) }
  132 + quantities: { type: Object, default: () => ({}) },
  133 + // 新增:父页面传入宽度(px),兜底默认 750
  134 + containerWidth: {
  135 + type: Number,
  136 + default: 750
  137 + }
115 138 })
116 139  
117 140 const emit = defineEmits(['update:show', 'confirm'])
... ...
pages-sub/daily/maintain-manage/add-record.vue
1 1 <template>
2 2 <view class="page-container">
3   - <view class="inspect-form-content commonPageLRpadding">
  3 + <view class="inspect-form-content commonPageLRpadding" ref="formContentRef">
4 4 <up-form label-position="left" :model="inspectForm" ref="inspectFormRef" label-width="140rpx">
5 5 <!-- ========== 动态表单区域 ========== -->
6 6 <template v-for="item in dynamicFields" :key="item.fieldCode">
... ... @@ -66,10 +66,24 @@
66 66 </view>
67 67 </view>
68 68 <!-- type7 图片:多张上传,提交 JSON 数组(URL) -->
69   - <up-upload v-else-if="item.fieldType === 7" :file-list="fileListMap[item.fieldCode] || []"
70   - @after-read="(event) => uploadFieldFiles(item, event)" @delete="(event) => deleteFieldFile(item, event)"
71   - multiple :max-count="pickCountOf(item, 5)" upload-text="选择图片" del-color="#ff4d4f"
72   - class="upload-wrap"></up-upload>
  69 + <!-- type7 图片:多张上传,提交 JSON 数组(URL) -->
  70 +<!-- type7 图片:多张上传,提交 JSON 数组(URL)【对齐工单上传组件】 -->
  71 +<up-upload
  72 + v-else-if="item.fieldType === 7"
  73 + :file-list="fileListMap[item.fieldCode] || []"
  74 + @after-read="(event) => uploadFieldFiles(item, event)"
  75 + @delete="(event) => deleteFieldFile(item, event)"
  76 + multiple
  77 + width="70"
  78 + height="70"
  79 + :sizeType="['compressed']"
  80 + :max-count="pickCountOf(item, 5)"
  81 + upload-text="选择图片"
  82 + del-color="#ff4d4f"
  83 + class="upload-wrap"
  84 +></up-upload>
  85 +
  86 +
73 87 <!-- type8 附件:微信只能从聊天记录选文件(无通用文件选择器),提交 JSON 数组(URL) -->
74 88 <view v-else-if="item.fieldType === 8" class="file-wrap">
75 89 <view v-for="(file, idx) in fileListMap[item.fieldCode] || []" :key="idx" class="file-row">
... ... @@ -106,15 +120,15 @@
106 120 </template>
107 121 <!-- ========== 动态表单结束 ========== -->
108 122 <!-- 1. 养护描述(文本域) -->
109   - <up-form-item prop="remark" class="form-item">
  123 + <!-- <up-form-item prop="remark" class="form-item">
110 124 <up-textarea v-model.trim="inspectForm.remark" placeholder="请输入养护描述" maxlength="200" count></up-textarea>
111   - </up-form-item>
  125 + </up-form-item> -->
112 126 <!-- 2. 上传图片 -->
113   - <up-form-item label="上传图片" prop="images" required class="form-item">
  127 + <!-- <up-form-item label="上传图片" prop="images" required class="form-item">
114 128 <up-upload :file-list="imagesList" @after-read="(event) => uploadImgs(event)"
115 129 @delete="(event) => deleteImg(event)" @on-exceed="handleExceed" multiple :max-count="3" upload-text="选择图片"
116 130 del-color="#ff4d4f" class="upload-wrap"></up-upload>
117   - </up-form-item>
  131 + </up-form-item> -->
118 132 </up-form>
119 133 </view>
120 134 <!-- 底部提交按钮 -->
... ... @@ -132,6 +146,7 @@
132 146 <grouped-picker :show="groupPicker.show" :title="groupPicker.title" :options="groupPicker.options"
133 147 :multiple="groupPicker.multiple" :max-count="groupPicker.maxCount"
134 148 :need-quantity="groupPicker.needQuantity" :value="groupPicker.value"
  149 + :container-width="groupPicker.containerWidth"
135 150 :quantities="groupPicker.quantities" @update:show="groupPicker.show = $event"
136 151 @confirm="onGroupedConfirm"></grouped-picker>
137 152 </view>
... ... @@ -206,7 +221,9 @@ export default {
206 221 value: '' as any,
207 222 quantities: {} as any,
208 223 // 数量单位不再传进弹层(原型列表行右侧只有步进器,没有单位),页面行内仍显示 item.unit
209   - unit: ''
  224 + unit: '',
  225 + // 新增:由父页面点击时赋值
  226 + containerWidth: 0
210 227 }
211 228 }
212 229 },
... ... @@ -300,7 +317,15 @@ export default {
300 317 this.groupPicker.needQuantity = item.fieldType === 6 && this.needQty(item)
301 318 this.groupPicker.value = multiple ? (this.inspectForm[code] || []).slice() : (this.inspectForm[code] || '')
302 319 this.groupPicker.quantities = Object.assign({}, this.qtyMap[code] || {})
303   - this.groupPicker.show = true
  320 + // ========== 新增:点击打开弹窗瞬间,获取父表单容器宽度 ==========
  321 + const query = uni.createSelectorQuery().in(this)
  322 + query.select('.inspect-form-content').boundingClientRect((rect) => {
  323 + if (rect && rect.width) {
  324 + // rect.width 单位 px,直接传给子组件
  325 + this.groupPicker.containerWidth = rect.width
  326 + }
  327 + this.groupPicker.show = true
  328 + }).exec()
304 329 },
305 330 /**
306 331 * 分层弹层确定回调。写入位置与原有两条路径完全一致(inspectForm/labelMap/qtyMap),
... ... @@ -668,15 +693,30 @@ export default {
668 693 /**
669 694 * 7图片 上传(u-upload 的 after-read 回调)
670 695 */
671   - uploadFieldFiles(item: any, event: any) {
672   - const rawFile = event && event.file
673   - const fileList = Array.isArray(rawFile) ? rawFile : [rawFile]
674   - return this.uploadToField(item, fileList.filter(file => file && file.url).map(file => ({
675   - url: file.url,
676   - name: file.name || '',
677   - size: file.size
678   - })))
679   - },
  696 + /**
  697 + * 7图片 上传(u-upload 的 after-read 回调)【对齐工单上传逻辑】
  698 + */
  699 +uploadFieldFiles(item: any, event: any) {
  700 + console.log('动态图片上传', item.fieldName, event)
  701 + const rawFile = event && event.file
  702 + const fileList = Array.isArray(rawFile) ? rawFile : [rawFile]
  703 + const targetImgList = this.fileListMap[item.fieldCode] || (this.fileListMap[item.fieldCode] = [])
  704 + const filePaths = fileList.map(file => file.url)
  705 + const tempItems = fileList.map(item => ({
  706 + ...item,
  707 + status: 'uploading',
  708 + message: '上传中'
  709 + }))
  710 + const startIndex = targetImgList.length
  711 + targetImgList.push(...tempItems)
  712 +
  713 + this.uploadToField(item, fileList.filter(file => file && file.url).map(file => ({
  714 + url: file.url,
  715 + name: file.name || '',
  716 + size: file.size
  717 + })))
  718 +},
  719 +
680 720 /**
681 721 * 8附件 选择并上传。
682 722 * 微信小程序没有通用文件选择器,只能从聊天记录里选(uni.chooseMessageFile)
... ... @@ -818,10 +858,12 @@ export default {
818 858 fields.push(row)
819 859 } else if (type === 3) {
820 860 // 3枚举:单选取裸 value;历史「枚举+是否多选」存逗号分隔
821   - fields.push({
822   - fieldCode: code,
823   - valueText: item.multiple === 1 ? (value || []).join(',') : String(value)
824   - })
  861 + fields.push({
  862 + fieldCode: code,
  863 + valueText: item.multiple === 1
  864 + ? (Array.isArray(value) ? value.join(',') : String(value || ''))
  865 + : String(value)
  866 +})
825 867 } else if (type === 6) {
826 868 const selected = (item.selectOptions || []).filter(opt => (value || []).indexOf(opt.value) > -1)
827 869 if (this.needQty(item)) {
... ...