Bladeren bron

批量新增

john 8 maanden geleden
bovenliggende
commit
977ca74bda

+ 1 - 1
frontEndMobile/src/components/RecordInRow.vue

@@ -18,7 +18,7 @@
       @click="showDetail(record)"
       :key="`${yearStr}_${monthlyStr}_${index}_${recordIndex}`"
     >
-      <div>{{ record.remark }}</div>
+      <div>类型:<span>{{record.type}}</span>{{ record.remark }}</div>
       <div>-{{ record.total_fee }}</div>
     </div>
   </div>

+ 233 - 0
frontEndMobile/src/views/AddAccountLogPage copy.vue

@@ -0,0 +1,233 @@
+<template>
+  <div>
+    <van-form @submit="onSubmit">
+      <van-cell-group inset>
+        <!-- 允许输入数字,调起带符号的纯数字键盘 -->
+        <van-field
+          v-model="totalFee"
+          name="totalFee"
+          type="number"
+          label="数字"
+        />
+
+        <div class="types-box">
+          <van-field
+            v-model="typeStr"
+            label="类型"
+            name="typeStr"
+            placeholder="请输入类型名称"
+          />
+          <div class="types-scroll-box" @click.stop>
+            <van-tag
+              type="primary"
+              @click="setTypes(item)"
+              mark
+              v-for="item in typeList"
+              :key="`tag${item.name}`"
+              >{{ item.name }}</van-tag
+            >
+          </div>
+        </div>
+        <br />
+        <van-field name="uploader" label="文件上传">
+          <template #input>
+            <van-uploader
+              :model-value="files"
+              multiple
+              :max-count="5"
+              :after-read="afterRead"
+              :before-delete="filesDelete"
+            />
+          </template>
+        </van-field>
+        <van-field
+          v-model="newTime"
+          is-link
+          readonly
+          name="newTime"
+          label="日历"
+          placeholder="点击选择日期"
+          @click="showCalendar = true"
+        />
+        <van-field
+          v-model="remark"
+          rows="2"
+          autosize
+          name="remark"
+          label="留言"
+          type="textarea"
+          maxlength="50"
+          placeholder="请输入留言"
+          show-word-limit
+        />
+      </van-cell-group>
+      <div style="margin: 16px">
+        <van-button round block type="primary" native-type="submit">
+          提交
+        </van-button>
+      </div>
+    </van-form>
+    <van-calendar
+      :min-date="new Date(2010, 0, 1)"
+      v-model:show="showCalendar"
+      @confirm="onConfirm"
+    />
+    <van-number-keyboard
+      v-model="totalFee"
+      :show="showKeyboard"
+      :maxlength="6"
+      @blur="showKeyboard = false"
+    />
+  </div>
+</template>
+
+<script setup>
+import { watch, ref, onMounted, toRaw } from 'vue'
+import { useRouter, useRoute } from 'vue-router'
+import dayjs from 'dayjs'
+import {
+  uploadFile,
+  addRecord,
+  getAllType,
+  getRecordInfo,
+  putRecordInfo
+} from '@/api/api'
+import { useCommonStore } from '@/store/common'
+const commonStore = useCommonStore()
+
+const router = useRouter()
+const route = useRoute()
+
+const files = ref([])
+const totalFee = ref()
+const showKeyboard = ref(false)
+const remark = ref('')
+const typeStr = ref('')
+const typeList = ref([])
+
+const afterRead = async (file) => {
+  // 将文件上传至服务器
+  let formData = new FormData()
+  formData.append('sampleFile', file.file)
+  const res = await uploadFile(formData)
+  files.value.push({
+    // url: window.origin + `/api/v1/files/${res.file_id}`,
+    url: file.objectUrl,
+    file_id: res.data.file_id,
+    isImage: true
+  })
+}
+
+const newTime = ref(dayjs().format('YYYY-MM-DD'))
+const showCalendar = ref(false)
+
+const onConfirm = (date) => {
+  // newTime.value = `${date.getMonth() + 1}/${date.getDate()}`
+  newTime.value = dayjs(date).format('YYYY-MM-DD')
+  showCalendar.value = false
+}
+const filesDelete = (file) => {
+  files.value = files.value.filter((elm) => elm.url !== file.url)
+}
+
+onMounted(() => {
+  commonStore.initBook()
+  setTimeout(() => {
+    getAllTypeByUser()
+    if (route.params.id) {
+      editPageInit()
+    }
+  }, 300)
+})
+
+async function getAllTypeByUser() {
+  const res = await getAllType(commonStore.bookInfo.id)
+  typeList.value = res.data
+}
+
+const onSubmit = async (values) => {
+  if (route.params.id) {
+    onEditSubmit(values)
+    return
+  }
+  await addRecord({
+    book_id: commonStore.bookInfo.id,
+    time: values.newTime,
+    total_fee: values.totalFee,
+    type: values.typeStr,
+    remark: values.remark,
+    files: files.value.map((elm) => elm.file_id)
+  })
+  router.back()
+}
+
+const onEditSubmit = async (values) => {
+  console.log(159, {
+    book_id: commonStore.bookInfo.id,
+    time: values.newTime,
+    total_fee: values.totalFee,
+    type: values.typeStr,
+    remark: values.remark,
+    files: files.value.map((elm) => elm.file_id)
+  })
+
+  await putRecordInfo(route.params.id, {
+    book_id: commonStore.bookInfo.id,
+    time: values.newTime,
+    total_fee: values.totalFee,
+    type: values.typeStr,
+    remark: values.remark,
+    files: files.value.map((elm) => elm.file_id)
+  })
+
+  router.back()
+}
+
+function setTypes(tag) {
+  typeStr.value = tag.name
+}
+
+async function editPageInit() {
+  const res = await getRecordInfo(route.params.id)
+  totalFee.value = Number(res.data.total_fee)
+  typeStr.value = res.data.type
+  newTime.value = res.data.time
+  remark.value = res.data.remark
+  if (res.data?.files?.length > 0) {
+    files.value = res.data?.files.map((imgStr) => ({
+      url: imgStr,
+      file_id: imgStr.replace(/.*api_files_/, ''),
+      isImage: true
+    }))
+  }
+  /*
+    const files = ref([])
+    const totalFee = ref()
+    const showKeyboard = ref(false)
+    const remark = ref('')
+    const typeStr = ref('')
+    const typeList = ref([])
+  */
+}
+</script>
+
+<style lang="scss" scoped>
+.types-box {
+  .types-scroll-box {
+    padding-left: 100px;
+    text-align: left;
+    padding-top: 10px;
+    padding-bottom: 10px;
+    max-height: 60px;
+    overflow-x: scroll;
+    > * {
+      margin-bottom: 10px;
+      margin-right: 10px;
+    }
+    // display: flex;
+    // overflow-y: scroll;
+    // flex-wrap: nowrap;
+    // margin-left: 24px;
+  }
+}
+</style>

