zhangwei
2025-08-20 115769e9ad3ddc64e21ad7285450c4c563c745ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import tenderForm from "../uploadform.vue";
import { ref, h, reactive } from "vue";
import { addDialog } from "@/components/ReDialog";
import type { TenderInfo } from "./types";
import { message } from "@/utils/message";
import { cloneDeep, deviceDetection } from "@pureadmin/utils";
import type { FormItemProps } from "./types";
import { getToken } from "@/utils/auth";
import {
  fabuzhaobiao,
  changezhaobiao,
  getTenderOrderDetail
} from "@/api/item/index";
 
const formRef = ref();
 
export function useDetail() {
  function openUploadDialog(title = "上传", row?: TenderInfo) {
    addDialog({
      title: `${title}公告`,
      props: {
        formInline: {
          tenderId: title == "上传变更" ? row?.id : "",
          id: title == "上传" ? row?.id : "",
          projectName: row?.projectName ?? "",
          toubiaoStartDate: row?.toubiaoStartDate ?? "", //投标报名开始时间
          toubiaoEndDate: row?.toubiaoEndDate ?? "", //投标报名结束时间
          kaibiaoDate: row?.kaibiaoDate ?? "", //开标时间
          biangengwenjian: "", //招标文件
          fujian: row?.fujian ?? "", //附件
          kaibiaodidian: row?.kaibiaodidian ?? "" //开标地点
        }
      },
      width: "30%",
      draggable: true,
      fullscreen: deviceDetection(),
      fullscreenIcon: true,
      sureBtnLoading: true,
      closeOnClickModal: false,
      contentRenderer: () =>
        h(tenderForm, {
          ref: formRef,
          formInline: null,
          isChange: title == "上传" ? false : true
        }),
      beforeSure: (done, { options, closeLoading }) => {
        const FormRef = formRef.value.getRef();
        const curData = cloneDeep(options.props.formInline as TenderInfo);
        async function chores() {
          // message(`您${title}了项目名称为${curData.projectName}的这条数据`, {
          //   type: "success"
          // });
          // curData.dingbiaoguize = curData.dingbiaoguize.join("");
          let res;
          if (title == "上传") {
            curData.id = state.nowInfo.id;
            res = await fabuzhaobiao(curData);
          } else {
            res = await changezhaobiao(curData);
          }
          if (res.code == "200") {
            getTenderOrderDetail({ id: row?.id });
            done(); // 关闭弹框
          } else {
            closeLoading();
            message(res.message, {
              type: "error"
            });
          }
        }
        FormRef.validate((valid, obj) => {
          if (valid) {
            // 表单规则校验通过
            if (title === "新增") {
              // 实际开发先调用新增接口,再进行下面操作
              chores();
            } else {
              // 实际开发先调用修改接口,再进行下面操作
              chores();
            }
          } else {
            closeLoading();
            const fail = [];
            for (const key in obj) {
              fail.push(obj[key][0].message);
            }
            message(fail[0], {
              type: "warning"
            });
            return false;
          }
        });
      }
    });
  }
  const state = reactive({
    headers: {
      // Accept: "application/json, text/plain, */*",
      // "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
      // "X-Requested-With": "XMLHttpRequest",
      Authorization: `Bearer ${getToken()?.accessToken}`
    },
    nowInfo: Object as PropType<FormItemProps>,
    formDataNew: {}
  });
  //生成时间戳+随机数
  // 生成时间戳+随机数的函数
  function generateTimestampWithRandom(dirPath, filename) {
    // 获取当前日期和时间
    const now = new Date();
    // 获取年份,确保为四位数
    const year = now.getFullYear();
    // 获取月份,确保为两位数
    const month = String(now.getMonth() + 1).padStart(2, "0");
    // 获取日期,确保为两位数
    const day = String(now.getDate()).padStart(2, "0");
    // 获取小时,确保为两位数
    const hours = String(now.getHours()).padStart(2, "0");
    // 获取分钟,确保为两位数
    const minutes = String(now.getMinutes()).padStart(2, "0");
    // 获取秒数,确保为两位数
    const seconds = String(now.getSeconds()).padStart(2, "0");
    // 拼接时间戳
    const timestamp = `${year}${month}${day}${hours}${minutes}${seconds}`;
    // 生成一个 0 到 9999 之间的随机数,并格式化为四位数
    const randomNumber = String(Math.floor(Math.random() * 10000)).padStart(
      4,
      "0"
    );
    // 拼接时间戳和随机数
    return (
      `${dirPath}/${timestamp}_${randomNumber}` + filename.match(/\.[^.]+$/)
    );
  }
  return {
    openUploadDialog,
    state,
    generateTimestampWithRandom
  };
}