Browse Source

1、审批详情放大镜
2、日期格式

RaoMeng 6 years ago
parent
commit
39d8983730

+ 5 - 4
uas-office-web/wxuasapproval/src/components/tableItem/TableItem.jsx

@@ -140,12 +140,11 @@ export default class TableItem extends Component {
           break
         case 4:
           //dbfind
-          /*valueItem = <Input className='value-input'
+          valueItem = <Input className='value-input'
                              readOnly unselectable='on'
                              placeholder={placeHolder}
                              onClick={this.onDbfindClick}
-                             value={inputValue}/>*/
-          valueItem = <div>{mApproval.values}</div>
+                             value={inputValue}/>
           break
         case 5:
           valueItem =
@@ -243,6 +242,8 @@ export default class TableItem extends Component {
   }
 
   onDbfindClick = () => {
-    console.log('dbfind跳页面选择')
+    if (this.props.onDbfindClick) {
+      this.props.onDbfindClick(this.props.approval.type, this.props.index)
+    }
   }
 }

+ 105 - 103
uas-office-web/wxuasapproval/src/model/ApprovalBean.js

@@ -1,124 +1,126 @@
-import {isObjNull} from "../utils/common";
+import { isObjNull } from '../utils/common'
 
-export default function ApprovalBean(type) {
-    this.neerInput = false//是否需要输入
-    this.mustInput = false//是否是必填字段
-    this.id = -1
-    this.type = type
-    this.idKey = ''
-    this.caller = ''
-    this.gCaller = ''
-    this.coreKey = ''
-    this.dfType = ''//返回的字段类型
-    this.dbFind = ''//是否dbfind的判断
-    this.caption = '';//字幕,表示备注
-    this.values = '';//字幕对应的值显示
-    this.oldValues = '';//变更前的值
-    this.valuesKey = '';//字幕对应的值显示的key值
-    this.datas = [];
+export default function ApprovalBean (type) {
+  this.neerInput = false//是否需要输入
+  this.mustInput = false//是否是必填字段
+  this.id = -1
+  this.type = type
+  this.idKey = ''
+  this.caller = ''
+  this.gCaller = ''
+  this.coreKey = ''
+  this.dfType = ''//返回的字段类型
+  this.dbFind = ''//是否dbfind的判断
+  this.caption = ''//字幕,表示备注
+  this.values = ''//字幕对应的值显示
+  this.oldValues = ''//变更前的值
+  this.valuesKey = ''//字幕对应的值显示的key值
+  this.datas = []
 
-    this.data2Values = function () {
-        switch (this.dfType) {
-            case 'D':
-                this.data2DType()
-                break
-            case 'B':
-                if (this.values == 1) {
-                    this.values = ApprovalBean.VALUES_YES
-                } else {
-                    this.values = ApprovalBean.VALUES_NO
-                }
-                this.setOldSelectValues()
-                break
-            case 'YN':
-                if (this.values == '-1') {
-                    this.values = ApprovalBean.VALUES_YES
-                } else if (this.values == 1 && this.type == ApprovalBean.DETAIL && this.neerInput) {
-                    this.values = ApprovalBean.VALUES_UNKNOWN
-                } else {
-                    this.values = ApprovalBean.VALUES_NO
-                }
-                this.setOldSelectValues()
-                break
-            case 'C':
-                if (this.values == '-1') {
-                    this.values = ApprovalBean.VALUES_YES
-                } else if (this.values == '1' && this.type == ApprovalBean.DETAIL && this.neerInput) {
-                    this.values = ApprovalBean.VALUES_UNKNOWN
-                } else if (this.values == '0') {
-                    this.values = ApprovalBean.VALUES_NO
-                }
-                this.setOldSelectValues()
-                break
+  this.data2Values = function () {
+    switch (this.dfType) {
+      case 'D':
+        this.data2DType()
+        break
+      case 'B':
+        if (this.values == 1) {
+          this.values = ApprovalBean.VALUES_YES
+        } else {
+          this.values = ApprovalBean.VALUES_NO
         }
-    }
-
-    this.isDBFind = function () {
-        return (this.dbFind == 'T' || this.dbFind == 'AT' || this.dbFind == 'M' || this.dbFind == 'DF')
-    }
-
-    this.setOldSelectValues = function () {
-        if (!isObjNull(this.oldValues)) {
-            if (this.oldValues == '0') {
-                this.oldValues = ApprovalBean.VALUES_NO
-            } else if (this.oldValues == '-1' || this.oldValues == '1') {
-                this.oldValues = ApprovalBean.VALUES_YES
-            }
+        this.setOldSelectValues()
+        break
+      case 'YN':
+        if (this.values == '-1') {
+          this.values = ApprovalBean.VALUES_YES
+        } else if (this.values == 1 && this.type == ApprovalBean.DETAIL &&
+          this.neerInput) {
+          this.values = ApprovalBean.VALUES_UNKNOWN
+        } else {
+          this.values = ApprovalBean.VALUES_NO
+        }
+        this.setOldSelectValues()
+        break
+      case 'C':
+        if (this.values == '-1') {
+          this.values = ApprovalBean.VALUES_YES
+        } else if (this.values == '1' && this.type == ApprovalBean.DETAIL &&
+          this.neerInput) {
+          this.values = ApprovalBean.VALUES_UNKNOWN
+        } else if (this.values == '0') {
+          this.values = ApprovalBean.VALUES_NO
         }
+        this.setOldSelectValues()
+        break
     }
+  }
 
-    this.data2DType = function () {
-        if (this.values.endWith('00:00:00')) {
-            let time = Date.parse(new Date(this.values))
-            if (time > 0) {
-                let newDate = new Date()
-                newDate.setTime(time)
-                this.values = newDate.format('yyyy-MM-dd')
-            }
-        }
+  this.isDBFind = function () {
+    return (this.dbFind == 'T' || this.dbFind == 'AT' || this.dbFind == 'M' ||
+      this.dbFind == 'DF')
+  }
 
-        if (!isObjNull(this.oldValues) && this.oldValues.endWith('00:00:00')) {
-            let time = Date.parse(new Date(this.oldValues))
-            if (time > 0) {
-                let newDate = new Date()
-                newDate.setTime(time)
-                this.oldValues = newDate.format('yyyy-MM-dd')
-            }
-        }
+  this.setOldSelectValues = function () {
+    if (!isObjNull(this.oldValues)) {
+      if (this.oldValues == '0') {
+        this.oldValues = ApprovalBean.VALUES_NO
+      } else if (this.oldValues == '-1' || this.oldValues == '1') {
+        this.oldValues = ApprovalBean.VALUES_YES
+      }
     }
+  }
 
-    this.isNumber = function () {
-        return this.dfType == 'N' || this.dfType == 'floatcolumn8' || this.dfType == 'SN'
+  this.data2DType = function () {
+    let time = Date.parse(new Date(this.values))
+    if (time > 0) {
+      let newDate = new Date()
+      newDate.setTime(time)
+      this.values = newDate.format('yyyy-MM-dd')
     }
 
-    this.isSelect = function () {
-        return this.dfType == 'C' || this.dfType == 'D' || this.dfType == 'DT'
-            || this.dfType == 'C' || this.dfType == 'YN' || this.dfType == 'B'
+    if (!isObjNull(this.oldValues)) {
+      let time = Date.parse(new Date(this.oldValues))
+      if (time > 0) {
+        let newDate = new Date()
+        newDate.setTime(time)
+        this.oldValues = newDate.format('yyyy-MM-dd')
+      }
     }
+  }
 
-    /**
-     * 输入类型:0字符输入  1.数字输入  2.日期输入选择  3.下拉选择  4.dbfind
-     */
-    this.inputType = function () {
-        if (this.isNumber()) {
-            return 1;
-        } else if (this.dfType == "DT" || this.dfType == "D") {
-            return 2;
-        } else if (this.dfType == "C") {
-            return 3;
-        } else if (this.isDBFind()) {
-            return 4;
-        } else if (this.dfType == "B" || this.dfType == "YN") {
-            return 5;
-        }
-        return 0;
+  this.isNumber = function () {
+    return this.dfType == 'N' || this.dfType == 'floatcolumn8' || this.dfType ==
+      'SN'
+  }
+
+  this.isSelect = function () {
+    return this.dfType == 'C' || this.dfType == 'D' || this.dfType == 'DT'
+      || this.dfType == 'C' || this.dfType == 'YN' || this.dfType == 'B'
+  }
+
+  /**
+   * 输入类型:0字符输入  1.数字输入  2.日期输入选择  3.下拉选择  4.dbfind
+   */
+  this.inputType = function () {
+    if (this.isNumber()) {
+      return 1
+    } else if (this.dfType == 'DT' || this.dfType == 'D') {
+      return 2
+    } else if (this.dfType == 'C') {
+      return 3
+    } else if (this.isDBFind()) {
+      return 4
+    } else if (this.dfType == 'B' || this.dfType == 'YN') {
+      return 5
     }
+    return 0
+  }
 
 }
 
 ApprovalBean.Data = function (value, display) {
-    this.value = value
-    this.display = display
+  this.value = value
+  this.display = display
 }
 
 ApprovalBean.VALUES_YES = '是'

+ 222 - 47
uas-office-web/wxuasapproval/src/pages/approval/Approval.jsx

@@ -31,6 +31,7 @@ import {
 import EnclosureItem from '../../components/enclosureItem/EnclosureItem'
 import { clearSendState, saveReceiveState } from '../../redux/actions/homeState'
 import EmployeeItem from '../../components/employeeItem/EmployeeItem'
+import LocalData from '../../model/LocalData'
 
 const operation = Modal.operation
 const alert = Modal.alert
@@ -52,9 +53,10 @@ let mEnclosureList = []//附件
 let mNodeList = []//审批节点
 let mPointsList = []//要点
 
-let mEmployeeList = []//组织架构
+let mModalList = []//组织架构、放大镜
 
 let mBaseUrl
+const SELECT_APPROVAL = 'select_approval'
 
 const defaultApprovalState = {
   approvalContent: '',
@@ -98,6 +100,7 @@ const defaultApprovalState = {
   changeDataSource: new ListView.DataSource({
     rowHasChanged: (row1, row2) => row1 !== row2,
   }),//变更处理人列表
+  selectModel: {},//被选中的item
 }
 
 class Approval extends Component {
@@ -166,7 +169,7 @@ class Approval extends Component {
     mEnclosureList = []//附件
     mNodeList = []//审批节点
     mPointsList = []//要点
-    mEmployeeList = []
+    mModalList = []
   }
 
   getSessionId () {
@@ -214,6 +217,7 @@ class Approval extends Component {
 
       changeModalOpen,//变更处理人弹框是否显示
       changeDataSource,//变更处理人列表
+      selectModel,
     } = this.state
 
     //审批常用语
@@ -230,8 +234,9 @@ class Approval extends Component {
       tableItems.push(<TableItem key={'main' + i} approval={mainList[i]}
                                  index={i}
                                  approvalAble={approvalAble}
+                                 onDbfindClick={this.onDbfindClick.bind(this)}
                                  valueListener={this.childStateListener.bind(
-                                   this)}></TableItem>)
+                                   this)}/>)
     }
 
     //从表字段
@@ -247,8 +252,10 @@ class Approval extends Component {
           tableItems.push(<TableItem key={'detail' + i} approval={detailList[i]}
                                      index={i}
                                      approvalAble={approvalAble}
+                                     onDbfindClick={this.onDbfindClick.bind(
+                                       this)}
                                      valueListener={this.childStateListener.bind(
-                                       this)}></TableItem>)
+                                       this)}/>)
         }
       }
     }
@@ -514,7 +521,7 @@ class Approval extends Component {
               )
             )
         }
-        {/*变更处理人弹出框*/}
+        {/*变更处理人、放大镜弹出框*/}
         {this.getChangeModal()}
       </div>
     </div>
@@ -534,22 +541,26 @@ class Approval extends Component {
     this.moreOperation = operation(actions)
   }
 
+  /*变更处理人、放大镜弹框*/
   getChangeModal () {
     const {
       changeModalOpen,//变更处理人弹框是否显示
       changeDataSource,//变更处理人列表
+      selectModel,//选中的item
     } = this.state
     return <Modal visible={changeModalOpen}
                   animationType={'slide-up'}
                   onClose={() => {
                     this.setState({
                       changeModalOpen: false,
+                      selectModel: {},
                     })
-                    if (this.state.approvalStatus == 1) {
+                    if (selectModel.type == SELECT_APPROVAL
+                      && this.state.approvalStatus == 1) {
                       this.loadNextProcess()
                     }
                   }}
-                  title={'指定处理人'}
+                  title={selectModel.caption}
                   popup
     >
       <SearchBar
@@ -559,15 +570,18 @@ class Approval extends Component {
           if (isObjEmpty(value)) {
             this.setState({
               changeDataSource: changeDataSource.cloneWithRows(
-                mEmployeeList),
+                mModalList),
             })
           } else {
             let searchList = []
-            if (!isObjEmpty(mEmployeeList)) {
-              mEmployeeList.forEach(item => {
+            if (!isObjEmpty(mModalList)) {
+              mModalList.forEach(item => {
                 if (!isObjNull(item)
                   && (
-                    strContain(item.EM_CODE, value)
+                    strContain(item.values, value)
+                    || strContain(item.display, value)
+                    || strContain(item.name, value)
+                    || strContain(item.EM_CODE, value)
                     || strContain(item.EM_NAME, value)
                     || strContain(item.EM_POSITION, value)
                     || strContain(item.EM_DEFAULTORNAME, value)
@@ -589,13 +603,13 @@ class Approval extends Component {
         onClear={value => {
           this.setState({
             changeDataSource: changeDataSource.cloneWithRows(
-              mEmployeeList),
+              mModalList),
           })
         }}
         /*onCancel={value => {
           this.setState({
             changeDataSource: changeDataSource.cloneWithRows(
-              mEmployeeList),
+              mModalList),
           })
         }}*/
       />
@@ -603,13 +617,23 @@ class Approval extends Component {
         dataSource={this.state.changeDataSource}
         initialListSize={30}
         renderRow={(rowData, sectionID, rowID) => {
-          return <List.Item
-            key={rowID}
-            wrap
-            onClick={this.onChangeSelect.bind(this,
-              rowData)}>
-            <EmployeeItem employee={rowData}/>
-          </List.Item>
+          switch (selectModel.type) {
+            case SELECT_APPROVAL:
+              return <List.Item
+                key={rowID}
+                wrap
+                onClick={this.onChangeSelect.bind(this,
+                  rowData)}>
+                <EmployeeItem employee={rowData}/>
+              </List.Item>
+            default:
+              return <List.Item
+                key={rowID}
+                wrap
+                onClick={this.onDbfindSelect.bind(this,
+                  selectModel,
+                  rowData)}>{rowData.value}</List.Item>
+          }
         }}
         style={{
           height: '72vh',
@@ -628,6 +652,157 @@ class Approval extends Component {
     this.setState(defaultApprovalState)
   }
 
+  /**
+   * 放大镜选项选中
+   */
+  onDbfindSelect = (selectModel, rowData) => {
+    const {
+      mainList,//主表
+      detailList,//从表
+    } = this.state
+    let selectData = rowData
+    let dataObj = selectData.obj
+    let isForm = (selectModel.type === ApprovalBean.MAIN)
+    if (isForm == true) {
+      mainList.forEach((showModel, index) => {
+        if (showModel.valuesKey in dataObj) {
+          showModel.values = dataObj[showModel.valuesKey]
+        }
+      })
+    } else {
+      detailList.forEach((showModel, index) => {
+        if (showModel.valuesKey in dataObj) {
+          showModel.values = dataObj[showModel.valuesKey]
+        }
+      })
+    }
+    this.setState({
+      mainList,
+      detailList,
+      changeModalOpen: false,
+      selectModel: {},
+    })
+  }
+
+  onDbfindClick = (type, index) => {
+    let {
+      mainList,//主表
+      detailList,//从表
+    } = this.state
+    let selectModel = {}
+    switch (type) {
+      case ApprovalBean.MAIN:
+        selectModel = mainList[index]
+        break
+      case ApprovalBean.DETAIL:
+        selectModel = detailList[index]
+        break
+    }
+    selectModel.type = type
+    selectModel.index = index
+    this.setState({ selectModel })
+    //DBFind选择
+    this.getDbfindList(selectModel)
+  }
+
+  /**
+   * 放大镜类型
+   * @param billModel
+   * @param billGroup
+   */
+  getDbfindList (selectModel) {
+    let fieldKey = selectModel.valuesKey
+    let isForm = (selectModel.type === ApprovalBean.MAIN)
+    // let corekey = selectModel.corekey
+    let gridCaller = selectModel.gCaller
+
+    let condition = '1=1'
+
+    let params = {
+      which: isForm == true ? 'form' : 'grid',
+      caller: isForm == true
+        ? (selectModel.caller)
+        : gridCaller,
+      field: fieldKey,
+      condition: condition,
+      page: 1,
+      pageSize: 1000,
+    }
+    if (isForm == false) {
+      params.gridField = fieldKey
+      params.gridCaller = (selectModel.caller)
+    }
+    fetchGet(mBaseUrl + '/uapproval/common/dbfind.action',
+      params).then(response => {
+      Toast.hide()
+      let dbfinds = response.dbfinds || response.gridDbfinds
+      if (isObjEmpty(dbfinds)) {
+        message.warn('选项数据为空')
+        return
+      }
+      let dataStr = response.data
+      let dataList = JSON.parse(dataStr)
+      if (isObjEmpty(dataList)) {
+        message.warn('选项数据为空')
+        return
+      }
+      let fieldKeyLike = ''
+      let configMap = {}
+      dbfinds.forEach((config, index) => {
+        //显示值对应字段名
+        let dbGridField = config.dbGridField || config.ds_dbfindfield
+        //实际字段名
+        let field = config.field || config.ds_gridfield
+        if (!isObjEmpty(dbGridField) && !isObjEmpty(field)) {
+          if (field == fieldKey) {
+            fieldKeyLike = dbGridField
+          }
+          configMap[dbGridField] = field
+        }
+      })
+      let dbList = []
+      dataList.forEach((item, index) => {
+        let localData = new LocalData()
+        localData.name = item[fieldKeyLike]
+        let jsonMap = {}
+        for (let key in configMap) {
+          jsonMap[configMap[key]] = item[key]
+        }
+        localData.value = this.getShowValue(jsonMap)
+        localData.obj = jsonMap
+        dbList.push(localData)
+      })
+      mModalList = dbList
+      if (dbList.length === 0) {
+        message.error('选项数据为空')
+      } else {
+        this.setState({
+          changeDataSource: this.state.changeDataSource.cloneWithRows(
+            mModalList),
+          changeModalOpen: true,
+        })
+      }
+    }).catch(error => {
+      Toast.hide()
+      if (typeof error === 'string') {
+        message.error(error)
+      } else {
+        message.error('选项获取失败')
+      }
+    })
+  }
+
+  getShowValue = (jsonMap) => {
+    let showValue = ''
+    for (let key in jsonMap) {
+      if (!isObjEmpty(jsonMap[key])) {
+        showValue += jsonMap[key] + ','
+      }
+    }
+    showValue = showValue.substr(0, showValue.length - 1)
+    return showValue
+  }
+
   childStateListener = (type, index, value, isDbfind) => {
     let {
       mainList,//主表
@@ -1905,33 +2080,29 @@ class Approval extends Component {
    * 变更处理人
    */
   approvalChange = () => {
-    if (!isObjEmpty(mEmployeeList)) {
+    Toast.loading('人员资料获取中', 0)
+    fetchGet(mBaseUrl + '/mobile/getAllHrorgEmps.action', {
+      master: mMaster,
+    }).then(response => {
+      Toast.hide()
+      mModalList = response.employees
       this.setState({
         changeModalOpen: true,
+        selectModel: {
+          type: SELECT_APPROVAL,
+          caption: '指定处理人',
+        },
         changeDataSource: this.state.changeDataSource.cloneWithRows(
-          mEmployeeList),
+          mModalList),
       })
-    } else {
-      Toast.loading('人员资料获取中', 0)
-      fetchGet(mBaseUrl + '/mobile/getAllHrorgEmps.action', {
-        master: mMaster,
-      }).then(response => {
-        Toast.hide()
-        mEmployeeList = response.employees
-        this.setState({
-          changeModalOpen: true,
-          changeDataSource: this.state.changeDataSource.cloneWithRows(
-            mEmployeeList),
-        })
-      }).catch(error => {
-        Toast.hide()
-        if (typeof error === 'string') {
-          message.error(error)
-        } else {
-          message.error('组织架构获取失败')
-        }
-      })
-    }
+    }).catch(error => {
+      Toast.hide()
+      if (typeof error === 'string') {
+        message.error(error)
+      } else {
+        message.error('组织架构获取失败')
+      }
+    })
   }
 
   //接管单据
@@ -2050,7 +2221,7 @@ class Approval extends Component {
       this.approvalAgreeRequest()
       return
     }
-    let formStoreJson = MapToJson(mFormStore);
+    let formStoreJson = MapToJson(mFormStore)
     let paramsJson = strMapToObj(mParams)
     fetchGet(mBaseUrl + '/common/processUpdate.action', {
       'caller': mApprovalRecord.caller,
@@ -2173,11 +2344,15 @@ class Approval extends Component {
 
           candidateList.push(candidate)
         })
-        mEmployeeList = candidateList
+        mModalList = candidateList
         this.setState({
           changeModalOpen: true,
+          selectModel: {
+            type: SELECT_APPROVAL,
+            caption: '指定处理人',
+          },
           changeDataSource: this.state.changeDataSource.cloneWithRows(
-            mEmployeeList),
+            mModalList),
         })
       } else {
         this.loadNextProcess()
@@ -2385,7 +2560,7 @@ class Approval extends Component {
     for (let i = 0; i < approvals.length; i++) {
       let approval = approvals[i]
       if (!isObjNull(approval)) {
-        if (approval.neerInput && !approval.isDBFind()) {
+        if (approval.neerInput) {
           if (isObjEmpty(approval.values)) {
             let msg = '必填字段  ' + approval.caption + '为必填项'
             if (showTocat) {

+ 0 - 22
uas-office-web/wxuasapproval/src/utils/common.js

@@ -286,25 +286,3 @@ String.prototype.startWith = function (s) {
     return false
   return true
 }
-
-//yyyy-MM-dd h:m:s
-Date.prototype.format = function (fmt) {
-  let o = {
-    'M+': this.getMonth() + 1,                 //月份
-    'd+': this.getDate(),                    //日
-    'h+': this.getHours(),                   //小时
-    'm+': this.getMinutes(),                 //分
-    's+': this.getSeconds(),                 //秒
-    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
-    'S': this.getMilliseconds(),             //毫秒
-  }
-  if (/(y+)/.test(fmt))
-    fmt = fmt.replace(RegExp.$1,
-      (this.getFullYear() + '').substr(4 - RegExp.$1.length))
-  for (var k in o)
-    if (new RegExp('(' + k + ')').test(fmt))
-      fmt = fmt.replace(RegExp.$1,
-        (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(
-          ('' + o[k]).length)))
-  return fmt
-}