index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <el-row>
  3. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  4. <el-col :span="24" class="one">
  5. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
  6. <template #status>
  7. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  8. </template>
  9. <template #brand>
  10. <el-option v-for="i in brandList" :key="i._id" :label="i.name" :value="i.name"></el-option>
  11. </template>
  12. </cSearch>
  13. </el-col>
  14. <el-col :span="24" class="two">
  15. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @evaluate="toEvaluate"> </cTable>
  16. </el-col>
  17. </el-col>
  18. </el-row>
  19. <cDialog :dialog="dialog" @toClose="toClose">
  20. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  21. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  22. <template #status>
  23. <el-option v-for="i in statusList" :key="i._id" :label="i.label" :value="i.value"></el-option>
  24. </template>
  25. </cForm>
  26. </el-col>
  27. </cDialog>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref, Ref, onMounted, inject } from 'vue';
  31. // NeedChange
  32. import { EstimateStore } from '@/stores/estimate';
  33. import { BrandStore } from '@/stores/system/brand';
  34. import { DictDataStore } from '@/stores/system/dictData';
  35. import type { IQueryResult } from '@/util/types.util';
  36. import { cloneDeep, get } from 'lodash';
  37. import baseStore from '@/stores/counter';
  38. const user = ref(baseStore.state.user);
  39. onMounted(async () => {
  40. loading.value = true;
  41. await searchOther();
  42. await search({ skip, limit });
  43. loading.value = false;
  44. });
  45. const loading: Ref<any> = ref(false);
  46. // NeedChange
  47. const store = EstimateStore();
  48. const brandStore = BrandStore();
  49. const dictDataStore = DictDataStore();
  50. const $checkRes = inject('$checkRes') as Function;
  51. // #region 字典
  52. // NeedChange
  53. const statusList: Ref<any> = ref([]);
  54. const brandList: Ref<any> = ref([]);
  55. const searchOther = async () => {
  56. const statusResult: IQueryResult = await dictDataStore.query({ code: 'valuation', is_use: '0' });
  57. if ($checkRes(statusResult)) statusList.value = statusResult.data;
  58. const brandResult: IQueryResult = await brandStore.query({ is_use: '0' });
  59. if ($checkRes(brandResult)) brandList.value = brandResult.data;
  60. };
  61. // #endregion
  62. // #region 查询相关
  63. let list: Ref<any> = ref([]);
  64. let total: Ref<number> = ref(0);
  65. let skip = 0;
  66. let limit = inject('$limit') as number;
  67. let searchForm: Ref<any> = ref({});
  68. const search = async (e: { skip: number; limit: number }) => {
  69. const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
  70. const res: IQueryResult = await store.query(info);
  71. if (res.errcode == '0') {
  72. list.value = res.data;
  73. total.value = res.total;
  74. }
  75. };
  76. const toSearch = (query) => {
  77. searchForm.value = query;
  78. search({ skip, limit });
  79. };
  80. // #endregion
  81. // #region 表格及操作
  82. // NeedChange
  83. let fields: Ref<any[]> = ref([
  84. { label: '品牌', model: 'brand', isSearch: true, type: 'select' },
  85. { label: '车系', model: 'bank' },
  86. { label: '车型', model: 'type' },
  87. { label: '上牌日期', model: 'start' },
  88. { label: '上牌城市', model: 'city', isSearch: true },
  89. { label: '所在地区', model: 'place', isSearch: true },
  90. { label: '行驶里程', model: 'course', isSearch: true },
  91. { label: '联系人', model: 'contacts', isSearch: true },
  92. { label: '联系电话', model: 'tel', isSearch: true },
  93. { label: '预估金额', model: 'estimate' },
  94. { label: '状态', model: 'status', format: (i) => getDict(i, 'status'), isSearch: true, type: 'select' }
  95. ]);
  96. // 操作
  97. let opera: Ref<any[]> = ref([{ label: '估价', method: 'evaluate', display: (i) => i.status === '0' }]);
  98. const getDict = (data, model) => {
  99. let list;
  100. switch (model) {
  101. case 'status':
  102. list = statusList.value;
  103. break;
  104. case 'brand':
  105. list = brandList.value;
  106. break;
  107. default:
  108. break;
  109. }
  110. if (!list) return;
  111. const res = list.find((f) => f.value == data);
  112. return get(res, 'label');
  113. };
  114. const toEvaluate = async (data) => {
  115. formFields.value = formFieldsForUpdate;
  116. form.value = { ...data };
  117. dialog.value.show = true;
  118. };
  119. // #endregion
  120. // #region 常规接口
  121. const toSave = async () => {
  122. const data = cloneDeep(form.value);
  123. let res: IQueryResult;
  124. if (get(data, '_id')) res = await store.update(data);
  125. else res = await store.create(data);
  126. if ($checkRes(res, true)) {
  127. search({ skip: 0, limit });
  128. toClose();
  129. }
  130. };
  131. // #endregion
  132. // #region 表单及操作
  133. // NeedChange
  134. const formFields: Ref<any> = ref();
  135. const dialog: Ref<any> = ref({ title: '数据信息', show: false, type: '1' });
  136. const form: Ref<any> = ref({ file: [] });
  137. const formFieldsForUpdate = [
  138. { label: '预估金额', model: 'estimate' },
  139. { label: '状态', model: 'status', type: 'select' }
  140. ];
  141. // 关闭弹框
  142. const toClose = () => {
  143. form.value = {};
  144. dialog.value.show = false;
  145. };
  146. // #endregion
  147. </script>
  148. <style scoped></style>