index.vue 7.0 KB

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