index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="m-4 modals">
  3. <div>
  4. <XTTitle title="宣教记录" />
  5. <div class="flex items-center justify-between my-4">
  6. <XTTab
  7. type="record"
  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 === 'treatmentStage'">
  19. <span
  20. :class="['table-dot']"
  21. :style="{
  22. backgroundColor: formatDictPreColor(responseTypeOptions, record.treatmentStage),
  23. }"
  24. />
  25. <span> {{ formatDictValue(responseTypeOptions, record.treatmentStage) }}</span>
  26. </template>
  27. <template v-if="column.key === 'action'">
  28. <TableAction
  29. :actions="[
  30. {
  31. auth: 'biz:drug:edit',
  32. icon: 'icon-xt-details_delete_default|iconfont',
  33. tooltip: '删除',
  34. popConfirm: {
  35. title: '是否确认删除',
  36. placement: 'left',
  37. confirm: handleDelete.bind(null, record),
  38. },
  39. },
  40. ]"
  41. />
  42. </template>
  43. </template>
  44. </BasicTable>
  45. </div>
  46. </template>
  47. <script lang="ts" setup>
  48. import { onBeforeMount, ref, reactive } from 'vue';
  49. import { BasicTable, useTable, TableAction } from '/@/components/TableCard';
  50. import { useMessage } from '/@/hooks/web/useMessage';
  51. import { formatDictValue, formatDictPreColor } from '/@/utils';
  52. import { columns } from './data';
  53. import { getrecordList, getRecordNumber, recordDel } from '/@/api/biz/mission/recordApi';
  54. import { listDictModel } from '/@/api/common';
  55. import { XTTitle } from '/@/components/XTTitle/index';
  56. import { XTTab } from '/@/components/XTTab/index';
  57. import { XTForm } from '/@/components/XTForm/index';
  58. import dayjs from 'dayjs';
  59. // formdata
  60. const formData = [
  61. {
  62. name: 'shiftDate',
  63. componentType: 'RangePicker',
  64. format: 'YYYY-MM-DD',
  65. valueFormat: 'YYYY-MM-DD',
  66. placeholder: '请选择日期',
  67. width: 300,
  68. },
  69. {
  70. name: 'searchNames',
  71. componentType: 'Input',
  72. prefix: 'icon-xt-search',
  73. placeholder: '请输入宣教标题',
  74. width: 240,
  75. },
  76. ];
  77. const formValue = reactive({
  78. shiftDate: [
  79. dayjs().subtract(1, 'month').format('YYYY-MM-DD'),
  80. dayjs().add(12, 'month').format('YYYY-MM-DD'),
  81. ],
  82. content: '',
  83. });
  84. // tab 切换选中
  85. const tabSelected = ref();
  86. // 操作名称
  87. const searchNames = ref('');
  88. // const shiftDate = ref([]);
  89. const typeOptions = ref();
  90. const responseTypeOptions = ref();
  91. onBeforeMount(async () => {
  92. responseTypeOptions.value = await listDictModel({ dictCode: 'd' });
  93. getTab();
  94. });
  95. const { createConfirm, createMessage } = useMessage();
  96. // const tableSort = ref([
  97. // {
  98. // field: 'create_time',
  99. // direction: 'DESC',
  100. // },
  101. // ]) as any;
  102. const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
  103. api: getrecordList,
  104. batchDelApi: recordDel,
  105. // batchExportApi: pharmaceuticalsExport,
  106. delAuthList: ['biz:educationRecord:remove'],
  107. rowKey: 'id',
  108. columns,
  109. showIndexColumn: true,
  110. bordered: true,
  111. actionColumn: {
  112. width: 200,
  113. title: '操作',
  114. dataIndex: 'action',
  115. },
  116. beforeFetch: handleBeforeFetch,
  117. });
  118. // 删除按钮事件
  119. async function handleDelete(record: Recordable) {
  120. if (record) {
  121. await recordDel([record.id]);
  122. createMessage.success('删除成功!');
  123. clearSelectedRowKeys();
  124. await reload();
  125. await getTab();
  126. } else {
  127. createConfirm({
  128. content: '你确定要删除?',
  129. iconType: 'warning',
  130. onOk: async () => {
  131. const keys = getSelectRowKeys();
  132. await recordDel(keys);
  133. createMessage.success('删除成功!');
  134. await reload();
  135. await getTab();
  136. },
  137. });
  138. }
  139. }
  140. // 表格请求之前,对参数进行处理, 添加默认 排序
  141. async function handleBeforeFetch(params) {
  142. console.log('searchNames:::', searchNames.value);
  143. return {
  144. ...params,
  145. // orders: tableSort.value,
  146. title: searchNames.value == '' ? undefined : searchNames.value,
  147. treatmentStage: tabSelected.value == '' ? undefined : tabSelected.value,
  148. // time: shiftDate.value.length <= 0 ? undefined : shiftDate.value,
  149. time: [
  150. formValue.shiftDate[0],
  151. dayjs(formValue.shiftDate[1]).add(1, 'day').format('YYYY-MM-DD'),
  152. ],
  153. };
  154. }
  155. async function getTab() {
  156. typeOptions.value = await listDictModel({ dictCode: 'd' });
  157. const typeNums = await getRecordNumber(); // 获取各类型数量
  158. let typeList = [];
  159. typeOptions.value.forEach(ele => {
  160. // 变量各类型放置对应数量
  161. let typeData = {};
  162. Object.keys(typeNums).forEach(numKey => {
  163. if (ele.value == numKey) {
  164. typeData = {
  165. key: ele.value,
  166. label: ele.label,
  167. value: typeNums[numKey],
  168. hasValue: true,
  169. prefixColor: ele.prefixColor,
  170. hasBracket: true,
  171. };
  172. typeList.push(typeData);
  173. }
  174. });
  175. });
  176. typeList = typeList.reverse();
  177. typeList.splice(0, 0, {
  178. key: '',
  179. label: '全部',
  180. value: typeNums.total,
  181. hasValue: true,
  182. hasBracket: true,
  183. });
  184. typeOptions.value = typeList;
  185. tabSelected.value = typeOptions.value[0].key;
  186. }
  187. // 选项卡组件回调
  188. async function callTab(data) {
  189. tabSelected.value = data.value;
  190. await reload();
  191. }
  192. // 查询组件回调
  193. async function callForm(data) {
  194. // shiftDate.value = data.shiftDate ? data.shiftDate : '';
  195. searchNames.value = data.searchNames ? data.searchNames : '';
  196. formValue.shiftDate = data.shiftDate || '';
  197. console.log('callForm:::', searchNames.value);
  198. await reload();
  199. }
  200. </script>
  201. <style lang="less" scoped>
  202. .table-dot {
  203. display: inline-block;
  204. width: 10px;
  205. height: 10px;
  206. margin-right: 6px;
  207. border-radius: 50%;
  208. }
  209. &--d_after {
  210. background-color: #1bc1b3;
  211. }
  212. &--d_among {
  213. background-color: #2d5aff;
  214. }
  215. &--d_before {
  216. background-color: #854aff;
  217. }
  218. ::v-deep(.ant-btn-link) {
  219. color: #3d4155;
  220. }
  221. .colUpdateAvatar {
  222. display: flex;
  223. justify-content: center;
  224. text-align: center;
  225. line-height: 28px;
  226. }
  227. .colImg {
  228. width: 28px;
  229. height: 28px;
  230. margin-right: 5px;
  231. }
  232. </style>