From 102be577a7f8df2ae30045d55a1a5fc584f90363 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 19 十二月 2022 18:31:38 +0800
Subject: [PATCH] 2022-12-19

---
 src/tabviews/zshare/actionList/printbutton/index.jsx | 1551 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 1,142 insertions(+), 409 deletions(-)

diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx
index e1ae252..a3c01ee 100644
--- a/src/tabviews/zshare/actionList/printbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -1,9 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import moment from 'moment'
-import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Button, Modal, notification, message, Icon } from 'antd'
+import { Button, Modal, notification, message } from 'antd'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -13,7 +12,8 @@
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
 import { updateForm } from '@/utils/utils-update.js'
 import MKEmitter from '@/utils/events.js'
-import './index.scss'
+import MkIcon from '@/components/mk-icon'
+// import './index.scss'
 
 const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform'))
 const { confirm } = Modal
@@ -21,41 +21,56 @@
 
 class PrintButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鎸夐挳鏄剧ず鏍峰紡鎺у埗
-    position: PropTypes.any,          // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar
     BID: PropTypes.string,            // 涓昏〃ID
     BData: PropTypes.any,             // 涓昏〃鏁版嵁
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
-    Tab: PropTypes.any,               // 濡傛灉褰撳墠鍏冪礌涓烘爣绛炬椂锛宼ab涓烘爣绛句俊鎭�
     MenuID: PropTypes.string,         // 鑿滃崟ID
     btn: PropTypes.object,            // 鎸夐挳
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
-    ContainerId: PropTypes.any,       // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒�
+    columns: PropTypes.array,
+    disabled: PropTypes.any,          // 琛屾寜閽鐢�
   }
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     visible: false,
     formdata: null,
-    tabledata: null,
+    selines: null,
     btnconfig: null,
+    confirmLoading: false,
     loading: false,
     disabled: false,
-    loadingNumber: ''
+    hidden: false,
+    autoMatic: false
   }
 
   UNSAFE_componentWillMount () {
-    const { btn, selectedData } = this.props
+    const { btn, selectedData, BData } = this.props
     let disabled = false
 
     if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
       selectedData.forEach(item => {
-        let s = item[btn.controlField] + ''
+        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
         if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
           disabled = true
         }
       })
-      this.setState({disabled})
+      this.setState({hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent') {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (this.props.disabled || disabled) {
+      this.setState({disabled: true})
     }
   }
 
@@ -64,28 +79,46 @@
   }
 
   componentDidMount () {
-    const { position } = this.props
+    const { btn } = this.props
 
-    if (position === 'toolbar') {
-      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+
+    if (btn.autoMatic) {
+      MKEmitter.addListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
     }
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { btn, selectedData } = this.props
+    const { btn, selectedData, BData } = this.props
 
+    let disabled = false
     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] + ''
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
           if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
             disabled = true
           }
         })
       }
-      this.setState({disabled})
+      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
+      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = nextProps.BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (nextProps.disabled || disabled) {
+      this.setState({disabled: true})
+    } else {
+      this.setState({disabled: false})
     }
   }
 
@@ -94,40 +127,39 @@
       return
     }
     MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
+    MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
   }
 
