zhangwei
2025-08-28 06e4c8c1bad514992186d94a65c0dc6250e34716
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import tenderForm from "../uploadform.vue";
import { ref, h, reactive } from "vue";
import { addDialog, closeDialog } 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,
  updateTittle,
  changeDetail,
  cHangeDelete
} from "@/api/item/index";
 
const formRef = ref();
const convertFujianToObjects = (fujianStr, fujianNameStr) => {
  // 分割字符串为数组并过滤空值
  const srcArray = fujianStr.split(",").filter(Boolean);
  const nameArray = fujianNameStr.split(",").filter(Boolean);
 
  // 提取文件后缀作为valu
  const getFileExtension = fileName => {
    const lastDotIndex = fileName.lastIndexOf(".");
    // 如果没有后缀或文件名以点结尾,返回空字符串
    if (lastDotIndex === -1 || lastDotIndex === fileName.length - 1) {
      return "";
    }
    return fileName.slice(lastDotIndex + 1).toLowerCase();
  };
 
  // 映射为目标对象数组
  return srcArray.map((src, index) => {
    // 确保名称数组有对应索引的元素
    const name = nameArray[index]?.trim() || `未知文件${index + 1}`;
 
    return {
      name: name,
      filePath: src.trim(),
      fileType: getFileExtension(name)
    };
  });
};
export function useDetail() {
  async function getDetailList(id) {
    const res = await getTenderOrderDetail({ id });
    state.nowInfo = res.result;
    if (state.nowInfo.fujian) {
      state.nowInfo.fujianList = convertFujianToObjects(
        state.nowInfo.fujian,
        state.nowInfo.fujianName
      );
    }
  }
  async function openUploadDialog(title = "上传", row?: TenderInfo) {
    const detail = await changeDetail({ id: row.id });
    if (detail.result) {
      row = detail.result;
    }
    addDialog({
      title: `${title}公告`,
      props: {
        formInline: {
          tenderId: title == "上传变更" ? row?.id : "",
          id: row?.id ?? "",
          projectName: row?.projectName ?? "",
          toubiaoStartDate: row?.toubiaoStartDate ?? "", //投标报名开始时间
          toubiaoEndDate: row?.toubiaoEndDate ?? "", //投标报名结束时间
          kaibiaoDate: row?.kaibiaoDate ?? "", //开标时间
          fujian: row?.fujian ?? "", //附件
          fujianName: row?.fujianName ?? "", //附件
          kaibiaodidian: row?.kaibiaodidian ?? "", //开标地点
          biangengwenjian: row?.biangengwenjian ?? "",
          // 变更文件
          biangengwenjianName: row?.biangengwenjianName ?? ""
        }
      },
      width: "30%",
      draggable: true,
      fullscreen: deviceDetection(),
      fullscreenIcon: true,
      sureBtnLoading: true,
      closeOnClickModal: false,
      contentRenderer: () =>
        h(tenderForm, {
          ref: formRef,
          formInline: null,
          isChange: title == "上传" ? false : true
        }),
      footerButtons: detail.result
        ? [
            {
              label: "删除",
              type: "danger",
              text: true,
              bg: true,
              popconfirm: { title: "是否确认删除当前变更公告" },
              btnClick: ({ dialog: { options, index }, button }) => {
                console.log(options, index, button);
                cHangeDelete({ id: row?.id }).then(res => {
                  if (res.code == "200") {
                    getDetailList(row?.tenderId);
                    // getTenderOrderDetail({ id: row?.tenderId }).then(res => {
                    //   state.nowInfo = res.result;
                    // });
                    closeDialog(options, index); // 关闭弹框
                  } else {
                    // closeLoading();
                    message(res.message, {
                      type: "error"
                    });
                  }
                });
              }
            }
          ]
        : [],
      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") {
            getDetailList(row?.id);
            // getTenderOrderDetail({ id: row?.id }).then(res => {
            //   state.nowInfo = res.result;
            // });
            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;
          }
        });
      }
    });
  }
  function changeDialog(title = "上传", row?: TenderInfo) {
    addDialog({
      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,
          changeDetail: true,
          isChange: 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("");
          curData.id = state.nowInfo.id;
          const res = await updateTittle(curData);
          if (res.code == "200") {
            getTenderOrderDetail({ id: row?.id }).then(res => {
              state.nowInfo = res.result;
            });
            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: {},
    srcList: []
  });
  //生成时间戳+随机数
  // 生成时间戳+随机数的函数
  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,
    changeDialog,
    getDetailList
  };
}