|
|
@@ -39,128 +39,129 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed, ref } from 'vue';
|
|
|
-import { Plus } from '@element-plus/icons-vue';
|
|
|
-import GoodsSelectDialog from '../../components/GoodsSelectDialog.vue';
|
|
|
-import request from '@/utils/request';
|
|
|
-import { EleMessage } from 'ele-admin-plus/es';
|
|
|
-
|
|
|
-const props = defineProps({
|
|
|
- modelValue: {
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
- },
|
|
|
- position: {
|
|
|
- type: String,
|
|
|
- default: 'right_banner'
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-const emit = defineEmits(['update:modelValue', 'success']);
|
|
|
-
|
|
|
-const visible = computed({
|
|
|
- get: () => props.modelValue,
|
|
|
- set: (val) => emit('update:modelValue', val)
|
|
|
-});
|
|
|
-
|
|
|
-const selectVisible = ref(false);
|
|
|
-const activeIndex = ref(0);
|
|
|
-const loading = ref(false);
|
|
|
-const goodsSelectRef = ref(null);
|
|
|
-
|
|
|
-// Fixed 2 items
|
|
|
-const items = ref([
|
|
|
- { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' },
|
|
|
- { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' }
|
|
|
-]);
|
|
|
-
|
|
|
-const handleOpen = async () => {
|
|
|
- // Reset selection in dialog if needed
|
|
|
- if (goodsSelectRef.value?.reset) {
|
|
|
- goodsSelectRef.value.reset();
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- const res = await request.get('/book/showIndex/getInfoByPosition', {
|
|
|
- params: { position: props.position }
|
|
|
- });
|
|
|
- const list = res.data?.data || [];
|
|
|
-
|
|
|
- if (list.length > 0) {
|
|
|
- items.value = Array(2).fill(null).map((_, i) => {
|
|
|
- const remote = list[i] || {};
|
|
|
- return {
|
|
|
- id: remote.showCateId || '', // Using showCateId to store product ID
|
|
|
- title: remote.title || '',
|
|
|
- imgUrl: remote.imgUrl || '',
|
|
|
- jumpUrl: remote.jumpUrl || '',
|
|
|
- price: '' // Backend doesn't return price, leave empty
|
|
|
- };
|
|
|
+ import { computed, ref } from 'vue';
|
|
|
+ import { Plus } from '@element-plus/icons-vue';
|
|
|
+ import GoodsSelectDialog from '../../components/GoodsSelectDialog.vue';
|
|
|
+ import request from '@/utils/request';
|
|
|
+ import { EleMessage } from 'ele-admin-plus/es';
|
|
|
+
|
|
|
+ const props = defineProps({
|
|
|
+ modelValue: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ position: {
|
|
|
+ type: String,
|
|
|
+ default: 'right_banner'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const emit = defineEmits(['update:modelValue', 'success']);
|
|
|
+
|
|
|
+ const visible = computed({
|
|
|
+ get: () => props.modelValue,
|
|
|
+ set: (val) => emit('update:modelValue', val)
|
|
|
+ });
|
|
|
+
|
|
|
+ const selectVisible = ref(false);
|
|
|
+ const activeIndex = ref(0);
|
|
|
+ const loading = ref(false);
|
|
|
+ const goodsSelectRef = ref(null);
|
|
|
+
|
|
|
+ // Fixed 2 items
|
|
|
+ const items = ref([
|
|
|
+ { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' },
|
|
|
+ { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' }
|
|
|
+ ]);
|
|
|
+
|
|
|
+ const handleOpen = async () => {
|
|
|
+ // Reset selection in dialog if needed
|
|
|
+ if (goodsSelectRef.value?.reset) {
|
|
|
+ goodsSelectRef.value.reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await request.get('/book/showIndex/getInfoByPosition', {
|
|
|
+ params: { position: props.position }
|
|
|
});
|
|
|
- } else {
|
|
|
- items.value = [
|
|
|
- { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' },
|
|
|
- { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' }
|
|
|
- ];
|
|
|
+ const list = res.data?.data || [];
|
|
|
+
|
|
|
+ if (list.length > 0) {
|
|
|
+ items.value = Array(2).fill(null).map((_, i) => {
|
|
|
+ const remote = list[i] || {};
|
|
|
+ return {
|
|
|
+ id: remote.showCateId || '', // Using showCateId to store product ID
|
|
|
+ title: remote.title || '',
|
|
|
+ imgUrl: remote.imgUrl || '',
|
|
|
+ jumpUrl: remote.jumpUrl || '',
|
|
|
+ price: '' // Backend doesn't return price, leave empty
|
|
|
+ };
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ items.value = [
|
|
|
+ { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' },
|
|
|
+ { id: '', title: '', imgUrl: '', price: '', jumpUrl: '' }
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- console.error(e);
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-const handleOpenSelect = (index) => {
|
|
|
- activeIndex.value = index;
|
|
|
- selectVisible.value = true;
|
|
|
-};
|
|
|
-
|
|
|
-const handleSelectConfirm = (selected) => {
|
|
|
- if (selected && selected.length > 0) {
|
|
|
- // Only take the first selected item for the active slot
|
|
|
- const product = selected[0];
|
|
|
- items.value[activeIndex.value] = {
|
|
|
- id: product.id, // Assuming product object has id
|
|
|
- title: product.bookName, // GoodsSelectDialog returns bookName
|
|
|
- imgUrl: product.cover, // GoodsSelectDialog returns cover
|
|
|
- price: product.price,
|
|
|
- jumpUrl: `/pages-sell/pages/product-detail?id=${product.id}` // Construct jumpUrl
|
|
|
- };
|
|
|
- }
|
|
|
- selectVisible.value = false;
|
|
|
-};
|
|
|
-
|
|
|
-const handleConfirm = async () => {
|
|
|
- loading.value = true;
|
|
|
- try {
|
|
|
- const showIndexInfoList = items.value
|
|
|
- .filter(item => item.imgUrl)
|
|
|
- .map((item, index) => ({
|
|
|
- imgUrl: item.imgUrl,
|
|
|
- jumpUrl: item.jumpUrl,
|
|
|
- title: item.title,
|
|
|
- showCateId: item.id || 0, // Store product ID
|
|
|
- orderNum: index
|
|
|
- }));
|
|
|
-
|
|
|
- await request.post('/book/showIndex/updateIndex', {
|
|
|
- position: props.position,
|
|
|
- showIndexInfoList
|
|
|
- });
|
|
|
-
|
|
|
- EleMessage.success('保存成功');
|
|
|
- visible.value = false;
|
|
|
- emit('success');
|
|
|
- } catch (e) {
|
|
|
- console.error(e);
|
|
|
- EleMessage.error(e.message || '保存失败');
|
|
|
- } finally {
|
|
|
- loading.value = false;
|
|
|
- }
|
|
|
-};
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOpenSelect = (index) => {
|
|
|
+ activeIndex.value = index;
|
|
|
+ selectVisible.value = true;
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleSelectConfirm = (selected) => {
|
|
|
+ if (selected && selected.length > 0) {
|
|
|
+ // Only take the first selected item for the active slot
|
|
|
+ const product = selected[0];
|
|
|
+ console.log(product,'xxxx');
|
|
|
+ items.value[activeIndex.value] = {
|
|
|
+ id: product.id, // Assuming product object has id
|
|
|
+ title: product.bookName, // GoodsSelectDialog returns bookName
|
|
|
+ imgUrl: product.cover, // GoodsSelectDialog returns cover
|
|
|
+ price: product.price,
|
|
|
+ jumpUrl: `/pages-sell/pages/detail?isbn=${product.isbn}` // Construct jumpUrl
|
|
|
+ };
|
|
|
+ }
|
|
|
+ selectVisible.value = false;
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleConfirm = async () => {
|
|
|
+ loading.value = true;
|
|
|
+ try {
|
|
|
+ const showIndexInfoList = items.value
|
|
|
+ .filter(item => item.imgUrl)
|
|
|
+ .map((item, index) => ({
|
|
|
+ imgUrl: item.imgUrl,
|
|
|
+ jumpUrl: item.jumpUrl,
|
|
|
+ title: item.title,
|
|
|
+ showCateId: item.id || 0, // Store product ID
|
|
|
+ orderNum: index
|
|
|
+ }));
|
|
|
+
|
|
|
+ await request.post('/book/showIndex/updateIndex', {
|
|
|
+ position: props.position,
|
|
|
+ showIndexInfoList
|
|
|
+ });
|
|
|
+
|
|
|
+ EleMessage.success('保存成功');
|
|
|
+ visible.value = false;
|
|
|
+ emit('success');
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ EleMessage.error(e.message || '保存失败');
|
|
|
+ } finally {
|
|
|
+ loading.value = false;
|
|
|
+ }
|
|
|
+ };
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-.hot-sales-edit {
|
|
|
- max-height: 60vh;
|
|
|
- overflow-y: auto;
|
|
|
-}
|
|
|
+ .hot-sales-edit {
|
|
|
+ max-height: 60vh;
|
|
|
+ overflow-y: auto;
|
|
|
+ }
|
|
|
</style>
|