-  /**
-   * @description 鎸夐挳鐘舵�佹敼鍙�
-   */
-  updateStatus = (type) => {
-    if (type === 'start') {
-      this.setState({
-        loading: true
-      })
-    } else if (type === 'over') {
-      this.setState({
-        loading: false
-      })
-    }
+  triggerBtnPopSubmit = (id) => {
+    const { btn } = this.props
+
+    if (btn.uuid !== id) return
+
+    this.handleOk()
   }
   
   /**
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
-  actionTrigger = (triggerId, record) => {
-    const { Tab, BID, btn, selectedData, setting } = this.props
-    const { loading } = this.state
+  actionTrigger = (triggerId, record, type) => {
+    const { BID, btn, selectedData, setting } = this.props
+    const { loading, disabled } = this.state
 
-    if ((triggerId && btn.uuid !== triggerId) || loading) return
+    if (loading || disabled) return
+    if (triggerId && btn.uuid !== triggerId) return
 
-    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
+    if (setting.supModule && !BID) {
       notification.warning({
         top: 92,
         message: '闇�瑕佷笂绾т富閿�硷紒',
         duration: 5
       })
       return
+    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
+      return
     }
+
+    this.setState({autoMatic: type === 'autoMatic'})
 
     let _this = this
     let data = record || selectedData || []
@@ -152,41 +184,47 @@
       // 鏁版嵁閫夋嫨绫诲瀷鏍¢獙
       this.actionSettingError()
       return
-    } else if (
-      !btn.verify ||
-      (btn.verify.printMode === 'normal' && (!btn.verify.Template || !btn.verify.linkUrl)) ||
-      (btn.verify.printMode === 'custom' && (!btn.verify.printFunc || !btn.verify.linkUrl))
-    ) {
+    } else if (!btn.verify || !btn.verify.printMode) {
       notification.warning({
         top: 92,
         message: '璇峰畬鍠勬墦鍗伴獙璇佷俊鎭紒',
         duration: 5
       })
       return
+    } else if (btn.intertype === 'system' && btn.verify.dataType === 'custom' && (!btn.verify.setting || btn.verify.columns.length === 0)) {
+      notification.warning({
+        top: 92,
+        message: '鑷畾涔夋墦鍗版暟鎹璁剧疆鏁版嵁婧愶紒',
+        duration: 5
+      })
+      return
     }
 
+    this.setState({
+      selines: data
+    })
+
     if (btn.execMode === 'pop') {
-      this.updateStatus('start')
       let modal = this.state.btnconfig
       if (!modal && btn.modal) {
         modal = this.handleModelConfig(btn.modal)
       }
 
       this.setState({
-        tabledata: data,
+        loading: true,
         btnconfig: modal
       }, () => {
         this.improveAction()
       })
     } else if (btn.execMode === 'prompt') {
-      this.updateStatus('start')
+      this.setState({ loading: true })
       confirm({
         title: this.state.dict['main.action.confirm.tip'],
         onOk() {
           _this.triggerPrint(data)
         },
         onCancel() {
-          _this.updateStatus('over')
+          _this.setState({ loading: false })
         }
       })
     } else {
@@ -198,82 +236,134 @@
     }
   }
 
+  triggerPrint = (data, formlist = []) => {
+    const { btn } = this.props
+
+    if (btn.verify.printMode === 'RFID') {
+      this.triggerRFIDPrint(data, formlist)
+    } else {
+      this.triggerNormalPrint(data, formlist)
+    }
+  }
+
   /**
    * @description 瑙﹀彂鎵撳嵃
    */
-  triggerPrint = (data, formlist = []) => {
+  triggerNormalPrint = (data, formlist) => {
     const { btn } = this.props
     let formdata = {}
     
     formlist.forEach(_data => {
-      formdata[_data.key] = _data.value
+      let _key = _data.key.toLowerCase()
+      formdata[_key] = _data.value
     })
 
     let printlist = []
     let templates = []
-    let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1)
-
-    if (isNaN(printCount) || printCount < 1) {
-      printCount = 1
-    }
 
     new Promise(resolve => {
-      if (btn.intertype === 'system') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁
-        let printcell = {}
-
-        printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || ''
-        printcell.printCount = printCount
-        printcell.templateID = btn.verify.Template || ''
-
+      if (btn.intertype === 'system' && btn.verify.dataType !== 'custom') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁
         if (btn.Ot === 'notRequired') {
+          let printcell = {}
+  
+          printcell.printType = formdata.printtype || ''
+          printcell.printCount = +(formdata.printcount || 1)
+          printcell.templateID = formdata.templateid || btn.verify.Template || ''
+
           printcell.data = [formdata]
+
+          if (isNaN(printcell.printCount) || printcell.printCount < 1) {
+            printcell.printCount = 1
+          }
+
+          templates.push(printcell.templateID)
+
+          printlist.push(printcell)
         } else {
-          printcell.data = data.map(cell => {
-            return {...cell, ...formdata}
+          data.forEach(cell => {
+            let _cell = {}
+
+            Object.keys(cell).forEach(key => {
+              let _key = key.toLowerCase()
+              _cell[_key] = cell[key]
+            })
+
+            _cell = {..._cell, ...formdata}
+            
+            let printcell = {data: [_cell]}
+  
+            printcell.printType = _cell.printtype || ''
+            printcell.printCount = +(_cell.printcount || 1)
+            printcell.templateID = _cell.templateid || btn.verify.Template || ''
+
+            if (isNaN(printcell.printCount) || printcell.printCount < 1) {
+              printcell.printCount = 1
+            }
+
+            templates.push(printcell.templateID)
+
+            printlist.push(printcell)
           })
         }
 
-        templates.push(printcell.templateID)
-
-        printlist.push(printcell)
-
-        resolve(true)
+        if (btn.verify.printMode === 'custom') {
+          this.execCustomPrint(printlist, formdata)
+          resolve(false)
+        } else {
+          resolve(true)
+        }
       } else {
         this.getprintdata(btn, data, formdata, formlist).then(result => {
-          if (result.next) {
-            result.list.forEach(cell => {
-              // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁
-              if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return
-
-              cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template
-              cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || ''
-
-              let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0)
-
-              if (isNaN(_printCount) || _printCount < 1) {
-                _printCount = printCount
-              }
-              
-              cell.printCount = _printCount
-
-              templates.push(cell.templateID)
-
-              printlist.push(cell)
-            })
+          if (!result.next) {
+            resolve(false)
+            return
           }
+
+          // 鑷畾涔夋墦鍗�
+          if (btn.verify.printMode === 'custom') {
+            this.execCustomPrint(result.list, formdata)
+            resolve(false)
+            return
+          }
+
+          result.list.forEach(cell => {
+            // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁
+            if (!cell.data || cell.data.length === 0) return
+
+            cell.data.forEach(item => {
+              let _item = {...formdata}
+
+              _item.printtype = cell.printtype || ''
+              _item.printcount = cell.printcount || 1
+              _item.templateid = cell.templateid || ''
+
+              Object.keys(item).forEach(key => {
+                let _key = key.toLowerCase()
+                _item[_key] = item[key]
+              })
+
+              let printcell = {data: [_item]}
+  
+              printcell.printType = _item.printtype || ''
+              printcell.printCount = +(_item.printcount || 1)
+              printcell.templateID = _item.templateid || btn.verify.Template || ''
+
+              if (isNaN(printcell.printCount) || printcell.printCount < 1) {
+                printcell.printCount = 1
+              }
+
+              templates.push(printcell.templateID)
+
+              printlist.push(printcell)
+            })
+          })
           
-          resolve(result.next)
+          resolve(true)
         })
       }
     }).then(res => {
       // 鑾峰彇鎵撳嵃妯℃澘 getTemp
       if (!res) return false
-
-      if (btn.verify.printMode === 'custom') {
-        this.execCustomPrint(printlist, formdata)
-
-        return false
-      }
 
       templates = Array.from(new Set(templates)) // 鍘婚噸
 
@@ -290,7 +380,7 @@
             param.rduri = window.GLOB.mainSystemApi
           }
     
-          Api.getLocalConfig(param).then(result => {
+          Api.getSystemCacheConfig(param).then(result => {
             result.tempId = tempId
             resolve(result)
           })
@@ -353,13 +443,116 @@
               })
             }
 
-            this.execPrint(printlist, _temps, formdata)
+            this.execPrint(printlist, _temps)
           }, 500)
         } else {
-          this.execPrint(printlist, _temps, formdata)
+          this.execPrint(printlist, _temps)
         }
       } else {
         this.execError(errorMsg)
+      }
+    })
+  }
+
+  /**
+   * @description 瑙﹀彂RFID鎵撳嵃
+   */
+  triggerRFIDPrint = (data, formlist) => {
+    const { btn } = this.props
+    let formdata = {}
+    let list = []
+    
+    formlist.forEach(_data => {
+      formdata[_data.key] = _data.value
+    })
+
+    new Promise(resolve => {
+      if (btn.intertype === 'system' && btn.verify.dataType !== 'custom') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁
+        if (btn.Ot === 'notRequired') {
+          if (formlist.length > 0) {
+            list = [formdata]
+          }
+        } else {
+          data.forEach(cell => {
+            let _cell = {...cell, ...formdata}
+            list.push(_cell)
+          })
+        }
+
+        resolve(true)
+      } else {
+        this.getprintdata(btn, data, formdata, formlist).then(result => {
+          if (result.next) {
+            result.list.forEach(cell => {
+              // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁
+              if (!cell.data || cell.data.length === 0) return
+
+              cell.data.forEach(m => {
+                let _cell = {...m, ...formdata}
+                list.push(_cell)
+              })
+            })
+          }
+          
+          resolve(result.next)
+        })
+      }
+    }).then(res => {
+      // 鑾峰彇鎵撳嵃妯℃澘 getTemp
+      if (!res) return false
+
+      if (list.length === 0) {
+        notification.warning({
+          top: 92,
+          message: '鏈幏鍙栧埌鎵撳嵃鏁版嵁锛�',
+          duration: 5
+        })
+        return false
+      }
+
+      let param = {
+        func: 's_PrintTemplateMGetData',
+        Type: 'Y',
+        // ID: tempId, // 娣诲姞妯℃澘鏃讹紝淇濆瓨鍙婃煡璇娇鐢ㄦā鏉垮弬鏁�
+        PrintTempNO: btn.verify.Template
+      }
+
+      if (window.GLOB.mainSystemApi) { // 浠庡崟鐐圭櫥褰曟湇鍔″櫒鍙栨墦鍗伴厤缃俊鎭�
+        param.rduri = window.GLOB.mainSystemApi
+      }
+
+      return Api.getSystemCacheConfig(param)
+    }).then(result => {
+      if (!result) {
+        this.setState({ loading: false })
+        return
+      }
+
+      if (!result.ConfigParam) {
+        notification.warning({
+          top: 92,
+          message: '鏈幏鍙栧埌鎵撳嵃妯℃澘淇℃伅锛�',
+          duration: 5
+        })
+        this.setState({ loading: false })
+      } else {
+        let configParam = ''
+        try {
+          configParam = JSON.parse(window.decodeURIComponent(window.atob(result.ConfigParam)))
+        } catch (e) {
+          configParam = ''
+        }
+  
+        if (!configParam) {
+          notification.warning({
+            top: 92,
+            message: '鎵撳嵃妯℃澘瑙f瀽閿欒锛�',
+            duration: 5
+          })
+          this.setState({ loading: false })
+        } else {
+          this.execRfidPrint(list, configParam)
+        }
       }
     })
   }
@@ -379,12 +572,20 @@
 
     try {
       // eslint-disable-next-line
-      let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc)
-      func(printlist, formdata, btn.verify, notification)
+      let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc)
+      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
 
       // 鑷畾涔夋墦鍗扮ず渚�
       // let defaultPrinter = printer.defaultPrinter || 'lackprinter'
       // let printers = {}
