Browse Source

大写功能及sql更新

laiguoran 2 years ago
parent
commit
2ff4d36e8b
4 changed files with 165 additions and 15 deletions
  1. 18 0
      app/controller/payment_controller.js
  2. 101 2
      app/public/js/payment_detail.js
  3. 35 1
      app/view/payment/detail.ejs
  4. 11 12
      sql/update.sql

+ 18 - 0
app/controller/payment_controller.js

@@ -384,12 +384,29 @@ module.exports = app => {
                 const rptAudit = await ctx.service.paymentRptAudit.getDataByCondition({ td_id: ctx.detail.id, uid: ctx.session.sessionUser.accountId });
                 const rptAudit = await ctx.service.paymentRptAudit.getDataByCondition({ td_id: ctx.detail.id, uid: ctx.session.sessionUser.accountId });
                 if (report_json.items[0].interact_cells.length > 0) {
                 if (report_json.items[0].interact_cells.length > 0) {
                     for (const [i, cell] of report_json.items[0].interact_cells.entries()) {
                     for (const [i, cell] of report_json.items[0].interact_cells.entries()) {
+                        cell.index = i;
+                    }
+                    const numberList = ctx.helper._.filter(report_json.items[0].interact_cells, { DataType: 'intact_type_number' });
+                    for (const [i, cell] of report_json.items[0].interact_cells.entries()) {
+                        if (cell.Label === '大写') {
+                            if (cell.link === undefined) {
+                                if (numberList.length > 0) {
+                                    const numberInfo = ctx.helper._.find(ctx.helper._.orderBy(numberList, ['index'], ['desc']), function(item) {
+                                        return item.index < i;
+                                    });
+                                    cell.link = numberInfo ? numberInfo.index : '';
+                                } else {
+                                    cell.link = '';
+                                }
+                            }
+                        }
                         const push_item = {
                         const push_item = {
                             type: paymentConst.rpt_dataType[cell.DataType],
                             type: paymentConst.rpt_dataType[cell.DataType],
                             value: cell.Prefix ? ctx.helper._.replace(cell.Value, cell.Prefix, '') : cell.Value,
                             value: cell.Prefix ? ctx.helper._.replace(cell.Value, cell.Prefix, '') : cell.Value,
                             label: cell.Label,
                             label: cell.Label,
                             index: i,
                             index: i,
                         };
                         };
+                        if (cell.link !== undefined) push_item.link = cell.link;
                         const thisBandName = paymentConst.rpt_band_name[cell.BandName] ? cell.BandName : 'content';
                         const thisBandName = paymentConst.rpt_band_name[cell.BandName] ? cell.BandName : 'content';
                         const oneShowContent = ctx.helper._.find(content, { BandName: thisBandName });
                         const oneShowContent = ctx.helper._.find(content, { BandName: thisBandName });
                         if (oneShowContent) {
                         if (oneShowContent) {
@@ -402,6 +419,7 @@ module.exports = app => {
                             });
                             });
                         }
                         }
                     }
                     }
