index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. <XTTab
  7. type="illness"
  8. :width="180"
  9. :selected="tabSelected"
  10. :data="typeOptions"
  11. @item-click="callTab"
  12. />
  13. <XTForm :form-data="formData" @change="callForm" />
  14. </div>
  15. </div>
  16. <BasicTable @register="registerTable">
  17. <template #bodyCell="{ column, record }">
  18. <template v-if="column.key === 'disable'">
  19. <span
  20. :class="['table-dot']"
  21. :style="{ backgroundColor: formatDictPreColor(responseTypeOptions, record.disable) }"
  22. />
  23. <span> {{ formatDictValue(responseTypeOptions, record.disable) }}</span>
  24. </template>
  25. <template v-if="column.key === 'supplierCategory'">
  26. <span>
  27. {{ formatDictValue(responsesupplierCategoryOptions, record.supplierCategory) }}</span
  28. >
  29. </template>
  30. <template v-if="column.key === 'action'">
  31. <TableAction
  32. :actions="[
  33. {
  34. auth: 'biz:consumable:edit',
  35. icon: 'icon-xt-details_edit_default|iconfont',
  36. tooltip: '编辑',
  37. onClick: handleEdit.bind(null, record),
  38. },
  39. {
  40. auth: 'biz:consumable:updateStatus',
  41. icon: 'icon-tingyong-moren|iconfont',
  42. tooltip: '停用',
  43. ifShow: record.disable === 0,
  44. popConfirm: {
  45. title: '是否确认停用',
  46. placement: 'left',
  47. confirm: handleDelete.bind(null, record),
  48. },
  49. },
  50. {
  51. auth: 'biz:consumable:updateStatus',
  52. icon: 'icon-xt-revocation_default|iconfont',
  53. tooltip: '启用',
  54. ifShow: record.disable === 1,
  55. popConfirm: {
  56. title: '是否确认启用',
  57. placement: 'left',
  58. confirm: handleDelete.bind(null, record),
  59. },
  60. },
  61. ]"
  62. />
  63. </template>
  64. </template>
  65. </BasicTable>
  66. <FormModal @register="registerModal" @success="callSuccess" @cancel="handleCancel" />
  67. <ImportModal @register="registerImpModal" />
  68. </div>
  69. </template>
  70. <script lang="ts" setup>
  71. import { onBeforeMount, ref } from 'vue';
  72. import { BasicTable, useTable, TableAction } from '/@/components/TableCard';
  73. import { useMessage } from '/@/hooks/web/useMessage';
  74. import FormModal from './formModal.vue';
  75. import { ImportModal } from '/@/components/XTImport/index';
  76. import { formatDictValue, formatDictPreColor } from '/@/utils';
  77. import { columns } from './data';
  78. import {
  79. getsuppliesList,
  80. suppliesDel,
  81. getStatusNumber,
  82. suppliesExport,
  83. suppliesImportBatch,
  84. } from '/@/api/biz/inventory/suppliesApi';
  85. import { listDictModel } from '/@/api/common';
  86. import { useModal } from '/@/components/Modal';
  87. import { XTTitle } from '/@/components/XTTitle/index';
  88. import { XTTab } from '/@/components/XTTab/index';
  89. import { XTForm } from '/@/components/XTForm/index';
  90. // 标题数据
  91. const titleData = [
  92. {
  93. type: 'print',
  94. icon: 'icon-xt-print_default',
  95. },
  96. {
  97. type: 'import',
  98. auth: ['archives:consumable:import'],
  99. icon: 'icon-xt-import_default',
  100. },
  101. {
  102. type: 'add',
  103. btnIcon: 'icon-xt-add_default',
  104. auth: ['biz:consumable:add'],
  105. btnText: '新增耗材',
  106. },
  107. ];
  108. // formdata
  109. const formData = [
  110. {
  111. name: 'shiftDate',
  112. componentType: 'RangePicker',
  113. format: 'YYYY-MM-DD',
  114. valueFormat: 'YYYY-MM-DD',
  115. placeholder: '请选择日期',
  116. width: 240,
  117. },
  118. {
  119. name: 'searchNames',
  120. componentType: 'Input',
  121. prefix: 'icon-xt-search',
  122. placeholder: '请输入耗材名称',
  123. width: 240,
  124. },
  125. ];
  126. // tab 切换选中
  127. const tabSelected = ref();
  128. // 操作名称
  129. const searchNames = ref('');
  130. const shiftDate = ref([]);
  131. const typeOptions = ref();
  132. const responseTypeOptions = ref();
  133. const responsesupplierCategoryOptions = ref();
  134. onBeforeMount(async () => {
  135. responseTypeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  136. responsesupplierCategoryOptions.value = await listDictModel({ dictCode: 'pht' });
  137. getTab();
  138. });
  139. const { createMessage } = useMessage();
  140. const [registerModal, { openModal }] = useModal();
  141. const [registerImpModal, { openModal: openImpModal }] = useModal();
  142. const tableSort = ref([
  143. {
  144. field: 'create_time',
  145. direction: 'DESC',
  146. },
  147. ]) as any;
  148. const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
  149. api: getsuppliesList,
  150. batchDelApi: suppliesDel,
  151. // batchExportApi: suppliesExport,
  152. delAuthList: ['biz:consumable:remove'],
  153. rowKey: 'id',
  154. columns,
  155. showIndexColumn: true,
  156. bordered: true,
  157. actionColumn: {
  158. width: 200,
  159. title: '操作',
  160. dataIndex: 'action',
  161. },
  162. beforeFetch: handleBeforeFetch,
  163. sortFn: handleSortFn,
  164. });
  165. // 详情按钮事件
  166. function handleEdit(record) {
  167. openModal(true, {
  168. record,
  169. isUpdate: true,
  170. });
  171. }
  172. // 新增按钮事件
  173. function callTitleClick(data) {
  174. if (data.type == 'add') {
  175. openModal(true, {
  176. isUpdate: false,
  177. record: data,
  178. });
  179. } else if (data.type == 'print') {
  180. console.log('打印中...');
  181. } else if (data.type == 'import') {
  182. openImpModal(true, {
  183. title: '导入耗材数据',
  184. importUrl: suppliesImportBatch,
  185. exportUrl: suppliesExport,
  186. });
  187. }
  188. }
  189. // 删除按钮事件
  190. async function handleDelete(record: Recordable) {
  191. if (record) {
  192. await suppliesDel(record.id);
  193. createMessage.success('停用成功!');
  194. clearSelectedRowKeys();
  195. await reload();
  196. await getTab();
  197. }
  198. }
  199. // 表格点击字段排序
  200. function handleSortFn(sortInfo) {
  201. if (sortInfo?.order && sortInfo?.columnKey) {
  202. // 默认单列排序
  203. tableSort.value = [
  204. {
  205. field: sortInfo.columnKey,
  206. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  207. },
  208. ];
  209. }
  210. }
  211. // 表格请求之前,对参数进行处理, 添加默认 排序
  212. async function handleBeforeFetch(params) {
  213. console.log('searchNames:::', searchNames.value);
  214. return {
  215. ...params,
  216. orders: tableSort.value,
  217. name: searchNames.value == '' ? undefined : searchNames.value,
  218. status: tabSelected.value == '' ? undefined : tabSelected.value,
  219. time: shiftDate.value.length <= 0 ? undefined : shiftDate.value,
  220. };
  221. }
  222. async function getTab() {
  223. typeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  224. const typeNums = await getStatusNumber(); // 获取各类型数量
  225. let typeList = [];
  226. typeOptions.value.forEach(ele => {
  227. // 变量各类型放置对应数量
  228. let typeData = {};
  229. Object.keys(typeNums).forEach(numKey => {
  230. if (ele.value == numKey) {
  231. typeData = {
  232. key: ele.value,
  233. label: ele.label,
  234. value: typeNums[numKey],
  235. hasValue: true,
  236. prefixColor: ele.prefixColor,
  237. hasBracket: true,
  238. };
  239. typeList.push(typeData);
  240. }
  241. });
  242. });
  243. typeList = typeList.reverse();
  244. typeList.splice(0, 0, {
  245. key: '',
  246. label: '全部',
  247. value: typeNums.total,
  248. hasValue: true,
  249. hasBracket: true,
  250. });
  251. typeOptions.value = typeList;
  252. tabSelected.value = typeOptions.value[0].key;
  253. }
  254. //取消按钮事件
  255. async function handleCancel() {
  256. clearSelectedRowKeys();
  257. await reload();
  258. await getTab();
  259. }
  260. // 弹窗回调事件
  261. async function callSuccess({ isUpdate, values }) {
  262. console.log(isUpdate);
  263. console.log(values);
  264. await reload();
  265. await getTab();
  266. }
  267. // 选项卡组件回调
  268. async function callTab(data) {
  269. tabSelected.value = data.value;
  270. await reload();
  271. }
  272. // 查询组件回调
  273. async function callForm(data) {
  274. shiftDate.value = data.shiftDate ? data.shiftDate : '';
  275. searchNames.value = data.searchNames ? data.searchNames : '';
  276. console.log('callForm:::', searchNames.value);
  277. await reload();
  278. }
  279. </script>
  280. <style lang="less" scoped>
  281. .table-dot {
  282. display: inline-block;
  283. width: 10px;
  284. height: 10px;
  285. margin-right: 6px;
  286. border-radius: 50%;
  287. }
  288. ::v-deep(.ant-btn-link) {
  289. color: #3d4155;
  290. }
  291. ::v-deep(.ant-input-prefix) {
  292. color: #8a99ac;
  293. }
  294. .colUpdateAvatar {
  295. display: flex;
  296. justify-content: center;
  297. text-align: center;
  298. line-height: 28px;
  299. }
  300. .colImg {
  301. width: 28px;
  302. height: 28px;
  303. margin-right: 5px;
  304. }
  305. </style>