moduleList.vue 22 KB

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