+      // let getuuid = () => {
+      //   let uuid = []
+      //   let _options = '0123456789abcdefghigklmnopqrstuv'
+      //   for (let i = 0; i < 32; i++) {
+      //     uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
+      //   }
+      //   return uuid.join('')
+      // }
       // if (printer.printerTypeList && printer.printerTypeList.length > 0) {
       //   printer.printerTypeList.forEach(cell => {
       //     if (cell.printer) {
@@ -393,29 +594,43 @@
       //   })
       // }
 
-      // let jdList = []
-      // let otherList = []
-      // data.forEach(item => {
-      //   if (item.CustomData) {
-      //     item.CustomData = JSON.parse(item.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
-      //   }
-      //   if (item.PrintData) {
-      //     item.PrintData = JSON.parse(item.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
-      //     item.PrintData.data = {...form, ...item.PrintData.data}
-      //   }
+      // let jdList = [];
+      // let jdNewList = [];
+      // let otherList = [];
+      // let _map = new Map()
+      // data.forEach(m => {
+      //   if (!m.print_data || m.print_data.length === 0) return
         
-      //   if (!item.PrintData) {
-      //     return
-      //   }
+      //   m.print_data.forEach(n => {
+      //     if (n.InsideBill) {
+      //       if (_map.has(n.InsideBill)) {
+      //         return
+      //       }
+      //       _map.set(n.InsideBill, true)
+      //     }
+      //     if (n.CustomData) {
+      //       n.CustomData = JSON.parse(n.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
+      //     }
 
-      //   if (item.PrintData.ectype === 'jdpop') {
-      //     jdList.push(item)
-      //   } else {
-      //     otherList.push(item)
-      //   }
+      //     if (n.hasOwnProperty('StdTemplate')) {
+      //       jdNewList.push(n);
+      //       return
+      //     } else if (!n.PrintData) {
+      //       return
+      //     }
+
+      //     n.PrintData = JSON.parse(n.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
+      //     n.PrintData.data = {...form, ...n.PrintData.data}
+
+      //     if (n.PrintData.ectype === 'jdpop') {
+      //       jdList.push(n)
+      //     } else {
+      //       otherList.push(n)
+      //     }
+      //   })
       // })
 
-      // if (jdList.length === 0 && otherList.length === 0) {
+      // if (jdList.length === 0 && otherList.length === 0 && jdNewList.length === 0) {
       //   notification.warning({
       //     top: 92,
       //     message: '鏃犳墦鍗版暟鎹紒',
@@ -424,79 +639,88 @@
       //   return
       // }
 
-      // let execPrint = (list, linkUrl) => {
-      //   let printdata = {}
+      // let execPrint = (list, linkUrl, type) => {
+      //   let printdata = {};
+      //   let printerList = [];
 
-      //   list.forEach(res => {
-      //     let _printer = defaultPrinter
+      //   if (type === 'jd') {
+      //     printerList = list.map(m => {
+      //       let _printer = defaultPrinter;
 
-      //     if (res.printType && printers[res.printType]) {
-      //       _printer = printers[res.printType]
-      //     }
-
-      //     printdata[_printer] = printdata[_printer] || []
-
-      //     printdata[_printer].push(res)
-      //   })
-
-      //   let printerList = []
-
-      //   Object.keys(printdata).forEach(printer => {
-      //     let _documents = []
-      //     printdata[printer].forEach(item => {
-      //       let _cell = {
-      //         documentID: new Date().getTime().toString(),
-      //         contents: []
+      //       if (m.printType && printers[m.printType]) {
+      //         _printer = printers[m.printType];
       //       }
 
-      //       if (item.PrintData) {
-      //         _cell.contents.push(item.PrintData)
+      //       return {
+      //         orderType: "print", 
+      //         parameters: {
+      //           printName: _printer === 'lackprinter' ? '' : _printer,
+      //           tempUrl: m.StdTemplate,
+      //           customTempUrl: m.CusTemplate,
+      //           customData: [m.CustomData],
+      //           printData: [m.PrintData]
+      //         } 
       //       }
-      //       if (item.CustomData) {
-      //         _cell.contents.push(item.CustomData)
+      //     })
+      //   } else {
+      //     list.forEach(res => {
+      //       let _printer = defaultPrinter
+
+      //       if (res.printType && printers[res.printType]) {
+      //         _printer = printers[res.printType]
       //       }
 
-      //       for (let i = 0; i < item.printCount; i++) {
+      //       printdata[_printer] = printdata[_printer] || []
+
+      //       printdata[_printer].push(res)
+      //     })
+
+      //     Object.keys(printdata).forEach(printer => {
+      //       let _documents = []
+      //       printdata[printer].forEach(item => {
+      //         let _cell = {
+      //           documentID: getuuid(),
+      //           contents: []
+      //         }
+
+      //         if (item.PrintData) {
+      //           _cell.contents.push(item.PrintData)
+      //         }
+      //         if (item.CustomData) {
+      //           _cell.contents.push(item.CustomData)
+      //         }
+
       //         _documents.push(_cell)
-      //       }
+      //       })
+      //       printerList.push({
+      //         cmd: 'print',
+      //         requestID: '',
+      //         version: '',
+      //         task: {
+      //           taskID: getuuid(),
+      //           preview: false,
+      //           printer: printer === 'lackprinter' ? '' : printer,
+      //           documents: _documents
+      //         }
+      //       })
       //     })
-      //     printerList.push({
-      //       cmd: 'print',
-      //       requestID: '',
-      //       version: '',
-      //       task: {
-      //         taskID: new Date().getTime().toString(),
-      //         preview: false,
-      //         printer: printer,
-      //         documents: _documents
-      //       }
-      //     })
-      //   })
-
-      //   let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0]
+      //   }
 
       //   let socket = new WebSocket('ws://' + linkUrl)
 
       //   // 鎵撳紑Socket
       //   socket.onopen = () =>{
-      //     if (lackItems) {
-      //       let request  = {
-      //         requestID: '',
-      //         version: '',
-      //         cmd: 'getPrinters'
-      //       }
-      //       socket.send(JSON.stringify(request))
-      //     } else {
-      //       printerList.forEach(cell => {
-      //         socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
-      //       })
+      //       printerList.forEach((cell, i) => {
+      //         setTimeout(() => {
+      //           socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
+      //       }, 1000 * i)
+      //       });
 
       //       notification.success({
       //         top: 92,
       //         message: '鎵撳嵃璇锋眰宸插彂鍑恒��',
       //         duration: 2
       //       })
-      //     }
       //   }
       //   // 鐩戝惉娑堟伅
       //   socket.onmessage = (event) => {
@@ -515,20 +739,7 @@
       //       }
       //     }
 
-      //     if (data && data.cmd === 'getPrinters' && data.status) {
-      //       printerList.forEach(cell => {
-      //         if (cell.task.printer === 'lackprinter') {
-      //           cell.task.printer = data.defaultPrinter
-      //         }
-      //         socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
-      //       })
-
-      //       notification.success({
-      //         top: 92,
-      //         message: '鎵撳嵃璇锋眰宸插彂鍑恒��',
-      //         duration: 2
-      //       })
-      //     } else if (data && data.message && !data.status) {
+      //     if (data && data.message && !data.status) {
       //       notification.warning({
       //         top: 92,
       //         message: data.message,
@@ -546,6 +757,9 @@
       //   }
       // }
 
+      // if (jdNewList.length > 0) {
+      //   execPrint(jdNewList, '127.0.0.1:9113', 'jd');
+      // }
       // if (jdList.length > 0) {
       //   execPrint(jdList, '127.0.0.1:13529')
       // }
