moduleList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 :class="`${item.needPin ? 'bg-slate-50' : 'bg-white'} px-5 py-5 flex items-center flex-row w-full listContent`">
  22. <div class="listOfImages items-justify-center rounded-full overflow-hidden bg-[#FFEEEC]">
  23. <img :src="queryParameters.homeImage" class="w-full h-full">
  24. </div>
  25. <div class="flex-1 h-full">
  26. <!-- 商机 -->
  27. <template v-if="queryParameters?.key == 'business'">{{ item.name }}</template>
  28. <!-- 线索 -->
  29. <template v-if="queryParameters?.key == 'thread'">{{ item.clueName }}</template>
  30. <!-- 客户 -->
  31. <template v-if="queryParameters?.key == 'customer'">{{ item.customName }}</template>
  32. <!-- 联系人 -->
  33. <template v-if="queryParameters?.key == 'contacts'">{{ item.name }}</template>
  34. <!-- 任务 -->
  35. <template v-if="queryParameters?.key == 'tasks'">{{ item.taskName }}</template>
  36. <!-- 产品 -->
  37. <template v-if="queryParameters?.key == 'product'">{{ item.productName }}</template>
  38. <!-- 合同 -->
  39. <template v-if="queryParameters?.key == 'contract'">{{ item.name }}</template>
  40. <!-- 销售 -->
  41. <template v-if="queryParameters?.key == 'order'">{{ item.orderName }}</template>
  42. </div>
  43. </div>
  44. <template #right>
  45. <div class="flex items-center h-full bg-white">
  46. <template v-if="!item.inchargerName">
  47. <div class="buttonCircle rounded-full" @click="claimAndClaim(item)" v-if="['business', 'thread',
  48. 'customer'].includes(queryParameters?.key)">
  49. <img src="/src/assets/image/claimAndClaim.png" class="w-full h-full">
  50. </div>
  51. </template>
  52. <template v-if="item.inchargerName || item.ownerName">
  53. <div class="buttonCircle rounded-full" @click="transfer(item)" v-if="['business', 'thread',
  54. 'customer', 'contacts'].includes(queryParameters?.key)">
  55. <img src="/src/assets/image/transfer.png" class="w-full h-full">
  56. </div>
  57. </template>
  58. <template v-if="!item.needPin">
  59. <div class="buttonCircle rounded-full" @click="topMounted(item)">
  60. <img src="/src/assets/image/topMounted.png" class="w-full h-full">
  61. </div>
  62. </template>
  63. <template v-if="item.needPin">
  64. <div class="buttonCircle rounded-full" @click="noTopMounted(item)">
  65. <img src="/src/assets/image/noTopMounted.png" class="w-full h-full">
  66. </div>
  67. </template>
  68. <div class="buttonCircle rounded-full" @click="edit(item)">
  69. <img src="/src/assets/image/edit.png" class="w-full h-full">
  70. </div>
  71. <div class="buttonCircle rounded-full" @click="deleteRow(item)">
  72. <img src="/src/assets/image/delete.png" class="w-full h-full">
  73. </div>
  74. </div>
  75. </template>
  76. </van-swipe-cell>
  77. </div>
  78. </van-list>
  79. </van-pull-refresh>
  80. </template>
  81. <template v-else>
  82. <van-skeleton title :row="20" class="w-full h-full" />
  83. </template>
  84. </div>
  85. </div>
  86. <!-- 可拖拽添加 -->
  87. <DragBox>
  88. <div class="addButton" @click="toAddEditor()">
  89. <img src="/src/assets/image/add.png" class="w-full h-full" />
  90. </div>
  91. </DragBox>
  92. <!-- 转移弹窗 -->
  93. <van-dialog v-model:show="showDialog" :title="`转移${queryParameters?.name || ''}`" show-cancel-button
  94. @confirm="confirmTransfer" :before-close="dialogCloseBefo">
  95. <van-cell title="转移至" is-link @click="showSelect = true">
  96. <template #value>
  97. {{ dialogSelection.label }}
  98. </template>
  99. </van-cell>
  100. <div class="themeTextColor text-size-small pl-4 pt-2 pb-2">转移后,将看不到此{{ queryParameters?.name || '' }}</div>
  101. </van-dialog>
  102. <!-- select 选择器 -->
  103. <van-popup v-model:show="showSelect" destroy-on-close position="bottom" :style="{ height: '80%' }">
  104. <PullDownSelector @change="selectChange" />
  105. </van-popup>
  106. </template>
  107. </Page>
  108. </template>
  109. <script setup>
  110. import { ref, onActivated } from 'vue';
  111. import { showConfirmDialog } from 'vant';
  112. import { useLifecycle } from '@hooks/useCommon.js';
  113. import { resetListData, getListFieldKey } from '@components/common/formForm/formCorrespondenceProcessing'
  114. import useShowToast from '@hooks/useToast'
  115. import { GET_CUSTOM_FORM_JSON } from '@hooks/useApi'
  116. import requests from "@common/requests";
  117. import useRouterStore from "@store/useRouterStore.js";
  118. import useFixedData from "@store/useFixedData.js"
  119. import useInfoStore from '@store/useInfoStore'
  120. // import ElementLongPress from "@components/common/elementLongPress.vue";
  121. import DragBox from '@components/common/dragBox.vue';
  122. const TRANSFER = 'transfer';
  123. const DELETE = 'delete';
  124. const EDIT = 'edit';
  125. const TOP_MOUNTED = 'topMounted';
  126. const { toastSuccess, toastFail, toastText } = useShowToast()
  127. const router = useRouterStore()
  128. const fixedData = useFixedData()
  129. const userInfo = useInfoStore()
  130. const searchVal = ref()
  131. const queryParameters = ref({})
  132. const loadingList = ref(false)
  133. const popUpWindowArray = ref([
  134. { text: '转移', event: TRANSFER, icon: '/src/assets/image/transfer.png', removeModule: ['contacts', 'tasks', 'product', 'contract', 'order'] },
  135. { text: '顶置', event: TOP_MOUNTED, icon: '/src/assets/image/topMounted.png', removeModule: [] },
  136. { text: '编辑', event: EDIT, icon: '/src/assets/image/edit.png', removeModule: [] },
  137. { text: '删除', event: DELETE, icon: '/src/assets/image/delete.png', removeModule: [] },
  138. ])
  139. const showSelect = ref(false)
  140. const showDialog = ref(false)
  141. const refreshing = ref(false);
  142. const isLoading = ref(false);
  143. const finished = ref(false);
  144. const listData = ref({
  145. records: [],
  146. pageIndex: 0,
  147. pageSize: 20,
  148. total: 0,
  149. totalPage: 0,
  150. });
  151. const excessiveData = ref({});
  152. const dialogSelection = ref({});
  153. // 按钮触发的事件: row 为当前点击的行数据, item 为当前点击的按钮
  154. function longPress(row, item) {
  155. switch (item.event) {
  156. case EDIT:
  157. edit(row);
  158. break;
  159. case TRANSFER:
  160. transfer(row);
  161. break;
  162. case DELETE:
  163. deleteRow(row);
  164. break;
  165. case TOP_MOUNTED:
  166. topMounted(row);
  167. break;
  168. default:
  169. console.warn('未知的类型', item.event);
  170. break;
  171. }
  172. }
  173. // 编辑事件
  174. function edit(row) {
  175. const formJson = fixedData.formJson[queryParameters.value.key] || []
  176. const formList = resetListData(formJson?.list)
  177. const filedObj = getListFieldKey(formList, row)
  178. let other = {}
  179. if (queryParameters.value.key == 'tasks') {
  180. other = { ...row }
  181. }
  182. toAddEditor({ ...other, ...filedObj, id: row.id })
  183. }
  184. // 转移事件
  185. function transfer(row) {
  186. dialogSelection.value = {}
  187. excessiveData.value = row
  188. showDialog.value = true
  189. }
  190. function confirmTransfer() {
  191. if (!dialogSelection.value.label) {
  192. return toastText('请选择要转移的人员')
  193. }
  194. const { id } = excessiveData.value
  195. const { value } = dialogSelection.value
  196. requests.post(queryParameters?.value.transferInterface, { ids: id, inchargerId: value }).then((res) => {
  197. toastSuccess('转移成功')
  198. onRefresh(true)
  199. showDialog.value = false
  200. })
  201. }
  202. // 认领
  203. function claimAndClaim(item) {
  204. const { id, name, clueName, customName } = item
  205. const userId = userInfo.userInfo.id
  206. showConfirmDialog({
  207. title: `认领${queryParameters.value.name}`,
  208. message: `确定认领【${name || clueName || customName}】${queryParameters.value.name}吗?`,
  209. }).then(() => {
  210. requests.post(queryParameters?.value.transferInterface, { ids: id, inchargerId: userId }).then((res) => {
  211. toastSuccess('认领成功')
  212. onRefresh(true)
  213. })
  214. })
  215. }
  216. // 删除事件
  217. function deleteRow(row) {
  218. const { name = '', searchFiled = {}, deteleFiled = '' } = queryParameters.value
  219. showConfirmDialog({
  220. title: `删除${name}`,
  221. message: `确定删除【${row[searchFiled?.search]}】${name}吗?`,
  222. }).then(() => {
  223. requests.post(deteleFiled, { ids: row.id }).then((res) => {
  224. toastSuccess('删除成功')
  225. onRefresh(true)
  226. }).catch((err) => {
  227. toastFail(err.msg ? err.msg : '删除失败')
  228. })
  229. })
  230. }
  231. // 顶置事件
  232. function topMounted(row) {
  233. requests.post(queryParameters?.value.topMountedInterface, { ids: row.id }).then((res) => {
  234. toastSuccess('顶置成功')
  235. onRefresh(true)
  236. })
  237. }
  238. function noTopMounted(row) {
  239. requests.post(queryParameters?.value.cancelTheTopMountedInterface, { ids: row.id }).then((res) => {
  240. toastSuccess('取消顶置成功')
  241. onRefresh(true)
  242. })
  243. }
  244. function toDetail(item) {
  245. router.navigateTo({
  246. pathName: 'details',
  247. success: () => {
  248. router.emit('detailParameter', {
  249. routerInfo: JSON.stringify(queryParameters.value),
  250. parameter: JSON.stringify(item)
  251. })
  252. }
  253. })
  254. }
  255. function toAddEditor(value) {
  256. router.navigateTo({
  257. pathName: 'addEditor',
  258. success: () => {
  259. router.emit('addEditorParameter', {
  260. routerInfo: JSON.stringify(queryParameters.value),
  261. filedValue: JSON.stringify(value)
  262. })
  263. }
  264. })
  265. }
  266. function onRefresh(flag = false) {
  267. finished.value = false;
  268. isLoading.value = true;
  269. listData.value.pageIndex = 1;
  270. fetchListData(flag);
  271. }
  272. function onLoad() {
  273. isLoading.value = true;
  274. listData.value.pageIndex++
  275. fetchListData()
  276. }
  277. async function fetchListData(flag = false) {
  278. console.log(listData.value.totalPage, listData.value.pageIndex)
  279. if (
  280. // 如果总页数小于等于现页数,并且不是第一次加载, 或者正在加载数据 直接跳出不请求
  281. listData.value.totalPage < listData.value.pageIndex &&
  282. listData.value.pageIndex !== 1
  283. ) {
  284. finished.value = true;
  285. return;
  286. }
  287. const res = await getListData(flag)
  288. if (res.code === 'ok') {
  289. const list = res.data.data || res.data.records || res.data.record
  290. const total = res.data.total
  291. if (refreshing.value) {
  292. refreshing.value = false;
  293. }
  294. isLoading.value = false;
  295. listData.value.records = (
  296. listData.value.pageIndex === 1 ? [] : listData.value.records
  297. ).concat(list || [])
  298. listData.value.totalPage = Math.ceil(total / listData.value.pageSize)
  299. listData.value.total = +total
  300. }
  301. }
  302. async function getListData(flag = false) {
  303. const url = queryParameters.value.listUrl
  304. if (flag) {
  305. loadingList.value = true
  306. }
  307. const res = await requests.post(url, {
  308. pageIndex: listData.value.pageIndex,
  309. pageSize: listData.value.pageSize,
  310. pageFrom: listData.value.pageSize,
  311. [queryParameters.value?.searchFiled?.search]: searchVal.value
  312. }).finally(() => {
  313. if (flag) {
  314. loadingList.value = false
  315. }
  316. })
  317. return res
  318. }
  319. function reloadListData(data) {
  320. queryParameters.value = JSON.parse(data.row || '{}')
  321. refreshing.value = false
  322. isLoading.value = false
  323. finished.value = false
  324. listData.value = { records: [], pageIndex: 0, pageSize: 20, total: 0, totalPage: 0 }
  325. popUpWindowArray.value = popUpWindowArray.value.filter(item => !item.removeModule.includes(queryParameters.value?.key))
  326. if (!fixedData.formJson[queryParameters.value.key]) {
  327. getFormJson(queryParameters.value)
  328. }
  329. onLoad()
  330. }
  331. function getFormJson(info = {}) {
  332. requests.get(`${GET_CUSTOM_FORM_JSON}/${info.key}`).then(res => {
  333. const { data = [] } = res
  334. fixedData.updateState({
  335. formJson: {
  336. ...fixedData.formJson,
  337. [info.key]: JSON.parse(data[0].config)
  338. }
  339. })
  340. })
  341. }
  342. function selectChange(value, label) {
  343. dialogSelection.value = {
  344. value, label
  345. }
  346. showSelect.value = false
  347. }
  348. function dialogCloseBefo(val) {
  349. if (val == 'confirm' && showDialog.value) {
  350. return false
  351. }
  352. return true
  353. }
  354. useLifecycle({
  355. load: () => {
  356. router.on('moduleListDetailParameter', (data) => {
  357. reloadListData(data)
  358. })
  359. }
  360. });
  361. </script>
  362. <style lang='scss' scoped>
  363. .buttonCircle {
  364. width: 37px;
  365. height: 37px;
  366. margin-left: 10px;
  367. &:last-child {
  368. margin-right: 10px;
  369. }
  370. }
  371. .addButton {
  372. width: 60px;
  373. height: 60px;
  374. }
  375. .listContent {
  376. border: 1px solid #F6F6FA;
  377. .listOfImages {
  378. width: 40px;
  379. height: 40px;
  380. margin-right: 10px;
  381. }
  382. }
  383. .headerModeuleList :deep(.van-search__content) {
  384. background: #fff !im\portant;
  385. height: 42px;
  386. align-items: center;
  387. border-radius: 6px;
  388. }
  389. </style>