hookehuyr

产品详情页下载产品逻辑修改

1 <!-- 1 <!--
2 * @Date: 2024-09-29 14:26:41 2 * @Date: 2024-09-29 14:26:41
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-10-24 12:51:33 4 + * @LastEditTime: 2024-10-25 11:07:10
5 * @FilePath: /hager/src/views/product/detail.vue 5 * @FilePath: /hager/src/views/product/detail.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -56,10 +56,16 @@ ...@@ -56,10 +56,16 @@
56 <el-row :gutter="0"> 56 <el-row :gutter="0">
57 <el-col :span="is_xs ? 24 : 19"> 57 <el-col :span="is_xs ? 24 : 19">
58 <div :class="['control-left', is_xs ? 'xs' : '']"> 58 <div :class="['control-left', is_xs ? 'xs' : '']">
59 - <div v-if="product_sample" :class="['button', is_xs ? 'xs' : '', is_active === product_sample.id ? 'active' : '']" @click="onClick(product_sample)">产品样本</div> 59 + <div
60 - <div v-if="technical_parameter" :class="['button', is_xs ? 'xs' : '', is_active === technical_parameter.id ? 'active' : '']" @click="onClick(technical_parameter)">技术参数</div> 60 + v-if="item.list.length"
61 - <div v-if="product_manual" :class="['button', is_xs ? 'xs' : '', is_active === product_manual.id ? 'active' : '']" @click="onClick(product_manual)">产品说明书</div> 61 + v-for="(item, index) in download_list" :key="item.id"
62 - <div v-if="installation_tutorial" :class="['button', is_xs ? 'xs' : '', is_active === installation_tutorial.id ? 'active' : '']" @click="onClick(installation_tutorial)">安装教程</div> 62 + :class="[
63 + 'button', is_xs ? 'xs' : '',
64 + item.show ? 'active' : ''
65 + ]"
66 + @click="onClick(item)">
67 + {{ item.name }}
68 + </div>
63 </div> 69 </div>
64 </el-col> 70 </el-col>
65 <el-col v-if="!is_xs" :span="5"> 71 <el-col v-if="!is_xs" :span="5">
...@@ -69,45 +75,41 @@ ...@@ -69,45 +75,41 @@
69 </el-col> 75 </el-col>
70 </el-row> 76 </el-row>
71 </div> 77 </div>
72 - <div> 78 + <div v-if="item.show" v-for="(item, index) in download_list" :key="item.id">
73 <div class="mini-download-wrapper" v-if="is_xs"> 79 <div class="mini-download-wrapper" v-if="is_xs">
74 <div> 80 <div>
75 - <span @click="checkAll">全选</span>&nbsp; 81 + <span @click="checkAll(item)">全选</span>&nbsp;
76 - <span v-if="checked_sum">已选 {{ checked_sum }}</span> 82 + <span v-if="item.checked_sum">已选 {{ item.checked_sum }}</span>
77 </div> 83 </div>
78 <div @click="goToDownload" :class="['button', is_download_checked ? 'active' : '']">发送到邮箱</div> 84 <div @click="goToDownload" :class="['button', is_download_checked ? 'active' : '']">发送到邮箱</div>
79 </div> 85 </div>
80 - <div class="info-list" v-for="(item, index) in download_list" :key="index"> 86 + <div class="info-list">
81 - <el-row :gutter="0"> 87 + <el-row :gutter="0" v-for="(file, idx) in item.list" :key="idx">
82 <el-col :span="18"> 88 <el-col :span="18">
83 <div class="info-list-title"> 89 <div class="info-list-title">
84 <el-row :gutter="0"> 90 <el-row :gutter="0">
85 <el-col :span="is_xs ? 4 : 2"> 91 <el-col :span="is_xs ? 4 : 2">
86 - <i v-if="item.checked" @click="checkItem(item)" class="el-icon-folder-checked download-checked"></i> 92 + <i v-if="file.checked" @click="checkItem(file)" class="el-icon-folder-checked download-checked"></i>
87 - <i v-else @click="checkItem(item)" class="el-icon-folder download-unchecked"></i>&nbsp; 93 + <i v-else @click="checkItem(file)" class="el-icon-folder download-unchecked"></i>&nbsp;
88 </el-col> 94 </el-col>
89 <el-col :span="is_xs ? 20 : 22"> 95 <el-col :span="is_xs ? 20 : 22">
90 <div class="info-list-title-content"> 96 <div class="info-list-title-content">
91 <div> 97 <div>
92 - <i class="el-icon-document" style="font-size: 1.35rem;"></i> 98 + <i v-if="!is_xs" class="el-icon-document" style="font-size: 1.35rem;"></i>
93 - {{ item.name }} 99 + {{ file.name }}
94 </div> 100 </div>
95 <div> 101 <div>
96 - &nbsp;{{ item.size }} 102 + &nbsp;{{ file.size }}
97 </div> 103 </div>
98 </div> 104 </div>
99 </el-col> 105 </el-col>
100 </el-row> 106 </el-row>
101 - <!-- <i v-if="item.checked" @click="checkItem(item)" class="el-icon-folder-checked download-checked"></i>
102 - <i v-else @click="checkItem(item)" class="el-icon-folder download-unchecked"></i>
103 - <i class="el-icon-document" style="font-size: 1.25rem; margin-left: 1rem;"></i>
104 - <p><span>{{ item.name }}</span><span>{{ item.size }}</span></p> -->
105 </div> 107 </div>
106 </el-col> 108 </el-col>
107 <el-col :span="6"> 109 <el-col :span="6">
108 <div class="info-list-control"> 110 <div class="info-list-control">
109 - <div @click="preview(item)">预览</div> 111 + <div @click="preview(file)">预览</div>
110 - <div @click="sendEmail" class="icon-wrapper"> 112 + <div @click="sendEmail(file)" class="icon-wrapper">
111 <img style="height: 1rem; width: auto;" src="https://cdn.ipadbiz.cn/hager/icon/%E9%82%AE%E4%BB%B6@2x.png"> 113 <img style="height: 1rem; width: auto;" src="https://cdn.ipadbiz.cn/hager/icon/%E9%82%AE%E4%BB%B6@2x.png">
112 </div> 114 </div>
113 </div> 115 </div>
...@@ -133,24 +135,52 @@ export default { ...@@ -133,24 +135,52 @@ export default {
133 mixins: [mixin.init], 135 mixins: [mixin.init],
134 data () { 136 data () {
135 return { 137 return {
136 - is_active: '', 138 + download_list: [{
137 - download_list: [], 139 + id: 1,
138 - images: [], 140 + type: 'yangben',
141 + name: '产品样本',
142 + show: false,
143 + list: [],
144 + checked_sum: 0,
145 + }, {
146 + id: 2,
147 + type: 'canshu',
148 + name: '技术参数',
149 + show: false,
150 + list: [],
151 + checked_sum: 0,
152 + }, {
153 + id: 3,
154 + type: 'shuomingshu',
155 + name: '产品说明书',
156 + show: false,
157 + list: [],
158 + checked_sum: 0,
159 + }, {
160 + id: 4,
161 + type: 'jiaocheng',
162 + name: '安装教程',
163 + show: false,
164 + list: [],
165 + checked_sum: 0,
166 + }],
139 info: {}, 167 info: {},
140 info_images: [], 168 info_images: [],
141 product_advantages: [], 169 product_advantages: [],
142 - product_sample: '', 170 + checked_items: [],
143 - technical_parameter: '',
144 - product_manual: '',
145 - installation_tutorial: '',
146 } 171 }
147 }, 172 },
148 computed: { 173 computed: {
149 is_download_checked () { 174 is_download_checked () {
150 - return this.download_list.filter(item => item.checked).length > 0; 175 + let sum = 0;
151 - }, 176 + this.download_list.forEach(item => {
152 - checked_sum () { 177 + item.list.forEach(file => {
153 - return this.download_list.filter(item => item.checked).length; 178 + if (file.checked) {
179 + sum++;
180 + }
181 + });
182 + });
183 + return sum;
154 }, 184 },
155 }, 185 },
156 async mounted () { 186 async mounted () {
...@@ -172,31 +202,41 @@ export default { ...@@ -172,31 +202,41 @@ export default {
172 if (this.info.file?.img) { 202 if (this.info.file?.img) {
173 this.info_images = this.info.file.img.map(item => item.value); 203 this.info_images = this.info.file.img.map(item => item.value);
174 } 204 }
175 - // 205 + // 产品优势
176 this.product_advantages = this.splitIntoEqualChunks(this.info.product_advantages); 206 this.product_advantages = this.splitIntoEqualChunks(this.info.product_advantages);
177 - // 207 + // 产品资料数据结构
178 - this.product_sample = this.info.file?.yangben?.map(item => ({ ...item, checked: false }));// 产品样本 208 + for (const key in this.info.file) {
179 - this.technical_parameter = this.info.file?.canshu?.map(item => ({ ...item, checked: false })); // 技术参数 209 + const element = this.info.file[key];
180 - this.product_manual = this.info.file?.shuomingshu?.map(item => ({ ...item, checked: false })); // 产品说明书 210 + this.download_list.forEach(item => {
181 - this.installation_tutorial = this.info.file?.jiaocheng?.map(item => ({ ...item, checked: false })); // 安装教程 211 + if (key === item.type) {
182 - let arr = [this.product_sample, this.technical_parameter, this.product_manual, this.installation_tutorial] 212 + item.list = element.map(item => ({ ...item, checked: false }));
183 - for (let index = 0; index < arr.length; index++) { 213 + }
184 - const element = arr[index]; 214 + });
185 - if (element) { 215 + };
186 - this.download_list = element; 216 + // 默认选中第一个有数据的分类
187 - this.is_active = this.download_list.id; 217 + for (let index = 0; index < this.download_list.length; index++) {
188 - return; 218 + if (this.download_list[index].list.length) {
219 + this.download_list[index].show = true;
220 + break;
189 } 221 }
190 } 222 }
191 } 223 }
192 }, 224 },
193 onClick (item) { 225 onClick (item) {
194 - this.is_active = item.id; 226 + this.download_list.forEach(item => item.show = false);
195 - this.download_list = item; 227 + item.show = true;
196 - this.download_list.forEach(item => item.checked = false);
197 }, 228 },
198 goToDownload () { 229 goToDownload () {
199 if (this.is_download_checked) { 230 if (this.is_download_checked) {
231 + let ids = [];
232 + this.download_list.forEach(item => {
233 + item.list.forEach(file => {
234 + if (file.checked) {
235 + ids.push(file.id)
236 + }
237 + })
238 + });
239 + console.warn(ids);
200 // 发送邮箱接口 240 // 发送邮箱接口
201 Message({ 241 Message({
202 type: 'success', 242 type: 'success',
...@@ -204,10 +244,12 @@ export default { ...@@ -204,10 +244,12 @@ export default {
204 }); 244 });
205 } 245 }
206 }, 246 },
207 - checkAll () { 247 + checkAll (item) { // 全选当前显示的下载列表
208 - this.download_list.forEach(item => item.checked = true); 248 + item.list.forEach(file => file.checked = true);
249 + item.checked_sum = item.list.filter(item => item.checked).length;
209 }, 250 },
210 - sendEmail () { 251 + sendEmail (item) {
252 + console.warn(item);
211 // 发送邮箱接口 253 // 发送邮箱接口
212 Message({ 254 Message({
213 type: 'success', 255 type: 'success',
...@@ -242,9 +284,12 @@ export default { ...@@ -242,9 +284,12 @@ export default {
242 284
243 return result; 285 return result;
244 }, 286 },
245 - checkItem (item) { 287 + checkItem (item) { // 选中资料项目
246 item.checked = !item.checked; 288 item.checked = !item.checked;
247 - // this.$forceUpdate(); 289 + console.warn(item);
290 + this.download_list.forEach(item => {
291 + item.checked_sum = item.list.filter(item => item.checked).length;
292 + });
248 }, 293 },
249 } 294 }
250 } 295 }
......