index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  6. <template #mode>
  7. <el-radio v-for="i in statusList" :key="i._id" :label="i.value">{{ i.label }}</el-radio>
  8. </template>
  9. <template #logo>
  10. <cUpload model="logo" :list="form.logo" :limit="1" url="/files/usedCar/config/upload" listType="picture-card" @change="onUpload"></cUpload>
  11. </template>
  12. </cForm>
  13. </el-col>
  14. </el-col>
  15. </el-row>
  16. </template>
  17. <script setup lang="ts">
  18. import { ref, Ref, onMounted, inject } from 'vue';
  19. // NeedChange
  20. import { ConfigStore } from '@/stores/system/config';
  21. import type { IQueryResult } from '@/util/types.util';
  22. import { cloneDeep, get } from 'lodash';
  23. import baseStore from '@/stores/counter';
  24. const user = ref(baseStore.state.user);
  25. onMounted(async () => {
  26. loading.value = true;
  27. await search();
  28. loading.value = false;
  29. });
  30. const loading: Ref<any> = ref(false);
  31. // NeedChange
  32. const store = ConfigStore();
  33. const $checkRes = inject('$checkRes') as Function;
  34. // #region 字典
  35. // NeedChange
  36. const statusList: Ref<any> = ref([
  37. { label: '平台销售', value: '0' },
  38. { label: '多店铺销售', value: '1' }
  39. ]);
  40. // #endregion
  41. const search = async () => {
  42. let res: IQueryResult = await store.query();
  43. if (res.errcode == '0') {
  44. form.value = res.data;
  45. }
  46. };
  47. // #endregion
  48. // #region 常规接口
  49. const toSave = async () => {
  50. const data = cloneDeep(form.value);
  51. let res: IQueryResult;
  52. if (get(data, '_id')) res = await store.update(data);
  53. else res = await store.create(data);
  54. if ($checkRes(res, true)) {
  55. search();
  56. }
  57. };
  58. // #endregion
  59. // #region 表单及操作
  60. // NeedChange
  61. const formFields: Ref<any> = ref([
  62. { label: '销售模式', model: 'mode', type: 'radio' },
  63. { label: '联系人', model: 'contacts' },
  64. { label: '联系电话', model: 'tel' },
  65. { label: 'logo', model: 'logo', custom: true },
  66. { label: '底部文案', model: 'bottom_title' }
  67. ]);
  68. const form: Ref<any> = ref({ logo: [] });
  69. // #endregion
  70. const onUpload = (e: { model: string; value: Array<[]> }) => {
  71. console.log(e);
  72. const { model, value } = e;
  73. form.value[model] = value;
  74. };
  75. </script>
  76. <style scoped></style>