@@ -557,8 +771,8 @@
 
       try {
         // eslint-disable-next-line
-        let evalfunc = eval('(true && function (data, form, printer, notification) {' + btn.verify.printFunc + '})')
-        evalfunc(printlist, formdata, btn.verify, notification)
+        let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})')
+        evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
       } catch (error) {
         console.warn(error)
         notification.warning({
@@ -574,65 +788,124 @@
    * @description 鑾峰彇鎵撳嵃鏁版嵁
    */
   getprintdata = (btn, data, formdata, formlist) => {
-    const { setting } = this.props
+    const { setting, BID } = this.props
 
     let _list = []
     return new Promise(resolve => {
       let params = []
-      let param = {}
 
-      if (this.props.BID) {
-        param.BID = this.props.BID
-      }
-
-      if (btn.Ot === 'notRequired') {
-        let _param = { ...param, ...formdata }
-        params.push(_param)
-      } else if (btn.Ot === 'requiredSgl') {
-        if (setting.primaryKey) {
-          param[setting.primaryKey] = data[0][setting.primaryKey]
-        }
-
-        let _param = { ...param, ...formdata }
-
-        params.push(_param)
-      } else if (btn.Ot === 'requiredOnce') {
-        if (setting.primaryKey) {
-          let ids = data.map(d => { return d[setting.primaryKey]})
-          ids = ids.filter(Boolean)
-          ids = ids.join(',')
+      if (btn.intertype === 'system' && btn.verify.dataType === 'custom') {
+        if (btn.Ot === 'notRequired') {
+          let _param = this.getDefaultSql(formlist, null, '')
   
-          param[setting.primaryKey] = ids
-        }
-
-        let _param = { ...param, ...formdata }
-
-        params.push(_param)
-      } else if (btn.Ot === 'required') {
-        params = data.map((cell, index) => {
-          let _param = { ...param }
-          
+          params.push(_param)
+        } else if (btn.Ot === 'requiredSgl') {
+          let ID = ''
           if (setting.primaryKey) {
-            _param[setting.primaryKey] = cell[setting.primaryKey]
+            ID = data[0][setting.primaryKey] || ''
           }
 
-          formlist.forEach(_data => {
-            if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) {
-              _param[_data.key] = cell[_data.key]
-            } else {
-              _param[_data.key] = _data.value
+          let _param = this.getDefaultSql(formlist, data[0], ID)
+  
+          params.push(_param)
+        } else if (btn.Ot === 'requiredOnce') {
+          let ID = ''
+  
+          if (setting.primaryKey) {
+            let ids = data.map(d => { return d[setting.primaryKey]})
+            ids = ids.filter(Boolean)
+            ID = ids.join(',')
+          }
+
+          let _param = this.getDefaultSql(formlist, data[0], ID)
+  
+          params.push(_param)
+        } else if (btn.Ot === 'required') {
+          params = data.map(cell => {
+            let ID = ''
+            if (setting.primaryKey) {
+              ID = cell[setting.primaryKey] || ''
             }
+
+            return this.getDefaultSql(formlist, cell, ID)
           })
-          return _param
-        })
+        }
+      } else {
+        if (btn.Ot === 'notRequired') {
+          let _param = { ...formdata }
+  
+          if (BID) {
+            _param.BID = BID
+          }
+  
+          params.push(_param)
+        } else if (btn.Ot === 'requiredSgl') {
+          let _param = { ...formdata }
+  
+          if (setting.primaryKey) {
+            _param[setting.primaryKey] = data[0][setting.primaryKey]
+          }
+  
+          if (BID) {
+            _param.BID = BID
+          }
+  
+          params.push(_param)
+        } else if (btn.Ot === 'requiredOnce') {
+          let _param = { ...formdata }
+  
+          if (setting.primaryKey) {
+            let ids = data.map(d => { return d[setting.primaryKey]})
+            ids = ids.filter(Boolean)
+            ids = ids.join(',')
+    
+            _param[setting.primaryKey] = ids
+          }
+  
+          if (BID) {
+            _param.BID = BID
+          }
+  
+          params.push(_param)
+        } else if (btn.Ot === 'required') {
+          params = data.map((cell, index) => {
+            let _param = {}
+            
+            if (setting.primaryKey) {
+              _param[setting.primaryKey] = cell[setting.primaryKey]
+            }
+  
+            if (BID) {
+              _param.BID = BID
+            }
+  
+            let _cell = {}
+            if (index !== 0) {
+              Object.keys(cell).forEach(key => {
+                _cell[key.toLowerCase()] = cell[key]
+              })
+            }
+  
+            formlist.forEach(_data => {
+              if (index !== 0 && _data.readin && _cell.hasOwnProperty(_data.key.toLowerCase())) {
+                _param[_data.key] = _cell[_data.key.toLowerCase()]
+              } else {
+                _param[_data.key] = _data.value
+              }
+            })
+            return _param
+          })
+        }
       }
 
-      if (btn.intertype === 'inner') {
-        params = params.map(_param => {
-          _param.func = btn.innerFunc
-
-          return _param
-        })
+      if (btn.intertype === 'inner' || btn.intertype === 'system') {
+        if (btn.intertype === 'inner') {
+          params = params.map(_param => {
+            _param.func = btn.innerFunc
+  
+            return _param
+          })
+        }
 
         if (params.length <= 20) {
           let deffers = params.map(par => {
@@ -650,7 +923,16 @@
               }
             })
             if (!errorMsg) {
-              resolve({next: true, list: result})
+              resolve({next: true, list: result.map(res => {
+                Object.keys(res).forEach(key => {
+                  let _key = key.toLowerCase()
+                  if (['templateid', 'printtype', 'printcount'].includes(_key)) {
+                    res[_key] = res[key]
+                  }
+                })
+
+                return res
+              })})
             } else {
               this.execError(errorMsg)
               resolve({next: false, list: []})
@@ -663,6 +945,233 @@
         this.printOuterLoopRequest(params, btn, _list, resolve)
       }
     })
+  }
+
+  /**
+   * @description 鑾峰彇榛樿瀛樺偍杩囩▼璇锋眰鍙傛暟
+   */
+  getDefaultSql = (formlist, data, ID) => {
+    const { BID, btn, columns } = this.props
+
+    let arrFields = btn.verify.columns.map(col => col.field).join(',')
+
+    let param = {
+      func: 'sPC_Get_TableData',
+      obj_name: 'data',
+      exec_type: 'y',
+      arr_field: arrFields,
+      default_sql: btn.verify.setting.defaultSql
+    }
+
+    if (BID) {
+      param.BID = BID
+    }
+    if (ID) {
+      param.ID = ID
+    }
+
+    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') || ''
+
+    let _dataresource = btn.verify.setting.dataresource
+    let _customScript = ''
+
+    btn.verify.scripts && btn.verify.scripts.forEach(script => {
+      if (script.status !== 'false') {
+        _customScript += `
+        ${script.sql}
+        `
+      }
+    })
+
+    if (btn.verify.setting.defaultSql === 'false') {
+      _dataresource = ''
+    }
+
+    if (/\s/.test(_dataresource)) {
+      _dataresource = '(' + _dataresource + ') tb'
+    }
+
+    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+      _dataresource = _dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
+      _dataresource = _dataresource.replace(/@\$/ig, '*/')
+      _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
+      _customScript = _customScript.replace(/@\$/ig, '*/')
+    } else {
+      _dataresource = _dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
+      _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
+    }
+
+    let initsql = `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)
+      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}'
+    `
+
+    let _vars = []
+    let _initvars = []
+    let _declare = []
+    // 鑾峰彇瀛楁閿�煎
+    formlist.forEach(form => {
+      let _key = form.key.toLowerCase()
+
+      if (_vars.includes(_key)) return
+
+      _vars.push(_key)
+
+      if (form.type === 'number' || form.type === 'rate') {
+        let val = form.value
+        if (isNaN(val)) {
+          val = 0
+        }
+        _initvars.push(`@${_key}=${val}`)
+      } else if (['date', 'datemonth'].includes(form.type)) {
+        _initvars.push(`@${_key}='${form.value || '1949-10-01'}'`)
+      } else {
+        _initvars.push(`@${_key}='${form.value}'`)
+      }
+
+      if (form.fieldlen && form.fieldlen > 2048) {
+        form.fieldlen = 'max'
+      }
+
+      let _type = `nvarchar(${form.fieldlen})`
+
+      if (form.type.match(/date/ig)) {
+        _type = 'datetime'
+      } else if (form.type === 'number') {
+        _type = `decimal(18,${form.fieldlen})`
+      } else if (form.type === 'rate') {
+        _type = `decimal(18,2)`
+      }
+
+      _declare.push(`@${_key} ${_type}`)
+    })
+
+    if (_declare.length > 0) {
+      initsql += `/* 琛ㄥ崟鍙橀噺 */
+        Declare ${_declare.join(',')}
+        select ${_initvars.join(',')}
+      `
+
+      _declare = []
+      _initvars = []
+    }
+
+    if (data && columns && columns.length > 0) {
+      let datavars = {}
+
+      Object.keys(data).forEach(key => {
+        datavars[key.toLowerCase()] = data[key]
+      })
+  
+      columns.forEach(col => {
+        if (!col.field || !col.datatype) return
+
+        let _key = col.field.toLowerCase()
+
+        if (_vars.includes(_key)) return
+  
+        let _val = datavars.hasOwnProperty(_key) ? datavars[_key] : ''
+
+        if (/^date/ig.test(col.datatype) && !_val) {
+          _val = '1949-10-01'
+        }
+
+        _initvars.push(`@${_key}='${_val}'`)
+        _declare.push(`@${_key} ${col.datatype}`)
+      })
+    }
+
+    if (_declare.length > 0) {
+      initsql += `/* 鏄剧ず鍒楀彉閲� */
+        Declare ${_declare.join(',')}
+        select ${_initvars.join(',')}
+      `
+    }
+
+    
+    if (_customScript) {
+      _customScript = `${initsql}
+        ${_customScript}
+      `
+    }
+
+    _dataresource = _dataresource.replace(/@select\$|\$select@/ig, '')
+    _customScript = _customScript.replace(/@select\$|\$select@/ig, '')
+    _dataresource = _dataresource.replace(/\$sum@/ig, '/*')
+    _dataresource = _dataresource.replace(/@sum\$/ig, '*/')
+    _customScript = _customScript.replace(/\$sum@/ig, '/*')
+    _customScript = _customScript.replace(/@sum\$/ig, '*/')
+
+    _dataresource = _dataresource.replace(/@ID@/ig, `'${ID}'`)
+    _customScript = _customScript.replace(/@ID@/ig, `'${ID}'`)
+    _dataresource = _dataresource.replace(/@BID@/ig, `'${BID || ''}'`)
+    _customScript = _customScript.replace(/@BID@/ig, `'${BID || ''}'`)
+    _dataresource = _dataresource.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    _customScript = _customScript.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
+    _dataresource = _dataresource.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    _customScript = _customScript.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
+    _dataresource = _dataresource.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    _customScript = _customScript.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
+    _dataresource = _dataresource.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    _customScript = _customScript.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+
+
+    let LText = ''
+
+    if (_dataresource) {
+      LText = `/*system_query*/select ${arrFields} from (select ${arrFields} ,ROW_NUMBER() over(order by ${btn.verify.setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
+    }
+
+    if (_customScript) {
+      if (LText) {
+        LText = `${LText}
+          aaa:
+          if @ErrorCode!=''
+            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ 
+        `
+      } else {
+        _customScript = `${_customScript}
+          aaa:
+          if @ErrorCode!=''
+            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ 
+        `
+      }
+    } else {
+      LText = `${initsql}
+        ${LText}
+      `
+    }
+
+    // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
+    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
+      _customScript && console.info(`${btn.logLabel ? `/*${btn.logLabel} 鑷畾涔夎剼鏈�*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      LText && console.info(`${btn.logLabel ? `/*${btn.logLabel} 鏁版嵁婧�*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
+    }
+
+    if (btn.logLabel) {
+      param.menuname = btn.logLabel
+    }
+
+    param.custom_script = Utils.formatOptions(_customScript)
+    param.LText = Utils.formatOptions(LText)
+
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+
+    if (window.GLOB.probation) {
+      param.s_debug_type = 'Y'
+    }
+
+    return param
   }
 
   /**
@@ -705,9 +1214,11 @@
       // 澶栭儴璇锋眰
       _outParam = JSON.parse(JSON.stringify(res))
 
-      if (this.props.menuType === 'HS') {
+      if (window.GLOB.mkHS) {
         if (btn.sysInterface === 'true' && options.cloudServiceApi) {
           res.rduri = options.cloudServiceApi
+          res.userid = sessionStorage.getItem('CloudUserID') || ''
+          res.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
         } else if (btn.sysInterface !== 'true') {
           if (window.GLOB.systemType === 'production' && btn.proInterface) {
             res.rduri = btn.proInterface
@@ -716,13 +1227,26 @@
           }
         }
       } else {
-        if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) {
-          res.rduri = window.GLOB.mainSystemApi
-        } else if (btn.sysInterface !== 'true') {
+        if (btn.sysInterface === 'true') {
+          if (window.GLOB.mainSystemApi) {
+            res.rduri = window.GLOB.mainSystemApi
+          }
+        } else if (btn.sysInterface === 'external') {
+          if (window.GLOB.systemType === 'production') {
+            res.$token = btn.exProInterface || ''
+          } else {
+            res.$token = btn.exInterface || ''
+          }
+        } else {
           if (window.GLOB.systemType === 'production' && btn.proInterface) {
             res.rduri = btn.proInterface
           } else {
             res.rduri = btn.interface
+          }
+
+          let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
+          if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) {
+            res.$login = true
           }
         }
       }
@@ -746,6 +1270,12 @@
 
         return Api.genericInterface(_callbackparam)
       } else if (response.status) {
+        Object.keys(response).forEach(key => {
+          let _key = key.toLowerCase()
+          if (['templateid', 'printtype', 'printcount'].includes(_key)) {
+            response[_key] = response[key]
+          }
+        })
 
         _list.push(response)
 
@@ -763,6 +1293,13 @@
       if (!response) return
 
       if (response.status) {
+        Object.keys(response).forEach(key => {
+          let _key = key.toLowerCase()
+          if (['templateid', 'printtype', 'printcount'].includes(_key)) {
+            response[_key] = response[key]
+          }
+        })
+
         _list.push(response)
 
         // 涓�娆¤姹傛垚鍔燂紝杩涜涓嬩竴椤硅姹�
@@ -786,6 +1323,12 @@
 
     Api.genericInterface(param).then(res => {
       if (res.status) {
+        Object.keys(res).forEach(key => {
+          let _key = key.toLowerCase()
+          if (['templateid', 'printtype', 'printcount'].includes(_key)) {
+            res[_key] = res[key]
+          }
+        })
         _list.push(res)
 
         if (params.length === 0) {
@@ -820,8 +1363,19 @@
       if (!configParam) {
         error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�'
       } else {
-        let control = configParam.elements.map(element => {
-          let _field = element.field
+        let control = []
+        let rotate = configParam.rotate || 0
+        let offsetTop = 0
+        let offsetLeft = 0
+
+        if (rotate === 90) {
+          offsetTop = configParam.width - configParam.height
+        } else if (rotate === 270) {
+          offsetLeft = configParam.height - configParam.width
+        }
+
+        configParam.elements.forEach(element => {
+          let _field = element.field || ''
 
           if (_field === 'other_field') {
             _field = element.cusfield || ''
@@ -831,12 +1385,13 @@
             Name: element.name || '',
             Type: element.type,
             Value: element.value || '',
-            Field: _field,
-            Left: element.left,
-            Top: element.top,
+            Field: _field.toLowerCase(),
+            Left: element.left + offsetLeft,
+            Top: element.top + offsetTop,
             Width: element.width,
             Height: element.height,
-            Rotate: element.rotate,
+            Rotate: rotate,
+            // Rotate: element.rotate,
             BorderSize: element.borderSize / 10,
             BorderColor: element.borderColor,
             Align: element.align,
@@ -856,21 +1411,24 @@
             item.Trimming = ''
             if (!item.Width) {
               item.Width = item.BorderSize
-              item.Left = item.Left - item.Width
+              item.Left = item.Left - item.Width + 0.1
             } else if (!item.Height) {
               item.Height = item.BorderSize
-              item.Top = item.Top - item.Height
+              item.Top = item.Top - item.Height + 0.1
             }
+            item.BackColor = element.borderColor
             item.BorderSize = 0
           } else if (item.Type === 'image') {
             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)
+            if (!item.Field) {
+              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
@@ -900,8 +1458,14 @@
             }
           }
 
-          return item
+          control.push(item)
         })
+
+        let down = false
+
+        if (rotate === 90 || rotate === 270) {
+          down = true
+        }
 
         _configparam = {
           Version: '',
@@ -910,8 +1474,8 @@
           Description: configParam.remark,
           PrintTempNO: configParam.PrintTempNO,
           PageSetting: {
-            Width: configParam.width,
-            Height: configParam.height,
+            Width: down ? configParam.height : configParam.width,
+            Height: down ? configParam.width : configParam.height,
             Left: '0',
             Right: '0',
             Top: '0',
@@ -931,16 +1495,159 @@
     return {
       error: error,
       config: _configparam,
-      fields: fields,
-      nonEFields: nonEFields,
+      fields: Array.from(new Set(fields)),
+      nonEFields: Array.from(new Set(nonEFields)),
       imgs: imgs
     }
   }
 
-  execPrint = (list, template, formdata) => {
+  execRfidPrint = (list, template) => {
+    const { btn } = this.props
+
+    list = list.filter(item => !!item[btn.verify.valueField])
+
+    if (list.length === 0) {
+      notification.warning({
+        top: 92,
+        message: '鏈幏鍙栧埌鎵撳嵃鏁版嵁锛�',
+        duration: 5
+      })
+      this.setState({ loading: false })
+      return
+    }
+
+    let width = template.width
+    let height = template.height
+    let gap = template.gap || 0
+    let mm = 12
+
+    if (btn.verify.DPI === '203') {
+      mm = 8
+    } else if (btn.verify.DPI === '600') {
+      mm = 24
+    }
+
+    let items = []
+    template.elements.forEach(element => {
+      if (!['text', 'barcode', 'qrcode'].includes(element.type)) return
+
+      let _field = element.field
+
+      if (_field === 'other_field') {
+        _field = element.cusfield || ''
+      }
+
+      let item = {
+        type: element.type,
+        value: element.value || '',
+        field: _field
+      }
+
+      if (item.type === 'text') {
+        let size = Math.floor(4 * mm * (element.fontSize || 12) / 12)
+        let fontWeight = 400
+        if (element.fontWeight === 'bold') {
+          fontWeight = 600
+        } else if (element.fontWeight === 'bolder') {
+          fontWeight = 800
+        } else if (element.fontWeight === 'lighter') {
+          fontWeight = 300
+        }
+        item.draw = `${element.left * mm},${element.top * mm},${size},0,${element.fontFamily || '寰蒋闆呴粦'},${element.align === 'center' ? 5 : 1},${fontWeight},0,0,0,`
+      } else if (item.type === 'barcode') {
+        let codeType = 1
+        if (element.barcodeType === 'EAN13') {
+          codeType = 'E30'
+        }
+        let narrowWidth = element.narrowWidth || 2
+        let horizontal = element.narrowWidth || 2
+        let vertical = Math.ceil(element.barcodeHeight * mm)
+
+        item.draw = `${element.left * mm},${element.top * mm},0,${codeType},${narrowWidth},${horizontal},${vertical},${element.barcodeLabel === 'true' ? 'B' : 'N'},`
+      } else if (item.type === 'qrcode') {
+        let r = Math.ceil(element.qrcodeWidth / 2)
+
+        item.draw = `${element.left * mm},${element.top * mm},0,0,0,${r},0,0,8,`
+      }
+
+      items.push(item)
+    })
+
+    let ip = '192.168.1.2'
+    let params = list.map(cell => {
+      let array = []
+      let value = cell[btn.verify.valueField]
+
+      if (btn.verify.linkType !== 'USB') {
+        array.push({PTK_Connect_Timer: `${ip},${btn.verify.port},5`}); // 鎵撳紑鎵撳嵃鏈虹綉缁滅鍙�
+      } else {
+        array.push({PTK_OpenUSBPort: btn.verify.port}); // 鎵撳紑鎵撳嵃鏈篣SB绔彛
+      }
+
+      array.push({PTK_ClearBuffer: ''}); // 娓呯┖缂撳瓨
+      array.push({PTK_SetDirection: 'B'}); // 璁剧疆鎵撳嵃鏂瑰悜
+      array.push({PTK_SetLabelHeight: height * mm + ',' + gap * mm + ',' + 0 + ',' + false}); // 璁剧疆鏍囩楂樺害銆侀棿闅欏強鍋忕Щ
+      array.push({PTK_SetLabelWidth: width * mm}); // 璁剧疆鏍囩瀹藉害
+      array.push({PTK_SetRFID: '0,0,0,0,0'}); // UHF RFID鎵撳嵃璁剧疆
+      array.push({PTK_RWRFIDLabel: '1,0,0,4,1,' + value});
+
+      items.forEach(m => {
+        let val = ''
+        if (m.field) {
+          val = cell[m.field]
+        } else {
+          val = m.value
+        }
+
+        if (!val && val !== 0) return
+
+        if (m.type === 'text') {
+          array.push({PTK_DrawText_TrueType: m.draw + val});
+        } else if (m.type === 'barcode') {
+          array.push({PTK_DrawBarcode: m.draw + val});
+        } else if (m.type === 'qrcode') {
+          array.push({PTK_DrawBar2D_QR: m.draw + val});
+        }
+      })
+      
+      array.push({PTK_PrintLabel: '1,1'});
+      array.push({PTK_CloseUSBPort: ''}); // 鍏抽棴USB閫氳绔彛
+
+      return {
+        reqParam: '1',
+        printparams: JSON.stringify(array)
+      }
+    })
+
+    this.loopRFIDPrint(params)
+  }
+
+  loopRFIDPrint = (params) => {
+    let param = params.shift()
+
+    Api.postekPrint(param).then(res => {
+      if (res.retval === '0') {
+        if (params.length === 0) {
+          this.execSuccess({ ErrCode: 'S', message: '', ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', status: true })
+        } else {
+          setTimeout(() => {
+            this.loopRFIDPrint(params)
+          }, 200)
+        }
+      } else {
+        if (res.retval === '30021') {
+          res.msg = res.msg.replace(/PTK_ClearBuffer[\s\S]*/, '')
+        }
+        
+        this.execError({ErrCode: 'N', message: res.msg})
+      }
+    })
+  }
+
+  execPrint = (list, template) => {
     const { btn } = this.props
     let _errors = []
-    
+
     let defaultPrinter = btn.verify.defaultPrinter || 'lackprinter'
     let printers = {}
     if (btn.verify.printerTypeList && btn.verify.printerTypeList.length > 0) {
@@ -977,30 +1684,25 @@
         _datalist.forEach(res => {
           res.data.forEach(_cell => {
             for (let i = 0; i < res.printCount; i++) {
-              _data.push({...formdata, ..._cell})
+              _data.push(_cell)
             }
           })
         })
 
-        let _fields = Array.from(new Set(template[key].fields))
-        let _nonEFields = Array.from(new Set(template[key].nonEFields))
         let lacks = []
         let emptys = []
 
         _data.forEach(d => {
-          _fields.forEach(f => {
+          template[key].fields.forEach(f => {
             if (!d.hasOwnProperty(f)) {
               lacks.push(f)
-            } else if (_nonEFields.includes(f) && !d[f] && d[f] !== 0) {
+            } else if (template[key].nonEFields.includes(f) && !d[f] && d[f] !== 0) {
               emptys.push(f)
             }
           })
         })
 
         if (lacks.length > 0 || emptys.length > 0) {
-          lacks = Array.from(new Set(lacks))
-          emptys = Array.from(new Set(emptys))
-
           _errors.push({
             title: template[key].config.Title,
             lacks: lacks,
@@ -1041,12 +1743,21 @@
     })
 
     if (list.length === 0) {
-      this.execError({
-        ErrCode: 'N',
-        message: '鏈幏鍙栧埌鎵撳嵃淇℃伅锛�',
-        ErrMesg: '',
-        status: false
-      })
+      if (btn.verify.emptyTip === 'false') {
+        this.execSuccess({
+          ErrCode: '-1',
+          message: '鏈幏鍙栧埌鎵撳嵃淇℃伅锛�',
+          ErrMesg: '',
+          status: true
+        })
+      } else {
+        this.execError({
+          ErrCode: 'N',
+          message: '鏈幏鍙栧埌鎵撳嵃淇℃伅锛�',
+          ErrMesg: '',
+          status: false
+        })
+      }
       return
     } else if (_errors.length > 0) {
       let lackerror = []
@@ -1079,49 +1790,29 @@
       return
     }
 
-    // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0]
-
     if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) {
       socket = new WebSocket('ws://' + btn.verify.linkUrl)
     } else {
-      // if (lackItems) {
-      //   let request  = {
-      //     requestID: '',
-      //     version: '',
-      //     cmd: 'getPrinters'
-      //   }
-      //   socket.send(JSON.stringify(request))
-      // } else {
-        this.syncMessageSend(printerList)
+      this.syncMessageSend(printerList)
 
-        this.execSuccess({
-          ErrCode: 'S',
-          message: '',
-          ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
-          status: true
-        })
-      // }
+      this.execSuccess({
+        ErrCode: 'S',
+        message: '',
+        ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
+        status: true
+      })
     }
 
     // 鎵撳紑Socket
     socket.onopen = () =>{
-      // if (lackItems) {
-      //   let request  = {
-      //     requestID: '',
-      //     version: '',
-      //     cmd: 'getPrinters'
-      //   }
-      //   socket.send(JSON.stringify(request))
-      // } else {
-        this.syncMessageSend(printerList)
+      this.syncMessageSend(printerList)
 
-        this.execSuccess({
-          ErrCode: 'S',
-          message: '',
-          ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
-          status: true
-        })
-      // }
+      this.execSuccess({
+        ErrCode: 'S',
+        message: '',
+        ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��',
+        status: true
+      })
     }
     // 鐩戝惉娑堟伅
     socket.onmessage = (event) => {
@@ -1200,27 +1891,40 @@
    */
   execSuccess = (res) => {
     const { btn } = this.props
+    const { autoMatic, btnconfig } = this.state
 
-    if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛
+    if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 鎵ц鎴愬姛
       notification.success({
         top: 92,
         message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
         duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
       })
-    } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛
+    } else if (res.ErrCode === 'Y') { // 鎵ц鎴愬姛
       Modal.success({
         title: res.ErrMesg || this.state.dict['main.action.confirm.success']
       })
-    } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
+    } else if (res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
 
     }
-    
+
+    if (autoMatic || !btnconfig || btnconfig.setting.finish !== 'unclose') {
+      this.setState({
+        visible: false
+      })
+    }
+
     this.setState({
-      loading: false
+      loading: false,
+      confirmLoading: false
     })
 
+    if (autoMatic) {
+      MKEmitter.emit('autoExecOver', btn.uuid, 'success')
+      return
+    }
+
     if (btn.execSuccess !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn)
+      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines)
     }
   }
 
@@ -1232,12 +1936,13 @@
    */
   execError = (res) => {
     const { btn } = this.props
+    const { btnconfig, autoMatic } = this.state
 
-    if (res.ErrCode === 'E') {
+    if (res.ErrCode === 'E' && !autoMatic) {
       Modal.error({
         title: res.message || res.ErrMesg,
       })
-    } else if (res.ErrCode === 'N') {
+    } else if (res.ErrCode === 'N' || autoMatic) {
       notification.error({
         top: 92,
         message: res.message || res.ErrMesg,
@@ -1255,11 +1960,21 @@
     }
     
     this.setState({
-      loading: false
+      loading: false,
+      confirmLoading: false
     })
 
+    if (autoMatic) {
+      MKEmitter.emit('autoExecOver', btn.uuid, 'error')
+      return
+    }
+
+    if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) {
+      MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus)
+    }
+
     if (btn.execError !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn)
+      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
     }
   }
 
@@ -1281,8 +1996,7 @@
       if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
         let _option = Utils.getSelectQueryOptions(cell)
 
-        cell.data_sql = Utils.formatOptions(_option.sql)
-        cell.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
+        cell.base_sql = _option.sql
         cell.arr_field = _option.field
       }
 
@@ -1302,10 +2016,10 @@
    */
   improveAction = () => {
     const { btn } = this.props
-    const { btnconfig } = this.state
+    const { btnconfig, autoMatic } = this.state
 
     if (btnconfig) {
-      if (btnconfig.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず
+      if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず
         this.modelconfirm()
       } else {
         this.setState({
@@ -1334,14 +2048,14 @@
             message: res.message,
             duration: 5
           })
-          this.updateStatus('over')
+          this.setState({ loading: false })
         } else if (!_LongParam || (btn.execMode === 'pop' && _LongParam.type !== 'Modal')) {
           notification.warning({
             top: 92,
             message: '鏈幏鍙栧埌鎸夐挳閰嶇疆淇℃伅锛�',
             duration: 5
           })
-          this.updateStatus('over')
+          this.setState({ loading: false })
         } else {
           _LongParam = updateForm(_LongParam)
           _LongParam = this.handleModelConfig(_LongParam)
@@ -1349,7 +2063,7 @@
           this.setState({
             btnconfig: _LongParam
           }, () => {
-            if (_LongParam.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず
+            if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず
               this.modelconfirm()
             } else {
               this.setState({
@@ -1366,11 +2080,11 @@
    * @description 妯℃�佹锛堣〃鍗曪級锛岀‘璁�
    */
   handleOk = () => {
+    if (!this.formRef) return
+
     this.formRef.handleConfirm().then(res => {
-      this.setState({
-        visible: false
-      })
-      this.triggerPrint(this.state.tabledata, res)
+      this.setState({ confirmLoading: true })
+      this.triggerPrint(this.state.selines, res)
     })
   }
 
@@ -1379,16 +2093,29 @@
    */
   handleCancel = () => {
     this.setState({
-      visible: false
+      loading: false,
+      visible: false,
+      confirmLoading: false
     })
-    this.updateStatus('over')
   }
 
   modelconfirm = () => {
-    const { BData } = this.props
-    const { btnconfig, tabledata } = this.state
+    const { btnconfig, selines } = this.state
     let _this = this
     let result = []
+    let _data = {}
+    let BData = {}
+
+    if (selines[0]) {
+      Object.keys(selines[0]).forEach(key => {
+        _data[key.toLowerCase()] = selines[0][key]
+      })
+    }
+    if (this.props.BData) {
+      Object.keys(this.props.BData).forEach(key => {
+        BData[key.toLowerCase()] = this.props.BData[key]
+      })
+    }
     
     btnconfig.fields.forEach(item => {
       if (!item.field) return
@@ -1399,10 +2126,10 @@
         _readin = false
       }
 
-      if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) {
-        _initval = BData[item.field]
-      } else if (_readin && tabledata[0] && tabledata[0].hasOwnProperty(item.field)) {
-        _initval = tabledata[0][item.field]
+      if (item.type === 'linkMain' && BData.hasOwnProperty(item.field.toLowerCase())) {
+        _initval = BData[item.field.toLowerCase()]
+      } else if (_readin && _data.hasOwnProperty(item.field.toLowerCase())) {
+        _initval = _data[item.field.toLowerCase()]
       } else if (item.type === 'date' && _initval) {
         _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD')
       } else if (item.type === 'datemonth' && _initval) {
@@ -1416,6 +2143,24 @@
         _fieldlen = item.fieldlength || 512
       } else if (item.type === 'number') {
         _fieldlen = item.decimal ? item.decimal : 0
+      } else if (item.type === 'rate') {
+        item.rateCount = item.rateCount || 5
+        let allowHalf = item.allowHalf === 'true'
+
+        if (allowHalf) {
+          _initval = parseFloat(_initval)
+          if (_initval % 0.5 !== 0) {
+            _initval = parseInt(_initval)
+          }
+        } else {
+          _initval = parseInt(_initval)
+        }
+
+        if (isNaN(_initval) || _initval < 0) {
+          _initval = 0
+        } else if (_initval > item.rateCount) {
+          _initval = item.rateCount
+        }
       }
 
       if (_initval === undefined) {
@@ -1425,44 +2170,45 @@
       result.push({
         key: item.field,
         readonly: item.readonly === 'true',
-        readin: _readin,
+        readin: item.readin !== 'false' && item.readin !== 'top',
         fieldlen: _fieldlen,
         type: item.type,
         value: _initval
       })
     })
 
-    confirm({
-      title: this.state.dict['main.action.confirm.tip'],
-      onOk() {
-        _this.triggerPrint(tabledata, result)
-      },
-      onCancel() {
-        _this.updateStatus('over')
-      }
-    })
+    if (btnconfig.setting.display === 'exec') {
+      this.execSubmit(selines, () => {}, result)
+    } else {
+      confirm({
+        title: this.state.dict['main.action.confirm.tip'],
+        onOk() {
+          _this.triggerPrint(selines, result)
+        },
+        onCancel() {
+          _this.setState({ loading: false })
+        }
+      })
+    }
   }
 
   /**
    * @description 鏄剧ず妯℃�佹
    */
   getModels = () => {
-    const { setting, BID, btn } = this.props
+    const { BID, btn } = this.props
     const { btnconfig } = this.state
 
     if (!this.state.visible || !btnconfig || !btnconfig.setting) return null
 
-    let title = btnconfig.setting.title
-    let width = btnconfig.setting.width + 'vw'
+    let title = btn.label
+    let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw'
     let clickouter = false
     let container = document.body
 
-    if (
-      (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) ||
-      (btnconfig.setting.container === 'tab' && btn.ContainerId)
-    ) {
-      width = btnconfig.setting.width + '%'
-      container = () => document.getElementById(this.props.ContainerId || btn.ContainerId)
+    if (btnconfig.setting.container === 'tab' && btn.ContainerId) {
+      width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
+      container = () => document.getElementById(btn.ContainerId)
     }
 
     if (btnconfig.setting.clickouter === 'close') {
@@ -1476,6 +2222,7 @@
         getContainer={container}
         wrapClassName='action-modal'
         visible={this.state.visible}
+        confirmLoading={this.state.confirmLoading}
         width={width}
         onOk={this.handleOk}
         onCancel={this.handleCancel}
@@ -1484,10 +2231,9 @@
         <MutilForm
           BID={BID}
           dict={this.state.dict}
-          menuType={this.props.menuType}
           action={btnconfig}
           inputSubmit={this.handleOk}
-          data={this.state.tabledata[0]}
+          data={this.state.selines[0]}
           BData={this.props.BData}
           wrappedComponentRef={(inst) => this.formRef = inst}
         />
@@ -1496,62 +2242,49 @@
   }
 
   render() {
-    const { btn, show } = this.props
-    const { loadingNumber, loading, disabled } = this.state
+    const { btn } = this.props
+    const { loading, disabled, hidden } = 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>
-        {this.getModels()}
-      </div>
-    } else { // icon銆乼ext銆� all 鍗$墖
-      let label = ''
-      let icon = ''
+    if (hidden) return null
 
-      if (show === 'button') {
-        label = btn.label
-        icon = btn.icon || ''
-      } else if (show === 'link') {
-        label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
-        icon = ''
-      } else if (show === 'icon') {
-        icon = btn.icon || ''
-      // } else if (show === 'text') {
-      } else {
-        label = btn.label
-      }
+    let label = ''
+    let icon = ''
+    let type = 'link'
+    let className = ''
 
-      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
-        <Button
-          type="link"
-          title={show === 'icon' ? btn.label : ''}
-          loading={loading}
-          disabled={disabled}
-          style={btn.style}
-          icon={icon}
-          onClick={() => {this.actionTrigger()}}
-        >{label}</Button>
-        {this.getModels()}
-      </div>
+    if (btn.show === 'button') {
+      label = btn.label
+      icon = btn.icon || ''
+    } else if (btn.show === 'link') {
+      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
+      icon = ''
+    } else if (btn.show === 'icon') {
+      icon = btn.icon || ''
+    } else if (!btn.$toolbtn) {
+      icon = btn.icon || ''
+      label = btn.label
+      className = 'mk-btn mk-' + btn.class
+    } else {
+      type = ''
+      icon = btn.icon || ''
+      label = btn.label
+      className = 'mk-btn mk-' + btn.class
     }
+
+    return <>
+      <Button
+        type={type}
+        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
+        loading={loading}
+        disabled={disabled}
+        style={btn.style || null}
+        icon={icon}
+        className={className}
+        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
+      >{label}</Button>
+      <span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span>
+    </>
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    tabviews: state.tabviews,
-    menuType: state.editLevel
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(PrintButton)
\ No newline at end of file
+export default PrintButton
\ No newline at end of file

--
Gitblit v1.8.0