|
@@ -0,0 +1,184 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import { ref, watchEffect, unref } from "vue";
|
|
|
+import { ElForm, ElMessage } from "element-plus";
|
|
|
+import { projectFormConfig } from "../config/_details";
|
|
|
+import { projectFormRules } from "../config/_rules";
|
|
|
+import { httpDetail } from "/@/api/parameter/good";
|
|
|
+import { BasicForm } from "/@/components/BasicForm";
|
|
|
+import LadderModal from "./ladder-modal.vue";
|
|
|
+import LadderTable from "./ladder-table.vue";
|
|
|
+import { ImageUpload } from "/@/components/Upload";
|
|
|
+import { ImageUploadList } from "/@/components/UploadList";
|
|
|
+// import SearchTerrace from "/@/components/SearchTerrace";
|
|
|
+import { Unit } from "/@/components/RemoteSelect";
|
|
|
+import { transform, createDefaultData } from "/@/components/BasicForm";
|
|
|
+import { Customer } from "/@/components/RemoteSelect";
|
|
|
+// import { AmountInput } from "/@/components/Input";
|
|
|
+import { useResponseHandle } from "/@/hooks/useAsync";
|
|
|
+
|
|
|
+const config = {
|
|
|
+ name: "project_name",
|
|
|
+ platform: "platform_name"
|
|
|
+};
|
|
|
+
|
|
|
+const emit = defineEmits(["create"]);
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ data: Record<string, string>;
|
|
|
+ readonly: boolean;
|
|
|
+ id?: string;
|
|
|
+}>();
|
|
|
+
|
|
|
+const loading = ref(false);
|
|
|
+const { formItems } = projectFormConfig;
|
|
|
+
|
|
|
+const responseHandle = useResponseHandle();
|
|
|
+const basicFormRef = ref<InstanceType<typeof ElForm>>(null);
|
|
|
+const formData = ref<Record<string, any>>(createDefaultData(formItems));
|
|
|
+const ladderModalRef = ref<InstanceType<typeof LadderModal>>(null);
|
|
|
+
|
|
|
+function requesetCategoryById(id: string) {
|
|
|
+ const transform = ({ cat_name, ...rest }: any) => ({
|
|
|
+ ...rest,
|
|
|
+ name: cat_name
|
|
|
+ });
|
|
|
+ return new Promise(resolve => {
|
|
|
+ httpDetail({ id }).then(({ code, message, data }) => {
|
|
|
+ responseHandle({
|
|
|
+ code,
|
|
|
+ message,
|
|
|
+ handler: () => resolve(transform(data))
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+async function ladderTransform(ladder) {
|
|
|
+ loading.value = true;
|
|
|
+ const { ladder: _ladder } = formData.value;
|
|
|
+ const tasks = ladder.cat_info.map(async id => await requesetCategoryById(id));
|
|
|
+ ladder.cat_info = await Promise.all(tasks);
|
|
|
+ loading.value = false;
|
|
|
+ return ladder;
|
|
|
+}
|
|
|
+
|
|
|
+async function handlePush(_ladder) {
|
|
|
+ const ladder = await ladderTransform(_ladder);
|
|
|
+ if (!Array.isArray(formData.value.ladder)) {
|
|
|
+ formData.value.ladder = [];
|
|
|
+ }
|
|
|
+ formData.value.ladder.push(ladder);
|
|
|
+}
|
|
|
+
|
|
|
+async function handleUpdate(_ladder, index) {
|
|
|
+ const ladder = await ladderTransform(_ladder);
|
|
|
+ formData.value.ladder[index] = ladder;
|
|
|
+}
|
|
|
+
|
|
|
+function disabledDate(date) {
|
|
|
+ return date.getTime() < new Date().getTime() - 86400000;
|
|
|
+}
|
|
|
+
|
|
|
+function handleDateChange(prop: string) {
|
|
|
+ const { arrtime, endtime } = formData.value;
|
|
|
+ const start = new Date(arrtime).valueOf();
|
|
|
+ const end = new Date(endtime).valueOf();
|
|
|
+ if (start > end) {
|
|
|
+ formData.value[prop] = "";
|
|
|
+ ElMessage.warning(`竞价截止时间不能大于要求到货时间!`);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function handleCreate() {
|
|
|
+ basicFormRef.value.validate(isValid => {
|
|
|
+ if (!isValid) return;
|
|
|
+ console.log("9897979");
|
|
|
+ // const { ladder, ...rest } = unref(formData);
|
|
|
+ // const transform = ladder => {
|
|
|
+ // return {
|
|
|
+ // ...(ladder.good_img ? { good_img: ladder.good_img } : {}),
|
|
|
+ // ...{
|
|
|
+ // budget_price: ladder.budget_price,
|
|
|
+ // good_name: ladder.good_name,
|
|
|
+ // good_type: ladder.good_type,
|
|
|
+ // num: ladder.num
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+ // };
|
|
|
+
|
|
|
+ // const params = {
|
|
|
+ // ...rest,
|
|
|
+ // ladder: ladder.map(transform)
|
|
|
+ // };
|
|
|
+
|
|
|
+ // emit("create", params);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+watchEffect(() => {
|
|
|
+ const { readonly, data } = props;
|
|
|
+ if (readonly && !data) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ formData.value = transform(formItems, data, config);
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <ElScrollbar>
|
|
|
+ <BasicForm
|
|
|
+ ref="basicFormRef"
|
|
|
+ v-bind="projectFormConfig"
|
|
|
+ :form-data="formData"
|
|
|
+ :rules="projectFormRules"
|
|
|
+ :disabled="readonly"
|
|
|
+ label-width="120px"
|
|
|
+ >
|
|
|
+ <template #unit_id>
|
|
|
+ <Unit v-model="formData.unit_id" placeholder="单位" />
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template #good_cover_img>
|
|
|
+ <ImageUpload v-model:url="formData.good_cover_img" />
|
|
|
+ </template>
|
|
|
+ <template #good_banner_img>
|
|
|
+ <ImageUploadList
|
|
|
+ v-model:urls="formData.good_banner_img"
|
|
|
+ :descs="['小于1Mb']"
|
|
|
+ :types="['png', 'jpg', 'jpeg']"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template #good_img>
|
|
|
+ <ImageUploadList
|
|
|
+ v-model:urls="formData.good_img"
|
|
|
+ :descs="['小于1Mb']"
|
|
|
+ :types="['png', 'jpg', 'jpeg']"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template #good_param>
|
|
|
+ 111 先展示
|
|
|
+ <!-- <LadderTable
|
|
|
+ :readonly="readonly"
|
|
|
+ :ladder="formData.good_param"
|
|
|
+ @choose="() => ladderModalRef.onDisplay()"
|
|
|
+ @update="({ data, index }) => ladderModalRef.onDisplay(data, index)"
|
|
|
+ @delete="index => formData.ladder.splice(index, 1)"
|
|
|
+ /> -->
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template #footer>
|
|
|
+ <div class="w-full flex justify-end" v-if="!readonly">
|
|
|
+ <ElButton type="primary" @click="handleCreate">保存</ElButton>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </BasicForm>
|
|
|
+
|
|
|
+ <!-- <LadderModal
|
|
|
+ ref="ladderModalRef"
|
|
|
+ @update="handleUpdate"
|
|
|
+ @push="handlePush"
|
|
|
+ /> -->
|
|
|
+ </ElScrollbar>
|
|
|
+</template>
|