OpportunitySelector.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="dialogVisible"
  5. width="1200px"
  6. align-center
  7. class="dialog-form-layout"
  8. modal-class="order-module-dialog-mask"
  9. :close-on-click-modal="false"
  10. append-to-body
  11. >
  12. <!-- 提示信息 -->
  13. <el-alert v-if="props.customerId" :title="`已筛选客户的商机`" type="info" :closable="false" class="mb-3" show-icon />
  14. <!-- 查询表单 -->
  15. <el-form :model="queryParams" ref="queryFormRef" :inline="true" class="mb-3 search-form-inline">
  16. <el-form-item label="商机名称" prop="opportunityName">
  17. <el-input v-model="queryParams.opportunityName" placeholder="请输入商机名称" clearable @keyup.enter="handleQuery" style="width: 180px" />
  18. </el-form-item>
  19. <el-form-item label="商机编号" prop="opportunityNo">
  20. <el-input v-model="queryParams.opportunityNo" placeholder="请输入商机编号" clearable @keyup.enter="handleQuery" style="width: 150px" />
  21. </el-form-item>
  22. <el-form-item label="商机阶段" prop="stage">
  23. <el-select v-model="queryParams.stage" placeholder="请选择商机阶段" clearable style="width: 150px">
  24. <el-option v-for="dict in dictStore.getOptions('crm_opportunity_stage')" :key="dict.value" :label="dict.label" :value="dict.value" />
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="商机状态" prop="status">
  28. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 120px">
  29. <el-option v-for="dict in dictStore.getOptions('crm_opportunity_status')" :key="dict.value" :label="dict.label" :value="dict.value" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item class="form-buttons-right">
  33. <el-button type="primary" :loading="loading" @click="handleQuery">
  34. <el-icon><Search /></el-icon>搜索
  35. </el-button>
  36. <el-button :loading="loading" @click="resetQuery">
  37. <el-icon><Refresh /></el-icon>重置
  38. </el-button>
  39. </el-form-item>
  40. </el-form>
  41. <!-- 商机列表 -->
  42. <div class="panel dialog-list-panel">
  43. <div class="list-body list-wrap dialog-list-body-only">
  44. <el-table
  45. v-loading="loading"
  46. :data="opportunityList"
  47. class="list-table"
  48. stripe
  49. highlight-current-row
  50. @current-change="handleCurrentChange"
  51. :max-height="400"
  52. >
  53. <el-table-column type="index" label="序号" min-width="60" align="center" header-align="center" />
  54. <el-table-column label="商机编号" prop="opportunityNo" min-width="140" align="center" header-align="center" :show-overflow-tooltip="true" />
  55. <el-table-column label="商机名称" prop="opportunityName" min-width="180" align="center" header-align="center" :show-overflow-tooltip="true" />
  56. <el-table-column label="客户名称" prop="customerName" min-width="150" align="center" header-align="center" :show-overflow-tooltip="true" />
  57. <el-table-column label="商机阶段" prop="stage" min-width="120" align="center" header-align="center">
  58. <template #default="scope">
  59. <DictTag dict-type="crm_opportunity_stage" :value="scope.row.stage" />
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="预计成交率" prop="winRate" min-width="100" align="center" header-align="center">
  63. <template #default="scope">
  64. <el-progress :percentage="scope.row.winRate || 0" :color="getWinRateColor(scope.row.winRate)" />
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="预计成交日期" prop="expectedCloseDate" min-width="120" align="center" header-align="center">
  68. <template #default="scope">
  69. <span>{{ scope.row.expectedCloseDate || '-' }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="负责人" prop="ownerUserName" min-width="100" align="center" header-align="center" :show-overflow-tooltip="true" />
  73. <el-table-column label="状态" prop="status" min-width="80" align="center" header-align="center">
  74. <template #default="scope">
  75. <DictTag dict-type="crm_opportunity_status" :value="scope.row.status" />
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <ListPagination
  80. v-show="total > 0"
  81. :total="total"
  82. v-model:page="queryParams.pageNum"
  83. v-model:limit="queryParams.pageSize"
  84. @pagination="getList"
  85. />
  86. </div>
  87. </div>
  88. <!-- 当前选中商机 -->
  89. <template v-if="currentOpportunity">
  90. <el-divider content-position="left">当前选中商机</el-divider>
  91. <div class="selected-opportunity">
  92. <el-descriptions :column="3" border>
  93. <el-descriptions-item label="商机名称">{{ currentOpportunity.opportunityName }}</el-descriptions-item>
  94. <el-descriptions-item label="商机编号">{{ currentOpportunity.opportunityNo }}</el-descriptions-item>
  95. <el-descriptions-item label="客户名称">{{ currentOpportunity.customerName }}</el-descriptions-item>
  96. <el-descriptions-item label="商机阶段">
  97. <DictTag dict-type="crm_opportunity_stage" :value="currentOpportunity.stage" />
  98. </el-descriptions-item>
  99. <el-descriptions-item label="预计成交率">{{ currentOpportunity.winRate || 0 }}%</el-descriptions-item>
  100. <el-descriptions-item label="预计成交日期">{{ currentOpportunity.expectedCloseDate || '-' }}</el-descriptions-item>
  101. </el-descriptions>
  102. </div>
  103. </template>
  104. <template #footer>
  105. <div class="dialog-footer">
  106. <el-button class="btn-ghost" @click="handleClose">
  107. <el-icon><Close /></el-icon>取消
  108. </el-button>
  109. <el-button class="btn-main" type="primary" @click="handleConfirm" :disabled="!currentOpportunity">
  110. <el-icon><Check /></el-icon>确定
  111. </el-button>
  112. </div>
  113. </template>
  114. </el-dialog>
  115. </template>
  116. <script setup lang="ts" name="OpportunitySelector">
  117. import { useDictStore } from '@/store/modules/dict'
  118. import DictTag from '@/components/DictTag/index.vue'
  119. import ListPagination from '@/components/ListPagination/index.vue'
  120. import { Check, Close, Refresh, Search } from '@element-plus/icons-vue'
  121. import { ref, watch, computed } from 'vue'
  122. import type { ElFormInstance } from 'element-plus'
  123. import { listOpportunity } from '@/api/crm/opportunity'
  124. import type { OpportunityQuery, OpportunityVO } from '@/api/crm/opportunity/types'
  125. interface Props {
  126. visible: boolean
  127. customerId?: number | string
  128. }
  129. const props = defineProps<Props>()
  130. const dictStore = useDictStore()
  131. const dialogTitle = computed(() => {
  132. return props.customerId ? '选择商机(已筛选当前客户)' : '选择商机'
  133. })
  134. const emit = defineEmits(['update:visible', 'confirm'])
  135. const dialogVisible = ref(false)
  136. watch(
  137. () => props.visible,
  138. async (val) => {
  139. dialogVisible.value = val
  140. if (val) {
  141. await dictStore.loadAllDict()
  142. getList()
  143. }
  144. }
  145. )
  146. watch(
  147. () => props.customerId,
  148. (val) => {
  149. if (dialogVisible.value) {
  150. queryParams.value.customerId = val
  151. getList()
  152. }
  153. }
  154. )
  155. watch(dialogVisible, (val) => {
  156. emit('update:visible', val)
  157. })
  158. const queryParams = ref<OpportunityQuery>({
  159. pageNum: 1,
  160. pageSize: 20,
  161. opportunityName: undefined,
  162. opportunityNo: undefined,
  163. customerId: props.customerId,
  164. stage: undefined,
  165. status: 'following'
  166. })
  167. const opportunityList = ref<OpportunityVO[]>([])
  168. const loading = ref(false)
  169. const total = ref(0)
  170. const currentOpportunity = ref<OpportunityVO | null>(null)
  171. const queryFormRef = ref<ElFormInstance>()
  172. const getList = async () => {
  173. loading.value = true
  174. try {
  175. queryParams.value.customerId = props.customerId
  176. const res = await listOpportunity({
  177. ...queryParams.value,
  178. customerId: props.customerId != null ? String(props.customerId) : undefined
  179. })
  180. opportunityList.value = res.rows || []
  181. total.value = res.total ?? 0
  182. } catch (error) {
  183. console.error('获取商机列表失败:', error)
  184. } finally {
  185. loading.value = false
  186. }
  187. }
  188. const handleQuery = () => {
  189. queryParams.value.pageNum = 1
  190. getList()
  191. }
  192. const resetQuery = () => {
  193. queryFormRef.value?.resetFields()
  194. handleQuery()
  195. }
  196. watchDebounced(
  197. () => ({
  198. opportunityName: queryParams.value.opportunityName,
  199. opportunityNo: queryParams.value.opportunityNo,
  200. stage: queryParams.value.stage,
  201. status: queryParams.value.status
  202. }),
  203. () => {
  204. queryParams.value.pageNum = 1
  205. getList()
  206. },
  207. { debounce: 300, deep: true }
  208. )
  209. const handleCurrentChange = (row: OpportunityVO) => {
  210. currentOpportunity.value = row
  211. }
  212. const handleConfirm = () => {
  213. emit('confirm', currentOpportunity.value)
  214. handleClose()
  215. }
  216. const handleClose = () => {
  217. currentOpportunity.value = null
  218. dialogVisible.value = false
  219. }
  220. const getWinRateColor = (winRate: number) => {
  221. if (winRate >= 80) return '#67c23a'
  222. if (winRate >= 60) return '#409eff'
  223. if (winRate >= 40) return '#e6a23c'
  224. return '#f56c6c'
  225. }
  226. </script>
  227. <style scoped>
  228. .selected-opportunity {
  229. padding: 10px;
  230. background-color: #f5f7fa;
  231. border-radius: 4px;
  232. }
  233. .mb-3 {
  234. margin-bottom: 16px;
  235. }
  236. .mt-3 {
  237. margin-top: 16px;
  238. }
  239. .search-form-inline {
  240. display: flex;
  241. flex-wrap: wrap;
  242. }
  243. .form-buttons-right {
  244. margin-left: auto !important;
  245. }
  246. </style>