index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. import dayjs from 'dayjs';
  91. // 标题数据
  92. const titleData = [
  93. {
  94. type: 'print',
  95. icon: 'icon-xt-print_default',
  96. },
  97. {
  98. type: 'import',
  99. auth: ['archives:consumable:import'],
  100. icon: 'icon-xt-import_default',
  101. },
  102. {
  103. type: 'add',
  104. btnIcon: 'icon-xt-add_default',
  105. auth: ['biz:consumable:add'],
  106. btnText: '新增耗材',
  107. },
  108. ];
  109. // formdata
  110. const formData = [
  111. {
  112. name: 'shiftDate',
  113. componentType: 'RangePicker',
  114. format: 'YYYY-MM-DD',
  115. valueFormat: 'YYYY-MM-DD',
  116. placeholder: '请选择日期',
  117. width: 240,
  118. },
  119. {
  120. name: 'searchNames',
  121. componentType: 'Input',
  122. prefix: 'icon-xt-search',
  123. placeholder: '请输入助记码',
  124. width: 240,
  125. },
  126. ];
  127. // tab 切换选中
  128. const tabSelected = ref();
  129. // 操作名称
  130. const searchNames = ref('');
  131. const shiftDate = ref([]);
  132. const typeOptions = ref();
  133. const responseTypeOptions = ref();
  134. const responsesupplierCategoryOptions = ref();
  135. onBeforeMount(async () => {
  136. responseTypeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  137. responsesupplierCategoryOptions.value = await listDictModel({ dictCode: 'pht' });
  138. getTab();
  139. });
  140. const { createMessage } = useMessage();
  141. const [registerModal, { openModal }] = useModal();
  142. const [registerImpModal, { openModal: openImpModal }] = useModal();
  143. const tableSort = ref([
  144. {
  145. field: 'create_time',
  146. direction: 'DESC',
  147. },
  148. ]) as any;
  149. const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
  150. api: getsuppliesList,
  151. batchDelApi: suppliesDel,
  152. // batchExportApi: suppliesExport,
  153. delAuthList: ['biz:consumable:remove'],
  154. rowKey: 'id',
  155. columns,
  156. showIndexColumn: true,
  157. bordered: true,
  158. actionColumn: {
  159. width: 200,
  160. title: '操作',
  161. dataIndex: 'action',
  162. },
  163. beforeFetch: handleBeforeFetch,
  164. sortFn: handleSortFn,
  165. });
  166. // 详情按钮事件
  167. function handleEdit(record) {
  168. openModal(true, {
  169. record,
  170. isUpdate: true,
  171. });
  172. }
  173. // 新增按钮事件
  174. function callTitleClick(data) {
  175. if (data.type == 'add') {
  176. openModal(true, {
  177. isUpdate: false,
  178. record: data,
  179. });
  180. } else if (data.type == 'print') {
  181. console.log('打印中...');
  182. } else if (data.type == 'import') {
  183. openImpModal(true, {
  184. title: '导入耗材数据',
  185. importUrl: suppliesImportBatch,
  186. exportUrl: suppliesExport,
  187. });
  188. }
  189. }
  190. // 删除按钮事件
  191. async function handleDelete(record: Recordable) {
  192. if (record) {
  193. await suppliesDel(record.id);
  194. createMessage.success('停用成功!');
  195. clearSelectedRowKeys();
  196. await reload();
  197. await getTab();
  198. }
  199. }
  200. // 表格点击字段排序
  201. function handleSortFn(sortInfo) {
  202. if (sortInfo?.order && sortInfo?.columnKey) {
  203. // 默认单列排序
  204. tableSort.value = [
  205. {
  206. field: sortInfo.columnKey,
  207. direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
  208. },
  209. ];
  210. }
  211. }
  212. // 表格请求之前,对参数进行处理, 添加默认 排序
  213. async function handleBeforeFetch(params) {
  214. const shiftTimes = [];
  215. if (shiftDate.value && shiftDate.value.length > 0) {
  216. shiftTimes.push(shiftDate.value[0]);
  217. shiftTimes.push(shiftDate.value[1]);
  218. shiftTimes[1] = dayjs(shiftTimes[1]).add(1, 'day').format('YYYY-MM-DD');
  219. }
  220. return {
  221. ...params,
  222. orders: tableSort.value,
  223. name: searchNames.value == '' ? undefined : searchNames.value,
  224. status: tabSelected.value == '' ? undefined : tabSelected.value,
  225. time: shiftTimes.length <= 0 ? undefined : shiftTimes,
  226. };
  227. }
  228. async function getTab() {
  229. typeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  230. const typeNums = await getStatusNumber(); // 获取各类型数量
  231. let typeList = [];
  232. typeOptions.value.forEach(ele => {
  233. // 变量各类型放置对应数量
  234. let typeData = {};
  235. Object.keys(typeNums).forEach(numKey => {
  236. if (ele.value == numKey) {
  237. typeData = {
  238. key: ele.value,
  239. label: ele.label,
  240. value: typeNums[numKey],
  241. hasValue: true,
  242. prefixColor: ele.prefixColor,
  243. hasBracket: true,
  244. };
  245. typeList.push(typeData);
  246. }
  247. });
  248. });
  249. typeList = typeList.reverse();
  250. typeList.splice(0, 0, {
  251. key: '',
  252. label: '全部',
  253. value: typeNums.total,
  254. hasValue: true,
  255. hasBracket: true,
  256. });
  257. typeOptions.value = typeList;
  258. tabSelected.value = typeOptions.value[0].key;
  259. }
  260. //取消按钮事件
  261. async function handleCancel() {
  262. clearSelectedRowKeys();
  263. await reload();
  264. await getTab();
  265. }
  266. // 弹窗回调事件
  267. async function callSuccess({ isUpdate, values }) {
  268. console.log(isUpdate);
  269. console.log(values);
  270. await reload();
  271. await getTab();
  272. }
  273. // 选项卡组件回调
  274. async function callTab(data) {
  275. tabSelected.value = data.value;
  276. await reload();
  277. }
  278. // 查询组件回调
  279. async function callForm(data) {
  280. shiftDate.value = data.shiftDate ? data.shiftDate : '';
  281. searchNames.value = data.searchNames ? data.searchNames : '';
  282. console.log('callForm:::', searchNames.value);
  283. await reload();
  284. }
  285. </script>
  286. <style lang="less" scoped>
  287. .table-dot {
  288. display: inline-block;
  289. width: 10px;
  290. height: 10px;
  291. margin-right: 6px;
  292. border-radius: 50%;
  293. }
  294. ::v-deep(.ant-btn-link) {
  295. color: #3d4155;
  296. }
  297. ::v-deep(.ant-input-prefix) {
  298. color: #8a99ac;
  299. }
  300. .colUpdateAvatar {
  301. display: flex;
  302. justify-content: center;
  303. text-align: center;
  304. line-height: 28px;
  305. }
  306. .colImg {
  307. width: 28px;
  308. height: 28px;
  309. margin-right: 5px;
  310. }
  311. </style>