moduleList.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. <template>
  2. <Page :title='`${queryParameters.name}列表`'>
  3. <template v-slot:body>
  4. <div class="flex flex-col h-full">
  5. <!-- 搜索 -->
  6. <div class="mx-1 headerModeuleList">
  7. <van-search v-model.trim="searchVal" background="#F8F8F8" :placeholder="`请输入${queryParameters?.name}关键词`"
  8. @search="onRefresh(true)" @clear="onRefresh(true)">
  9. <template v-slot:left-icon>
  10. <van-icon name="search" class="themeTextColor font-bold" />
  11. </template>
  12. </van-search>
  13. </div>
  14. <!-- 主题内容 -->
  15. <div class="flex-1 overflow-y-auto">
  16. <template v-if="listData?.records && listData.records.length && !loadingList">
  17. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  18. <van-list v-model:loading="isLoading" :finished="finished" finished-text="没有更多了" @load="onLoad">
  19. <div v-for="item in listData.records" :key="item.id" @click="toDetail(item)">
  20. <van-swipe-cell>
  21. <div
  22. :class="`${item.needPin ? 'bg-slate-50' : 'bg-white'} px-5 py-5 flex items-center flex-row w-full listContent`">
  23. <div class="listOfImages items-justify-center rounded-full overflow-hidden bg-[#FFEEEC]">
  24. <img :src="queryParameters.homeImage" class="w-full h-full">
  25. </div>
  26. <div class="flex-1 h-full">
  27. <!-- 商机 -->
  28. <template v-if="queryParameters?.key == 'business'">
  29. <div>
  30. <div class="flex items-center flex-row">
  31. <div class="flex-1 truncate mr-8 titles relative">{{ item.name }}</div>
  32. <div><van-tag type="primary">{{ item.stageValue }}</van-tag></div>
  33. </div>
  34. <div class="flex items-center flex-row mt-1">
  35. <van-text-ellipsis :content="item.customerName"
  36. class="flex-1 text-[#B9B9B9] text-size-small" />
  37. <div class="text-[#B9B9B9] text-size-small" v-if="item.inchargerName">负责人:{{
  38. item.inchargerName }}</div>
  39. </div>
  40. </div>
  41. </template>
  42. <!-- 线索 -->
  43. <template v-if="queryParameters?.key == 'thread'">
  44. <div>
  45. <div class="flex items-center flex-row">
  46. <div class="flex-1 truncate mr-8 titles relative">{{ item.clueName }}</div>
  47. <div class="text-[#B9B9B9]">{{ item.customerLevelValue }}</div>
  48. </div>
  49. <div class="flex items-center flex-row mt-1">
  50. <div class="text-[#B9B9B9] text-size-small" v-if="item.inchargerName">负责人:{{
  51. item.inchargerName }}</div>
  52. <div></div>
  53. </div>
  54. </div>
  55. </template>
  56. <!-- 客户 -->
  57. <template v-if="queryParameters?.key == 'customer'">
  58. <div>
  59. <div class="flex items-center flex-row">
  60. <div class="flex-1 truncate mr-8 titles relative">{{ item.customName }}</div>
  61. <div class="text-[#B9B9B9]">{{ item.customerLevelValue }}</div>
  62. </div>
  63. <div class="flex items-center flex-row mt-1">
  64. <div class="text-[#B9B9B9] text-size-small" v-if="item.inchargerName">负责人:{{
  65. item.inchargerName }}</div>
  66. <div></div>
  67. </div>
  68. </div>
  69. </template>
  70. <!-- 联系人 -->
  71. <template v-if="queryParameters?.key == 'contacts'">
  72. <div>
  73. <div class="flex items-center flex-row">
  74. <div class="flex-1 truncate mr-8 titles relative">{{ item.name }}</div>
  75. <div class="text-[#B9B9B9]">{{ item.position }}</div>
  76. </div>
  77. <div class="flex items-center justify-between flex-row mt-1">
  78. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate" v-if="item.ownerName">客户:{{
  79. item.customName }}</div>
  80. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate text-right" v-if="item.ownerName">负责人:{{
  81. item.ownerName }}</div>
  82. </div>
  83. </div>
  84. </template>
  85. <!-- 任务 -->
  86. <template v-if="queryParameters?.key == 'tasks'">
  87. <div>
  88. <div class="flex items-center flex-row">
  89. <div class="flex-1 truncate mr-8 titles relative">{{ item.taskName }}</div>
  90. <div :style="`color: ${fixedFieldTaskStatus.find(subItem => subItem.value == item.status)?.color}`">
  91. {{ fixedFieldTaskStatus.find(subItem => subItem.value == item.status)?.label || '' }}
  92. </div>
  93. </div>
  94. <div class="flex items-center justify-between flex-row mt-1">
  95. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate">
  96. {{ item.businessName || item.orderName || item.clueName || item.customName }}
  97. </div>
  98. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate text-right">优先级:
  99. {{ fixedFieldPriority.find(subItem => subItem.value == item.priority)?.label || '' }}
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. <!-- 产品 -->
  105. <template v-if="queryParameters?.key == 'product'">
  106. <div>
  107. <div class="flex items-center flex-row">
  108. <div class="flex-1 truncate mr-8 titles relative">{{ item.productName }}</div>
  109. <div class="text-[#B9B9B9]">{{ item.status ? '上架' : '下架' }}</div>
  110. </div>
  111. <div class="flex items-center justify-between flex-row mt-1">
  112. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate">负责人:{{
  113. item.inchargerName }}</div>
  114. <div class="text-[#B9B9B9] text-size-small w-2/5 truncate text-right">库存:{{
  115. item.unit || 0 }}</div>
  116. </div>
  117. </div>
  118. </template>
  119. <!-- 合同 -->
  120. <template v-if="queryParameters?.key == 'contract'">
  121. <div>
  122. <div class="flex items-center flex-row">
  123. <div class="flex-1 truncate mr-8 titles relative">{{ item.name }}</div>
  124. <div class="text-[#B9B9B9]">
  125. <span :style="fixedFieldStatusArray[item.status].color">
  126. {{ fixedFieldStatusArray[item.status].label }}
  127. </span>
  128. </div>
  129. </div>
  130. <div class="flex items-center justify-between flex-row mt-1">
  131. <div class="text-[#B9B9B9] text-size-small w-2/6 truncate">{{ item.number }}</div>
  132. <div class="text-[#B9B9B9] text-size-small w-2/3 truncate text-right">
  133. 合同金额¥{{ item.amounts }} / 回款进度 {{ item.payment ? (100 * item.payment / item.amounts).toFixed(1) + '%' : '0%' }}
  134. </div>
  135. </div>
  136. </div>
  137. </template>
  138. <!-- 销售 -->
  139. <template v-if="queryParameters?.key == 'order'">
  140. <div>
  141. <div class="flex items-center flex-row">
  142. <div class="flex-1 truncate mr-8 titles relative">{{ item.orderName }}</div>
  143. <div class="text-[#B9B9B9]">{{ fixedFieldPaymentStatus.find(subItem => subItem.value == item.receivedStatus)?.label || '' }}</div>
  144. </div>
  145. <div class="flex items-center justify-between flex-row mt-1">
  146. <div class="text-[#B9B9B9] text-size-small w-2/6 truncate">{{ item.customName }}</div>
  147. <div class="text-[#B9B9B9] text-size-small w-2/3 truncate text-right">
  148. 订单金额¥{{ item.price }} / 已回款¥ {{ item.receivedPayment }}
  149. </div>
  150. </div>
  151. </div>
  152. </template>
  153. </div>
  154. </div>
  155. <template #right>
  156. <div class="flex items-center h-full bg-white">
  157. <template v-if="!item.inchargerName">
  158. <div class="buttonCircle rounded-full" @click="claimAndClaim(item)" v-if="['business', 'thread',
  159. 'customer'].includes(queryParameters?.key)">
  160. <img src="/src/assets/image/claimAndClaim.png" class="w-full h-full">
  161. </div>
  162. </template>
  163. <template v-if="item.inchargerName || item.ownerName">
  164. <div class="buttonCircle rounded-full" @click="transfer(item)" v-if="['business', 'thread',
  165. 'customer', 'contacts'].includes(queryParameters?.key)">
  166. <img src="/src/assets/image/transfer.png" class="w-full h-full">
  167. </div>
  168. </template>
  169. <template v-if="!item.needPin">
  170. <div class="buttonCircle rounded-full" @click="topMounted(item)">
  171. <img src="/src/assets/image/topMounted.png" class="w-full h-full">
  172. </div>
  173. </template>
  174. <template v-if="item.needPin">
  175. <div class="buttonCircle rounded-full" @click="noTopMounted(item)">
  176. <img src="/src/assets/image/noTopMounted.png" class="w-full h-full">
  177. </div>
  178. </template>
  179. <div class="buttonCircle rounded-full" @click="edit(item)" v-permission="[queryParameters?.jurisdiction?.edit]">
  180. <img src="/src/assets/image/edit.png" class="w-full h-full">
  181. </div>
  182. <div class="buttonCircle rounded-full" @click="deleteRow(item)" v-permission="[queryParameters?.jurisdiction?.delete]">
  183. <img src="/src/assets/image/delete.png" class="w-full h-full">
  184. </div>
  185. </div>
  186. </template>
  187. </van-swipe-cell>
  188. </div>
  189. </van-list>
  190. </van-pull-refresh>
  191. </template>
  192. <template v-else>
  193. <template v-if="!isLoading && listData?.records && !listData.records.length">
  194. <van-empty description="暂无数据" />
  195. </template>
  196. <template v-else>
  197. <van-skeleton title :row="20" class="w-full h-full" />
  198. </template>
  199. </template>
  200. </div>
  201. </div>
  202. <!-- 可拖拽添加 -->
  203. <DragBox>
  204. <div class="addButton" @click="toAddEditor()" v-permission="[queryParameters?.jurisdiction?.newlyAdded]">
  205. <img src="/src/assets/image/add.png" class="w-full h-full" />
  206. </div>
  207. </DragBox>
  208. <!-- 转移弹窗 -->
  209. <van-dialog v-model:show="showDialog" :title="`转移${queryParameters?.name || ''}`" show-cancel-button
  210. @confirm="confirmTransfer" :before-close="dialogCloseBefo">
  211. <van-cell title="转移至" is-link @click="showSelect = true">
  212. <template #value>
  213. {{ dialogSelection.label }}
  214. </template>
  215. </van-cell>
  216. <div class="themeTextColor text-size-small pl-4 pt-2 pb-2">转移后,将看不到此{{ queryParameters?.name || '' }}</div>
  217. </van-dialog>
  218. <!-- select 选择器 -->
  219. <van-popup v-model:show="showSelect" destroy-on-close position="bottom" :style="{ height: '80%' }">
  220. <PullDownSelector :showElement="showSelect" @change="selectChange" />
  221. </van-popup>
  222. </template>
  223. </Page>
  224. </template>
  225. <script setup>
  226. import { ref, onActivated } from 'vue';
  227. import { showConfirmDialog } from 'vant';
  228. import { useLifecycle } from '@hooks/useCommon.js';
  229. import { resetListData, getListFieldKey } from '@components/common/formForm/formCorrespondenceProcessing'
  230. import useShowToast from '@hooks/useToast'
  231. import { GET_CUSTOM_FORM_JSON } from '@hooks/useApi'
  232. import { fixedFieldPaymentStatus, fixedFieldPriority, fixedFieldTaskStatus, fixedFieldStatusArray } from "@utility/defaultData"
  233. import requests from "@common/requests";
  234. import useRouterStore from "@store/useRouterStore.js";
  235. import useFixedData from "@store/useFixedData.js"
  236. import useInfoStore from '@store/useInfoStore'
  237. // import ElementLongPress from "@components/common/elementLongPress.vue";
  238. import DragBox from '@components/common/dragBox.vue';
  239. const TRANSFER = 'transfer';
  240. const DELETE = 'delete';
  241. const EDIT = 'edit';
  242. const TOP_MOUNTED = 'topMounted';
  243. const { toastSuccess, toastFail, toastText } = useShowToast()
  244. const router = useRouterStore()
  245. const fixedData = useFixedData()
  246. const userInfo = useInfoStore()
  247. const searchVal = ref()
  248. const queryParameters = ref({})
  249. const loadingList = ref(false)
  250. const popUpWindowArray = ref([
  251. { text: '转移', event: TRANSFER, icon: '/src/assets/image/transfer.png', removeModule: ['contacts', 'tasks', 'product', 'contract', 'order'] },
  252. { text: '顶置', event: TOP_MOUNTED, icon: '/src/assets/image/topMounted.png', removeModule: [] },
  253. { text: '编辑', event: EDIT, icon: '/src/assets/image/edit.png', removeModule: [] },
  254. { text: '删除', event: DELETE, icon: '/src/assets/image/delete.png', removeModule: [] },
  255. ])
  256. const showSelect = ref(false)
  257. const showDialog = ref(false)
  258. const refreshing = ref(false);
  259. const isLoading = ref(false);
  260. const finished = ref(false);
  261. const listData = ref({
  262. records: [],
  263. pageIndex: 0,
  264. pageSize: 20,
  265. total: 0,
  266. totalPage: 0,
  267. });
  268. const excessiveData = ref({});
  269. const dialogSelection = ref({});
  270. // 按钮触发的事件: row 为当前点击的行数据, item 为当前点击的按钮
  271. function longPress(row, item) {
  272. switch (item.event) {
  273. case EDIT:
  274. edit(row);
  275. break;
  276. case TRANSFER:
  277. transfer(row);
  278. break;
  279. case DELETE:
  280. deleteRow(row);
  281. break;
  282. case TOP_MOUNTED:
  283. topMounted(row);
  284. break;
  285. default:
  286. console.warn('未知的类型', item.event);
  287. break;
  288. }
  289. }
  290. // 编辑事件
  291. function edit(row) {
  292. const formJson = fixedData.formJson[queryParameters.value.key] || []
  293. const formList = resetListData(formJson?.list)
  294. const filedObj = getListFieldKey(formList, row)
  295. let other = {}
  296. if (queryParameters.value.key == 'tasks') {
  297. other = { ...row }
  298. }
  299. toAddEditor({ ...other, ...filedObj, id: row.id })
  300. }
  301. // 转移事件
  302. function transfer(row) {
  303. dialogSelection.value = {}
  304. excessiveData.value = row
  305. showDialog.value = true
  306. }
  307. function confirmTransfer() {
  308. if (!dialogSelection.value.label) {
  309. return toastText('请选择要转移的人员')
  310. }
  311. const { id } = excessiveData.value
  312. const { value } = dialogSelection.value
  313. let formVal = {}
  314. if(queryParameters?.value.key == 'contacts') {
  315. formVal = { id, inchargerId: value, ownerId: value }
  316. } else {
  317. formVal = { ids: id, inchargerId: value, }
  318. }
  319. requests.post(queryParameters?.value.transferInterface, { ...formVal }).then((res) => {
  320. toastSuccess('转移成功')
  321. onRefresh(true)
  322. showDialog.value = false
  323. })
  324. }
  325. // 认领
  326. function claimAndClaim(item) {
  327. const { id, name, clueName, customName } = item
  328. const userId = userInfo.userInfo.id
  329. showConfirmDialog({
  330. title: `认领${queryParameters.value.name}`,
  331. message: `确定认领【${name || clueName || customName}】${queryParameters.value.name}吗?`,
  332. }).then(() => {
  333. requests.post(queryParameters?.value.transferInterface, { ids: id, inchargerId: userId }).then((res) => {
  334. toastSuccess('认领成功')
  335. onRefresh(true)
  336. })
  337. })
  338. }
  339. // 删除事件
  340. function deleteRow(row) {
  341. const { name = '', searchFiled = {}, deteleFiled = '' } = queryParameters.value
  342. const foemVal = { [queryParameters.value.key == 'tasks' ? 'taskIds' : 'ids']: row.id }
  343. showConfirmDialog({
  344. title: `删除${name}`,
  345. message: `确定删除【${row[searchFiled?.search]}】${name}吗?`,
  346. }).then(() => {
  347. requests.post(deteleFiled, { ...foemVal }).then((res) => {
  348. toastSuccess('删除成功')
  349. onRefresh(true)
  350. }).catch((err) => {
  351. toastFail(err.msg ? err.msg : '删除失败')
  352. })
  353. })
  354. }
  355. // 顶置事件
  356. function topMounted(row) {
  357. requests.post(queryParameters?.value.topMountedInterface, { id: row.id }).then((res) => {
  358. toastSuccess('顶置成功')
  359. onRefresh(true)
  360. })
  361. }
  362. function noTopMounted(row) {
  363. requests.post(queryParameters?.value.cancelTheTopMountedInterface, { id: row.id }).then((res) => {
  364. toastSuccess('取消顶置成功')
  365. onRefresh(true)
  366. })
  367. }
  368. function toDetail(item) {
  369. if (queryParameters.value?.key == 'tasks') {
  370. return
  371. }
  372. router.navigateTo({
  373. pathName: 'details',
  374. success: () => {
  375. router.emit('detailParameter', {
  376. routerInfo: JSON.stringify(queryParameters.value),
  377. parameter: JSON.stringify(item)
  378. })
  379. }
  380. })
  381. }
  382. function toAddEditor(value) {
  383. router.navigateTo({
  384. pathName: 'addEditor',
  385. success: () => {
  386. router.emit('addEditorParameter', {
  387. routerInfo: JSON.stringify(queryParameters.value),
  388. filedValue: JSON.stringify(value)
  389. })
  390. }
  391. })
  392. }
  393. function onRefresh(flag = false) {
  394. finished.value = false;
  395. isLoading.value = true;
  396. listData.value.pageIndex = 1;
  397. fetchListData(flag);
  398. }
  399. function onLoad() {
  400. isLoading.value = true;
  401. listData.value.pageIndex++
  402. fetchListData()
  403. }
  404. async function fetchListData(flag = false) {
  405. console.log(listData.value.totalPage, listData.value.pageIndex)
  406. if (
  407. // 如果总页数小于等于现页数,并且不是第一次加载, 或者正在加载数据 直接跳出不请求
  408. listData.value.totalPage < listData.value.pageIndex &&
  409. listData.value.pageIndex !== 1
  410. ) {
  411. finished.value = true;
  412. return;
  413. }
  414. const res = await getListData(flag)
  415. if (res.code === 'ok') {
  416. const list = res.data.data || res.data.records || res.data.record
  417. const total = res.data.total
  418. if (refreshing.value) {
  419. refreshing.value = false;
  420. }
  421. isLoading.value = false;
  422. listData.value.records = (
  423. listData.value.pageIndex === 1 ? [] : listData.value.records
  424. ).concat(list || [])
  425. listData.value.totalPage = Math.ceil(total / listData.value.pageSize)
  426. listData.value.total = +total
  427. }
  428. }
  429. async function getListData(flag = false) {
  430. const url = queryParameters.value.listUrl
  431. if (flag) {
  432. loadingList.value = true
  433. }
  434. const res = await requests.post(url, {
  435. pageIndex: listData.value.pageIndex,
  436. pageSize: listData.value.pageSize,
  437. pageFrom: listData.value.pageSize,
  438. [queryParameters.value?.searchFiled?.search]: searchVal.value
  439. }).finally(() => {
  440. if (flag) {
  441. loadingList.value = false
  442. }
  443. })
  444. return res
  445. }
  446. function reloadListData(data) {
  447. queryParameters.value = JSON.parse(data.row || '{}')
  448. refreshing.value = false
  449. isLoading.value = false
  450. finished.value = false
  451. searchVal.value = ''
  452. listData.value = { records: [], pageIndex: 0, pageSize: 20, total: 0, totalPage: 0 }
  453. popUpWindowArray.value = popUpWindowArray.value.filter(item => !item.removeModule.includes(queryParameters.value?.key))
  454. if (!fixedData.formJson[queryParameters.value.key]) {
  455. getFormJson(queryParameters.value)
  456. }
  457. onLoad()
  458. }
  459. function getFormJson(info = {}) {
  460. requests.get(`${GET_CUSTOM_FORM_JSON}/${info.key}`).then(res => {
  461. const { data = [] } = res
  462. fixedData.updateState({
  463. formJson: {
  464. ...fixedData.formJson,
  465. [info.key]: JSON.parse(data[0].config)
  466. }
  467. })
  468. })
  469. }
  470. function selectChange(value, label) {
  471. dialogSelection.value = {
  472. value, label
  473. }
  474. showSelect.value = false
  475. }
  476. function dialogCloseBefo(val) {
  477. if (val == 'confirm' && showDialog.value) {
  478. return false
  479. }
  480. return true
  481. }
  482. useLifecycle({
  483. load: () => {
  484. router.on('moduleListDetailParameter', (data) => {
  485. reloadListData(data)
  486. })
  487. router.eventOn('moduleListRefreshData', (data) => {
  488. onRefresh(true)
  489. })
  490. }
  491. });
  492. </script>
  493. <style lang='scss' scoped>
  494. .buttonCircle {
  495. width: 37px;
  496. height: 37px;
  497. margin-left: 10px;
  498. &:last-child {
  499. margin-right: 10px;
  500. }
  501. }
  502. .addButton {
  503. width: 60px;
  504. height: 60px;
  505. }
  506. .listContent {
  507. border: 1px solid #F6F6FA;
  508. .listOfImages {
  509. width: 40px;
  510. height: 40px;
  511. margin-right: 10px;
  512. }
  513. }
  514. .headerModeuleList :deep(.van-search__content) {
  515. background: #fff !im\portant;
  516. height: 42px;
  517. align-items: center;
  518. border-radius: 6px;
  519. }
  520. </style>