index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch"> </cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cButton @toAdd="toAdd()"> </cButton>
  10. </el-col>
  11. <el-col :span="24" class="thr">
  12. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel">
  13. <template #leader="{ item, row }">
  14. <template v-if="item.model === 'leader'">
  15. <span size="small" type="primary">{{ getProps(row, item.model) }}</span>
  16. </template>
  17. </template>
  18. <template #accounting="{ item, row }">
  19. <template v-if="item.model === 'accounting'">
  20. <span size="small" type="primary">{{ getProps(row, item.model) }}</span>
  21. </template>
  22. </template>
  23. </cTable>
  24. </el-col>
  25. </el-col>
  26. </el-row>
  27. <cDialog :dialog="dialog" @toClose="toClose">
  28. <template v-slot:info>
  29. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  30. <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="toSave">
  31. <template #office>
  32. <el-option @click="toChange(i)" v-for="i in officeList" :key="i._id" :label="i.name"
  33. :value="i._id"></el-option>
  34. </template>
  35. <template #is_use>
  36. <el-radio v-for="(i, index) in is_useList" :key="index" :label="i.value">{{ i.label }}</el-radio>
  37. </template>
  38. <template #leader>
  39. <el-select v-model="form.leader" multiple placeholder="请选择审批领导" style="width: 100%">
  40. <el-option v-for="item in ldList" :key="item._id" :label="item.name" :value="item._id" />
  41. </el-select>
  42. </template>
  43. <template #accounting>
  44. <el-select v-model="form.accounting" multiple placeholder="请选择审批会计" style="width: 100%">
  45. <el-option v-for="item in kjList" :key="item._id" :label="item.name" :value="item._id" />
  46. </el-select>
  47. </template>
  48. </cForm>
  49. </el-col>
  50. </template>
  51. </cDialog>
  52. </div>
  53. </template>
  54. <script setup lang="ts">
  55. // 基础
  56. import _ from 'lodash';
  57. import type { FormRules } from 'element-plus';
  58. import type { Ref } from 'vue';
  59. import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
  60. import { ElMessage } from 'element-plus';
  61. // 接口
  62. import { CollectionStore } from '@/stores/collection/collection';
  63. import { DictDataStore } from '@/stores/dict/dictData';
  64. import { OfficeStore } from '@/stores/office/office';
  65. import { UserStore } from '@/stores/users/user';
  66. import type { IQueryResult } from '@/util/types.util';
  67. const dictData = DictDataStore();
  68. const collectionAxios = CollectionStore();
  69. const officeAxios = OfficeStore();
  70. const userAxios = UserStore();
  71. const { proxy } = getCurrentInstance() as any;
  72. // 加载中
  73. const loading: Ref<any> = ref(false);
  74. // 列表数据
  75. let list: Ref<any> = ref([]);
  76. let total: Ref<number> = ref(0);
  77. let skip = 0;
  78. let limit: number = proxy.$limit;
  79. let fields: Ref<any[]> = ref([
  80. { label: '街道', model: 'office', format: (i: any) => getDict(i, 'office') },
  81. { label: '领导', model: 'leader', custom: true },
  82. { label: '会计', model: 'accounting', custom: true },
  83. { label: '是否使用', model: 'is_use', format: (i: any) => getDict(i, 'is_use') }
  84. ]);
  85. // 操作
  86. let opera: Ref<any[]> = ref([
  87. { label: '修改', method: 'edit' },
  88. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  89. ]);
  90. // 弹框
  91. const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
  92. let form: Ref<{ leader: Array<any>; accounting: Array<any> }> = ref({ leader: [], accounting: [] });
  93. // 表单
  94. let formFields: Ref<any[]> = ref([
  95. { label: '街道', model: 'office', type: 'select' },
  96. { label: '领导', model: 'leader', custom: true },
  97. { label: '会计', model: 'accounting', custom: true },
  98. { label: '是否使用', model: 'is_use', type: 'radio' }
  99. ]);
  100. const rules = reactive<FormRules>({
  101. office: [{ required: true, message: '街道', trigger: 'blur' }],
  102. leader: [{ required: true, message: '领导', trigger: 'blur' }],
  103. accounting: [{ required: true, message: '会计', trigger: 'blur' }]
  104. });
  105. // 查询数据
  106. let searchForm: Ref<any> = ref({});
  107. // 字典表
  108. let is_useList: Ref<any> = ref([]);
  109. let officeList: Ref<any> = ref([]);
  110. let ldList: Ref<any> = ref([]);
  111. let kjList: Ref<any> = ref([]);
  112. // 请求
  113. onMounted(async () => {
  114. loading.value = true;
  115. await searchOther();
  116. await search({ skip, limit });
  117. loading.value = false;
  118. });
  119. const search = async (e: { skip: number; limit: number }) => {
  120. const { skip, limit } = e;
  121. const condition = _.cloneDeep(searchForm.value);
  122. let info = { limit: limit, skip: skip, ...condition };
  123. let res: IQueryResult = await collectionAxios.query(info);
  124. if (res.errcode == 0) {
  125. list.value = res.data;
  126. total.value = res.total;
  127. }
  128. };
  129. const toSearch = (query: any) => {
  130. searchForm.value = query;
  131. search({ skip, limit });
  132. };
  133. const toChange = async (val: any) => {
  134. let res: IQueryResult;
  135. let info: any = { status: '1', street: val._id };
  136. form.value.leader = [];
  137. form.value.accounting = [];
  138. // 领导
  139. res = await userAxios.query({ role: 'ld', ...info });
  140. if (res.errcode == '0') ldList.value = res.data;
  141. // 会计
  142. res = await userAxios.query({ role: 'kj', ...info });
  143. if (res.errcode == '0') kjList.value = res.data;
  144. };
  145. const getDict = (value: any, model: any) => {
  146. if (model == 'is_use') {
  147. if (value) {
  148. let data = is_useList.value.find((i: any) => i.value == value);
  149. if (data) return data.label;
  150. else return '暂无';
  151. }
  152. } else if (model == 'office') {
  153. if (value) {
  154. let data = officeList.value.find((i: any) => i._id == value);
  155. if (data) return data.name;
  156. else return '暂无';
  157. }
  158. }
  159. };
  160. const getProps = (data: any, prop: any) => {
  161. let list = [];
  162. let res;
  163. if (prop == 'leader') {
  164. for (const val of data[prop]) {
  165. res = ldList.value.find((i) => i._id == val._id);
  166. if (res) list.push(res.name);
  167. }
  168. } else {
  169. for (const val of data[prop]) {
  170. res = kjList.value.find((i) => i._id == val._id);
  171. if (res) list.push(res.name);
  172. }
  173. }
  174. return list.toString();
  175. };
  176. // 新增
  177. const toAdd = () => {
  178. dialog.value = { title: '信息管理', show: true, type: '1' };
  179. };
  180. // 修改
  181. const toEdit = async (data: any) => {
  182. form.value = data;
  183. dialog.value = { title: '信息管理', show: true, type: '1' };
  184. };
  185. // 提交保存
  186. const toSave = async (data: any) => {
  187. if (data.accounting) {
  188. if (!data.accounting[0]._id) {
  189. data.accounting = data.accounting.map((i) => {
  190. let arrObj = { _id: '' };
  191. arrObj._id = i;
  192. return arrObj;
  193. });
  194. }
  195. }
  196. if (data.leader) {
  197. if (!data.leader[0]._id) {
  198. data.leader = data.leader.map((i) => {
  199. let arrObj = { _id: '' };
  200. arrObj._id = i;
  201. return arrObj;
  202. });
  203. }
  204. }
  205. let res: IQueryResult;
  206. if (data._id) res = await collectionAxios.update(data);
  207. else res = await collectionAxios.create(data);
  208. if (res.errcode == 0) {
  209. ElMessage({ type: `success`, message: `维护信息成功` });
  210. toClose();
  211. } else ElMessage({ type: `warning`, message: `${res.errmsg}` });
  212. };
  213. // 删除
  214. const toDel = async (data: any) => {
  215. let res: IQueryResult = await collectionAxios.del(data._id);
  216. if (res.errcode == 0) {
  217. ElMessage({ type: `success`, message: `刪除信息成功` });
  218. search({ skip, limit });
  219. }
  220. };
  221. // 弹框关闭
  222. const toClose = () => {
  223. form.value = { leader: [], accounting: [] };
  224. dialog.value = { title: '信息管理', show: false, type: '1' };
  225. search({ skip, limit });
  226. searchOther();
  227. };
  228. // 查询其他信息
  229. const searchOther = async () => {
  230. let res: IQueryResult;
  231. // 是否使用
  232. res = await dictData.query({ type: 'is_use' });
  233. if (res.errcode == '0') is_useList.value = res.data;
  234. // 街道
  235. res = await officeAxios.query({ is_use: '0', type: '0' });
  236. if (res.errcode == '0') officeList.value = res.data;
  237. // 领导
  238. res = await userAxios.query({ role: 'ld', status: '1' });
  239. if (res.errcode == '0') ldList.value = res.data;
  240. // 会计
  241. res = await userAxios.query({ role: 'kj', status: '1' });
  242. if (res.errcode == '0') kjList.value = res.data;
  243. };
  244. </script>
  245. <style scoped lang="scss">
  246. .main {
  247. .two {
  248. margin: 0 0 10px 0;
  249. }
  250. }
  251. </style>