addRecords.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="form">
  3. <van-nav-bar :title="$t('customerFile.followUpRecord')" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft"> </van-nav-bar>
  4. <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit" ref="formDom">
  5. <template #date>
  6. <div style="width: 100%">
  7. <van-cell-group inset>
  8. <van-field
  9. v-model="formData.data.date"
  10. is-link
  11. readonly
  12. :label="$t('customerFile.date')"
  13. :placeholder="$t('common.pleaseSelect')"
  14. style="padding: 0 !important"
  15. :required="true"
  16. @click="clickDate" />
  17. <van-popup v-model:show="showPicker" round position="bottom">
  18. <van-picker-group
  19. :title="$t('customerFile.date')"
  20. :tabs="[$t('common.selectDate'), $t('common.selectTime')]"
  21. @confirm="onConfirm"
  22. @cancel="onCancel">
  23. <van-date-picker v-model="currentDate" />
  24. <van-time-picker v-model="currentTime" :columns-type="columnsType" />
  25. </van-picker-group>
  26. </van-popup>
  27. </van-cell-group>
  28. </div>
  29. </template>
  30. </testForm>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, getCurrentInstance, reactive } from "vue";
  35. import { showSuccessToast } from "vant";
  36. import testForm from "@/components/testForm/index.vue";
  37. import { formatDate } from "@/utils/auth";
  38. import { useRoute } from "vue-router";
  39. const proxy = getCurrentInstance().proxy;
  40. const onClickLeft = () => history.back();
  41. const route = useRoute();
  42. const currentDate = ref([]);
  43. const currentTime = ref([]);
  44. const columnsType = ["hour", "minute", "second"];
  45. const onConfirm = () => {
  46. formData.data.date = currentDate.value.join("-") + " " + currentTime.value.join(":");
  47. showPicker.value = false;
  48. };
  49. const onCancel = () => {
  50. showPicker.value = false;
  51. };
  52. const clickDate = () => {
  53. currentDate.value = formatDate(new Date(formData.data.date), "yyyy-MM-dd").split("-");
  54. currentTime.value = formatDate(new Date(formData.data.date), "hh:mm:ss").split(":");
  55. showPicker.value = true;
  56. };
  57. const formData = reactive({
  58. data: {
  59. date: formatDate(new Date(), "yyyy-MM-dd hh:mm:ss"),
  60. content: null,
  61. },
  62. });
  63. const formDom = ref(null);
  64. const showPicker = ref(false);
  65. const formOption = reactive({
  66. readonly: false, //用于控制整个表单是否只读
  67. disabled: false,
  68. labelAlign: "top",
  69. scroll: true,
  70. labelWidth: "62pk",
  71. });
  72. const formConfig = reactive([
  73. {
  74. type: "slot",
  75. slotName: "date",
  76. },
  77. {
  78. type: "input",
  79. label: proxy.t("customerFile.contentTwo"),
  80. prop: "content",
  81. itemType: "textarea",
  82. },
  83. ]);
  84. const rules = {
  85. date: [{ required: true, message: proxy.t("customerFile.dateMsg") }],
  86. content: [{ required: true, message: proxy.t("customerFile.contentTwoMsg") }],
  87. };
  88. const onSubmit = () => {
  89. proxy.post("/customerFollowRecords/add", { ...formData.data, customerId: route.query.id }).then(() => {
  90. showSuccessToast(proxy.t("common.addSuccess"));
  91. setTimeout(() => {
  92. history.back();
  93. }, 500);
  94. });
  95. };
  96. </script>