|
|
@@ -0,0 +1,143 @@
|
|
|
+<template>
|
|
|
+ <z-paging ref="paging" v-model="list" @onRefresh="onRefresh" bgColor="#fff" @query="query" :auto="false" safe-area-inset-bottom>
|
|
|
+ <up-navbar :title="title" @leftClick="navigateBackOrHome()" :fixed="false"></up-navbar>
|
|
|
+ <up-sticky offset-top="10" class="pd-20">
|
|
|
+ <ut-search ref="searchRef" v-model="form.keywords" @search="changeSeach" @change="changeSeach" margin="0" :border="false" :placeholder="placeholder" bgColor="#f7f7f7" height="86rpx" borderRadius="16rpx"></ut-search>
|
|
|
+ </up-sticky>
|
|
|
+ <template v-if="list.length == 0 && !form.keywords.trim()">
|
|
|
+ <view class="pd-20">
|
|
|
+ <view class="f-s-32 c-333 f-w-5 mb-20">已配置的主营品种</view>
|
|
|
+ <!-- speLable 组件使用示例 -->
|
|
|
+ <view class="d-flex a-c f-w-wrap">
|
|
|
+ <spe-lable class="mr-20 mb-20" v-for="(item, index) in speArray" :key="index" :text="item?.name" size="30rpx" :id="item?.id" @close="() => handleLabelClose(item?.id)" />
|
|
|
+ </view>
|
|
|
+ <ut-empty class="mg-at" v-if="speArray.length == 0">
|
|
|
+ <view class="d-flex a-c j-c f-s-28 c-ccc">暂未配置单位主营品种 </view>
|
|
|
+ <view class="d-flex a-c j-c f-s-28 c-ccc">点击上方搜索框搜索后添加~</view>
|
|
|
+ </ut-empty>
|
|
|
+ </view>
|
|
|
+ </template>
|
|
|
+ <template v-for="(item, index) in list" :key="index">
|
|
|
+ <spe-list :text="item?.name" :searchText="form.keywords" :check="item?.check" @update:check="(value) => handleCheckChange(value, item.id)"> </spe-list>
|
|
|
+ </template>
|
|
|
+ <template #empty>
|
|
|
+ <ut-empty class="mg-at">
|
|
|
+ <view class="d-flex a-c j-c f-s-28 c-ccc">暂未搜索到该品种</view>
|
|
|
+ </ut-empty>
|
|
|
+ </template>
|
|
|
+ <template #bottom v-if="form.keywords.trim()">
|
|
|
+ <view class="base-bottom-wrap pd-20 pb-0">
|
|
|
+ <up-button type="primary" @click="subMit">确认</up-button>
|
|
|
+ </view>
|
|
|
+ </template>
|
|
|
+ </z-paging>
|
|
|
+ <ut-confirm-dialog v-model:show="showDeleteDialog" title="删除确认" :confirmText="'删除'" :cancelText="'取消'" @confirm="handleDeleteConfirm" @cancel="handleDeleteCancel">
|
|
|
+ <text>确定要删除这个品种吗?删除后不可恢复。</text>
|
|
|
+ </ut-confirm-dialog>
|
|
|
+</template>
|
|
|
+<script setup lang="ts">
|
|
|
+import speLable from '../models/speLable.vue';
|
|
|
+import SpeList from '../models/speList.vue';
|
|
|
+interface ListItem {
|
|
|
+ id: number;
|
|
|
+ name: string;
|
|
|
+ check: boolean;
|
|
|
+}
|
|
|
+//定义speArray
|
|
|
+interface speArray {
|
|
|
+ id: number;
|
|
|
+ name: string;
|
|
|
+}
|
|
|
+const list = ref<ListItem[]>([]);
|
|
|
+const paging = ref();
|
|
|
+const title = ref('配置单位主营品种');
|
|
|
+const placeholder = ref('请搜索药材品种名称选择添加');
|
|
|
+const form = ref({
|
|
|
+ keywords: '',
|
|
|
+});
|
|
|
+const speArray = ref<speArray[]>([]);
|
|
|
+// 删除确认相关状态
|
|
|
+const showDeleteDialog = ref(false);
|
|
|
+const currentDeleteId = ref<number | null>(null);
|
|
|
+
|
|
|
+setTimeout(() => {
|
|
|
+ speArray.value = [
|
|
|
+ { id: 1, name: '三七' },
|
|
|
+ { id: 2, name: '天麻' },
|
|
|
+ { id: 3, name: '白及' },
|
|
|
+ ];
|
|
|
+}, 200);
|
|
|
+// 处理标签关闭事件
|
|
|
+const handleLabelClose = (id: string | number) => {
|
|
|
+ currentDeleteId.value = id as number;
|
|
|
+ showDeleteDialog.value = true;
|
|
|
+};
|
|
|
+const handleCheckChange = (newCheckValue: boolean, id: number) => {
|
|
|
+ // 根据ID找到对应的列表项并更新
|
|
|
+ const item = list.value.find((item) => item.id === id);
|
|
|
+ if (item) {
|
|
|
+ item.check = newCheckValue;
|
|
|
+ }
|
|
|
+};
|
|
|
+const query = async (pageNum: number, pageSize: number) => {
|
|
|
+ const params = {
|
|
|
+ pageNum,
|
|
|
+ pageSize,
|
|
|
+ ...form.value,
|
|
|
+ };
|
|
|
+ if (!params.keywords?.trim()) {
|
|
|
+ // 处理空、null、undefined、纯空格的情况
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // const res = await cpyList(params);
|
|
|
+ let res: ListItem[] = [];
|
|
|
+ //循环push10条数据
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ res.push({
|
|
|
+ id: i + 1,
|
|
|
+ name: `${params.keywords}${i + 1}${params.keywords}`,
|
|
|
+ check: false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // const { rows } = res;
|
|
|
+ paging.value.complete(res);
|
|
|
+};
|
|
|
+const changeSeach = () => {
|
|
|
+ paging.value.reload();
|
|
|
+ console.log(form.value?.keywords, 'keywords');
|
|
|
+};
|
|
|
+const onRefresh = () => {
|
|
|
+ paging.value.reload();
|
|
|
+};
|
|
|
+const subMit = () => {
|
|
|
+ list.value.forEach((item) => {
|
|
|
+ if (item.check) {
|
|
|
+ console.log(item, 'item');
|
|
|
+ //判断item.id是否不在speArray中
|
|
|
+ if (!speArray.value.find((speItem) => speItem.id === item.id)) {
|
|
|
+ speArray.value.push({
|
|
|
+ id: item.id,
|
|
|
+ name: item.name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ form.value.keywords = '';
|
|
|
+ onRefresh();
|
|
|
+};
|
|
|
+
|
|
|
+// 处理删除确认
|
|
|
+const handleDeleteConfirm = () => {
|
|
|
+ if (currentDeleteId.value !== null) {
|
|
|
+ speArray.value = speArray.value.filter((item) => item.id !== currentDeleteId.value);
|
|
|
+ }
|
|
|
+ showDeleteDialog.value = false;
|
|
|
+ currentDeleteId.value = null;
|
|
|
+};
|
|
|
+
|
|
|
+// 处理删除取消
|
|
|
+const handleDeleteCancel = () => {
|
|
|
+ showDeleteDialog.value = false;
|
|
|
+ currentDeleteId.value = null;
|
|
|
+};
|
|
|
+</script>
|