hookehuyr

选择物资组件逻辑完善

1 <!-- 1 <!--
2 * @Date: 2024-07-23 16:24:08 2 * @Date: 2024-07-23 16:24:08
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-07-24 09:39:18 4 + * @LastEditTime: 2024-07-24 18:14:14
5 * @FilePath: /temple_material_request/src/components/chooseMaterial/index.vue 5 * @FilePath: /temple_material_request/src/components/chooseMaterial/index.vue
6 * @Description: 选择物资组件 6 * @Description: 选择物资组件
7 --> 7 -->
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
20 <van-row gutter="10" justify="center" align="center"> 20 <van-row gutter="10" justify="center" align="center">
21 <van-col span="16"> 21 <van-col span="16">
22 <div style="background-color: #FBF9F1; display: flex; border-radius: 5rem; padding: 0 1rem; align-items: center; justify-content: center;"> 22 <div style="background-color: #FBF9F1; display: flex; border-radius: 5rem; padding: 0 1rem; align-items: center; justify-content: center;">
23 - <van-icon name="search" /><van-field v-model="value" label="" placeholder="搜索物资" style="background-color: #FBF9F1;" /> 23 + <van-icon name="search" /><van-field v-model="search_value" @blur="onBlur" label="" placeholder="搜索物资" style="background-color: #FBF9F1;" />
24 </div> 24 </div>
25 </van-col> 25 </van-col>
26 <van-col span="8"> 26 <van-col span="8">
...@@ -42,25 +42,30 @@ ...@@ -42,25 +42,30 @@
42 > 42 >
43 <div v-for="item in list" :key="item" > 43 <div v-for="item in list" :key="item" >
44 <van-row justify="space-around" align="center" style="padding: 1rem; background-color: #F2F2F2;"> 44 <van-row justify="space-around" align="center" style="padding: 1rem; background-color: #F2F2F2;">
45 - <van-col span="8"><van-icon name="passed" size="1.25rem" />&nbsp;&nbsp;<span :style="{ color: styleColor.baseColor }">全选</span></van-col> 45 + <van-col span="8" @click="onCheckAll(item)">
46 - <van-col span="8" style="text-align: center; font-size: 0.95rem; color: #666666; font-weight: bold;">物资分类1</van-col> 46 + <van-icon v-if="item.checked" name="checked" size="1.25rem" :color="styleColor.baseColor" />
47 + <van-icon v-else name="passed" size="1.25rem" />
48 + <span :style="{ color: styleColor.baseColor }">&nbsp;&nbsp;全选</span>
49 + </van-col>
50 + <van-col span="8" style="text-align: center; font-size: 0.95rem; color: #666666; font-weight: bold;">{{ item.name }}</van-col>
47 <van-col span="8"></van-col> 51 <van-col span="8"></van-col>
48 </van-row> 52 </van-row>
49 <van-row align="center" justify="space-between" style=""> 53 <van-row align="center" justify="space-between" style="">
50 - <van-col span="24" style="display: flex; padding: 1rem; border-bottom: 1px solid #F5F5F5;"> 54 + <van-col v-for="m in item.m_list" :key="m.id" span="24" style="display: flex; padding: 1rem; border-bottom: 1px solid #F5F5F5;">
51 - <van-icon name="passed" size="1.25rem" />&nbsp;&nbsp;<div class="van-ellipsis" :style="{ color: styleColor.baseColor, textDecoration: 'underline' }" @click="onClickTitle(item)">床垫 1.2m*2m</div> 55 + <van-icon v-if="m.checked" @click="onCheck(item, m)" name="checked" size="1.25rem" :color="styleColor.baseColor" />
52 - </van-col> 56 + <van-icon v-else name="passed" @click="onCheck(item, m)" size="1.25rem" />&nbsp;&nbsp;
53 - <van-col span="24" style="display: flex; padding: 1rem; border-bottom: 1px solid #F5F5F5;"> 57 + <div class="van-ellipsis" :style="{ color: styleColor.baseColor, textDecoration: 'underline' }" @click="onClickTitle(m)">
54 - <van-icon name="passed" size="1.25rem" />&nbsp;&nbsp;<div class="van-ellipsis" :style="{ color: styleColor.baseColor, textDecoration: 'underline' }" @click="onClickTitle(item)">床垫 1.2m*2m</div> 58 + {{ m.name }}
59 + </div>
55 </van-col> 60 </van-col>
56 </van-row> 61 </van-row>
57 </div> 62 </div>
58 </van-list> 63 </van-list>
59 <div style="height: 6rem;"></div> 64 <div style="height: 6rem;"></div>
60 <div class="control-bar"> 65 <div class="control-bar">
61 - <van-button plain block type="primary" :color="styleColor.baseColor" @click="addMore">加入购物车</van-button> 66 + <van-button plain block type="primary" :color="styleColor.baseColor" @click="addShoppingCart">加入购物车</van-button>
62 <div style="display: flex; align-items: center; margin-left: 1rem;"> 67 <div style="display: flex; align-items: center; margin-left: 1rem;">
63 - <van-badge :content="5"> 68 + <van-badge :content="cart_count">
64 <van-icon name="shopping-cart-o" size="2.5rem" :color="styleColor.baseColor" @click="goShoppingCart" /> 69 <van-icon name="shopping-cart-o" size="2.5rem" :color="styleColor.baseColor" @click="goShoppingCart" />
65 </van-badge> 70 </van-badge>
66 </div> 71 </div>
...@@ -68,25 +73,31 @@ ...@@ -68,25 +73,31 @@
68 <van-back-top class="custom" bottom="12vh" z-index="9999">返回顶部</van-back-top> 73 <van-back-top class="custom" bottom="12vh" z-index="9999">返回顶部</van-back-top>
69 <van-dialog v-model:show="show_type" title="请选择筛选分类" @confirm="onConfirm" show-cancel-button :confirm-button-color="styleColor.baseColor"> 74 <van-dialog v-model:show="show_type" title="请选择筛选分类" @confirm="onConfirm" show-cancel-button :confirm-button-color="styleColor.baseColor">
70 <div style="padding: 1rem;"> 75 <div style="padding: 1rem;">
71 - <van-checkbox-group v-model="type_checked" shape="square" :checked-color="styleColor.baseColor"> 76 + <van-checkbox-group v-model="type_checked" shape="square" direction="horizontal" :checked-color="styleColor.baseColor">
72 <van-checkbox name="a" style="margin-bottom: 0.5rem;">复选框 a</van-checkbox> 77 <van-checkbox name="a" style="margin-bottom: 0.5rem;">复选框 a</van-checkbox>
73 <van-checkbox name="b" style="margin-bottom: 0.5rem;">复选框 b</van-checkbox> 78 <van-checkbox name="b" style="margin-bottom: 0.5rem;">复选框 b</van-checkbox>
79 + <van-checkbox name="c" style="margin-bottom: 0.5rem;">复选框 c</van-checkbox>
80 + <van-checkbox name="d" style="margin-bottom: 0.5rem;">复选框 d</van-checkbox>
74 </van-checkbox-group> 81 </van-checkbox-group>
75 </div> 82 </div>
76 </van-dialog> 83 </van-dialog>
77 </van-popup> 84 </van-popup>
78 </div> 85 </div>
86 +
87 + <material-detail :show="show_material_detail" @close="onCloseDetail"></material-detail>
88 +
79 </template> 89 </template>
80 90
81 <script setup> 91 <script setup>
82 import { ref } from 'vue' 92 import { ref } from 'vue'
83 import { useRoute, useRouter } from 'vue-router' 93 import { useRoute, useRouter } from 'vue-router'
84 - 94 +import { showToast } from 'vant';
85 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' 95 import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js'
86 //import { } from '@/utils/generateModules.js' 96 //import { } from '@/utils/generateModules.js'
87 //import { } from '@/utils/generateIcons.js' 97 //import { } from '@/utils/generateIcons.js'
88 //import { } from '@/composables' 98 //import { } from '@/composables'
89 import { styleColor } from "@/constant.js"; 99 import { styleColor } from "@/constant.js";
100 +import materialDetail from '@/components/materialDetail/index.vue';
90 101
91 const $route = useRoute(); 102 const $route = useRoute();
92 const $router = useRouter(); 103 const $router = useRouter();
...@@ -122,10 +133,16 @@ const onLoad = () => { ...@@ -122,10 +133,16 @@ const onLoad = () => {
122 // 异步更新数据 133 // 异步更新数据
123 // setTimeout 仅做示例,真实场景中一般为 ajax 请求 134 // setTimeout 仅做示例,真实场景中一般为 ajax 请求
124 setTimeout(() => { 135 setTimeout(() => {
125 - for (let i = 0; i < 10; i++) { 136 + for (let i = 0; i < 5; i++) {
126 - list.value.push(list.value.length + 1); 137 + list.value.push({ id: i, name: '物资分类' + i, checked: false, m_list: [] });
127 } 138 }
128 139
140 + list.value.forEach((item) => {
141 + for (let j = 0; j < 5; j++) {
142 + item.m_list.push({ id: j, name: '标题' + j, checked: false });
143 + }
144 + })
145 +
129 // 加载状态结束 146 // 加载状态结束
130 loading.value = false; 147 loading.value = false;
131 148
...@@ -138,6 +155,7 @@ const onLoad = () => { ...@@ -138,6 +155,7 @@ const onLoad = () => {
138 155
139 const onClickTitle = (item) => { // 点击物资标题回调 156 const onClickTitle = (item) => { // 点击物资标题回调
140 console.warn(item); 157 console.warn(item);
158 + show_material_detail.value = true;
141 } 159 }
142 160
143 const show_type = ref(false); 161 const show_type = ref(false);
...@@ -148,6 +166,58 @@ const type_checked = ref([]); ...@@ -148,6 +166,58 @@ const type_checked = ref([]);
148 const onConfirm = () => { 166 const onConfirm = () => {
149 console.warn(type_checked.value); 167 console.warn(type_checked.value);
150 } 168 }
169 +
170 +const search_value = ref('');
171 +const onBlur = () => {
172 + // TODO: 输入框失去焦点,接口需要一个搜索接口,返回相应的值
173 + console.warn(search_value.value);
174 +}
175 +
176 +const show_material_detail = ref(false);
177 +const onCloseDetail = () => { // 关闭物资详情窗口
178 + show_material_detail.value = false;
179 +}
180 +
181 +const onCheckAll = (item) => { // 全选分类
182 + item.checked = !item.checked;
183 + item.m_list.forEach((m) => {
184 + m.checked = item.checked;
185 + });
186 +}
187 +const onCheck = (item, m) => { // 选中单个物资
188 + m.checked = !m.checked;
189 + item.checked = item.m_list.every(m => m.checked);
190 +}
191 +
192 +const addShoppingCart = () => { // 新增购物车
193 + shop_cart_list.value = [];
194 + list.value.forEach(item => {
195 + item.m_list.forEach(m => {
196 + if (m.checked) {
197 + shop_cart_list.value.push(m);
198 + }
199 + })
200 + });
201 + // 购物车为空提示
202 + if (!shop_cart_list.value.length) {
203 + showToast('请选择物资');
204 + return;
205 + }
206 + // TODO: 请求购物车接口,更新购物车数量
207 + console.warn(shop_cart_list.value);
208 +}
209 +
210 +const goShoppingCart = () => { // 点击购物车图标
211 + if ($route.path === '/material_pre_request') { // 待申领物资页面
212 + onClose()
213 + } else {
214 + $router.push({ path: '/material_pre_request' });
215 + }
216 +}
217 +
218 +const cart_count = ref(0); // 购物车数量
219 +
220 +const shop_cart_list = ref([]); // 购物车列表
151 </script> 221 </script>
152 222
153 <style lang="less"> 223 <style lang="less">
......