index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="m-4 modals">
  3. <div>
  4. <XTTitle title="水处理设备" :right-data="titleData" @click="callTitleClick" />
  5. <div class="flex items-center justify-between my-4">
  6. <div />
  7. <XTForm :form-data="formData" @change="callForm" />
  8. </div>
  9. </div>
  10. <BasicTable @register="registerTable">
  11. <template #bodyCell="{ column, record }">
  12. <template v-if="column.key === 'purchaseDate'">
  13. <span> {{ dayjs(record.purchaseDate).format('YYYY-MM-DD') }}</span>
  14. </template>
  15. <template v-if="column.key === 'useDate'">
  16. <span> {{ record.useDate ? dayjs(record.useDate).format('YYYY-MM-DD') : '' }}</span>
  17. </template>
  18. <template v-if="column.key === 'produceDate'">
  19. <span> {{ dayjs(record.produceDate).format('YYYY-MM-DD') }}</span>
  20. </template>
  21. <template v-if="column.key === 'name'">
  22. <a @click="goDetail(record)">{{ record.name }}</a>
  23. </template>
  24. <template v-if="column.key === 'action'">
  25. <TableAction
  26. :actions="[
  27. {
  28. label: '编辑',
  29. auth: 'biz:consumable:edit',
  30. tooltip: '编辑',
  31. onClick: handleEdit.bind(null, record),
  32. },
  33. {
  34. label: '维修',
  35. auth: 'biz:consumable:edit',
  36. tooltip: '维修',
  37. onClick: handleMaintenance.bind(null, record),
  38. },
  39. {
  40. label: '保养',
  41. auth: 'biz:consumable:edit',
  42. tooltip: '保养',
  43. onClick: handleUpkeep.bind(null, record),
  44. },
  45. ]"
  46. />
  47. </template>
  48. </template>
  49. </BasicTable>
  50. <FormModal @register="registerModal" @success="callSuccess" @cancel="handleCancel" />
  51. <MaintenanceFormModal
  52. @register="registerMaintenanceModal"
  53. @success="callSuccess"
  54. @cancel="handleCancel"
  55. />
  56. <UpkeepFormModal
  57. @register="registerUpkeepModal"
  58. @success="callSuccess"
  59. @cancel="handleCancel"
  60. />
  61. </div>
  62. </template>
  63. <script lang="ts" setup>
  64. import { onBeforeMount, ref } from 'vue';
  65. import { BasicTable, useTable, TableAction } from '/@/components/TableCard';
  66. import FormModal from './formModal.vue';
  67. import MaintenanceFormModal from './maintenanceFormModal.vue';
  68. import UpkeepFormModal from './upkeepFormModal.vue';
  69. import { columns } from './data';
  70. import { waterQueryPage } from '/@/api/biz/engineer/waterApi';
  71. import { listDictModel } from '/@/api/common';
  72. import { useModal } from '/@/components/Modal';
  73. import { XTTitle } from '/@/components/XTTitle/index';
  74. import { XTForm } from '/@/components/XTForm/index';
  75. import { useRouter } from 'vue-router';
  76. import dayjs from 'dayjs';
  77. // 路由跳转
  78. const router = useRouter();
  79. // 标题数据
  80. const titleData = [
  81. {
  82. type: 'add',
  83. btnIcon: 'icon-xt-add_default',
  84. auth: ['biz:consumable:add'],
  85. btnText: '新增设备',
  86. },
  87. ];
  88. // formdata
  89. const formData = [
  90. {
  91. name: 'searchNames',
  92. componentType: 'Input',
  93. prefix: 'icon-xt-search',
  94. placeholder: '请输入设备编号',
  95. width: 240,
  96. },
  97. ];
  98. // 操作名称
  99. const searchNames = ref('');
  100. const shiftDate = ref([]);
  101. const responsesupplierCategoryOptions = ref();
  102. onBeforeMount(async () => {
  103. responsesupplierCategoryOptions.value = await listDictModel({ dictCode: 'pht' });
  104. });
  105. const [registerModal, { openModal }] = useModal();
  106. const [registerMaintenanceModal, { openModal: openMaintenanceModal }] = useModal();
  107. const [registerUpkeepModal, { openModal: openUpkeepModal }] = useModal();
  108. const tableSort = ref([
  109. {
  110. field: 'create_time',
  111. direction: 'DESC',
  112. },
  113. ]) as any;
  114. const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
  115. api: waterQueryPage,
  116. rowKey: 'id',
  117. columns,
  118. showIndexColumn: true,
  119. bordered: true,
  120. actionColumn: {
  121. width: 200,
  122. title: '操作',
  123. dataIndex: 'action',
  124. },
  125. beforeFetch: handleBeforeFetch,
  126. sortFn: handleSortFn,
  127. });
  128. // 详情按钮事件
  129. function handleEdit(record) {
  130. openModal(true, {
  131. record,
  132. isUpdate: true,
  133. });
  134. }
  135. // 新增按钮事件
  136. function callTitleClick(data) {
  137. if (data.type == 'add') {
  138. openModal(true, {
  139. isUpdate: false,
  140. record: data,
  141. });
  142. }
  143. }
  144. // 表格点击字段排序
  145. function handleSortFn(sortInfo) {
  146. if (sortInfo?.order && sortInfo?.columnKey) {
  147. // 默认单列排序
  148. tableSort.value = [
  149. {
  150. field: sortInfo.columnKey,
  151. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  152. },
  153. ];
  154. }
  155. }
  156. // 打开维修弹框
  157. function handleMaintenance(record) {
  158. openMaintenanceModal(true, {
  159. record,
  160. });
  161. }
  162. // 打开保养弹框
  163. function handleUpkeep(record) {
  164. openUpkeepModal(true, {
  165. record,
  166. });
  167. }
  168. // 表格请求之前,对参数进行处理, 添加默认 排序
  169. async function handleBeforeFetch(params) {
  170. return {
  171. ...params,
  172. orders: tableSort.value,
  173. uniqueCode: searchNames.value == '' ? undefined : searchNames.value,
  174. };
  175. }
  176. //取消按钮事件
  177. async function handleCancel() {
  178. clearSelectedRowKeys();
  179. await reload();
  180. }
  181. // 弹窗回调事件
  182. async function callSuccess({ isUpdate, values }) {
  183. console.log(isUpdate);
  184. console.log(values);
  185. await reload();
  186. }
  187. // 查询组件回调
  188. async function callForm(data) {
  189. shiftDate.value = data.shiftDate ? data.shiftDate : '';
  190. searchNames.value = data.searchNames ? data.searchNames : '';
  191. await reload();
  192. }
  193. // 打开详情页面
  194. function goDetail(record) {
  195. console.log('record::', record);
  196. router.push({
  197. path: '/bizEngineer/otherDetail',
  198. query: {
  199. id: record.id,
  200. name: record.name,
  201. },
  202. });
  203. }
  204. </script>
  205. <style lang="less" scoped>
  206. .table-dot {
  207. display: inline-block;
  208. width: 10px;
  209. height: 10px;
  210. margin-right: 6px;
  211. border-radius: 50%;
  212. }
  213. ::v-deep(.ant-input-prefix) {
  214. color: #8a99ac;
  215. }
  216. .colUpdateAvatar {
  217. display: flex;
  218. justify-content: center;
  219. text-align: center;
  220. line-height: 28px;
  221. }
  222. .colImg {
  223. width: 28px;
  224. height: 28px;
  225. margin-right: 5px;
  226. }
  227. </style>