From d82fec9e2a4238ff1833e67c01bc9b34e525d904 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 25 二月 2022 16:37:12 +0800
Subject: [PATCH] 2022-02-25

---
 src/tabviews/zshare/actionList/normalbutton/index.jsx |  144 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 124 insertions(+), 20 deletions(-)

diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx
index c28aaa3..55ca27b 100644
--- a/src/tabviews/zshare/actionList/normalbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -3,7 +3,7 @@
 import moment from 'moment'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Button, Modal, notification, message, Drawer } from 'antd'
+import { Button, Modal, notification, message, Drawer, Switch, Checkbox } from 'antd'
 
 import Api from '@/api'
 import Utils, { getSysDefaultSql } from '@/utils/utils.js'
@@ -33,6 +33,7 @@
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
     ContainerId: PropTypes.any,       // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒�
     disabled: PropTypes.any,          // 琛屾寜閽鐢�
+    lineId: PropTypes.any,            // 琛岀储寮�+涓婚敭鍊硷紝鐢ㄤ簬琛屾寜閽弻鍑�
   }
 
   state = {
@@ -47,7 +48,8 @@
     disabled: false,
     hidden: false,
     checkParam: null,
-    autoMatic: false
+    autoMatic: false,
+    check: false
   }
 
   moduleParams = null
@@ -78,6 +80,15 @@
     }
     if (this.props.disabled || disabled) {
       this.setState({disabled: true})
+    }
+    
+    if (btn.OpenType === 'form') {
+      let data = selectedData && selectedData[0] ? selectedData[0] : null
+      this.setState({check: data && data[btn.field] === btn.openVal})
+    } else if (btn.OpenType === 'formSubmit') {
+      this.setState({
+        selines: selectedData || []
+      })
     }
   }
 
@@ -131,6 +142,15 @@
     } else {
       this.setState({disabled: false})
     }
+
+    if (btn.OpenType === 'form') {
+      let data = nextProps.selectedData && nextProps.selectedData[0] ? nextProps.selectedData[0] : null
+      this.setState({check: data && data[btn.field] === btn.openVal})
+    } else if (btn.OpenType === 'formSubmit') {
+      this.setState({
+        selines: nextProps.selectedData || []
+      })
+    }
   }
 
   componentWillUnmount () {
@@ -152,13 +172,39 @@
   }
 
   actionSubmit = (res) => {
-    const { btn } = this.props
+    const { btn, setting, BID } = this.props
+    const { selines } = this.state
 
     if (btn.uuid !== res.menuId) return
 
+    let data = selines || []
+
+    if (setting.supModule && !BID) {
+      notification.warning({
+        top: 92,
+        message: '闇�瑕佷笂绾т富閿�硷紒',
+        duration: 3
+      })
+      return
+    } else if (btn.Ot !== 'notRequired' && data.length === 0) {
+      notification.warning({
+        top: 92,
+        message: '璇烽�夋嫨琛岋紒',
+        duration: 5
+      })
+      return
+    } else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
+      notification.warning({
+        top: 92,
+        message: '璇烽�夋嫨鍗曡鏁版嵁锛�',
+        duration: 5
+      })
+      return
+    }
+
     this.setState({ loading: true })
 
-    this.execSubmit(this.state.selines, () => {}, res.form)
+    this.execSubmit(data, () => {}, res.form)
   }
 
   resetModuleParam = (menuId, btnId, param) => {
@@ -187,7 +233,13 @@
     const { Tab, BID, btn, selectedData, setting } = this.props
     const { loading, disabled } = this.state
 
-    if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return
+    if (loading || disabled) return
+    if (triggerId) {
+      if (btn.uuid !== triggerId) return
+      if (this.props.lineId && record && record[0] && this.props.lineId !== record[0].$$key) {
+        return
+      }
+    }
 
     if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
       notification.warning({
@@ -282,12 +334,14 @@
     })
     
     if (btn.OpenType === 'formSubmit') {
-      MKEmitter.emit('mkFormSubmit', btn.uuid)
+      this.setState({}, () => {
+        MKEmitter.emit('mkFormSubmit', btn.uuid)
+      })
       return
     } else if (btn.OpenType === 'prompt') {
       this.setState({loading: true})
       confirm({
-        title: this.state.dict['main.action.confirm.tip'],
+        title: btn.tipTitle || this.state.dict['main.action.confirm.tip'],
         onOk() {
           return new Promise(resolve => {
             _this.execSubmit(data, resolve)
@@ -311,6 +365,31 @@
         btnconfig: modal
       }, () => {
         this.improveAction()
+      })
+    } else if (btn.OpenType === 'form') {
+      this.setState({
+        loading: true,
+        check: !this.state.check
+      }, () => {
+        let type = 'text'
+        let fieldlen = 50
+        let value = this.state.check ? btn.openVal : btn.closeVal
+
+        if (typeof(value) === 'number') {
+          type = 'number'
+          fieldlen = 0
+        }
+        
+        let item = {
+          type: type,
+          readonly: false,
+          readin: true,
+          writein: true,
+          fieldlen: fieldlen,
+          key: btn.field,
+          value: value
+        }
+        this.execSubmit(data, () => { this.setState({loading: false})}, [item])
       })
     }
 
@@ -381,7 +460,7 @@
         }
 
         param.LText = Utils.formatOptions(param.LText)
-      } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟
+      } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 琛ㄥ崟
         if (btn.sqlType === 'insert') { // 绯荤粺鍑芥暟娣诲姞鏃讹紝鐢熸垚uuid
           primaryId = ''
 
@@ -629,7 +708,7 @@
         param[setting.primaryKey] = primaryId // 璁剧疆涓婚敭鍙傛暟
       }
 
-      if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟
+      if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 琛ㄥ崟
         formdata.forEach(_data => {
           param[_data.key] = _data.value
         })
@@ -804,7 +883,7 @@
           param.BID = this.props.BID
         }
 
