moduleList.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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', 'product'].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', 'product', 'order'].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. const timeout = ref(null)
  271. // 按钮触发的事件: row 为当前点击的行数据, item 为当前点击的按钮
  272. function longPress(row, item) {
  273. switch (item.event) {
  274. case EDIT:
  275. edit(row);
  276. break;
  277. case TRANSFER:
  278. transfer(row);
  279. break;
  280. case DELETE:
  281. deleteRow(row);
  282. break;
  283. case TOP_MOUNTED:
  284. topMounted(row);
  285. break;
  286. default:
  287. console.warn('未知的类型', item.event);
  288. break;
  289. }
  290. }
  291. // 编辑事件
  292. function edit(row) {
  293. const formJson = fixedData.formJson[queryParameters.value.key] || []
  294. const formList = resetListData(formJson?.list)
  295. const filedObj = getListFieldKey(formList, row)
  296. let other = {}
  297. if (queryParameters.value.key == 'tasks') {
  298. other = { ...row }
  299. }
  300. toAddEditor({ ...other, ...filedObj, id: row.id })
  301. }
  302. // 转移事件
  303. function transfer(row) {
  304. dialogSelection.value = {}
  305. excessiveData.value = row
  306. showDialog.value = true
  307. }
  308. function confirmTransfer() {
  309. if (!dialogSelection.value.label) {
  310. return toastText('请选择要转移的人员')
  311. }
  312. const { id } = excessiveData.value
  313. const { value } = dialogSelection.value
  314. let formVal = {}
  315. if(queryParameters?.value.key == 'contacts') {
  316. formVal = { id, inchargerId: value, ownerId: value }
  317. } else if(queryParameters?.value.key == 'product' || queryParameters?.value.key == 'order') {
  318. formVal = { id, userId: value }
  319. } else {
  320. formVal = { ids: id, inchargerId: value, }
  321. }
  322. requests.post(queryParameters?.value.transferInterface, { ...formVal }).then((res) => {
  323. toastSuccess('转移成功')
  324. onRefresh(true)
  325. showDialog.value = false
  326. })
  327. }
  328. // 认领
  329. function claimAndClaim(item) {
  330. const { id, name, clueName, customName, productName } = item
  331. const { key } = queryParameters.value
  332. const userId = userInfo.userInfo.id
  333. const formVal = {
  334. [key == 'product' ? 'id' : 'ids']: id,
  335. [key == 'product' ? 'userId' : 'inchargerId']: userId
  336. }
  337. showConfirmDialog({
  338. title: `认领${queryParameters.value.name}`,
  339. message: `确定认领【${name || clueName || customName || productName}】${queryParameters.value.name}吗?`,
  340. }).then(() => {
  341. requests.post(queryParameters?.value.transferInterface, { ...formVal }).then((res) => {
  342. toastSuccess('认领成功')
  343. onRefresh(true)
  344. })
  345. })
  346. }
  347. // 删除事件
  348. function deleteRow(row) {
  349. const { name = '', searchFiled = {}, deteleFiled = '' } = queryParameters.value
  350. const foemVal = { [queryParameters.value.key == 'tasks' ? 'taskIds' : queryParameters.value.key == 'contract' ? 'id' : 'ids']: row.id }
  351. showConfirmDialog({
  352. title: `删除${name}`,
  353. message: `确定删除【${row[searchFiled?.search]}】${name}吗?`,
  354. }).then(() => {
  355. requests.post(deteleFiled, { ...foemVal }).then((res) => {
  356. toastSuccess('删除成功')
  357. onRefresh(true)
  358. }).catch((err) => {
  359. toastFail(err.msg ? err.msg : '删除失败')
  360. })
  361. })
  362. }
  363. // 顶置事件
  364. function topMounted(row) {
  365. requests.post(queryParameters?.value.topMountedInterface, { id: row.id }).then((res) => {
  366. toastSuccess('顶置成功')
  367. onRefresh(true)
  368. })
  369. }
  370. function noTopMounted(row) {
  371. requests.post(queryParameters?.value.cancelTheTopMountedInterface, { id: row.id }).then((res) => {
  372. toastSuccess('取消顶置成功')
  373. onRefresh(true)
  374. })
  375. }
  376. function toDetail(item) {
  377. router.navigateTo({
  378. pathName: 'details',
  379. success: () => {
  380. router.emit('detailParameter', {
  381. routerInfo: JSON.stringify(queryParameters.value),
  382. parameter: JSON.stringify(item)
  383. })
  384. }
  385. })
  386. }
  387. function toAddEditor(value) {
  388. router.navigateTo({
  389. pathName: 'addEditor',
  390. success: () => {
  391. router.emit('addEditorParameter', {
  392. routerInfo: JSON.stringify(queryParameters.value),
  393. filedValue: JSON.stringify(value)
  394. })
  395. }
  396. })
  397. }
  398. function onRefresh(flag = false) {
  399. finished.value = false;
  400. isLoading.value = true;
  401. listData.value.pageIndex = 1;
  402. fetchListData(flag);
  403. }
  404. function onLoad() {
  405. isLoading.value = true;
  406. listData.value.pageIndex++
  407. fetchListData()
  408. }
  409. async function fetchListData(flag = false) {
  410. console.log(listData.value.totalPage, listData.value.pageIndex)
  411. if (
  412. // 如果总页数小于等于现页数,并且不是第一次加载, 或者正在加载数据 直接跳出不请求
  413. listData.value.totalPage < listData.value.pageIndex &&
  414. listData.value.pageIndex !== 1
  415. ) {
  416. finished.value = true;
  417. return;
  418. }
  419. const res = await getListData(flag)
  420. if (res.code === 'ok') {
  421. const list = res.data.data || res.data.records || res.data.record
  422. const total = res.data.total
  423. if (refreshing.value) {
  424. refreshing.value = false;
  425. }
  426. isLoading.value = false;
  427. listData.value.records = (
  428. listData.value.pageIndex === 1 ? [] : listData.value.records
  429. ).concat(list || [])
  430. listData.value.totalPage = Math.ceil(total / listData.value.pageSize)
  431. listData.value.total = +total
  432. }
  433. }
  434. async function getListData(flag = false) {
  435. const url = queryParameters.value.listUrl
  436. if (flag) {
  437. loadingList.value = true
  438. }
  439. let formVal = {
  440. pageIndex: listData.value.pageIndex,
  441. pageSize: listData.value.pageSize,
  442. pageFrom: listData.value.pageSize,
  443. [queryParameters.value?.searchFiled?.search]: searchVal.value,
  444. }
  445. const res = await requests.post(url, { ...formVal }).finally(() => {
  446. if (flag) {
  447. loadingList.value = false
  448. }
  449. })
  450. return res
  451. }
  452. function reloadListData(data) {
  453. queryParameters.value = JSON.parse(data.row || '{}')
  454. refreshing.value = false
  455. isLoading.value = false
  456. finished.value = false
  457. searchVal.value = ''
  458. listData.value = { records: [], pageIndex: 0, pageSize: 20, total: 0, totalPage: 0 }
  459. popUpWindowArray.value = popUpWindowArray.value.filter(item => !item.removeModule.includes(queryParameters.value?.key))
  460. if (!fixedData.formJson[queryParameters.value.key]) {
  461. getFormJson(queryParameters.value)
  462. }
  463. onLoad()
  464. }
  465. function getFormJson(info = {}) {
  466. requests.get(`${GET_CUSTOM_FORM_JSON}/${info.key}`).then(res => {
  467. const { data = [] } = res
  468. fixedData.updateState({
  469. formJson: {
  470. ...fixedData.formJson,
  471. [info.key]: JSON.parse(data[0].config)
  472. }
  473. })
  474. })
  475. }
  476. function selectChange(value, label) {
  477. dialogSelection.value = {
  478. value, label
  479. }
  480. showSelect.value = false
  481. }
  482. function dialogCloseBefo(val) {
  483. if (val == 'confirm' && showDialog.value) {
  484. return false
  485. }
  486. return true
  487. }
  488. function chuliReloadListData(data) {
  489. clearTimeout(timeout.value);
  490. timeout.value = setTimeout(() => {
  491. reloadListData(data)
  492. }, 100);
  493. }
  494. function chuliOnRefresh(data) {
  495. clearTimeout(timeout.value);
  496. timeout.value = setTimeout(() => {
  497. onRefresh(true)
  498. }, 100);
  499. }
  500. useLifecycle({
  501. load: () => {
  502. chuliOnRefresh(true)
  503. router.on('moduleListDetailParameter', (data) => {
  504. chuliReloadListData(data)
  505. })
  506. router.eventOn('moduleListRefreshData', (data) => {
  507. chuliOnRefresh(true)
  508. })
  509. }
  510. });
  511. </script>
  512. <style lang='scss' scoped>
  513. .buttonCircle {
  514. width: 37px;
  515. height: 37px;
  516. margin-left: 10px;
  517. &:last-child {
  518. margin-right: 10px;
  519. }
  520. }
  521. .addButton {
  522. width: 60px;
  523. height: 60px;
  524. }
  525. .listContent {
  526. border: 1px solid #F6F6FA;
  527. .listOfImages {
  528. width: 40px;
  529. height: 40px;
  530. margin-right: 10px;
  531. }
  532. }
  533. .headerModeuleList :deep(.van-search__content) {
  534. background: #fff !im\portant;
  535. height: 42px;
  536. align-items: center;
  537. border-radius: 6px;
  538. }
  539. </style>