index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div class="h-full flex">
  3. <div class="p-5 w-80 pr-0">
  4. <div class="bg-white w-full h-full shadow-md rounded-md flex flex-col">
  5. <div class="flex-1 p-3 overflow-y-auto">
  6. <el-form :model="customerCriteriaForm" label-width="70px" style="max-width: 600px">
  7. <el-form-item label="客户名称">
  8. <el-input v-model="customerCriteriaForm.customName" clearable placeholder="请输入"></el-input>
  9. </el-form-item>
  10. <el-form-item label="客户来源">
  11. <el-select v-model="customerCriteriaForm.customSourceId" placeholder="请选择">
  12. <el-option v-for="item in fixedData.ClueSources" :key="item.id" :label="item.name" :value="item.id" />
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="电话号码">
  16. <el-input v-model="customerCriteriaForm.telPhone" clearable placeholder="请输入"></el-input>
  17. </el-form-item>
  18. <el-form-item label="邮箱">
  19. <el-input v-model="customerCriteriaForm.email" clearable placeholder="请输入"></el-input>
  20. </el-form-item>
  21. <el-form-item label="客户行业">
  22. <el-select v-model="customerCriteriaForm.customerIndustryId" placeholder="请选择">
  23. <el-option v-for="item in fixedData.CustomIndustry" :key="item.id" :label="item.name" :value="item.id" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="客户级别">
  27. <el-select v-model="customerCriteriaForm.customerLevelId" placeholder="请选择">
  28. <el-option v-for="item in fixedData.CustomLevel" :key="item.id" :label="item.name" :value="item.id" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="负责人">
  32. <el-select v-model="customerCriteriaForm.inchargerId" placeholder="请选择">
  33. <el-option v-for="item in fixedData.Personnel" :key="item.id" :label="item.name" :value="item.id" />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="创建时间">
  37. <el-date-picker v-model="customerCriteriaForm.startTime" type="date" placeholder="请选择" :clearable="false"
  38. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  39. </el-form-item>
  40. <el-form-item label="">
  41. <el-date-picker v-model="customerCriteriaForm.endTime" type="date" placeholder="请选择" :clearable="false"
  42. format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. <div class="w-full flex p-3 shadow-[0_-3px_5px_0px_rgba(0,0,0,0.2)]">
  47. <El-button class="w-full" @click="resetTable()">重置</El-Button>
  48. <El-button type="primary" class="w-full" @click="searchTable()">搜索</El-Button>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="flex-1 p-5 overflow-auto">
  53. <div class="bg-white w-full h-full p-3 shadow-md rounded-md flex flex-col">
  54. <div class="flex justify-end pb-3">
  55. <el-button type="primary" @click="editCustomer(false)">新建客户</el-button>
  56. <el-button type="primary">批量转移</el-button>
  57. <el-button type="primary">批量删除</el-button>
  58. <el-button type="primary">回收站</el-button>
  59. <el-button type="primary">导入</el-button>
  60. <el-button type="primary">导出</el-button>
  61. </div>
  62. <div class="flex-1 w-full overflow-hidden">
  63. <el-table ref="clueTableRef" :data="customerTable" border v-loading="allLoading.customerTableLading"
  64. style="width: 100%;height: 100%;">
  65. <el-table-column type="selection" width="55" />
  66. <el-table-column prop="customName" label="客户名称" width="180">
  67. <template #default="scope">
  68. <el-button link type="primary" size="large" @click.prevent="toCustomerTableDetail(scope.row)">{{
  69. scope.row.customName
  70. }}</el-button>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="customSourceValue" label="客户来源" width="180"></el-table-column>
  74. <el-table-column prop="companyPhone" label="公司电话" width="180"></el-table-column>
  75. <el-table-column prop="email" label="邮箱" width="200"></el-table-column>
  76. <el-table-column prop="customerIndustryValue" label="客户行业" width="180"></el-table-column>
  77. <el-table-column prop="customerLevelValue" label="客户级别" width="180"></el-table-column>
  78. <el-table-column prop="inchargerName" label="负责人" width="190"></el-table-column>
  79. <el-table-column prop="creatorName" label="创建人" width="180"></el-table-column>
  80. <el-table-column prop="newCreateTime" label="创建时间" width="180"></el-table-column>
  81. <el-table-column label="操作" fixed="right" width="200">
  82. <template #default="scope">
  83. <el-button link type="primary" size="large" @click="editCustomer(scope.row)">编辑</el-button>
  84. <el-button link type="primary" size="large">新建任务</el-button>
  85. <el-button link type="danger" size="large">删除</el-button>
  86. </template>
  87. </el-table-column>
  88. </el-table>
  89. </div>
  90. <div class="flex justify-end pt-3">
  91. <el-pagination layout="total, prev, pager, next, sizes" :total="customerTotalTable"
  92. :hide-on-single-page="true" />
  93. </div>
  94. </div>
  95. </div>
  96. <!-- 新建客户 -->
  97. <el-dialog v-model="allVisible.editCustomerVisible" width="1000" :show-close="false" top="10vh">
  98. <template #header="{ close, titleId, titleClass }">
  99. <div class="flex justify-between items-center border-b pb-3 dialog-header">
  100. <h4 :id="titleId">{{ allText.editCustomerText }}</h4>
  101. <div>
  102. <el-button type="primary" :loading="allLoading.editCustomerSaveLoading" @click="editCustomerSave(true)">保存并新建</el-button>
  103. <el-button type="primary" :loading="allLoading.editCustomerSaveLoading" @click="editCustomerSave(false)">保存</el-button>
  104. <el-button @click="closeVisible('editCustomerVisible')">取消</el-button>
  105. </div>
  106. </div>
  107. </template>
  108. <div class="h-[60vh] overflow-y-auto scroll-bar pt-3">
  109. <div class="ml-4 mr-4">
  110. <GenerateForm ref="customerTemplateRef" :data="customerTemplate" :value="customerTemplateValue" />
  111. </div>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script lang="ts" setup>
  117. import { ref, reactive, onMounted, inject } from "vue";
  118. import { MOD, GETSYSFILED, GETPERSONNEL, URL_TABLELIST, URL_TEMPLALE, URL_EDITSAVE } from './api.ts'
  119. import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate } from '@/utils/tools'
  120. import { post, get } from "@/utils/request";
  121. import { useRouter, useRoute } from "vue-router";
  122. import { GenerateForm } from '@zmjs/form-design';
  123. // 定义类型
  124. interface fixedDataInterface {
  125. id: string | number,
  126. companyId: string | number,
  127. code: string,
  128. name: string,
  129. seq: string | number,
  130. }
  131. interface personnelInterface {
  132. id: string | number,
  133. name: string,
  134. phone: string,
  135. jobNumber: string
  136. }
  137. interface customerCriteriaFormType { // 线索筛选条件类型
  138. customName: string,
  139. customSourceId: string | number,
  140. telPhone: string,
  141. email: string,
  142. customerIndustryId: string | number,
  143. customerLevelId: string | number,
  144. inchargerId: string | number,
  145. startTime: string | number,
  146. endTime: string | number,
  147. pageIndex: string | number,
  148. pageFrom: string | number
  149. }
  150. // 定义变量
  151. const router = useRouter()
  152. const globalPopup = inject<GlobalPopup>('globalPopup')
  153. const customerCriteriaForm = reactive<customerCriteriaFormType>({ // 筛选条件form
  154. customName: '',
  155. customSourceId: '',
  156. telPhone: '',
  157. email: '',
  158. customerIndustryId: '',
  159. customerLevelId: '',
  160. inchargerId: '',
  161. startTime: getFirstDayOfMonth(new Date()),
  162. endTime: formatDate(new Date()),
  163. pageIndex: 1,
  164. pageFrom: 10
  165. })
  166. const customerTable = ref([]) // 线索table数据
  167. const customerTotalTable = ref(0) // 线索 table 数据总数
  168. const allLoading = reactive({
  169. customerTableLading: false,
  170. editCustomerSaveLoading: false
  171. })
  172. const allVisible = reactive({
  173. editCustomerVisible: false,
  174. })
  175. const allText = reactive({
  176. editCustomerText: '新建客户',
  177. })
  178. const fixedData = reactive({
  179. ClueSources: [] as fixedDataInterface[],
  180. CustomIndustry: [] as fixedDataInterface[],
  181. CustomLevel: [] as fixedDataInterface[],
  182. Personnel: [] as personnelInterface[]
  183. })
  184. const customerTemplate = ref({
  185. list: [],
  186. config: {}
  187. })
  188. const customerTemplateRef = ref<typeof GenerateForm>() // 自定义表单dom
  189. const customerTemplateValue = ref({})
  190. // 定义方法
  191. function editCustomerSave(flag: boolean) {
  192. customerTemplateRef.value?.getData().then((res: any) => {
  193. allLoading.editCustomerSaveLoading = true
  194. post(URL_EDITSAVE, { ...res }).then((_res) => {
  195. allVisible.editCustomerVisible = flag
  196. globalPopup?.showSuccess('保存成功')
  197. if(flag) {
  198. customerTemplateRef.value?.reset()
  199. }
  200. getCustomerTable()
  201. }).finally(() => {
  202. allLoading.editCustomerSaveLoading = false
  203. })
  204. }).catch((_err: any) => {
  205. console.log(_err)
  206. globalPopup?.showError('请填写完整')
  207. })
  208. }
  209. function editCustomer(row: any) { // row 有数据代表编辑
  210. if (row) {
  211. const templateKey = customerTemplate.value.list.map((item: any) => item.model)
  212. console.log(templateKey, '<==== key')
  213. } else { // 没有数据代表新建
  214. customerTemplateRef.value?.reset()
  215. }
  216. showVisible('editCustomerVisible')
  217. }
  218. function toCustomerTableDetail(_row: any) {
  219. console.log('点击跳转详情')
  220. router.push({ path: `${MOD}/detail`, query: { id: _row.id } })
  221. }
  222. function searchTable() {
  223. getCustomerTable()
  224. }
  225. function resetTable() {
  226. let newResetForm = resetFromValue(customerCriteriaForm, { startTime: getFirstDayOfMonth(new Date()), endTime: formatDate(new Date()), pageIndex: 1, pageFrom: 10 })
  227. Object.assign(customerCriteriaForm, newResetForm)
  228. getCustomerTable()
  229. }
  230. function getCustomerTable() {
  231. let valueForm = getFromValue(customerCriteriaForm)
  232. allLoading.customerTableLading = true
  233. post(URL_TABLELIST, { ...valueForm }).then((res) => {
  234. const { data, total } = res.data
  235. customerTable.value = (data || []).map((item: any) => {
  236. return {
  237. ...item,
  238. newCreateTime: formatDate(new Date(item.createTime)),
  239. }
  240. })
  241. customerTotalTable.value = total
  242. }).finally(() => {
  243. allLoading.customerTableLading = false
  244. })
  245. }
  246. async function getSystemField() {
  247. const systemField = getAllListByCode(['线索来源', '客户行业', '客户级别'])
  248. for (let i in systemField) {
  249. const { data } = await get(`${GETSYSFILED}?code=${systemField[i]}`)
  250. for (let key of Object.keys(fixedData)) {
  251. if (systemField[i] == key) {
  252. Object.assign(fixedData, { [key]: data })
  253. }
  254. }
  255. }
  256. const { data } = await post(GETPERSONNEL, {})
  257. fixedData.Personnel = data.map((item: any) => {
  258. const { id, name, phone, jobNumber } = item
  259. return {
  260. id, name, phone, jobNumber
  261. }
  262. })
  263. const res = await get(URL_TEMPLALE)
  264. customerTemplate.value = JSON.parse(res.data[0].config)
  265. }
  266. function showVisible(type: keyof typeof allVisible) {
  267. allVisible[type] = true
  268. }
  269. function closeVisible(type: keyof typeof allVisible) {
  270. allVisible[type] = false
  271. }
  272. onMounted(() => {
  273. getSystemField()
  274. getCustomerTable()
  275. })
  276. </script>
  277. <style lang="scss" scoped></style>