From b69b5f6329ca5f87932436b7a6c1ddfc3377e10f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 16 五月 2024 10:56:41 +0800
Subject: [PATCH] 2024-05-16

---
 src/tabviews/zshare/actionList/newpagebutton/index.jsx |  286 ++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 194 insertions(+), 92 deletions(-)

diff --git a/src/tabviews/zshare/actionList/newpagebutton/index.jsx b/src/tabviews/zshare/actionList/newpagebutton/index.jsx
index 517e7fa..5a78f3e 100644
--- a/src/tabviews/zshare/actionList/newpagebutton/index.jsx
+++ b/src/tabviews/zshare/actionList/newpagebutton/index.jsx
@@ -3,8 +3,6 @@
 import { is, fromJS } from 'immutable'
 import { Button, notification, Modal } from 'antd'
 
-import zhCN from '@/locales/zh-CN/main.js'
-import enUS from '@/locales/en-US/main.js'
 import MKEmitter from '@/utils/events.js'
 import MkIcon from '@/components/mk-icon'
 import './index.scss'
@@ -13,32 +11,27 @@
 
 class NewPageButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鎸夐挳鏄剧ず鏍峰紡鎺у埗
+    BID: PropTypes.any,               // BID
     BData: PropTypes.any,             // 涓昏〃鏁版嵁
     btn: PropTypes.object,            // 鎸夐挳
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
-    setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
+    disabled: PropTypes.any,          // 琛屾寜閽鐢�
+    name: PropTypes.any
   }
 
   state = {
-    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     disabled: false,
     hidden: false,
     visible: false
   }
 
   UNSAFE_componentWillMount () {
-    const { btn, selectedData } = this.props
-    let disabled = false
+    const { btn, selectedData, BData, disabled } = this.props
 
-    if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
-      selectedData.forEach(item => {
-        let s = item[btn.controlField] + ''
-        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-          disabled = true
-        }
-      })
-      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
+    if (btn.controlField) {
+      this.setStatus(btn, selectedData || [], BData, disabled)
+    } else if (disabled) {
+      this.setState({disabled: true})
     }
   }
 
@@ -51,20 +44,12 @@
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { btn, selectedData } = this.props
+    const { btn } = this.props
 
-    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
-      let disabled = false
-
-      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
-        nextProps.selectedData.forEach(item => {
-          let s = item[btn.controlField] + ''
-          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
-            disabled = true
-          }
-        })
-      }
-      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
+    if (btn.controlField) {
+      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
+    } else {
+      this.setState({disabled: nextProps.disabled === true})
     }
   }
 
@@ -74,29 +59,62 @@
     }
     MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
   }