+ 9 - 7
frontEndMobile/src/views/MePage.vue

@@ -1,29 +1,31 @@
 <template>
   <div class="me-box">
-    <van-cell @click="toPage(item)" v-for="item in list" :key="item" :title="item" />
+    <van-cell
+      @click="toPage(item)"
+      v-for="item in list"
+      :key="item"
+      :title="item"
+    />
   </div>
 </template>
 
 <script setup>
 import { onMounted, ref } from 'vue'
-import { useRouter } from 'vue-router';
+import { useRouter } from 'vue-router'
 const router = useRouter()
 
 const list = ref([])
 
 onMounted(() => {
-  console.log(1313);
-  list.value = ['账本管理', '批量记录',]
+  list.value = ['账本管理', '批量记录']
 })
 
-
 const toPage = (item) => {
   switch (item) {
     case '账本管理':
-    router.push('/books')
+      router.push('/books')
       break
   }
-
 }
 </script>
 

+ 4 - 3
frontEndMobile/src/views/RecordPage.vue

@@ -16,9 +16,10 @@
       />
     </div>
 
-    <div>
-      <van-button @click="toEdit" type="primary"> 编辑 </van-button>
-      <van-button @click="toDel" type="danger"> 删除 </van-button>
+    <div style="display: flex; margin-top: 24px;">
+      <van-button @click="toEdit" round block type="primary"> 编辑 </van-button>
+      <div style="width: 36px;"></div>
+      <van-button @click="toDel" round block type="danger"> 删除 </van-button>
     </div>
   </div>
 </template>

+ 22 - 2
node_expores/db/record.js

@@ -157,7 +157,16 @@ export function getRecordInfoById(record_id) {
 export function getRecordsInfoByTime(time, book_id) {
   return new Promise((resolve, reject) => {
     connection.query(
-      `SELECT * FROM record WHERE DATE_FORMAT(time, '%Y-%m-%d') = ? AND book_id = ?`,
+      `SELECT record.*, types.name AS type
+        FROM
+            record
+        JOIN
+            types
+        ON
+            record.type_id = types.id
+        WHERE
+        DATE_FORMAT(record.time, '%Y-%m-%d') = ?
+        AND record.book_id = ?;`,
       [time, book_id],
       (err, rows) => {
         if (err) {
@@ -174,9 +183,20 @@ export function getRecordsInfoByTime(time, book_id) {
 export function getRecordsInfoByMonth(time, book_id) {
   return new Promise((resolve, reject) => {
     connection.query(
-      `SELECT * FROM record WHERE DATE_FORMAT(time, '%Y-%m') = ? AND book_id = ?`,
+      // `SELECT * FROM record WHERE DATE_FORMAT(time, '%Y-%m') = ? AND book_id = ?`,
+      `SELECT record.*, types.name AS type
+        FROM
+            record
+        JOIN
+            types
+        ON
+            record.type_id = types.id
+        WHERE
+        DATE_FORMAT(record.time, '%Y-%m') = ?
+        AND record.book_id = ?;`,
       [time, book_id],
       (err, rows) => {
+        console.log(192, err, rows);
         if (err) {
           // reject(err);
           resolve(false); // 如果存在记录,则返回 true,否则返回 false