-        if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') && formdata) { // 琛ㄥ崟
+        if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') && formdata) { // 琛ㄥ崟
           formdata.forEach(_data => {
             param[_data.key] = _data.value
           })
@@ -942,6 +1021,12 @@
       _resolve()
     })
   }
+  // xml璋冪敤鏂瑰紡
+  // Api.directRequest('http://localhost:3001/test.xml', 'get', null, 'true').then(res => {
+  //   let $x2js = new x2js()
+  //   let jsonObj = $x2js.xml2js(res);
+  //   console.info(jsonObj)
+  // })
 
   /**
    * @description 鑷畾涔夎姹傚惊鐜墽琛�
@@ -1406,7 +1491,7 @@
     const { btn } = this.props
     const { btnconfig, autoMatic } = this.state
 
-    if ((res && res.ErrCode === 'S') || autoMatic) { // 鎵ц鎴愬姛
+    if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 鎵ц鎴愬姛
       notification.success({
         top: 92,
         message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
@@ -1442,6 +1527,15 @@
     if (btn.output) {
       id = res.mk_b_id || res[btn.output] || ''
     }
+    let tabId = ''
+    if (btn.refreshTab && btn.refreshTab.length > 0) {
+      tabId = btn.refreshTab[btn.refreshTab.length - 1]
+    }
+
+    if (tabId && btn.$MenuID === tabId) { // 鍒锋柊褰撳墠鑿滃崟鏃讹紝鍋滄鍏朵粬鎿嶄綔
+      MKEmitter.emit('reloadMenuView', tabId, 'table')
+      return
+    }
 
     if (btn.execSuccess === 'closetab') {
       MKEmitter.emit('closeTabView', btn.$MenuID)
@@ -1451,9 +1545,10 @@
       MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines)
     }
 
-    if (btn.refreshTab && btn.refreshTab.length > 0) {
-      MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table')
+    if (tabId) {
+      MKEmitter.emit('reloadMenuView', tabId, 'table')
     }
+    
     if (btn.switchTab && btn.switchTab.length > 0) {
       let id = btn.switchTab[btn.switchTab.length - 1]
       let node = document.getElementById('tab' + id)
@@ -1683,6 +1778,9 @@
       MKEmitter.emit('popclose')
     } else if (btn.execError !== 'never') {
       MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
+    } else if (btn.OpenType === 'form') {
+      let data = this.props.selectedData && this.props.selectedData[0] ? this.props.selectedData[0] : null
+      this.setState({check: data && data[btn.field] === btn.openVal})
     }
   }
 
@@ -1809,7 +1907,7 @@
   }
 
   modelconfirm = () => {
-    const { BData } = this.props
+    const { BData, btn } = this.props
     const { btnconfig, selines } = this.state
     let _this = this
 
@@ -1885,7 +1983,7 @@
       this.execSubmit(selines, () => {}, result)
     } else {
       confirm({
-        title: this.state.dict['main.action.confirm.tip'],
+        title: btn.tipTitle || this.state.dict['main.action.confirm.tip'],
         onOk() {
           return new Promise(resolve => {
             _this.execSubmit(selines, resolve, result)
@@ -1908,14 +2006,14 @@
     if (!btnconfig || !btnconfig.setting) return null
 
     let title = btnconfig.setting.title
-    let width = btnconfig.setting.width + 'vw'
+    let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw'
     let clickouter = btnconfig.setting.clickouter === 'close'
 
     if (btnconfig.setting.display === 'drawer') {
       let height = '100vh'
       if (btnconfig.setting.placement === 'top' || btnconfig.setting.placement === 'bottom') {
         width = '100vw'
-        height = btnconfig.setting.width + 'vh'
+        height = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vh'
       }
       return (
         <Drawer
@@ -1956,7 +2054,7 @@
         (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) ||
         (btnconfig.setting.container === 'tab' && btn.ContainerId)
       ) {
-        width = btnconfig.setting.width + '%'
+        width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
         container = () => document.getElementById(this.props.ContainerId || btn.ContainerId)
       }
       return (
@@ -1989,11 +2087,17 @@
 
   render() {
     const { btn, show, style } = this.props
-    const { loadingNumber, loading, disabled, hidden } = this.state
+    const { loadingNumber, loading, disabled, hidden, check } = this.state
 
     if (hidden) return null
 
-    if (show === 'actionList') {
+    if (btn.OpenType === 'form') {
+      if (btn.formType === 'switch') {
+        return <Switch loading={loading} checked={check} disabled={disabled || loading} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={style} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/>
+      } else {
+        return <Checkbox disabled={disabled || loading} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={style}></Checkbox>
+      }
+    } else if (show === 'actionList') {
       return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
         <Button
           style={style}

--
Gitblit v1.8.0