gaoluyang
5 天以前 6c497f71f5441633099fc7a7896da8e8c7835f05
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
<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"
                        placeholder="请输入客户名称搜索"
                        v-model="customerName"
                        @change="getList"
                        clearable
                    />
                </view>
                <view class="filter-button" @click="getList">
                    <up-icon name="search" size="24" color="#999"></up-icon>
                </view>
            </view>
        </view>
        
        <!-- 商机列表 -->
        <view class="ledger-list" v-if="opportunityList.length > 0">
            <view v-for="(item, index) in opportunityList" :key="item.id || index">
                <view class="ledger-item" @click="openOpportunity('detail', item)">
                    <view class="item-header">
                        <view class="item-left">
                            <view class="document-icon">
                                <up-icon name="file-text" size="16" color="#ffffff"></up-icon>
                            </view>
                            <text class="item-id">{{ item.customerName || '-' }}</text>
                        </view>
                        <view class="item-right">
                            <u-tag
                                size="mini"
                                :type="getStatusTagType(item.status)"
                            >
                                {{ getStatusText(item.status) }}
                            </u-tag>
                        </view>
                    </view>
                    <up-divider></up-divider>
                    
                    <view class="item-details">
                        <view class="detail-row">
                            <text class="detail-label">城市</text>
                            <text class="detail-value">{{ item.city || '-' }}</text>
                        </view>
                        <view class="detail-row">
                            <text class="detail-label">商机来源</text>
                            <text class="detail-value">{{ item.businessSource || '-' }}</text>
                        </view>
                        <view class="detail-row">
                            <text class="detail-label">合同金额(元)</text>
                            <text class="detail-value highlight">{{ item.contractAmount || '-' }}</text>
                        </view>
                        <view class="detail-row">
                            <text class="detail-label">录入人</text>
                            <text class="detail-value">{{ item.entryPerson || '-' }}</text>
                        </view>
                        <view class="detail-row">
                            <text class="detail-label">更新时间</text>
                            <text class="detail-value">
                                {{ formatDate(item.updateTime || item.entryDate) || '-' }}
                            </text>
                        </view>
                    </view>
                    
                    <!-- 操作按钮 -->
                    <view class="action-buttons">
                        <u-button
                            type="primary"
                            size="small"
                            class="action-btn"
                            @click.stop="openOpportunity('edit', item)"
                        >
                            编辑
                        </u-button>
                        <u-button
                            type="warning"
                            size="small"
                            class="action-btn"
                            @click.stop="openOpportunity('addOperation', item)"
                        >
                            添加拜访记录
                        </u-button>
                        <u-button
                            type="default"
                            size="small"
                            class="action-btn"
                            @click.stop="openOpportunity('detail', item)"
                        >
                            详情
                        </u-button>
                    </view>
                </view>
            </view>
        </view>
        <view v-else class="no-data">
            <text>暂无商机数据</text>
        </view>
        
        <!-- 浮动新增按钮 -->
        <view class="fab-button" @click="addOpportunity">
            <up-icon name="plus" size="24" color="#ffffff"></up-icon>
        </view>
    </view>
</template>
 
<script setup>
import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import dayjs from 'dayjs'
import PageHeader from '@/components/PageHeader.vue'
import { opportunityListPage } from '@/api/salesManagement/opportunityManagement.js'
 
// 搜索条件
const customerName = ref('')
 
// 列表数据
const opportunityList = ref([])
const total = ref(0)
 
// 返回
const goBack = () => {
    uni.navigateBack()
}
 
// 加载中提示
const showLoadingToast = (message) => {
    uni.showLoading({
        title: message,
        mask: true
    })
}
 
const closeToast = () => {
    uni.hideLoading()
}
 
// 状态标签类型
const getStatusTagType = (status) => {
    const typeMap = {
        '新建': 'info',
        '项目跟踪': 'primary',
        '放弃': 'error',
        '合同签约': 'warning',
        '备案申报': 'primary',
        '项目交付': 'success',
        '项目验收': 'success',
        '项目回款': 'success',
        '回补贴': 'success'
    }
    return typeMap[status] || 'default'
}
 
// 状态文本
const getStatusText = (status) => {
    const textMap = {
        '新建': '新建',
        '项目跟踪': '项目跟踪',
        '放弃': '放弃',
        '合同签约': '合同签约',
        '备案申报': '备案申报',
        '项目交付': '项目交付',
        '项目验收': '项目验收',
        '项目回款': '项目回款',
        '回补贴': '回补贴'
    }
    return textMap[status] || '未知'
}
 
// 格式化日期
const formatDate = (date) => {
    if (!date) return ''
    return dayjs(date).format('YYYY-MM-DD')
}
 
// 获取列表
const getList = () => {
    showLoadingToast('加载中...')
    const params = {
        current: -1,
        size: -1,
        customerName: customerName.value || undefined
    }
    
    opportunityListPage(params)
        .then((res) => {
            const data = res.data || res
            opportunityList.value = data.records || []
            total.value = data.total || 0
        })
        .catch(() => {
            uni.showToast({
                title: '获取商机数据失败',
                icon: 'none'
            })
            opportunityList.value = []
            total.value = 0
        })
        .finally(() => {
            closeToast()
        })
}
 
// 打开商机操作页面(新增、编辑、详情、添加描述)
const openOpportunity = (type, row) => {
    console.log('openOpportunity called with type:', type, 'row:', row)
    try {
        uni.setStorageSync('opportunityOperationType', type)
        if (row) {
            uni.setStorageSync('opportunityData', JSON.stringify(row))
        } else {
            uni.removeStorageSync('opportunityData')
        }
        uni.navigateTo({
            url: '/pages/opportunityManagement/detail'
        })
    } catch (error) {
        console.error('打开商机页面失败:', error)
        uni.showToast({
            title: '操作失败,请重试',
            icon: 'none'
        })
    }
}
 
// 新建商机
const addOpportunity = () => {
    openOpportunity('add')
}
 
onShow(() => {
    getList()
})
</script>
 
<style scoped lang="scss">
@import '@/styles/sales-common.scss';
</style>