moduleList.vue 23 KB

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