Kaynağa Gözat

feat: add document create and delete

wangyuan 2 yıl önce
ebeveyn
işleme
bff8e3d86e

+ 7 - 1
api/document.js

@@ -4,7 +4,13 @@ import { wxRequest } from './request'
 
 const documentListURL = '/get/document/list'
 const createQRcodeURL = '/create/qrcode'
+const deleteDocumentURL =  '/delete/document'
+const createDocumentURL =  '/create/document'
 
 export const documentList =  (data) => wxRequest(documentListURL, data)
 
-export const createQRcode =  (data) => wxRequest(createQRcodeURL, data)
+export const createQRcode =  (data) => wxRequest(createQRcodeURL, data)
+
+export const deleteDocument =  (data) => wxRequest(deleteDocumentURL, data)
+
+export const createDocument =  (data) => wxRequest(createDocumentURL, data)

+ 71 - 11
pages/createFile/createFile.js

@@ -1,4 +1,6 @@
 // pages/createFile/createFile.js
+import { createDocument } from "../../api/document";
+
 Page({
 
   /**
@@ -7,10 +9,12 @@ Page({
   data: {
     choseAvatar: false,
     choseAvaSrc: '',
+    username: '',
     sexIndex: '0',
+    relateIndex: 1,
     pickerText: '请选择',
     relativeText: '请选择',
-    relativeRange: ['爸爸','妈妈', '爷爷', '奶奶']
+    relativeRange: ['本人','父母', '子女', '配偶', '朋友']  // 关系  关系  1.本人 2.父母 3.子女 4.配偶  5.朋友
   },
 
   /**
@@ -34,28 +38,84 @@ Page({
 
   },
 
+  bindUserNameInput (e) {
+    this.setData({
+      username: e.detail.value
+    })
+  },
+
   /**
    * 保存
    */
   handleSave() {
+    if (this.data.choseAvaSrc == '') {
+      wx.showToast({
+        title: '请选择头像',
+        icon: 'error'
+      })
+      return
+    }
+    if (this.data.username == '') {
+      wx.showToast({
+        title: '请输入姓名',
+        icon: 'error'
+      })
+      return
+    }
+    if (this.data.pickerText == '请选择') {
+      wx.showToast({
+        title: '请选择生日',
+        icon: 'error'
+      })
+      return
+    }
+    if (this.data.relativeText == '请选择') {
+      wx.showToast({
+        title: '请选择关系',
+        icon: 'error'
+      })
+      return
+    }
+    var data = {
+      realName: this.data.username,
+      sex: this.data.sexIndex == 0 ? true : false,
+      birthday: this.data.pickerText,
+      relationship: this.data.relateIndex,
+      headImg: this.data.choseAvaSrc
+    }
+    console.log(data);
     wx.showLoading({
       title: '加载中...',
       mask: true
     })
-    setTimeout(() => {
-      wx.hideLoading({
-        success: (res) => {},
+    createDocument(data).then(res => {
+      wx.hideLoading()
+      wx.showToast({
+        title: '保存成功',
+        icon: 'success'
       })
-    }, 1400);
+      wx.navigateBack()
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
   },
 
   /**
    * 选择关系
    */
   bindReaPickerChange(e) {
+    console.log(e);
     var value = this.data.relativeRange[e.detail.value]
+    var selsectKey = Number(e.detail.value) + 1
+    console.log(selsectKey);
     this.setData({
-      relativeText: value
+      relativeText: value,
+      relateIndex: selsectKey
     })
   },
 
@@ -83,14 +143,14 @@ Page({
    */
   handleChoseAvatar() {
     var that = this
-    wx.chooseImage({
+    wx.chooseMedia({
       count: 1,
-      sizeType: ['original', 'compressed'],
-      sourceType: ['album', 'camera'],
+      mediaType: ['image'],
+      sourceType: ['album'],
       success (res) {
+        console.log(res);
         // tempFilePath可以作为 img 标签的 src 属性显示图片
-        const tempFilePaths = res.tempFilePaths
-        console.log(tempFilePaths);
+        const tempFilePaths = res.tempFiles[0].tempFilePath
         that.setData({
           choseAvatar: true,
           choseAvaSrc: tempFilePaths

+ 1 - 1
pages/createFile/createFile.wxml

@@ -19,7 +19,7 @@
       <view class="form-item username ittflex-jcb">
         <view class="label ittflex-jcs">姓名:</view>
         <view class="actions file-input">
-          <input class="weui-input"  placeholder="请输入" 	placeholder-style="text-align: right;font-size:26rpx;color:#999;"/>
+          <input bindinput="bindUserNameInput" class="weui-input"  placeholder="请输入" 	placeholder-style="text-align: right;font-size:26rpx;color:#999;"/>
         </view>
       </view>
       <view class="form-item sex ittflex-jcs">

+ 86 - 29
pages/handleFile/handleFile.js

@@ -1,22 +1,15 @@
-// pages/handleFile/handleFile.js
+ // pages/handleFile/handleFile.js
+import { documentList, deleteDocument } from "../../api/document";
+
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    fileList: [
-      {
-        name: '测试用户',
-        date: '1995/12',
-        choseFlag: false
-      },
-      {
-        name: '汪渊',
-        date: '1993/02',
-        choseFlag: false
-      }
-    ],
+    currentPage: 1,
+    hasNext: false,
+    fileList: [],
     delFileList: []
   },
 
@@ -38,7 +31,36 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    this.initDelList()
+    this.getDocumentList()
+  },
+
+   // 获取档案列表
+   getDocumentList () {
+    var data = {
+      currentPage: this.data.currentPage
+    }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
+    documentList(data).then(res => {
+      wx.hideLoading()
+      var response = res.data.vos
+      response.map(item => {
+        item.birthDay = item.birthday.split(' ')[0]
+      })
+      this.setData({
+        hasNext: res.data.hasNext,
+        fileList: response
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
   },
 
   /**
@@ -60,9 +82,16 @@ Page({
    */
   handleDelFile() {
     var that = this
+    var delArr = []
     var flag = this.data.delFileList.find(item => {
       return item == true
     })
+    this.data.delFileList.forEach(item => {
+      if (item) {
+        delArr.push(item)
+      }
+    })
+    console.log(this.data.delFileList, delArr);
     if (!flag) {
       wx.showToast({
         title: '请选择删除的档案!',
@@ -70,31 +99,59 @@ Page({
         mask: true,
         duration: 2000
       })
-    } else {
-      wx.showModal({
-        content: '确定要删除档案信息吗相对应的体检报告也会相应删除哦!',
-        cancelColor: '#666',
-        confirmColor: '#333',
-        success (res) {
-          if (res.confirm) {
-            that.handleConfirm()
-          }
-        }
+      return
+    } 
+    if (delArr.length > 1) {
+      wx.showToast({
+        title: '请选择一条数据!',
+        icon: 'error',
+        mask: true,
+        duration: 2000
       })
+      return
     }
+    wx.showModal({
+      content: '确定要删除档案信息吗相对应的体检报告也会相应删除哦!',
+      cancelColor: '#666',
+      confirmColor: '#333',
+      success (res) {
+        if (res.confirm) {
+          that.handleConfirm()
+        }
+      }
+    })
   },
 
   /* 确定 */
   handleConfirm () {
+    console.log(this.data.fileList);
+    console.log(this.data.delFileList);
+    var delPara = {}
+    for (let index = 0; index < this.data.delFileList.length; index++) {
+      const element = this.data.delFileList[index];
+      if (element) {
+        delPara.documentId = this.data.fileList[index].documentId
+      }
+    }
     wx.showLoading({
-      title: '加载中...',
+      title: '删除中...',
       mask: true
     })
-    setTimeout(() => {
-      wx.hideLoading({
-        success: (res) => {},
+    deleteDocument(delPara).then(res => {
+      wx.hideLoading()
+      wx.showToast({
+        title: '删除成功',
+        icon: 'success'
       })
-    }, 2000);
+      wx.navigateBack()
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
   },
 
   /**

+ 6 - 4
pages/handleFile/handleFile.wxml

@@ -6,15 +6,17 @@
       <view class="ittflex f-radio {{item.choseFlag ? 'f-radio-active' : ''}}" data-index="{{index}}" bindtap="handleRadio">
         <van-icon name="success" color="#fff"/>
       </view>
-        <view class="f-avatar"></view>
+        <view class="f-avatar">
+          <image class="head-img" src="{{item.headImg}}"></image>
+        </view>
         <view class="f-user">
           <view class="fu-top ittflex-jcs">
-            <text class="fu-name">{{item.name}}</text>
+            <text class="fu-name">{{item.realName}}</text>
             <view class="suer-sex ittflex">
-              <image class="img" src="../../imaes/nan@2x.png"></image>
+              <image class="img" src="{{item.sex ? '../../imaes/nan@2x.png' : '../../imaes/nv@2x.png'}}"></image>
             </view>
           </view>
-          <view class="fu-bottom fu-date">{{item.date}}</view>
+          <view class="fu-bottom fu-date">{{item.birthDay}}</view>
         </view>
         <view class="f-qrcode ittflex">
           <image class="qrcode-item" src="../../imaes/erweima@2x.png"></image>

+ 5 - 1
pages/handleFile/handleFile.wxss

@@ -38,9 +38,13 @@
   width: 80rpx;
   height: 80rpx;
   border-radius: 50%;
-  background-color: var(--maincolor);
   margin: 0 14rpx 0 20rpx;
 }
+.head-img {
+  width: 100%;
+  height: 100%;
+  border-radius: 50%;
+}
 .report-text {
   padding: 20rpx;
   font-size: 26rpx;

+ 12 - 7
pages/myFile/myFile.js

@@ -63,10 +63,8 @@ Page({
    * 新建档案
    */
   handleAddFile() {
-    wx.showModal({
-      content: '建档人数已达上限',
-      confirmColor: '#333',
-      showCancel: false
+    wx.navigateTo({
+      url: '/pages/createFile/createFile?from=myFile'
     })
   },
 
@@ -74,9 +72,16 @@ Page({
    * 管理档案
    */
   handleFile() {
-    wx.navigateTo({
-      url: '/pages/handleFile/handleFile',
-    })
+    if (this.data.fileList.length !== 0) {
+      wx.navigateTo({
+        url: '/pages/handleFile/handleFile',
+      })
+    } else {
+      wx.showToast({
+        title: '暂无档案',
+        icon: 'error'
+      })
+    }
   },
   handleShowQRCode (e) {
     var that = this