zjh
2025-05-22 a05d27a8148b8f2fe3061c4fb3908d7333ac45d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<template>
  <view class="container">
    <!-- 表格头部 -->
    <view class="table-header" v-if="components.length>0">
      <view class="th name">元器件名称</view>
      <view class="th spec">规格</view>
      <view class="th manufacturer">制造商</view>
      <view class="th operation">上传图片</view>
      
    </view>
 
    <!-- 表格内容 -->
    <view class="table-body" v-if="components.length>0">
      <!-- 循环渲染元器件 -->
      <view class="tr" v-for="(item, index) in components" :key="index">
        <view class="td name">{{ item.name }}</view>
        
        <!-- 规格列 -->
       <view class="td spec"v-if="current=='true'">
          <view v-for="(spec, sIndex) in item.specs" :key="sIndex" 
                class="option-item" @click="selectSpec(item, sIndex)">
            <radio :value="String(sIndex)" 
                   :checked="item.selectedSpec === sIndex"/>
            <text class="option-text">{{ spec }}</text>
          </view>
        </view>
 
        <!-- 制造商列 -->
       <view class="td manufacturer" v-if="current=='true'">
          <view v-for="(mfg, mIndex) in item.manufacturers" :key="mIndex" 
                class="option-item" @click="selectMfg(item, mIndex)">
            <radio :value="String(mIndex)" 
                   :checked="item.selectedMfg === mIndex"/>
            <text class="option-text">{{ mfg }}</text>
          </view>
        </view>
        
        <view class="td operation" v-if="current=='true'">
           <button class="secondary-btn" @click="uploadImages(item.id)">上传/查看图片</button>
        </view>
 
 <!-- 规格列 -->
 <view class="td spec" v-if="current!='true'">
   <view v-for="(spec, sIndex) in item.specs" :key="sIndex" 
         class="option-item">
     <radio :value="String(sIndex)" 
            :checked="item.selectedSpec === sIndex"
            :disabled="true"/>
     <text class="option-text">{{ spec }}</text>
   </view>
 </view>
 
 <!-- 制造商列 -->
 <view class="td manufacturer" v-if="current!='true'">
   <view v-for="(mfg, mIndex) in item.manufacturers" :key="mIndex" 
         class="option-item">
     <radio :value="String(mIndex)" 
            :checked="item.selectedMfg === mIndex"
            :disabled="true"/>
     <text class="option-text">{{ mfg }}</text>
   </view>
 </view>
 <view class="td operation" v-if="current!='true'">
    <button class="secondary-btn" @click="uploadImages(item.id)">上传/查看图片</button>
 </view>
 
 
      </view>
    </view>
 
    <!-- 提交按钮 -->
    <view class="submit-container" v-if="components.length>0">
      <button v-if="this.current=='true'" class="primary-btn" 
              :disabled="isSubmitting" 
              @tap="handleSubmit">
        {{ isSubmitting ? '提交中...' : '保存清单' }}
      </button>
      <!-- <button class="secondary-btn" @click="uploadImages">上传/查看图片</button> -->
    </view>
    <view class="submit-container" v-if="components.length==0">
      <h1>温馨提示:</h1>
       <h1>该物料没有维护一致性核对项目,请先维护!</h1>
    </view>
  </view>
</template>
 
<script>
export default {
  data() {
    return {
      isSubmitting: false,
      formid:0,
      components: [],
      current:'false'
    }
  },
  methods: {
    selectSpec(item, index) {
      if (this.isSubmitting) return
      item.selectedSpec = index
      if (index < item.manufacturers.length) {
        item.selectedMfg = index
      }
    },
    selectMfg(item, index) {
      if (this.isSubmitting) return
      item.selectedMfg = index
      if (index < item.specs.length) {
        item.selectedSpec = index
      }
    },
    uploadImages(id) {
      // 上传/查看图片的逻辑
     uni.navigateTo({
         url: 'ImageItem?id=888' + id.sort()[0]
     });
    },
    async handleSubmit() {
      if (this.isSubmitting) return
      
      try {
        this.isSubmitting = true
        
        // 表单验证
        const validation = this.validateForm()
        if (!validation.valid) {
          uni.showToast({
            title: validation.msg,
            icon: 'none',
            duration: 2000
          })
          return
        }
 
        // 获取提交数据
        const submitData = this.components.map(item => ({
          name: item.name,
          spec: item.specs[item.selectedSpec],
          manufacturer: item.manufacturers[item.selectedMfg],
          id: item.id[item.selectedMfg]
        }))
 
        // 实际提交时可取消注释以下代码
        // const res = await uni.request({
        //   url: 'your_api_url',
        //   method: 'POST',
        //   data: submitData
        // })
        this.$post({
            url: "/LLJ/saveYzxItem",
            data: {
                id:this.formid,
                data: submitData
            }
        }).then(res => {
            if(res.status==0){
                uni.showToast({
                  title: '保存成功',
                  icon: 'success',
                  duration: 2000
                })
            }else{
                uni.showModal({
                    title: "提示",
                    content: res.message,
                    confirmText: "确定",
                    showCancel: false,
                    success: (res) => {
                        
                    }
                })
            }
        }).catch(() => {
            this.isLoading = false; // 出现错误时结束加载
        });
 
      
        
      } finally {
        this.isSubmitting = false
      }
    },
    validateForm() {
      for (const item of this.components) {
        if (item.selectedSpec === -1 || item.selectedMfg === -1) {
          return {
            valid: false,
            msg: `${item.name} 未完成选择`
          }
        }
      }
      return { valid: true }
    },
            onLoad(options) {
                //options中包含了url附带的参数
                let params = options;
                this.formid = params["id"];
                this.current=params["current"];
                 
                //页面加载时调用的事件
                this.$post({
                    url: "/LLJ/getYzxItem",
                    data: {
                        id:this.formid
                    }
                }).then(res => {
                    console.log(res);
                    this.components=res.data
                }).catch(() => {
                    this.isLoading = false; // 出现错误时结束加载
                });
            },
  }
}
</script>
 
<style scoped>
.container {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}
 
/* 表格样式 */
.table-header, .tr {
  display: flex;
  border-bottom: 1rpx solid #eee;
  background-color: #fff;
}
 
.th, .td {
  padding: 20rpx;
  border-right: 1rpx solid #eee;
}
 
.th {
  background-color: #f8f9fa;
  font-weight: bold;
  color: #333;
}
 
.name { width: 20%; }
.spec { width: 30%; }
.manufacturer { width: 30%; }
.operation { width: 20%; }
 
/* 选项样式 */
.option-item {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  min-height: 80rpx;
}
 
radio {
  transform: scale(0.9);
  margin-right: 15rpx;
}
 
.option-text {
  flex: 1;
  font-size: 28rpx;
  color: #444;
}
 
.primary-btn, .secondary-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
}
 
.primary-btn {
  background-color: #3498db;
  color: white;
}
 
.primary-btn:hover {
  background-color: #2980b9;
}
 
/* 提交按钮样式 */
.submit-container {
  /* margin: 40rpx 20rpx; */
  padding: 20rpx 0;
  background-color: #fff;
  /* border-radius: 16rpx; */
}
 
 
/* 响应式适配 */
@media (max-width: 768px) {
  .th, .td {
    padding: 16rpx;
    font-size: 26rpx;
  }
  
  .option-text {
    font-size: 26rpx;
  }
 
  .submit-btn {
    width: 95%;
    font-size: 28rpx;
  }
}
</style>