From c8804ceb1fe2dea76f9949c5ea04423876ee2c81 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 28 六月 2024 14:02:47 +0800
Subject: [PATCH] 2024-06-28

---
 src/tabviews/zshare/actionList/newpagebutton/index.jsx |  282 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 257 insertions(+), 25 deletions(-)

diff --git a/src/tabviews/zshare/actionList/newpagebutton/index.jsx b/src/tabviews/zshare/actionList/newpagebutton/index.jsx
index 55bdf19..1c7f2bb 100644
--- a/src/tabviews/zshare/actionList/newpagebutton/index.jsx
+++ b/src/tabviews/zshare/actionList/newpagebutton/index.jsx
@@ -1,8 +1,11 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Button, notification, Modal } from 'antd'
+import { Button, notification, Modal, message } from 'antd'
+import moment from 'moment'
 
+import Api from '@/api'
+import Utils from '@/utils/utils.js'
 import MKEmitter from '@/utils/events.js'
 import MkIcon from '@/components/mk-icon'
 import './index.scss'
@@ -21,8 +24,10 @@
 
   state = {
     disabled: false,
+    loading: false,
     hidden: false,
-    visible: false
+    visible: false,
+    dict: window.GLOB.dict
   }
 
   UNSAFE_componentWillMount () {
@@ -102,7 +107,7 @@
    */
   actionTrigger = (triggerId, record, type, lid) => {
     const { btn, selectedData, BID, LID } = this.props
-    const { disabled } = this.state
+    const { disabled, dict } = this.state
 
     if (disabled) return
     if (triggerId && btn.uuid !== triggerId) return
@@ -114,7 +119,7 @@
       // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾暟鎹�
       notification.warning({
         top: 92,
-        message: window.GLOB.dict['select_row'] || '璇烽�夋嫨琛岋紒',
+        message: dict['select_row'] || '璇烽�夋嫨琛岋紒',
         duration: 5
       })
       return
@@ -122,14 +127,14 @@
       // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁
       notification.warning({
         top: 92,
-        message: window.GLOB.dict['select_single_row'] || '璇烽�夋嫨鍗曡鏁版嵁锛�',
+        message: dict['select_single_row'] || '璇烽�夋嫨鍗曡鏁版嵁锛�',
         duration: 5
       })
       return
     } else if (btn.pageTemplate === 'custom' && window.GLOB.systemType === 'production' && !btn.proUrl) {
       notification.warning({
         top: 92,
-        message: window.GLOB.dict['no_prod_link'] || '灏氭湭璁剧疆姝e紡绯荤粺閾炬帴鍦板潃锛�',
+        message: dict['no_prod_link'] || '灏氭湭璁剧疆姝e紡绯荤粺閾炬帴鍦板潃锛�',
         duration: 5
       })
       return
@@ -234,25 +239,34 @@
       let src = '#/print/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, lang })))
       window.open(src)
     } else if (btn.pageTemplate === 'pay') {
-      let _p = `ID=${Id}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID')}&logo=${window.GLOB.doclogo}&name=${sessionStorage.getItem('Full_Name')}&icp=${window.GLOB.ICP}&copyRight=${window.GLOB.copyRight}`
-      let url = '#/pay/' +  window.btoa(window.encodeURIComponent(_p))
       _name = '鏀粯'
-      
-      confirm({
-        title: '璇峰湪浠樻椤甸潰瀹屾垚璁㈠崟鏀粯銆�',
-        content: '',
-        className: 'pay-query',
-        okText: '鏀粯鎴愬姛',
-        cancelText: '鏀粯閬囧埌闂',
-        onOk() {
-          // 鏀粯鍚庡埛鏂扮晫闈�
-          MKEmitter.emit('reloadMenuView', btn.$MenuID)
-        },
-        onCancel() {
-          MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
-        },
-      })
-      window.open(url)
+
+      if (btn.payMode === 'system' || btn.payMode === 'inner') {
+        this.prequest(Id, data[0] || {})
+      } else {
+        confirm({
+          title: '璇峰湪浠樻椤甸潰瀹屾垚璁㈠崟鏀粯銆�',
+          content: '',
+          className: 'pay-query',
+          okText: '鏀粯鎴愬姛',
+          cancelText: '鏀粯閬囧埌闂',
+          onOk() {
+            // 鏀粯鍚庡埛鏂扮晫闈�
+            MKEmitter.emit('reloadMenuView', btn.$MenuID)
+          },
+          onCancel() {
+            MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
+          },
+        })
+
+        let appId = ''
+
+        if (btn.wxApp && window.GLOB.WXApps && window.GLOB.WXApps.findIndex(item => item.appId === btn.wxApp) > -1) {
+          appId = btn.wxApp
+        }
+
+        window.open('#/pay/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, appId: appId }))))
+      }
     } else if (btn.pageTemplate === 'custom') {
       let url = btn.url
       if (window.GLOB.systemType === 'production') {
@@ -309,9 +323,226 @@
     }
   }
 
+  prequest = (ID, data) => {
+    const { btn, BID } = this.props
+
+    let param = null
+    if (btn.payMode === 'inner') {
+      param = {
+        func: btn.innerFunc || '',
+        BID: BID || '',
+        username: sessionStorage.getItem('User_Name') || '',
+        fullname: sessionStorage.getItem('Full_Name') || '',
+        dataM: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        ID: ID
+      }
+    } else {
+      let sql = this.getSysDeclareSql(ID, data)
+
+      param = {
+        func: 'sPC_TableData_InUpDe',
+        BID: BID || '',
+        exec_type: window.GLOB.execType || 'y',
+        timestamp: moment().format('YYYY-MM-DD HH:mm:ss')
+      }
+
+      param.secretkey = Utils.encrypt('', param.timestamp)
+      param.LText = Utils.formatOptions(sql, param.exec_type)
+
+      if (btn.output) {
+        param.key_back_type = 'Y'
+      }
+
+      if (window.GLOB.mkHS) { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
+        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+      }
+
+      param.menuname = btn.logLabel
+
+      if (window.GLOB.probation) {
+        param.s_debug_type = 'Y'
+      }
+    }
+
+    this.setState({loading: true})
+    Api.genericInterface(param).then(res => {
+      this.setState({loading: false})
+      if (res.status) {
+        let id = ID
+        if (btn.output) {
+          id = res.mk_b_id || res[btn.output] || ID
+        }
+
+        confirm({
+          title: '璇峰湪浠樻椤甸潰瀹屾垚璁㈠崟鏀粯銆�',
+          content: '',
+          className: 'pay-query',
+          okText: '鏀粯鎴愬姛',
+          cancelText: '鏀粯閬囧埌闂',
+          onOk() {
+            // 鏀粯鍚庡埛鏂扮晫闈�
+            MKEmitter.emit('reloadMenuView', btn.$MenuID)
+          },
+          onCancel() {
+            MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
+          },
+        })
+
+        let appId = ''
+
+        if (btn.wxApp && window.GLOB.WXApps && window.GLOB.WXApps.findIndex(item => item.appId === btn.wxApp) > -1) {
+          appId = btn.wxApp
+        }
+
+        window.open('#/pay/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: id, appId: appId }))))
+      } else {
+        this.execError(res)
+      }
+    })
+  }
+
+  getSysDeclareSql = (ID, data) => {
+    const { columns, btn, BID } = this.props
+
+    // 绯荤粺鍙橀噺
+    let _vars = ['tbid', 'errorcode', 'retmsg', 'username', 'fullname', 'roleid', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'bid']
+    let _declare = []
+    let _initVal = []
+  
+    let _data = {}
+    Object.keys(data).forEach(key => {
+      _data[key.toLowerCase()] = data[key]
+    })
+  
+    columns.forEach(col => {
+      let _key = col.field.toLowerCase()
+
+      if (_vars.includes(_key)) return
+
+      _declare.push(`@${_key} ${col.datatype}`)
+
+      let _val = _data.hasOwnProperty(_key) ? _data[_key] : ''
+
+      if (/^date/ig.test(col.datatype) && !_val) {
+        _val = '1949-10-01'
+      }
+
+      if (/'/.test(_val)) {
+        _val = _val.replace(/'/ig, '"')
+      }
+
+      _initVal.push(`@${_key}='${_val}'`)
+    })
+  
+    // 鍙橀噺澹版槑
+    _declare = _declare.join(',')
+    if (_declare) {
+      _declare = ',' + _declare
+    }
+
+    let _sql = `/* 绯荤粺鐢熸垚 */
+      Declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000), @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@bid nvarchar(50),@tbid nvarchar(50)${_declare}
+    `
+  
+    let userName = sessionStorage.getItem('User_Name') || ''
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+    let RoleID = sessionStorage.getItem('role_id') || ''
+    let departmentcode = sessionStorage.getItem('departmentcode') || ''
+    let organization = sessionStorage.getItem('organization') || ''
+    let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
+    let nation = sessionStorage.getItem('nation') || ''
+    let province = sessionStorage.getItem('province') || ''
+    let city = sessionStorage.getItem('city') || ''
+    let district = sessionStorage.getItem('district') || ''
+    let address = sessionStorage.getItem('address') || ''
+  
+    // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁
+    _sql += `
+      /* 鐢ㄦ埛淇℃伅鍒濆鍖栬祴鍊� */
+      select @ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}', @bid='${BID}'
+    `
+    _sql += `
+      /* 鏄剧ず鍒楀彉閲忚祴鍊� */
+      select ${_initVal.join(',')}
+    `
+
+    btn.verify.scripts.forEach(item => {
+      if (item.status === 'false') return
+
+      _sql += `
+      ${item.sql}
+      `
+    })
+
+    if (btn.output) {
+      _sql += `
+        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg,${btn.output} as mk_b_id`
+    } else {
+      _sql += `
+        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+    }
+
+    _sql = _sql.replace(/@ID@/ig, `'${ID || ''}'`)
+    _sql = _sql.replace(/@BID@/ig, `'${BID || ''}'`)
+    _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    _sql = _sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
+    _sql = _sql.replace(/@typename@/ig, `'admin'`)
+
+    if (window.GLOB.externalDatabase !== null) {
+      _sql = _sql.replace(/@db@/ig, window.GLOB.externalDatabase)
+    }
+
+    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+      _sql = _sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, `'Y'`)
+    } else {
+      _sql = _sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`)
+    }
+
+    if (window.GLOB.debugger === true) {
+      console.info('%c' + btn.logLabel, 'color: blue')
+      console.info(_sql)
+    }
+
+    return _sql
+  }
+
+  execError = (res) => {
+    const { btn } = this.props
+    const { dict } = this.state
+
+    if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) {
+      res.ErrCode = 'E'
+    }
+
+    if (res.ErrCode === 'E') {
+      Modal.error({
+        title: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
+        okText: dict['got_it'] || '鐭ラ亾浜�'
+      })
+    } else if (res.ErrCode === 'N') {
+      notification.error({
+        top: 92,
+        message: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
+        duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
+      })
+    } else if (res.ErrCode === 'F') {
+      notification.error({
+        className: 'notification-custom-error',
+        top: 92,
+        message: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
+        duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
+      })
+    } else if (res.ErrCode === 'NM') {
+      message.error(res.message || dict['exc_fail'] || '鎵ц澶辫触锛�')
+    }
+  }
+
   render() {
     const { btn, name } = this.props
-    const { disabled, hidden } = this.state
+    const { disabled, hidden, loading } = this.state
 
     if (hidden) return null
 
@@ -331,6 +562,7 @@
         id={'button' + btn.uuid}
         title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
         style={btn.style || null}
+        loading={loading}
         disabled={disabled}
         className={btn.hover || ''}
         onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}

--
Gitblit v1.8.0