gaoluyang
3 天以前 e449a5408265e4bd1f6c66f5be28a42efac444ee
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<template>
  <view class="sales-account">
    <PageHeader title="项目管理"
                @back="goBack" />
 
    <view class="search-section">
      <view class="search-bar">
        <view class="search-input">
          <up-input class="search-text"
                    v-model="query.projectNameOrCode"
                    placeholder="请输入项目名称/编号"
                    clearable
                    @change="getList" />
        </view>
        <view class="filter-button"
              @click="showFilter = true">
          <up-icon name="list"
                   size="24"
                   color="#999"></up-icon>
        </view>
      </view>
    </view>
 
    <view v-if="projectList.length > 0"
          class="ledger-list">
      <view v-for="item in projectList"
            :key="item.id"
            class="ledger-item">
        <view class="item-header">
          <view class="item-left">
            <view class="document-icon">
              <up-icon name="grid"
                       size="16"
                       color="#ffffff"></up-icon>
            </view>
            <text class="item-id">{{ item.billNo || "-" }}</text>
          </view>
          <up-tag :text="dictLabel(auditOptions, item.auditStatus)"
                  :type="dictTagType(auditOptions, item.auditStatus)"
                  size="mini"
                  shape="circle" />
        </view>
        <up-divider></up-divider>
        <view class="item-details">
          <view class="detail-row">
            <text class="detail-label">项目名称</text>
            <text class="detail-value highlight">{{ item.projectName || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">客户名称</text>
            <text class="detail-value">{{ item.customerName || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">立项日期</text>
            <text class="detail-value">{{ item.setupDate || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">项目来源</text>
            <text class="detail-value">{{ item.projectSource || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">项目分类</text>
            <text class="detail-value">{{ item.projectClassification || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">计划状态</text>
            <text class="detail-value">{{ dictLabel(stageOptions, item.projectStage) || "-" }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">项目金额</text>
            <text class="detail-value">{{ formatAmount(item.projectAmount) }}</text>
          </view>
          <view class="detail-row">
            <text class="detail-label">销售合同总数</text>
            <text class="detail-value">{{ item.salesContractCount ?? 0 }}</text>
          </view>
        </view>
        <view class="action-buttons">
          <up-button class="action-btn"
                     size="small"
                     type="primary"
                     @click="goDetail(item)">详情</up-button>
          <up-button class="action-btn"
                     size="small"
                     @click="goEdit(item)">编辑</up-button>
          <up-button class="action-btn"
                     size="small"
                     @click="goProgress(item)">进度汇报</up-button>
          <up-button class="action-btn"
                     size="small"
                     @click="goArchive(item)">文档归档</up-button>
          <up-button v-if="canSubmit(item)"
                     class="action-btn"
                     size="small"
                     type="success"
                     @click="handleSubmitRow(item)">提交</up-button>
          <up-button v-if="canAudit(item)"
                     class="action-btn"
                     size="small"
                     type="warning"
                     @click="handleAuditRow(item)">审核</up-button>
          <up-button class="action-btn"
                     size="small"
                     type="error"
                     plain
                     @click="handleDelete(item)">删除</up-button>
        </view>
      </view>
    </view>
    <view v-else
          class="no-data">
      <text>暂无项目数据</text>
    </view>
 
    <view class="fab-button"
          @click="goAdd">
      <up-icon name="plus"
               size="28"
               color="#ffffff"></up-icon>
    </view>
 
    <FilterPanel v-model:show="showFilter"
                 :model-value="query"
                 title="项目筛选"
                 :fields="filterFields"
                 @search="onFilterSearch"
                 @reset="onFilterSearch" />
  </view>
</template>
 
<script setup>
  import { computed, reactive, ref } from "vue";
  import { onShow } from "@dcloudio/uni-app";
  import PageHeader from "@/components/PageHeader.vue";
  import FilterPanel from "@/components/FilterPanel.vue";
  import { useDict } from "@/utils/dict";
  import { unwrapList } from "@/utils/list";
  import {
    auditProject,
    delProject,
    listProject,
    submitProject,
  } from "@/api/projectManagement/project";
  import { toListRow } from "./_utils/mapper";
  import { dictLabel, dictTagType, toPickerOptions } from "./_utils/dict";
 
  const { bill_status, project_management, plan_status } = useDict(
    "bill_status",
    "project_management",
    "plan_status"
  );
 
  const billOptions = computed(() => toPickerOptions(bill_status.value));
  const auditOptions = computed(() => toPickerOptions(project_management.value));
  const stageOptions = computed(() => toPickerOptions(plan_status.value));
 
  const projectList = ref([]);
  const showFilter = ref(false);
 
  // 后端没有单据状态(billStatus)的查询参数,管理端也是拉回列表后本地过滤
  const query = reactive({
    projectNameOrCode: "",
    customerName: "",
    salesperson: "",
    billStatus: "",
    projectStage: "",
    auditStatus: "",
  });
 
  const filterFields = computed(() => [
    {
      prop: "projectNameOrCode",
      label: "项目名称/编号",
      type: "input",
      placeholder: "请输入项目名称/编号",
    },
    {
      prop: "customerName",
      label: "客户名称",
      type: "input",
      placeholder: "请输入客户名称",
    },
    {
      prop: "salesperson",
      label: "业务人员",
      type: "input",
      placeholder: "请输入业务人员",
    },
    {
      prop: "billStatus",
      label: "单据状态",
      type: "select",
      options: billOptions.value,
    },
    {
      prop: "projectStage",
      label: "计划状态",
      type: "select",
      options: stageOptions.value,
    },
    {
      prop: "auditStatus",
      label: "审核状态",
      type: "select",
      options: auditOptions.value,
    },
  ]);
 
  const goBack = () => uni.navigateBack();
 
  const goAdd = () => {
    uni.removeStorageSync("projectDetail");
    uni.navigateTo({ url: "/pages/projectManagement/project/edit" });
  };
 
  const goEdit = item => {
    uni.setStorageSync("projectDetail", item || {});
    uni.navigateTo({
      url: `/pages/projectManagement/project/edit?id=${item.id}`,
    });
  };
 
  const goDetail = item => {
    uni.setStorageSync("projectDetail", item || {});
    uni.navigateTo({
      url: `/pages/projectManagement/project/detail?id=${item.id}`,
    });
  };
 
  const goProgress = item => {
    uni.setStorageSync("projectDetail", item || {});
    uni.navigateTo({
      url: `/pages/projectManagement/project/progress?id=${item.id}`,
    });
  };
 
  const goArchive = item => {
    uni.navigateTo({
      url: `/pages/projectManagement/project/archive?id=${item.id}&name=${encodeURIComponent(item.projectName || "")}`,
    });
  };
 
  const formatAmount = amount =>
    amount === null || amount === undefined || amount === ""
      ? "-"
      : `¥${Number(amount).toFixed(2)}`;
 
  // 提交 / 审核是线性流程:新建(无状态) → 提交(reviewStatus 0) → 审核(reviewStatus 1)。
  // 管理端另有反审核,手机端按约定不做。
  const canSubmit = item => String(item?.auditStatus ?? "") === "";
  const canAudit = item => String(item?.auditStatus) === "0";
 
  const getList = () => {
    listProject({
      noOrName: query.projectNameOrCode || undefined,
      clientName: query.customerName || undefined,
      salesmanName: query.salesperson || undefined,
      reviewStatus: query.auditStatus || undefined,
      stage: query.projectStage || undefined,
      current: -1,
      size: -1,
    })
      .then(res => {
        const rows = unwrapList(res).map(toListRow);
        projectList.value = query.billStatus
          ? rows.filter(
              item => String(item.billStatus) === String(query.billStatus)
            )
          : rows;
      })
      .catch(() => {
        uni.showToast({ title: "查询失败", icon: "none" });
      });
  };
 
  // FilterPanel 只回吐筛选值,写回 query 后统一查询
  const onFilterSearch = values => {
    Object.assign(query, values);
    getList();
  };
 
  const confirmStatusAction = (item, label, content, action) => {
    uni.showModal({
      title: `${label}确认`,
      content,
      success: res => {
        if (!res.confirm) return;
        uni.showLoading({ title: "处理中...", mask: true });
        action({ id: item.id })
          .then(() => {
            uni.showToast({ title: `${label}成功`, icon: "success" });
            getList();
          })
          .catch(() => {
            uni.showToast({ title: `${label}失败`, icon: "none" });
          })
          .finally(() => {
            uni.hideLoading();
          });
      },
    });
  };
 
  const handleSubmitRow = item => {
    if (!item?.id) return;
    confirmStatusAction(item, "提交", "确认提交该项目吗?", submitProject);
  };
 
  const handleAuditRow = item => {
    if (!item?.id) return;
    confirmStatusAction(item, "审核", "确认审核通过该项目吗?", auditProject);
  };
 
  const handleDelete = item => {
    if (!item?.id) return;
    uni.showModal({
      title: "删除确认",
      content: `确认删除项目「${item.projectName || ""}」吗?`,
      success: res => {
        if (!res.confirm) return;
        uni.showLoading({ title: "处理中...", mask: true });
        delProject([item.id])
          .then(() => {
            uni.showToast({ title: "删除成功", icon: "success" });
            getList();
          })
          .catch(() => {
            uni.showToast({ title: "删除失败", icon: "none" });
          })
          .finally(() => {
            uni.hideLoading();
          });
      },
    });
  };
 
  onShow(() => {
    getList();
  });
</script>
 
<style scoped lang="scss">
  @import "@/styles/sales-common.scss";
 
  .detail-value {
    max-width: 70%;
    word-break: break-all;
  }
 
  .action-buttons {
    flex-wrap: wrap;
  }
 
  .action-btn {
    flex: 0 0 calc(33.33% - 8px);
  }
</style>