|
@@ -3,9 +3,14 @@ import { defineComponent, reactive, ref } from "vue";
|
|
|
import ToolBar from "@/components/tool-bar/index.vue";
|
|
|
|
|
|
import usePagination from "@/hooks/usePagination";
|
|
|
-import { getDeliveryBookList } from "@/api";
|
|
|
+import useFormLayout from "@/hooks/useFormLayout";
|
|
|
+import useDebounceFn from "@/hooks/useDebounceFn";
|
|
|
+
|
|
|
+import { getDeliveryBookList, getBooksByName } from "@/api";
|
|
|
import { TableColumnOfPutBooks } from "../_pageOptions/table-put";
|
|
|
-import { IDeliveryBook } from "@/types/api";
|
|
|
+import { IBookSearchResult, IDeliveryBook } from "@/types/api";
|
|
|
+
|
|
|
+// TODO 结构待优化
|
|
|
|
|
|
const PutBooks = defineComponent({
|
|
|
components: {
|
|
@@ -14,6 +19,8 @@ const PutBooks = defineComponent({
|
|
|
setup() {
|
|
|
let { loading, meta, tablePageOptions } = usePagination();
|
|
|
|
|
|
+ const { labelCol, wrapperCol } = useFormLayout();
|
|
|
+
|
|
|
const state = reactive({
|
|
|
inSearching: false,
|
|
|
open: false,
|
|
@@ -21,6 +28,13 @@ const PutBooks = defineComponent({
|
|
|
columns: TableColumnOfPutBooks,
|
|
|
});
|
|
|
|
|
|
+ const addFormState = reactive({
|
|
|
+ official_id: 0,
|
|
|
+ book: ref<Partial<IBookSearchResult>>({}),
|
|
|
+ platforms: 0,
|
|
|
+ books: ref<IBookSearchResult[]>([]),
|
|
|
+ });
|
|
|
+
|
|
|
const onSearch = async (fields: Record<string, string>) => {
|
|
|
try {
|
|
|
const { official_name, book_name } = fields;
|
|
@@ -38,11 +52,70 @@ const PutBooks = defineComponent({
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 弹窗
|
|
|
- const onOpenModal = () => {
|
|
|
+ // 添加书籍弹窗
|
|
|
+ const renderAddForm = () => {
|
|
|
+ const onBookSearch = useDebounceFn(async (keywords: string) => {
|
|
|
+ if (!keywords) return;
|
|
|
+ const { data } = await getBooksByName(keywords);
|
|
|
+ addFormState.books.push(...data.list);
|
|
|
+ }, 500);
|
|
|
+
|
|
|
+ const onBookCheck = (value: any, options: any) => {
|
|
|
+ addFormState.book = options.key;
|
|
|
+ };
|
|
|
+
|
|
|
+ const ok = () => {
|
|
|
+ console.log("ok");
|
|
|
+ };
|
|
|
+
|
|
|
+ const renderSearchBooksList = () => {
|
|
|
+ return addFormState.books.map((book) => (
|
|
|
+ <a-select-option value={book.bid} key={book}>
|
|
|
+ {book.name}
|
|
|
+ </a-select-option>
|
|
|
+ ));
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
- <a-modal v-model={[state.open, "visible"]}>
|
|
|
- <p>123</p>
|
|
|
+ <a-modal
|
|
|
+ title="投放书籍添加"
|
|
|
+ width="400px"
|
|
|
+ v-model={[state.open, "visible"]}
|
|
|
+ onOk={ok}
|
|
|
+ >
|
|
|
+ <a-form
|
|
|
+ model={addFormState}
|
|
|
+ labelCol={labelCol}
|
|
|
+ wrapperCol={wrapperCol}
|
|
|
+ >
|
|
|
+ <a-form-item label="公众号名称">
|
|
|
+ <a-select v-model={[addFormState.official_id, "value"]}>
|
|
|
+ <a-select-option value="1">1</a-select-option>
|
|
|
+ <a-select-option value="2">2</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="书籍">
|
|
|
+ <a-select
|
|
|
+ show-search
|
|
|
+ placeholder="请输入要搜索的书名"
|
|
|
+ default-active-first-option={false}
|
|
|
+ filter-option={false}
|
|
|
+ show-arrow={false}
|
|
|
+ not-found-content="暂无数据"
|
|
|
+ value={addFormState.book.bid}
|
|
|
+ onSearch={onBookSearch}
|
|
|
+ onChange={onBookCheck}
|
|
|
+ >
|
|
|
+ {renderSearchBooksList()}
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="流量平台">
|
|
|
+ <a-select v-model={[addFormState.platforms, "value"]}>
|
|
|
+ <a-select-option value="1">1</a-select-option>
|
|
|
+ <a-select-option value="2">2</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
</a-modal>
|
|
|
);
|
|
|
};
|
|
@@ -55,6 +128,11 @@ const PutBooks = defineComponent({
|
|
|
v-model={[state.inSearching, "loading"]}
|
|
|
onConfirm={onSearch}
|
|
|
/>
|
|
|
+ <div class="operator-bar">
|
|
|
+ <a-button type="primary" onClick={() => (state.open = true)}>
|
|
|
+ 添加
|
|
|
+ </a-button>
|
|
|
+ </div>
|
|
|
<a-table
|
|
|
row-key="id"
|
|
|
pagination={tablePageOptions}
|
|
@@ -62,6 +140,7 @@ const PutBooks = defineComponent({
|
|
|
columns={state.columns}
|
|
|
data-source={state.list}
|
|
|
></a-table>
|
|
|
+ {renderAddForm()}
|
|
|
</div>
|
|
|
);
|
|
|
},
|