index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div>
  3. <div class="flex justify-between mb-4">
  4. <div>
  5. <a-button type="primary" size="large" class="btn-add" @click="handleCreate"
  6. ><template #icon> <Icon icon="icon-xt-add_default|iconfont" /> </template
  7. >新增消毒</a-button
  8. >
  9. </div>
  10. <div>
  11. <XTForm :form-data="formData" @change="callForm" />
  12. </div>
  13. </div>
  14. <BasicTable @register="registerTable">
  15. <template #bodyCell="{ column, record }">
  16. <template v-if="column.key === 'maintainCompany'">
  17. {{ formatDictValue(bizDictOptions.dmc, record.maintainCompany) }}
  18. </template>
  19. <template v-if="column.key === 'picture'">
  20. <Image
  21. v-if="record.files && record.files.length > 0"
  22. :src="record.files[0].absolutePath"
  23. :width="60"
  24. />
  25. </template>
  26. <template v-if="column.key === 'action'">
  27. <TableAction
  28. :actions="[
  29. {
  30. auth: 'archives:patrolWard:edit',
  31. icon: 'icon-xt-details_edit_default|iconfont',
  32. tooltip: '编辑',
  33. onClick: handleEdit.bind(null, record),
  34. },
  35. {
  36. auth: 'archives:patrolWard:remove',
  37. icon: 'icon-xt-details_delete_default|iconfont',
  38. tooltip: '删除',
  39. popConfirm: {
  40. title: '是否取消删除',
  41. placement: 'left',
  42. confirm: handleDelete.bind(null, record, column),
  43. },
  44. },
  45. ]"
  46. />
  47. </template>
  48. </template>
  49. </BasicTable>
  50. <FormModal @register="registerModal" @success="callSuccess" />
  51. </div>
  52. </template>
  53. <script lang="ts" setup>
  54. import { onBeforeMount, onMounted, reactive, ref } from 'vue';
  55. import { XTForm } from '/@/components/XTForm/index';
  56. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  57. import { useMessage } from '/@/hooks/web/useMessage';
  58. import FormModal from './upkeepFormModal.vue';
  59. import Icon from '/@/components/Icon/index';
  60. import { columns } from './data';
  61. import { listDictModelBatch } from '/@/api/common';
  62. import { upkeepQueryPage, upkeepRemove } from '/@/api/biz/engineer/dialysisDeviceApi';
  63. import { useModal } from '/@/components/Modal';
  64. import { Image } from 'ant-design-vue';
  65. import dayjs from 'dayjs';
  66. import { formatDictValue } from '/@/utils';
  67. const props = defineProps({
  68. info: {
  69. type: Object,
  70. default: () => {},
  71. },
  72. });
  73. const { createMessage } = useMessage();
  74. const [registerModal, { openModal }] = useModal();
  75. const tableSort = ref([
  76. {
  77. field: 'create_time',
  78. direction: 'DESC',
  79. },
  80. ]) as any;
  81. const dictsOption = ref([]) as any;
  82. // formdata
  83. const formData = [
  84. {
  85. label: '保养厂商',
  86. name: 'maintainCompany',
  87. componentType: 'Select',
  88. dicts: dictsOption.value,
  89. placeholder: '请选择维修方',
  90. prefix: 'icon-xt-search',
  91. width: 280,
  92. },
  93. {
  94. name: 'patrolTime',
  95. label: '保养时间',
  96. componentType: 'RangePicker',
  97. placeholder: '请选择保养时间',
  98. format: 'YYYY-MM-DD',
  99. valueFormat: 'YYYY-MM-DD',
  100. },
  101. ];
  102. const formValue = reactive({
  103. patrolTime: [],
  104. maintainCompany: '',
  105. });
  106. const [registerTable, { reload }] = useTable({
  107. api: upkeepQueryPage,
  108. rowKey: 'id',
  109. columns,
  110. showIndexColumn: false,
  111. bordered: true,
  112. striped: false,
  113. actionColumn: {
  114. width: 200,
  115. title: '操作',
  116. dataIndex: 'action',
  117. },
  118. beforeFetch: handleBeforeFetch,
  119. sortFn: handleSortFn,
  120. });
  121. const bizDictData = ref([{ key: 'dmc', dictCode: 'dmc' }]);
  122. const bizDictOptions = reactive<any>({});
  123. onBeforeMount(async () => {
  124. const res = await listDictModelBatch(bizDictData.value.map(ele => ele.dictCode));
  125. for (const i in res) {
  126. const filter = bizDictData.value.filter(ele => ele.dictCode == i)[0];
  127. bizDictOptions[filter.key] = res[i];
  128. }
  129. const types = bizDictOptions.dmc;
  130. dictsOption.value.push({
  131. label: '全部',
  132. value: '',
  133. });
  134. types.forEach(item => {
  135. dictsOption.value.push({
  136. label: item.label,
  137. value: item.value,
  138. });
  139. });
  140. });
  141. onMounted(async () => {
  142. // callForm({
  143. // patrolTime: [
  144. // dayjs().subtract(3, 'month').format('YYYY-MM-DD'),
  145. // dayjs().add(1, 'day').format('YYYY-MM-DD'),
  146. // ],
  147. // });
  148. });
  149. // 新增按钮事件
  150. function handleCreate() {
  151. openModal(true, {
  152. isUpdate: false,
  153. record: { id: props.info.id },
  154. });
  155. }
  156. // 编辑按钮事件
  157. function handleEdit(record: Recordable) {
  158. openModal(true, {
  159. record: { id: props.info.id },
  160. upkeepRecord: record,
  161. isUpdate: true,
  162. });
  163. }
  164. // 删除按钮事件
  165. async function handleDelete(record: Recordable) {
  166. await upkeepRemove([record.id]);
  167. createMessage.success('删除成功!');
  168. await reload();
  169. }
  170. // 表格点击字段排序
  171. function handleSortFn(sortInfo) {
  172. if (sortInfo?.order && sortInfo?.columnKey) {
  173. // 默认单列排序
  174. tableSort.value = [
  175. {
  176. field: sortInfo.columnKey,
  177. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  178. },
  179. ];
  180. }
  181. }
  182. // 表格请求之前,对参数进行处理, 添加默认 排序
  183. function handleBeforeFetch(params) {
  184. return {
  185. ...params,
  186. orders: tableSort.value,
  187. deviceId: props.info?.id,
  188. maintainTime:
  189. formValue.patrolTime && formValue.patrolTime.length > 0
  190. ? [
  191. formValue.patrolTime[0],
  192. dayjs(formValue.patrolTime[1]).add(1, 'day').format('YYYY-MM-DD'),
  193. ]
  194. : undefined,
  195. maintainCompany: formValue.maintainCompany,
  196. };
  197. }
  198. // 弹窗回调事件
  199. async function callSuccess() {
  200. await reload();
  201. }
  202. // 查询回调
  203. async function callForm(data) {
  204. formValue.maintainCompany = data.maintainCompany || '';
  205. formValue.patrolTime = data.patrolTime || [];
  206. await reload();
  207. }
  208. </script>
  209. <style lang="less" scoped>
  210. ::v-deep(.ant-btn-link) {
  211. color: rgb(61 65 85 / 100%);
  212. }
  213. ::v-deep(.ant-input) {
  214. border-color: #c2ccd4;
  215. border-radius: 4px;
  216. }
  217. ::v-deep(.ant-input-affix-wrapper) {
  218. border-color: #c2ccd4;
  219. border-radius: 4px;
  220. }
  221. ::v-deep(.ant-picker) {
  222. border-color: #c2ccd4;
  223. border-radius: 4px;
  224. }
  225. ::v-deep(.ant-table-tbody > tr > td) {
  226. border-right: 0 !important;
  227. border-left: 0 !important;
  228. border-bottom: 1px solid #f0f0f0;
  229. }
  230. ::v-deep(.ant-table-wrapper table) {
  231. border: 0;
  232. }
  233. ::v-deep(.ant-table-cell-fix-right-first::after, .ant-table-cell-fix-right-last::after) {
  234. content: '';
  235. top: auto;
  236. width: 0;
  237. }
  238. .btn-add {
  239. width: 120px;
  240. border-radius: 4px;
  241. }
  242. </style>