+
+  setStatus = (btn, data, BData, disprop) => {
+    let disabled = false
+    let hidden = false
+
+    if (btn.control !== 'parent') {
+      if (data.length > 0) {
+        data.forEach(item => {
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
+          if (btn.controlVals.includes(s) || item.$lock) {
+            disabled = true
+          }
+        })
+      } else if (btn.controlVals.includes('')) {
+        disabled = true
+      }
+    } else {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        hidden = true
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (btn.controlVals.includes(s)) {
+          hidden = true
+        }
+      }
+    }
+
+    if (disabled && btn.control === 'hidden') {
+      hidden = true
+    }
+
+    if (disprop) {
+      disabled = true
+    }
+
+    this.setState({hidden, disabled})
+  }
   
   /**
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
-  actionTrigger = (triggerId, record, type) => {
-    const { setting, btn, selectedData } = this.props
+  actionTrigger = (triggerId, record, type, lid) => {
+    const { btn, selectedData, BID, LID } = this.props
     const { disabled } = this.state
 
-    if ((triggerId && btn.uuid !== triggerId) || disabled) return
-
-    if (type === 'linkbtn' && selectedData && selectedData.length === 1) {
-      if (record[0].$Index !== selectedData[0].$Index) {
-        return
-      }
-    }
+    if (disabled) return
+    if (triggerId && btn.uuid !== triggerId) return
+    if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
 
     let data = record || selectedData || []
 
-    if (btn.Ot && btn.Ot !== 'notRequired' && data.length === 0) {
+    if (btn.Ot !== 'notRequired' && data.length === 0) {
       // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾暟鎹�
       notification.warning({
         top: 92,
-        message: this.state.dict['main.action.confirm.selectline'],
+        message: '璇烽�夋嫨琛岋紒',
         duration: 5
       })
       return
@@ -104,7 +122,14 @@
       // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁
       notification.warning({
         top: 92,
-        message: this.state.dict['main.action.confirm.selectSingleLine'],
+        message: '璇烽�夋嫨鍗曡鏁版嵁锛�',
+        duration: 5
+      })
+      return
+    } else if (btn.pageTemplate === 'custom' && window.GLOB.systemType === 'production' && !btn.proUrl) {
+      notification.warning({
+        top: 92,
+        message: '灏氭湭璁剧疆姝e紡绯荤粺閾炬帴鍦板潃锛�',
         duration: 5
       })
       return
@@ -122,7 +147,7 @@
     let MenuNo = ''
     let Remark = ''
     if (btn.Ot === 'requiredSgl' && data[0]) {
-      Id = setting.primaryKey ? (data[0][setting.primaryKey] || '') : ''
+      Id = data[0].$$uuid || ''
       name = data[0].PrintTempName || ''
       MenuNo = data[0].PrintTempNO || ''
       Remark = data[0].Remark || ''
@@ -132,14 +157,75 @@
 
     if (btn.pageTemplate === 'billprint') {
       _name = '鍗曟嵁鎵撳嵃'
-      if (btn.Ot === 'required' && data && data.length > 0) {
-        data.forEach((item, i) => {
-          let _id = setting.primaryKey ? (item[setting.primaryKey] || '') : ''
-          let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: _id, tempId: btn.printTemp, dataM: sessionStorage.getItem('dataM') })))
-          window.open(url)
+      if (btn.preHandle === 'true' && btn.pre_func) {
+        MKEmitter.emit('queryModuleParam', btn.$menuId, (res) => {
+          let searches = {}
+          res.search && res.search.forEach(item => {
+            searches[item.key] = item.value
+          })
+
+          if (btn.Ot === 'requiredOnce') {
+            Id = data.map(item => item.$$uuid).filter(Boolean).join(',')
+          }
+
+          if (btn.Ot === 'required') {
+            data.forEach(item => {
+              let _param = { id: item.$$uuid || '', tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
+              try {
+                // eslint-disable-next-line
+                let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func)
+                _param = func(btn, searches, [item], _param, window.GLOB.systemType)
+              } catch (e) {
+                console.warn(e)
+              }
+
+              if (!_param || _param.error) {
+                notification.warning({
+                  top: 92,
+                  message: _param ? _param.error : '鏈幏鍙栧埌鎵撳嵃鍙傛暟锛岃嚜瀹氫箟鑴氭湰閿欒锛�',
+                  duration: 5
+                })
+                return
+              }
+              
+              window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
+            })
+          } else {
+            let _param = { id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
+            try {
+              // eslint-disable-next-line
+              let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func)
+              _param = func(btn, searches, data, _param, window.GLOB.systemType)
+            } catch (e) {
+              console.warn(e)
+            }
+
+            if (!_param || _param.error) {
+              notification.warning({
+                top: 92,
+                message: _param ? _param.error : '鏈幏鍙栧埌鎵撳嵃鍙傛暟锛岃嚜瀹氫箟鑴氭湰閿欒锛�',
+                duration: 5
+              })
+              return
+            }
+
+            window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
+          }
         })
       } else {
-        window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, dataM: sessionStorage.getItem('dataM') }))))
+        if (btn.Ot === 'required') {
+          data.forEach(item => {
+            let _id = item.$$uuid || ''
+            let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: _id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') })))
+            window.open(url)
+          })
+        } else if (btn.Ot === 'requiredOnce') {
+          Id = data.map(item => item.$$uuid).filter(Boolean).join(',')
+  
+          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') }))))
+        } else {
+          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') }))))
+        }
       }
     } else if (btn.pageTemplate === 'billprintTemp') {
       let src = '#/menudesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'billPrint', MenuId: Id, MenuNo: MenuNo, MenuName: name || '鎵撳嵃', Remark: Remark })))
@@ -162,7 +248,7 @@
         cancelText: '鏀粯閬囧埌闂',
         onOk() {
           // 鏀粯鍚庡埛鏂扮晫闈�
-          MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
+          MKEmitter.emit('reloadMenuView', btn.$MenuID)
         },
         onCancel() {
           MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
@@ -171,18 +257,50 @@
       window.open(url)
     } else if (btn.pageTemplate === 'custom') {
       let url = btn.url
-      let con = '?'
+      if (window.GLOB.systemType === 'production') {
+        url = btn.proUrl
+      }
 
-      if (/\?/ig.test(url)) {
-        con = '&'
+      if (btn.Ot === 'notRequired' && BID) {
+        Id = BID
       }
       
-      if (btn.Ot === 'requiredSgl' && btn.joint !== 'false') {
+      if (/#\/iframe\//.test(url)) {
+        url = url.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
+        url = url + '/' + Id
+
+        let menu = {
+          MenuID: btn.uuid,
+          MenuName: btn.label,
+          type: 'iframe',
+          OpenType: 'newtab',
+          src: url
+        }
+        MKEmitter.emit('modifyTabs', menu)
+
+        return
+      }
+      
+      if (btn.joint === 'true') {
+        let con = '?'
+  
+        if (/\?/ig.test(url)) {
+          con = '&'
+        }
         url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
-      } else if (btn.Ot === 'requiredSgl' && btn.joint === 'false') {
-        url = url + `${con}id=${Id}`
-      } else if (btn.joint !== 'false') {
-        url = url + `${con}appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
+      } else if (/@/.test(url)) {
+        url = url.replace(/@id@/ig, Id)
+        url = url.replace(/@appkey@/ig, window.GLOB.appkey)
+        url = url.replace(/@userid@/ig, sessionStorage.getItem('UserID'))
+        url = url.replace(/@LoginUID@/ig, sessionStorage.getItem('LoginUID'))
+
+        if (btn.Ot === 'requiredSgl' && data[0]) {
+          Object.keys(data[0]).forEach(key => {
+            if (/^\$/.test(key)) return
+            let reg = new RegExp('@' + key + '@', 'ig')
+            url = url.replace(reg, data[0][key])
+          })
+        }
       }
 
       window.open(url)
@@ -194,48 +312,32 @@
   }
 
   render() {
-    const { btn, show } = this.props
+    const { btn, name } = this.props
     const { disabled, hidden } = this.state
 
     if (hidden) return null
 
-    if (show === 'actionList') {
-      return (
-        <Button
-          className={'mk-btn mk-' + btn.class}
-          icon={btn.icon}
-          disabled={disabled}
-          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{btn.label}</Button>
-      )
-    } else { // icon銆乼ext銆� all 鍗$墖
-      let label = ''
-      let icon = ''
+    let label = ''
 
-      if (show === 'button') {
-        label = btn.label
-        icon = btn.icon || ''
-      } else if (show === 'link') {
-        label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
-        icon = ''
-      } else if (show === 'icon') {
-        icon = btn.icon || ''
-      // } else if (show === 'text') {
-      } else {
-        label = btn.label
-      }
-
-      return (
-        <Button
-          type="link"
-          title={show === 'icon' ? btn.label : ''}
-          style={btn.style}
-          disabled={disabled}
-          icon={icon}
-          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{label}</Button>
-      )
+    if (btn.show === 'link') {
+      label = <span>{name || btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
+    } else if (btn.show === 'icon') {
+      label = <MkIcon type={btn.icon} />
+    } else {
+      label = <span>{btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{name || btn.label}</span>
     }
+
+    return (
+      <Button
+        type="link"
+        id={'button' + btn.uuid}
+        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
+        style={btn.style || null}
+        disabled={disabled}
+        className={btn.hover || ''}
+        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
+      >{label}</Button>
+    )
   }
 }
 

--
Gitblit v1.8.0