moduleList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 class="text-[#B9B9B9]">
  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. <van-skeleton title :row="20" class="w-full h-full" />
  194. </template>
  195. </div>
  196. </div>
  197. <!-- 可拖拽添加 -->
  198. <DragBox>
  199. <div class="addButton" @click="toAddEditor()" v-permission="[queryParameters?.jurisdiction?.newlyAdded]">
  200. <img src="/src/assets/image/add.png" class="w-full h-full" />
  201. </div>
  202. </DragBox>
  203. <!-- 转移弹窗 -->
  204. <van-dialog v-model:show="showDialog" :title="`转移${queryParameters?.name || ''}`" show-cancel-button
  205. @confirm="confirmTransfer" :before-close="dialogCloseBefo">
  206. <van-cell title="转移至" is-link @click="showSelect = true">
  207. <template #value>
  208. {{ dialogSelection.label }}
  209. </template>
  210. </van-cell>
  211. <div class="themeTextColor text-size-small pl-4 pt-2 pb-2">转移后,将看不到此{{ queryParameters?.name || '' }}</div>
  212. </van-dialog>
  213. <!-- select 选择器 -->
  214. <van-popup v-model:show="showSelect" destroy-on-close position="bottom" :style="{ height: '80%' }">
  215. <PullDownSelector @change="selectChange" />
  216. </van-popup>
  217. </template>
  218. </Page>
  219. </template>
  220. <script setup>
  221. import { ref, onActivated } from 'vue';
  222. import { showConfirmDialog } from 'vant';
  223. import { useLifecycle } from '@hooks/useCommon.js';
  224. import { resetListData, getListFieldKey } from '@components/common/formForm/formCorrespondenceProcessing'
  225. import useShowToast from '@hooks/useToast'
  226. import { GET_CUSTOM_FORM_JSON } from '@hooks/useApi'
  227. import { fixedFieldPaymentStatus, fixedFieldPriority, fixedFieldTaskStatus, fixedFieldStatusArray } from "@utility/defaultData"
  228. import requests from "@common/requests";
  229. import useRouterStore from "@store/useRouterStore.js";
  230. import useFixedData from "@store/useFixedData.js"
  231. import useInfoStore from '@store/useInfoStore'
  232. // import ElementLongPress from "@components/common/elementLongPress.vue";
  233. import DragBox from '@components/common/dragBox.vue';
  234. const TRANSFER = 'transfer';
  235. const DELETE = 'delete';
  236. const EDIT = 'edit';
  237. const TOP_MOUNTED = 'topMounted';
  238. const { toastSuccess, toastFail, toastText } = useShowToast()
  239. const router = useRouterStore()
  240. const fixedData = useFixedData()
  241. const userInfo = useInfoStore()
  242. const searchVal = ref()
  243. const queryParameters = ref({})
  244. const loadingList = ref(false)
  245. const popUpWindowArray = ref([
  246. { text: '转移', event: TRANSFER, icon: '/src/assets/image/transfer.png', removeModule: ['contacts', 'tasks', 'product', 'contract', 'order'] },
  247. { text: '顶置', event: TOP_MOUNTED, icon: '/src/assets/image/topMounted.png', removeModule: [] },
  248. { text: '编辑', event: EDIT, icon: '/src/assets/image/edit.png', removeModule: [] },
  249. { text: '删除', event: DELETE, icon: '/src/assets/image/delete.png', removeModule: [] },
  250. ])
  251. const showSelect = ref(false)
  252. const showDialog = ref(false)
  253. const refreshing = ref(false);
  254. const isLoading = ref(false);
  255. const finished = ref(false);
  256. const listData = ref({
  257. records: [],
  258. pageIndex: 0,
  259. pageSize: 20,
  260. total: 0,
  261. totalPage: 0,
  262. });
  263. const excessiveData = ref({});
  264. const dialogSelection = ref({});
  265. // 按钮触发的事件: row 为当前点击的行数据, item 为当前点击的按钮
  266. function longPress(row, item) {
  267. switch (item.event) {
  268. case EDIT:
  269. edit(row);
  270. break;
  271. case TRANSFER:
  272. transfer(row);
  273. break;
  274. case DELETE:
  275. deleteRow(row);
  276. break;
  277. case TOP_MOUNTED:
  278. topMounted(row);
  279. break;
  280. default:
  281. console.warn('未知的类型', item.event);
  282. break;
  283. }
  284. }
  285. // 编辑事件
  286. function edit(row) {
  287. const formJson = fixedData.formJson[queryParameters.value.key] || []
  288. const formList = resetListData(formJson?.list)
  289. const filedObj = getListFieldKey(formList, row)
  290. let other = {}
  291. if (queryParameters.value.key == 'tasks') {
  292. other = { ...row }
  293. }
  294. toAddEditor({ ...other, ...filedObj, id: row.id })
  295. }
  296. // 转移事件
  297. function transfer(row) {
  298. dialogSelection.value = {}
  299. excessiveData.value = row
  300. showDialog.value = true
  301. }
  302. function confirmTransfer() {
  303. if (!dialogSelection.value.label) {
  304. return toastText('请选择要转移的人员')
  305. }
  306. const { id } = excessiveData.value
  307. const { value } = dialogSelection.value
  308. requests.post(queryParameters?.value.transferInterface, { ids: id, inchargerId: value }).then((res) => {
  309. toastSuccess('转移成功')
  310. onRefresh(true)
  311. showDialog.value = false
  312. })
  313. }
  314. // 认领
  315. function claimAndClaim(item) {
  316. const { id, name, clueName, customName } = item
  317. const userId = userInfo.userInfo.id
  318. showConfirmDialog({
  319. title: `认领${queryParameters.value.name}`,
  320. message: `确定认领【${name || clueName || customName}】${queryParameters.value.name}吗?`,
  321. }).then(() => {
  322. requests.post(queryParameters?.value.transferInterface, { ids: id, inchargerId: userId }).then((res) => {
  323. toastSuccess('认领成功')
  324. onRefresh(true)
  325. })
  326. })
  327. }
  328. // 删除事件
  329. function deleteRow(row) {
  330. const { name = '', searchFiled = {}, deteleFiled = '' } = queryParameters.value
  331. showConfirmDialog({
  332. title: `删除${name}`,
  333. message: `确定删除【${row[searchFiled?.search]}】${name}吗?`,
  334. }).then(() => {
  335. requests.post(deteleFiled, { ids: row.id }).then((res) => {
  336. toastSuccess('删除成功')
  337. onRefresh(true)
  338. }).catch((err) => {
  339. toastFail(err.msg ? err.msg : '删除失败')
  340. })
  341. })
  342. }
  343. // 顶置事件
  344. function topMounted(row) {
  345. requests.post(queryParameters?.value.topMountedInterface, { id: row.id }).then((res) => {
  346. toastSuccess('顶置成功')
  347. onRefresh(true)
  348. })
  349. }
  350. function noTopMounted(row) {
  351. requests.post(queryParameters?.value.cancelTheTopMountedInterface, { id: row.id }).then((res) => {
  352. toastSuccess('取消顶置成功')
  353. onRefresh(true)
  354. })
  355. }
  356. function toDetail(item) {
  357. if (queryParameters.value?.key == 'tasks') {
  358. return
  359. }
  360. router.navigateTo({
  361. pathName: 'details',
  362. success: () => {
  363. router.emit('detailParameter', {
  364. routerInfo: JSON.stringify(queryParameters.value),
  365. parameter: JSON.stringify(item)
  366. })
  367. }
  368. })
  369. }
  370. function toAddEditor(value) {
  371. router.navigateTo({
  372. pathName: 'addEditor',
  373. success: () => {
  374. router.emit('addEditorParameter', {
  375. routerInfo: JSON.stringify(queryParameters.value),
  376. filedValue: JSON.stringify(value)
  377. })
  378. }
  379. })
  380. }
  381. function onRefresh(flag = false) {
  382. finished.value = false;
  383. isLoading.value = true;
  384. listData.value.pageIndex = 1;
  385. fetchListData(flag);
  386. }
  387. function onLoad() {
  388. isLoading.value = true;
  389. listData.value.pageIndex++
  390. fetchListData()
  391. }
  392. async function fetchListData(flag = false) {
  393. console.log(listData.value.totalPage, listData.value.pageIndex)
  394. if (
  395. // 如果总页数小于等于现页数,并且不是第一次加载, 或者正在加载数据 直接跳出不请求
  396. listData.value.totalPage < listData.value.pageIndex &&
  397. listData.value.pageIndex !== 1
  398. ) {
  399. finished.value = true;
  400. return;
  401. }
  402. const res = await getListData(flag)
  403. if (res.code === 'ok') {
  404. const list = res.data.data || res.data.records || res.data.record
  405. const total = res.data.total
  406. if (refreshing.value) {
  407. refreshing.value = false;
  408. }
  409. isLoading.value = false;
  410. listData.value.records = (
  411. listData.value.pageIndex === 1 ? [] : listData.value.records
  412. ).concat(list || [])
  413. listData.value.totalPage = Math.ceil(total / listData.value.pageSize)
  414. listData.value.total = +total
  415. }
  416. }
  417. async function getListData(flag = false) {
  418. const url = queryParameters.value.listUrl
  419. if (flag) {
  420. loadingList.value = true
  421. }
  422. const res = await requests.post(url, {
  423. pageIndex: listData.value.pageIndex,
  424. pageSize: listData.value.pageSize,
  425. pageFrom: listData.value.pageSize,
  426. [queryParameters.value?.searchFiled?.search]: searchVal.value
  427. }).finally(() => {
  428. if (flag) {
  429. loadingList.value = false
  430. }
  431. })
  432. return res
  433. }
  434. function reloadListData(data) {
  435. queryParameters.value = JSON.parse(data.row || '{}')
  436. refreshing.value = false
  437. isLoading.value = false
  438. finished.value = false
  439. searchVal.value = ''
  440. listData.value = { records: [], pageIndex: 0, pageSize: 20, total: 0, totalPage: 0 }
  441. popUpWindowArray.value = popUpWindowArray.value.filter(item => !item.removeModule.includes(queryParameters.value?.key))
  442. if (!fixedData.formJson[queryParameters.value.key]) {
  443. getFormJson(queryParameters.value)
  444. }
  445. onLoad()
  446. }
  447. function getFormJson(info = {}) {
  448. requests.get(`${GET_CUSTOM_FORM_JSON}/${info.key}`).then(res => {
  449. const { data = [] } = res
  450. fixedData.updateState({
  451. formJson: {
  452. ...fixedData.formJson,
  453. [info.key]: JSON.parse(data[0].config)
  454. }
  455. })
  456. })
  457. }
  458. function selectChange(value, label) {
  459. dialogSelection.value = {
  460. value, label
  461. }
  462. showSelect.value = false
  463. }
  464. function dialogCloseBefo(val) {
  465. if (val == 'confirm' && showDialog.value) {
  466. return false
  467. }
  468. return true
  469. }
  470. useLifecycle({
  471. load: () => {
  472. router.on('moduleListDetailParameter', (data) => {
  473. reloadListData(data)
  474. })
  475. router.eventOn('moduleListRefreshData', (data) => {
  476. onRefresh(true)
  477. })
  478. }
  479. });
  480. </script>
  481. <style lang='scss' scoped>
  482. .buttonCircle {
  483. width: 37px;
  484. height: 37px;
  485. margin-left: 10px;
  486. &:last-child {
  487. margin-right: 10px;
  488. }
  489. }
  490. .addButton {
  491. width: 60px;
  492. height: 60px;
  493. }
  494. .listContent {
  495. border: 1px solid #F6F6FA;
  496. .listOfImages {
  497. width: 40px;
  498. height: 40px;
  499. margin-right: 10px;
  500. }
  501. }
  502. .headerModeuleList :deep(.van-search__content) {
  503. background: #fff !im\portant;
  504. height: 42px;
  505. align-items: center;
  506. border-radius: 6px;
  507. }
  508. </style>