+                    renderData.numberList = numberList;
                     if (rptAudit && ((ctx.detail.status !== auditConst.status.checkNo && ctx.detail.status !== auditConst.status.checked) ||
                     if (rptAudit && ((ctx.detail.status !== auditConst.status.checkNo && ctx.detail.status !== auditConst.status.checked) ||
                         (ctx.detail.status === auditConst.status.checked && !renderData.nextDetail) ||
                         (ctx.detail.status === auditConst.status.checked && !renderData.nextDetail) ||
                         (ctx.detail.status === auditConst.status.checkNo && ctx.detail.uid === ctx.session.sessionUser.accountId))) {
                         (ctx.detail.status === auditConst.status.checkNo && ctx.detail.uid === ctx.session.sessionUser.accountId))) {

+ 101 - 2
app/public/js/payment_detail.js

@@ -28,7 +28,7 @@ $(function () {
     //初始化所有附件列表
     //初始化所有附件列表
     getAllList();
     getAllList();
 
 
-    $('#rpt-form input').on('change', function () {
+    $('#rpt-form input[type!="radio"]').on('change', function () {
        let newVal = $(this).val();
        let newVal = $(this).val();
        const index = parseInt($(this).data('index'));
        const index = parseInt($(this).data('index'));
        const type = $(this).attr('type');
        const type = $(this).attr('type');
@@ -44,10 +44,61 @@ $(function () {
                newVal = ZhCalc.round(val, 6);
                newVal = ZhCalc.round(val, 6);
                $(this).val(newVal);
                $(this).val(newVal);
            }
            }
+           // find link(大写转换)
+           const linkList = _.filter(tesRpttData.items[0].interact_cells, { link: index });
+           if (linkList.length > 0) {
+               const chineseNum = numberToChinese(newVal);
+               // 赋值到input框并展示在报表里
+               for (const cell of linkList) {
+                   $('#rpt-form input[data-index="'+ cell.index +'"]').val(chineseNum);
+                   tesRpttData.items[0].interact_cells[cell.index].Value =
+                       tesRpttData.items[0].interact_cells[cell.index].Prefix ? tesRpttData.items[0].interact_cells[cell.index].Prefix + chineseNum : chineseNum;
+               }
+           }
        }
        }
+
        checkAndUpdate(index, newVal, $(this));
        checkAndUpdate(index, newVal, $(this));
     });
     });
 
 
+    $(".link-dropdown").on("click",function (e) {
+        e.stopPropagation();
+    });
+
+    $('.change-link').on('click', function () {
+        const link = $(this).parents('.link-dropdown').find('input:checked').val();
+        const index = parseInt($(this).attr('item-index'));
+        const old_link = $(this).attr('old-link');
+        if (old_link !== link) {
+            let showTips = '';
+            if (link !== '') {
+                const numberInfo = _.find(tesRpttData.items[0].interact_cells, { index: parseInt(link) });
+                if (numberInfo) showTips = '关联数据:' + numberInfo.Label;
+            }
+            $(this).parents('.link-dropdown').siblings('.show-link').html(showTips);
+            $(this).attr('old-link', link);
+            const info = link !== '' ? tesRpttData.items[0].interact_cells[link] : null;
+            const linkValue = removePreFix(info.Prefix, info.Value);
+            const chineseNum = linkValue ? numberToChinese(linkValue) : '';
+            tesRpttData.items[0].interact_cells[index].link = link !== '' ? parseInt(link) : '';
+            tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + chineseNum : chineseNum;
+            postData('/payment/' + tenderId + '/detail/' + detailId + '/save', { type: 'update_rpt', report_json: tesRpttData }, function (result) {
+                $('#rpt-form input[data-index="'+ index +'"]').val(chineseNum);
+                auditRptPrintHelper.showPage();
+            });
+        }
+    });
+
+    function removePreFix(prefix, value) {
+       const result = prefix ? _.replace(value, prefix, '') : value;
+       return result ? parseFloat(result) : '';
+    }
+
+    $('.show-link-dropdown').on('show.bs.dropdown', function () {
+        const link = $(this).find('button').attr('old-link');
+        const index = $(this).find('button').attr('item-index');
+        $('input:radio[name="radio_'+ index +'"][value="'+ link + '"]').prop('checked', true);
+    });
+
     $('#rpt-form textarea').on('change', function () {
     $('#rpt-form textarea').on('change', function () {
         const newVal = $(this).val();
         const newVal = $(this).val();
         const index = parseInt($(this).data('index'));
         const index = parseInt($(this).data('index'));
@@ -143,7 +194,6 @@ $(function () {
         if (tesRpttData.items[0].interact_cells[index].DataType === 'intact_type_number' && _.indexOf(tesRpttData.items[0].interact_cells[index].Value, '元') !== -1) {
         if (tesRpttData.items[0].interact_cells[index].DataType === 'intact_type_number' && _.indexOf(tesRpttData.items[0].interact_cells[index].Value, '元') !== -1) {
             newVal = newVal + '元';
             newVal = newVal + '元';
         }
         }
-        console.log(index, newVal);
         clearTimeout(timer);
         clearTimeout(timer);
         timer = setTimeout(() => {
         timer = setTimeout(() => {
             tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + newVal : newVal;
             tesRpttData.items[0].interact_cells[index].Value = tesRpttData.items[0].interact_cells[index].Prefix ? tesRpttData.items[0].interact_cells[index].Prefix + newVal : newVal;
@@ -355,3 +405,52 @@ function bytesToSize(bytes) {
     // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
     // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
     return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
     return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
 }
 }
+// 大写转换
+// 向右移位
+function shiftRight(number, digit) {
+    digit = parseInt(digit, 10);
+    var value = number.toString().split('e');
+    return +(value[0] + 'e' + (value[1] ? +value[1] + digit : digit));
+}
+// 向左移位
+function shiftLeft(number, digit) {
+    digit = parseInt(digit, 10);
+    var value = number.toString().split('e');
+    return +(value[0] + 'e' + (value[1] ? +value[1] - digit : -digit));
+}
+
+var numberToChinese = function (n) {
+    var fraction = ['角', '分'];
+    var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
+    var unit = [
+        ['元', '万', '亿'],
+        ['', '拾', '佰', '仟'],
+    ];
+    var head = n < 0 ? '负' : '';
+    n = Math.abs(n);
+    var s = '';
+    for (var i = 0; i < fraction.length; i++) {
+        s += (digit[Math.floor(shiftRight(n, 1 + i)) % 10] + fraction[i]).replace(
+            /零./,
+            ''
+        );
+    }
+    s = s || '';
+    n = Math.floor(n);
+    for (var i = 0; i < unit[0].length && n > 0; i++) {
+        var p = '';
+        for (var j = 0; j < unit[1].length && n > 0; j++) {
+            p = digit[n % 10] + unit[1][j] + p;
+            n = Math.floor(shiftLeft(n, 1));
+        }
+        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
+    }
+    return (
+        head +
+        s
+            .replace(/(零.)*零元/, '元')
+            .replace(/(零.)+/g, '零')
+            // .replace(/^整$/, '零元整')
+    );
+};
+

+ 35 - 1
app/view/payment/detail.ejs

@@ -61,7 +61,41 @@
                                         <h5><%- c.title %>内容</h5>
                                         <h5><%- c.title %>内容</h5>
                                         <% for (const item of c.items) { %>
                                         <% for (const item of c.items) { %>
                                         <div class="form-group">
                                         <div class="form-group">
-                                            <label><%- item.label %></label>
+                                            <label class="d-flex"><%- item.label %>
+                                                <% if (item.link !== undefined) { %>
+                                                    <div class="dropdown dropup mx-2 show-link-dropdown">
+                                                        <% if (ctx.detail.uid === ctx.session.sessionUser.accountId &&
+                                                                (ctx.detail.status === auditConst.status.uncheck || ctx.detail.status === auditConst.status.checkNo)) { %>
+                                                            <a href="javascript:void(0)" data-toggle="dropdown" title="关联数据" data-target="#link-data1"><i class="fa fa-paperclip"></i></a>
+                                                        <% } %>
+                                                        <span class="show-link"><% if (item.link !== '') { %>关联数据:<%= ctx.helper._.find(numberList, { index: item.link }) ? ctx.helper._.find(numberList, { index: item.link }).Label : '' %><% } %></span>
+                                                        <% if (ctx.detail.uid === ctx.session.sessionUser.accountId &&
+                                                                (ctx.detail.status === auditConst.status.uncheck || ctx.detail.status === auditConst.status.checkNo)) { %>
+                                                            <div class="link-dropdown dropdown-menu pb-1" aria-labelledby="dropdownMenuButton">
+                                                                <div class="px-3">
+                                                                    <% if (numberList.length > 0) { %>
+                                                                        <% for (const numberInfo of numberList) { %>
+                                                                            <div class="form-check py-1">
+                                                                                <input class="form form-check-input" type="radio" id="item_<%- item.index %>_number_<%- numberInfo.index %>"
+                                                                                       value="<%- numberInfo.index %>" name="radio_<%- item.index %>" <% if (item.link === numberInfo.index) { %>checked<% } %> />
+                                                                                <label class="form-check-label" for="item_<%- item.index %>_number_<%- numberInfo.index %>"><%- numberInfo.Label %></label>
+                                                                            </div>
+                                                                        <% } %>
+                                                                    <% } %>
+                                                                    <div class="form-check py-1">
+                                                                        <input class="form form-check-input" type="radio" id="item_<%- item.index %>_number_" value="" <% if (item.link === '') { %>checked<% } %> name="radio_<%- item.index %>" />
+                                                                        <label class="form-check-label" for="item_<%- item.index %>_number_">无</label>
+                                                                    </div>
+                                                                    <hr class="m-1">
+                                                                    <div class="float-right">
+                                                                        <button type="button" item-index="<%- item.index %>" old-link="<%- item.link %>" class="btn btn-sm btn-primary change-link">确定</button>
+                                                                    </div>
+                                                                </div>
+                                                            </div>
+                                                        <% } %>
+                                                    </div>
+                                                <% } %>
+                                            </label>
                                             <% if (item.type === 'textarea') { %>
                                             <% if (item.type === 'textarea') { %>
                                                 <textarea <% if (ctx.detail.readOnly) { %>readonly<% } %> class="form-control form-control-sm" data-index="<%- item.index %>"><%- item.value %></textarea>
                                                 <textarea <% if (ctx.detail.readOnly) { %>readonly<% } %> class="form-control form-control-sm" data-index="<%- item.index %>"><%- item.value %></textarea>
                                             <% } else { %>
                                             <% } else { %>

+ 11 - 12
sql/update.sql

@@ -82,19 +82,18 @@ CREATE TABLE `zh_file` (
 
 
 ALTER TABLE `zh_project` ADD `payment_setting` JSON NULL DEFAULT NULL COMMENT '支付审批模块设置' AFTER `fun_set`;
 ALTER TABLE `zh_project` ADD `payment_setting` JSON NULL DEFAULT NULL COMMENT '支付审批模块设置' AFTER `fun_set`;
 
 
-CREATE TABLE `zh_payment_attachment`  (
-  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-  `tid` int(11) UNSIGNED NOT NULL COMMENT '标段id',
-  `sid` int(11) UNSIGNED NOT NULL COMMENT '期id',
-  `pid` int(11) NOT NULL COMMENT '合同支付id',
-  `uid` int(11) UNSIGNED NOT NULL COMMENT '用户id',
-  `filename` varchar(255) CHARACTER SET utf16 COLLATE utf16_general_ci NOT NULL COMMENT '文件名',
+CREATE TABLE `zh_payment_detail_attachment`  (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `tender_id` int(11) NOT NULL COMMENT '标段id',
+  `tr_id` int(11) NOT NULL COMMENT '表单id',
+  `td_id` int(11) NOT NULL COMMENT '详情id',
+  `uid` int(11) NOT NULL COMMENT '上传者id',
+  `filename` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件名称',
   `fileext` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
   `fileext` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件后缀',
-  `filesize` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
-  `filepath` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
-  `in_time` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
-  `renew` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否审批通过后上传',
-  `username` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT '用户名',
+  `filesize` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件大小',
+  `filepath` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '文件存储路径',
+  `upload_time` datetime NOT NULL COMMENT '上传时间',
+  `extra_upload` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否为审核通过后再次上传的文件,0为否',
   PRIMARY KEY (`id`) USING BTREE
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '支付审批详情附件表';
 ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_unicode_ci COMMENT = '支付审批详情附件表';