From 137fb8ea6af2789b3238b22bac31d80bced41dfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 28 七月 2021 11:39:39 +0800
Subject: [PATCH] 2021-07-28

---
 src/tabviews/zshare/actionList/printbutton/index.jsx |  119 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 97 insertions(+), 22 deletions(-)

diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx
index 323d5ab..fb45054 100644
--- a/src/tabviews/zshare/actionList/printbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -40,7 +40,23 @@
     tabledata: null,
     btnconfig: null,
     loading: false,
+    disabled: false,
     loadingNumber: ''
+  }
+
+  UNSAFE_componentWillMount () {
+    const { btn, selectedData } = this.props
+    let disabled = false
+
+    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})
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -52,6 +68,24 @@
 
     if (position === 'toolbar') {
       MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+    }
+  }
+
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { btn, selectedData } = 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})
     }
   }
 
@@ -81,12 +115,12 @@
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
   actionTrigger = (triggerId, record) => {
-    const { setting, Tab, BID, btn, selectedData } = this.props
+    const { Tab, BID, btn, selectedData, setting } = this.props
     const { loading } = this.state
 
     if ((triggerId && btn.uuid !== triggerId) || loading) return
 
-    if (Tab && Tab.supMenu && !BID) {
+    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
       notification.warning({
         top: 92,
         message: '闇�瑕佷笂绾т富閿�硷紒',
@@ -111,14 +145,6 @@
       notification.warning({
         top: 92,
         message: this.state.dict['main.action.confirm.selectSingleLine'],
-        duration: 5
-      })
-      return
-    } else if (!setting.primaryKey) {
-      // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾槸鍚﹁缃富閿�
-      notification.warning({
-        top: 92,
-        message: '鏈缃富閿紒',
         duration: 5
       })
       return
@@ -276,6 +302,7 @@
 
       let errorMsg = ''
       let _temps = {}
+      let images = []
 
       result.forEach(res => {
         if (res.status && !errorMsg) {
@@ -289,6 +316,7 @@
               status: false
             }
           } else {
+            images = [...images, ..._temp.imgs]
             _temps[res.tempId] = _temp
           }
         } else if (!errorMsg) {
@@ -297,7 +325,38 @@
       })
 
       if (!errorMsg) {
-        this.execPrint(printlist, _temps, formdata)
+        if (images.length > 0) {
+          let errorUrls = []
+          images.forEach(url => {
+            let img = new Image()
+            img.onerror = () => {
+              errorUrls.push(url)
+            }
+            img.src = url
+          })
+
+          setTimeout(() => {
+            if (errorUrls.length > 0) {
+              notification.warning({
+                top: 92,
+                message: '妯℃澘涓浘鐗� ' + errorUrls.join('锛�') + ' 宸插け鏁堬紒',
+                duration: 5
+              })
+              Object.keys(_temps).forEach(key => {
+                _temps[key].config.ReportHeader.Control = _temps[key].config.ReportHeader.Control.map(item => {
+                  if (item.Type === 'image' && errorUrls.includes(item.Value)) {
+                    item.Value = ''
+                  }
+                  return item
+                })
+              })
+            }
+
+            this.execPrint(printlist, _temps, formdata)
+          }, 500)
+        } else {
+          this.execPrint(printlist, _temps, formdata)
+        }
       } else {
         this.execError(errorMsg)
       }
@@ -358,17 +417,21 @@
         let _param = { ...param, ...formdata }
         params.push(_param)
       } else if (btn.Ot === 'requiredSgl') {
-        param[setting.primaryKey] = data[0][setting.primaryKey]
+        if (setting.primaryKey) {
+          param[setting.primaryKey] = data[0][setting.primaryKey]
+        }
 
         let _param = { ...param, ...formdata }
 
         params.push(_param)
       } else if (btn.Ot === 'requiredOnce') {
-        let ids = data.map(d => { return d[setting.primaryKey]})
-        ids = ids.filter(Boolean)
-        ids = ids.join(',')
-
-        param[setting.primaryKey] = ids
+        if (setting.primaryKey) {
+          let ids = data.map(d => { return d[setting.primaryKey]})
+          ids = ids.filter(Boolean)
+          ids = ids.join(',')
+  
+          param[setting.primaryKey] = ids
+        }
 
         let _param = { ...param, ...formdata }
 
@@ -376,7 +439,10 @@
       } else if (btn.Ot === 'required') {
         params = data.map((cell, index) => {
           let _param = { ...param }
-          _param[setting.primaryKey] = cell[setting.primaryKey]
+          
+          if (setting.primaryKey) {
+            _param[setting.primaryKey] = cell[setting.primaryKey]
+          }
 
           formlist.forEach(_data => {
             if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) {
@@ -568,6 +634,7 @@
     let _configparam = ''  // 鎵撳嵃閰嶇疆淇℃伅
     let fields = []        // 妯℃澘涓墍闇�瀛楁
     let nonEFields = []    // 闈炵┖瀛楁
+    let imgs = []
 
     if (!res.ConfigParam) {
       error = '鏈幏鍙栧埌鎵撳嵃妯℃澘淇℃伅锛�'
@@ -581,7 +648,6 @@
       if (!configParam) {
         error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�'
       } else {
-        
         let control = configParam.elements.map(element => {
           let _field = element.field
 
@@ -628,6 +694,12 @@
             item.ImageWidth = element.imgWidth
             item.ImageHeight = element.imgHeight
             item.Trimming = ''
+            if (element.productValue && window.GLOB.systemType === 'production') {
+              item.Value = element.productValue
+              imgs.push(item.Value)
+            } else if (item.Value) {
+              imgs.push(item.Value)
+            }
           } else if (item.Type === 'text') {
             item.FontFamily = element.fontFamily
             item.FontSize = element.fontSize
@@ -688,7 +760,8 @@
       error: error,
       config: _configparam,
       fields: fields,
-      nonEFields: nonEFields
+      nonEFields: nonEFields,
+      imgs: imgs
     }
   }
 
@@ -1251,13 +1324,14 @@
 
   render() {
     const { btn, show } = this.props
-    const { loadingNumber, loading } = this.state
+    const { loadingNumber, loading, disabled } = this.state
 
     if (show === 'actionList') {
       return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
         <Button
           icon={btn.icon}
           loading={loading}
+          disabled={disabled}
           className={'mk-btn mk-' + btn.class}
           onClick={() => {this.actionTrigger()}}
         >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button>
@@ -1269,7 +1343,8 @@
           type="link"
           title={show === 'icon' ? btn.label : ''}
           loading={loading}
-          style={btn.btnstyle}
+          disabled={disabled}
+          style={btn.style}
           icon={show === 'text' ? '' : (btn.icon || '')}
           onClick={() => {this.actionTrigger()}}
         >{show === 'icon' && btn.icon ? '' : btn.label}</Button>

--
Gitblit v1.8.0