john 8 months ago
parent
commit
8185e8fd08

+ 7 - 0
frontEndMobile/src/api/api.ts

@@ -71,3 +71,10 @@ export const addRecord = async (params: any): Promise<User> => {
   const response = await http.post<User>(`/api/v1/record`, params)
   return response.data
 }
+
+// 添加数据
+export const getAllType = async (book_id: string): Promise<User> => {
+
+  const response = await http.get<User>(`/api/v1/types?book_id=${book_id}`,)
+  return response.data
+}

+ 74 - 3
frontEndMobile/src/views/AddAccountLogPage.vue

@@ -8,7 +8,30 @@
           name="totalFee"
           type="number"
           label="数字"
+          readonly
+          clickable
+          @touchstart.stop="showKeyboard = true"
         />
+
+        <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
@@ -52,6 +75,12 @@
       v-model:show="showCalendar"
       @confirm="onConfirm"
     />
+    <van-number-keyboard
+      v-model="totalFee"
+      :show="showKeyboard"
+      :maxlength="6"
+      @blur="showKeyboard = false"
+    />
   </div>
 </template>
 
@@ -59,7 +88,7 @@
 import { watch, ref, onMounted, toRaw } from 'vue'
 import { useRouter, useRoute } from 'vue-router'
 import dayjs from 'dayjs'
-import { uploadFile, addRecord } from '@/api/api'
+import { uploadFile, addRecord, getAllType } from '@/api/api'
 import { useCommonStore } from '@/store/common'
 const commonStore = useCommonStore()
 
@@ -67,8 +96,11 @@ const router = useRouter()
 const route = useRoute()
 
 const files = ref([])
-const totalFee = ref(0)
+const totalFee = ref()
+const showKeyboard = ref(false)
 const remark = ref('')
+const typeStr = ref('')
+const typeList = ref([])
 
 const afterRead = async (file) => {
   // 将文件上传至服务器
@@ -94,6 +126,19 @@ const onConfirm = (date) => {
 const filesDelete = (file) => {
   files.value = files.value.filter((elm) => elm.url !== file.url)
 }
+
+onMounted(() => {
+  commonStore.initBook();
+  setTimeout(() => {
+    getAllTypeByUser()
+  }, 300)
+})
+
+async function getAllTypeByUser() {
+  const res = await getAllType(commonStore.bookInfo.id)
+  typeList.value = res
+}
+
 const onSubmit = async (values) => {
   // 金额
   // 附件
@@ -110,9 +155,35 @@ const onSubmit = async (values) => {
     book_id: commonStore.bookInfo.id,
     time: values.calendar,
     total_fee: values.totalFee,
-    types: 'consectetur',
+    type: values.typeStr,
     remark: values.remark,
     files: files.value.map((elm) => elm.file_id)
   })
 }
+
+function setTypes(tag) {
+  console.log(146, tag)
+  typeStr.value = tag.name
+}
 </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>

+ 18 - 0
node_expores/db/type.js

@@ -1,5 +1,23 @@
 import connection from "./base.js";
 
+// 获取用户所有的类型
+export function getTypesByUserId({ book_id = "", author_id = ""}) {
+  console.log(555, book_id, author_id);
+
+  return new Promise((resolve, reject) => {
+    connection.query(
+      `SELECT * FROM types WHERE book_id = ? AND author_id = ?`,
+      [book_id, author_id],
+      (err, rows) => {
+        if (err) {
+          resolve(false);
+        } else {
+          resolve(rows);
+        }
+      },
+    );
+  });
+}
 // 用户是否已经注册
 export function isType({ book_id = "", author_id = "", type = "" }) {
   return new Promise((resolve, reject) => {

+ 0 - 16
node_expores/router/record/index.js

@@ -53,15 +53,6 @@ router.post("/", async function (req, res) {
   } else {
     typeInfo = { ...isAddType };
   }
-  console.log(51, {
-      book_id,
-      type_id: typeInfo.id,
-      author_id: userInfo.user_id,
-      total_fee,
-      remark,
-      create_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
-      update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
-  })
   const insertId = await record_insert({
     book_id,
     type_id: typeInfo.id,
@@ -73,9 +64,6 @@ router.post("/", async function (req, res) {
     update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
   });
 
-  console.log(7171, userInfo);
-  
-
   const filesRes = await Promise.all(files.map((file_id) => addFileByRecordId({
     file_id,
     record_id: insertId,
@@ -85,8 +73,6 @@ router.post("/", async function (req, res) {
     update_time: shanghaiTime().format("YYYY-MM-DD HH:mm:ss"),
   })))
 
-  console.log(82, filesRes);
-
   res.json({
     code: 200,
     data: {
@@ -129,11 +115,9 @@ router.get("/about", function (req, res) {
 
 // 根据日期获取数据
 router.get("/:book_id/:time", async function (req, res) {
-  console.log(13423);
   const time = req.params.time; // 获取 fileId 参数
   const book_id = req.params.book_id; // 获取 fileId 参数
   const recordsInfoRes = await getRecordsInfoByTime(time, book_id);
-  console.log(136, recordsInfoRes);
 
   res.json({
     code: 200,

+ 20 - 2
node_expores/router/types/index.js

@@ -2,6 +2,7 @@
 import express from "express";
 
 const router = express.Router();
+import { getTypesByUserId } from "#db";
 
 // middleware that is specific to this router
 router.use(function timeLog(req, res, next) {
@@ -9,8 +10,25 @@ router.use(function timeLog(req, res, next) {
   next();
 });
 // define the home page route
-router.get("/", function (req, res) {
-  res.send("Types home page");
+router.get("/", async function (req, res) {
+  const { userInfo = {} } = req.body;
+  // getTypesByUserId
+  const { book_id = "" } = req.query;
+  console.log(16161, req);
+
+  const typesRes = await getTypesByUserId({
+    book_id,
+    author_id: userInfo.user_id,
+  });
+  console.log(25, typesRes);
+
+  res.json({
+    code: 200,
+    data: typesRes.map((elm) => ({
+      name: elm.name,
+      id: elm.id,
+    })),
+  });
 });
 // define the about route
 router.get("/about", function (req, res) {