فهرست منبع

feat: 计量台账-附件新增定位查看功能

lanjianrong 5 سال پیش
والد
کامیت
dfd9a13201
6فایلهای تغییر یافته به همراه67 افزوده شده و 24 حذف شده
  1. 25 0
      app/controller/stage_controller.js
  2. 30 16
      app/public/js/stage.js
  3. 1 0
      app/router.js
  4. 2 2
      app/service/stage_att.js
  5. 8 6
      app/view/stage/index.ejs
  6. 1 0
      app/view/tender/index.ejs

+ 25 - 0
app/controller/stage_controller.js

@@ -1330,6 +1330,31 @@ module.exports = app => {
         }
 
         /**
+         * 查看附件
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        async checkFile(ctx) {
+            const responseData = { err: 0, msg: '' };
+            const { id = '' } = JSON.parse(ctx.request.body.data);
+            if (id) {
+                try {
+                    const fileInfo = await ctx.service.stageAtt.getDataById(id);
+                    console.log(fileInfo);
+                    if (fileInfo && Object.keys(fileInfo).length) {
+                        fileInfo.filepath && (responseData.data = { filepath: fileInfo.filepath.slice(3) });
+                    }
+                } catch (error) {
+                    this.log(error);
+                    this.setMessage(error.toString(), this.messageType.ERROR);
+                    responseData.err = 1;
+                    responseData.msg = error.toString();
+                }
+            }
+            ctx.body = responseData;
+        }
+
+        /**
          * 删除附件
          * @param {Object} ctx - egg全局变量
          * @return {void}

+ 30 - 16
app/public/js/stage.js

@@ -3021,22 +3021,23 @@ $(document).ready(() => {
             $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
             const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
             $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
-            $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
+            // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
+            $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
             $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
             $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
             $('#show-att tr').eq(4).children('td').text(att.remark);
             if (parseInt(userID) === att.uid) {
                 $('#btn-att').show();
-                $('#btn-att a').eq(1).show();
-                $('#btn-att a').eq(0).hide();
+                $('#btn-att a').eq(3).show();
                 $('#btn-att a').eq(2).hide();
-                $('#btn-att a').eq(3).hide();
+                $('#btn-att a').eq(4).hide();
+                $('#btn-att a').eq(5).hide();
             } else {
                 $('#btn-att').hide();
-                $('#btn-att a').eq(1).hide();
-                $('#btn-att a').eq(0).hide();
-                $('#btn-att a').eq(2).hide();
                 $('#btn-att a').eq(3).hide();
+                $('#btn-att a').eq(2).hide();
+                $('#btn-att a').eq(4).hide();
+                $('#btn-att a').eq(5).hide();
             }
             $('#showAttachment').attr('file-id', fid);
             $('#showAttachment').show();
@@ -3051,10 +3052,10 @@ $(document).ready(() => {
         const fid = $('#showAttachment').attr('file-id');
         const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
         if (content === 'edit') {
-            $('#btn-att a').eq(1).hide();
-            $('#btn-att a').eq(0).show();
+            $('#btn-att a').eq(3).hide();
             $('#btn-att a').eq(2).show();
-            $('#btn-att a').eq(3).show();
+            $('#btn-att a').eq(4).show();
+            $('#btn-att a').eq(5).show();
             $('#show-att').hide();
             $('#edit-att').show();
             const att = attData.find(function (item) {
@@ -3069,10 +3070,10 @@ $(document).ready(() => {
         } else if (content === 'cancel') {
             $('#show-att').show();
             $('#edit-att').hide();
-            $('#btn-att a').eq(1).show();
-            $('#btn-att a').eq(0).hide();
+            $('#btn-att a').eq(3).show();
             $('#btn-att a').eq(2).hide();
-            $('#btn-att a').eq(3).hide();
+            $('#btn-att a').eq(4).hide();
+            $('#btn-att a').eq(5).hide();
         } else if (content === 'save') {
             const formData = new FormData();
             formData.append('id', fid);
@@ -3103,10 +3104,10 @@ $(document).ready(() => {
                 $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
                 $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
                 $('#show-att tr').eq(4).children('td').text(data.remark);
-                $('#btn-att a').eq(1).show();
-                $('#btn-att a').eq(0).hide();
+                $('#btn-att a').eq(3).show();
                 $('#btn-att a').eq(2).hide();
-                $('#btn-att a').eq(3).hide();
+                $('#btn-att a').eq(4).hide();
+                $('#btn-att a').eq(5).hide();
             }, function () {
                 toastr.error('附件上传失败');
             });
@@ -3125,6 +3126,19 @@ $(document).ready(() => {
                 $('#showAttachment').hide();
                 $('#showAttachment').attr('file-id', '');
             });
+        } else if (content === 'view') {
+            const data = {id: fid};
+            postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
+              const { filepath } = result
+              $('#show-att tr').eq(2).find('a').attr('href', filepath)
+              $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
+            });
+        } else if (content === 'location') {
+            const att = attData.find(item => item.id === parseInt(fid));
+            if (Object.keys(att).length) {
+                SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
+                stagePosSpreadObj.loadCurPosData();
+            }
         }
     });
 

+ 1 - 0
app/router.js

@@ -184,6 +184,7 @@ module.exports = app => {
     app.get('/tender/:id/measure/stage/:order/download/file/:fid', sessionAuth, 'stageController.downloadFile');
     app.post('/tender/:id/measure/stage/:order/delete/file', sessionAuth, tenderCheck, stageCheck, 'stageController.deleteFile');
     app.post('/tender/:id/measure/stage/:order/save/file', sessionAuth, tenderCheck, stageCheck, 'stageController.saveFile');
+    app.post('/tender/:id/measure/stage/:order/check/file', sessionAuth, tenderCheck, stageCheck, 'stageController.checkFile');
     // 中间计量
     app.get('/tender/:id/measure/stage/:order/detail', sessionAuth, tenderCheck, stageCheck, 'stageController.detail');
     app.post('/tender/:id/measure/stage/:order/detail/build', sessionAuth, tenderCheck, stageCheck, 'stageController.buildDetailData');

+ 2 - 2
app/service/stage_att.js

@@ -63,7 +63,7 @@ module.exports = app => {
          */
         async getDataByTenderIdAndStageId(tid, sid) {
             const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.remark, att.in_time,' +
-                ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.b_code as `b_code`' +
+                ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`, leg.b_code as `b_code`' +
                 ' FROM ?? AS att,?? AS pa,?? AS leg' +
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.tid = ? AND att.sid = ? ORDER BY att.id DESC';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, tid, sid];
@@ -78,7 +78,7 @@ module.exports = app => {
          */
         async getDataByFid(id) {
             const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.remark, att.in_time,' +
-                ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.b_code as `b_code`' +
+                ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`,leg.b_code as `b_code`' +
                 ' FROM ?? AS att,?? AS pa,?? AS leg' +
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.id = ? ORDER BY att.in_time DESC';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, id];

+ 8 - 6
app/view/stage/index.ejs

@@ -293,20 +293,22 @@
                                 <div class="tab-content" id="showAttachment" style="display: none" file-id="">
                                     <div class="sjs-bottom-2">
                                         <div class="d-flex justify-content-end mb-1" id="btn-att">
+                                            <a href="javascript:void(0);" content="location" class="btn btn-sm btn-outline-primary" style="margin-right: 5px">定位</a>
+                                            <a href="javascript:void(0);" content="view" class="btn btn-sm btn-outline-primary" style="margin-right: 5px">查看</a>
                                             <!--默认 有删除权限-->
-                                            <a href="javascript:void(0);" content="del" class="btn btn-sm text-danger" style="display: none">删除</a>
+                                            <a href="javascript:void(0);" content="del" class="btn btn-sm text-danger" style="display: none; margin-right: 5px">删除</a>
                                             <!--默认 有编辑权限-->
-                                            <a href="javascript:void(0);" content="edit" class="btn btn-sm btn-outline-primary" style="display: none">编辑</a>
+                                            <a href="javascript:void(0);" content="edit" class="btn btn-sm btn-outline-primary" style="display: none; margin-right: 5px">编辑</a>
                                             <!--编辑模式-->
-                                            <a href="javascript:void(0);" content="save" class="btn btn-sm btn-outline-success mr-1" style="display: none">保存</a>
-                                            <a href="javascript:void(0);" content="cancel" class="btn btn-sm btn-outline-secondary" style="display: none">取消</a>
+                                            <a href="javascript:void(0);" content="save" class="btn btn-sm btn-outline-success mr-1" style="display: none; margin-right: 5px">保存</a>
+                                            <a href="javascript:void(0);" content="cancel" class="btn btn-sm btn-outline-secondary" style="display: none; margin-right: 5px">取消</a>
                                         </div>
                                         <!--显示信息-->
                                         <table class="table table-sm table-bordered" id="show-att" style="word-break:break-all; table-layout: fixed">
                                             <tbody>
                                             <tr><th>文件名</th><td colspan="3">asdasd.jpg</td></tr>
-                                            <tr><th>所在节点</th><td colspan="3">1 第一部分 建筑安装工程非</td></tr>
-                                            <tr><td colspan="4"><a href="javascript:void(0);">下载附件</a></td></tr>
+                                            <tr><th>所在节点</th><td colspan="3" id="show-att-node">1 第一部分 建筑安装工程非</td></tr>
+                                            <tr><td colspan="4"><a href="javascript:void(0);" target="_blank"><span>下载附件</span></a></td></tr>
                                             <tr><th>上传者</th><td>张三</td><th>上传时间</th><td>2018-10-20</td></tr>
                                             <tr><th>备注</th><td colspan="3"></td></tr>
                                             </tbody>

+ 1 - 0
app/view/tender/index.ejs

@@ -15,5 +15,6 @@
     const measureType = JSON.parse('<%- JSON.stringify(measureType) %>');
     const uid = '<%- uid %>';
     const pid = '<%- pid %>';
+
     const uphlname = 'user_' + uid + '_pro_' + pid + '_category_hide_list';
 </script>