edit-table.vue 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115
  1. <!-- @desc:编辑表格 @auth:周兴 @time:2022/11/15 13:06 -->
  2. <template>
  3. <div :style="{height: 100 + '%',width:divWidth,paddingRight:'3px'}" ref="edit-table-div" v-if="existsFlag">
  4. <div v-if="title" class="table-title">{{ title }}
  5. <Poptip trigger="hover" transfer placement="top-start" :content="titleInfo" v-if="titleInfo">
  6. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 12px" color="#909399" ref="info-icon"/>
  7. </Poptip>
  8. </div>
  9. <vxe-table
  10. border
  11. size="mini"
  12. show-overflow
  13. :cell-style="cellStyle"
  14. :height="height +'px'"
  15. show-footer
  16. align="center"
  17. auto-resize
  18. sync-resize
  19. :ref="name"
  20. :edit-rules="validRules"
  21. :valid-config="{showMessage:false}"
  22. :data="tableData"
  23. :show-header="showHeader"
  24. :show-footer="showFooter"
  25. :highlight-current-row="highlightCurrentRow"
  26. :footer-method="footerMethod"
  27. :mouse-config="{selected: true}"
  28. :checkbox-config="{range: true}"
  29. :column-config="{resizable: true}"
  30. :menu-config="{body:header,header:header,visibleMethod:visibleMethod}"
  31. :keyboard-config="{isArrow: true, isDel: true, isEnter: true, isTab: true, isEdit: true, editMethod}"
  32. :edit-config="{ mode: 'row',trigger:'click',autoClear:false, enabled:enabledEdit}"
  33. :row-config="{isCurrent: true}"
  34. @contextmenu.native.prevent
  35. @scroll="handleScroll"
  36. @cell-click="handleCellClick"
  37. @keydown="handleTableKeyDown"
  38. @cell-mouseenter="handleCellMouseEnter"
  39. @cell-mouseleave="handleCellMouseLeave"
  40. @edit-closed="editClosed"
  41. @current-change="currentChangeGetData"
  42. @menu-click="menuClick"
  43. >
  44. <div v-for="(colItem,colIndex) in columnsData" :key="colIndex">
  45. <!-- 空白 (TODO第一列留一个余白,不然顺序就会乱,没有找到原因 周兴 2022-6-11) -->
  46. <vxe-column type="blank" v-if="colItem.type === 'blank'" :field="colItem.field" :width="colItem.width"
  47. :resizable="false">
  48. </vxe-column>
  49. <!--校验信息-->
  50. <vxe-column type="info" v-if="colItem.type === 'info'" :field="colItem.field" :width="colItem.width"
  51. :resizable="false">
  52. <template #default="{ row,rowIndex,column }">
  53. <Poptip trigger="hover" transfer placement="top-start" :content="row.info" v-if="row.info">
  54. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 14px" color="red" ref="info-icon"/>
  55. </Poptip>
  56. </template>
  57. </vxe-column>
  58. <!-- 序列 -->
  59. <vxe-column v-if="colItem.type === 'seq'" type="seq" :field="colItem.field" width="60" :title="vm.$t('seq')">
  60. <template #default="{row, seq, rowIndex}">
  61. <div v-if="!row._hover" :class="row.parentId === null ?'seq-class':'seq-class-s'">
  62. {{ seq }}
  63. </div>
  64. <seq-button :delete-flag="deleteFlag && canDelete(row,colItem)" v-if="row._hover" :add-flag="addFlag"
  65. @add="add(rowIndex)" @del="del(rowIndex)"/>
  66. </template>
  67. </vxe-column>
  68. <!-- 选取类型 -->
  69. <vxe-column v-if="colItem.type === 'tableSelect'" :field="colItem.field"
  70. :type="colItem.type"
  71. :header-class-name="colItem.required?'required-class':''"
  72. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  73. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  74. :title="colItem.title?colItem.title:$t(colItem.field)" :params="{type:'tableSelect'}"
  75. :edit-render="{autofocus: '.vxe-input--inner'}">
  76. <template #header="{ row }">
  77. <span :ref="'title_' + colItem.field ">{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
  78. <!--提示信息-->
  79. <Poptip trigger="hover" transfer placement="top-start" :content="colItem.info" v-if="colItem.info">
  80. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 14px;margin-top:-1px"
  81. color="#909399" ref="info-icon"/>
  82. </Poptip>
  83. <Poptip trigger="click" transfer @on-popper-hide="popperHide">
  84. <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
  85. v-if="colItem.copyVisible"/>
  86. <div slot="content">
  87. <div style="display: flex;align-items: center;justify-content: center;">
  88. <TableSelect :field="colItem.field" :dataType="colItem.dataType"
  89. :sortBoolean="colItem.sortBoolean"
  90. :multiple="false"
  91. :showType="colItem.showType"
  92. :promotionType="colItem.promotionType"
  93. :searchDetailFlag="false"
  94. :clickCloseFlag="false"
  95. @onBatchChoose="onBatchChooseCopy($event,colItem,'batch')"
  96. @onChoose="onBatchChooseCopy($event,colItem)"
  97. :search-param="typeof colItem.param === 'function'? colItem.param():colItem.param"
  98. :search-init-param="typeof colItem.initParam === 'function'? colItem.initParam():colItem.initParam"></TableSelect>
  99. <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
  100. </div>
  101. </div>
  102. </Poptip>
  103. <!--冻结/解冻列-->
  104. <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
  105. v-if="freezeData && colItem.freezeFlag"
  106. type="ios-lock"
  107. @click="handleFreeze(colItem.field)"/>
  108. </template>
  109. <template style="width:100%;" #edit="{ row,column,rowIndex }">
  110. <TableSelect :text="row[colItem.field]" :field="colItem.field" :dataType="colItem.dataType"
  111. v-if="setCellCanTableSelect(row,colItem) "
  112. :sortBoolean="colItem.sortBoolean"
  113. :multiple="colItem.multiple"
  114. :showType="colItem.showType"
  115. :promotionType="colItem.promotionType"
  116. :clearFlag="true"
  117. :search-param="typeof colItem.param === 'function'? colItem.param():colItem.param"
  118. :search-init-param="typeof colItem.initParam === 'function'? colItem.initParam():colItem.initParam"
  119. @on-input-blur="handleSelectInputBlur($event,row,rowIndex,colItem,colIndex)"
  120. @change="(val)=>inputChange(row,rowIndex,colItem,val)"
  121. @keydown.stop="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex,row}))"
  122. @onBatchChoose="onBatchChoose($event,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"
  123. @onChoose="onChoose($event,row,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"
  124. :ref="colItem.field+rowIndex"
  125. :select-field="colItem.selectField"></TableSelect>
  126. <div class="edit-div-class" v-else @dblclick.stop="copyValue(row,colItem,rowIndex)"
  127. style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;display: inline-block;width: 100%;">
  128. {{ row[colItem.field] }}
  129. </div>
  130. </template>
  131. </vxe-column>
  132. <!-- 无法修改类型 -->
  133. <vxe-column v-if="colItem.type === 'disabled' && !colItem.switch" :field="colItem.field"
  134. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  135. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  136. :formatter="formatColumn" :params="colItem"
  137. :title="colItem.title?colItem.title:$t(colItem.field)">
  138. <!--标题-->
  139. <!-- <template #header="{ row,column,columnIndex }">-->
  140. <!-- <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>-->
  141. <!-- &lt;!&ndash;冻结/解冻列&ndash;&gt;-->
  142. <!-- <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "-->
  143. <!-- v-if="freezeData && colItem.freezeFlag"-->
  144. <!-- type="ios-lock"-->
  145. <!-- @click="handleFreeze(colItem.field)"/>-->
  146. <!-- </template>-->
  147. <template #default="{ row,rowIndex,column }">
  148. <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)">{{
  149. formatColumn({
  150. column: column,
  151. cellValue: row[colItem.field],
  152. row: row
  153. })
  154. }}
  155. </div>
  156. </template>
  157. </vxe-column>
  158. <!-- 无法修改类型 开关 -->
  159. <vxe-column v-if="colItem.type === 'disabled' && colItem.switch" :field="colItem.field"
  160. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  161. :min-width="colItem.width?colItem.width:vm.$config.columnWidthMin" :params="colItem"
  162. :title="colItem.title?colItem.title:$t(colItem.field)">
  163. <!--标题-->
  164. <!-- <template #header="{ row,column,columnIndex }">-->
  165. <!-- <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>-->
  166. <!-- &lt;!&ndash;冻结/解冻列&ndash;&gt;-->
  167. <!-- <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "-->
  168. <!-- v-if="freezeData && colItem.freezeFlag"-->
  169. <!-- type="ios-lock"-->
  170. <!-- @click="handleFreeze(colItem.field)"/>-->
  171. <!-- </template>-->
  172. <template #default="{ row,rowIndex }">
  173. <div class="switch-class">
  174. <i-switch size="small" :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
  175. :disabled="true"/>
  176. </div>
  177. </template>
  178. </vxe-column>
  179. <!-- 文本类型 -->
  180. <vxe-column v-if="colItem.type === 'text'" :field="colItem.field"
  181. :title="colItem.title?colItem.title:$t(colItem.field)"
  182. :type="colItem.type"
  183. :header-class-name="colItem.required?'required-class':''"
  184. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  185. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  186. :edit-render="{autofocus: '.vxe-input--inner'}">
  187. <template #header="{ row }">
  188. <span :ref="'title_' + colItem.field ">{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
  189. <!--提示信息-->
  190. <Poptip trigger="hover" transfer placement="top-start" :content="colItem.info" v-if="colItem.info">
  191. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 14px;margin-top:-1px"
  192. color="#909399" ref="info-icon"/>
  193. </Poptip>
  194. <Poptip trigger="click" transfer @on-popper-hide="popperHide">
  195. <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
  196. v-if="colItem.copyVisible"/>
  197. <div slot="content">
  198. <div style="display: flex;align-items: center;justify-content: center;">
  199. <Input size="small" v-model="inputDownValue"
  200. :maxlength="colItem.maxlength?colItem.maxlength:vm.$config.maxlength"
  201. @keydown.13.native.stop="inputDown(colItem)" :name="colItem.field"></Input>
  202. <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
  203. </div>
  204. </div>
  205. </Poptip>
  206. <!--冻结/解冻列-->
  207. <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
  208. v-if="freezeData && colItem.freezeFlag"
  209. type="ios-lock"
  210. @click="handleFreeze(colItem.field)"/>
  211. </template>
  212. <template #edit="{ row,rowIndex }">
  213. <vxe-input v-model="row[colItem.field]" type="text" v-if="setCellCanInput( row ,colItem)"
  214. :maxlength="colItem.maxlength?colItem.maxlength:vm.$config.maxlength"
  215. :ref="colItem.field+rowIndex"
  216. @dblclick.native.stop="copyValue(row,colItem,rowIndex)"
  217. @change.native="changeValue(colItem,rowIndex,row)"
  218. @keydown.native="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"></vxe-input>
  219. <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>{{
  220. row[colItem.field]
  221. }}
  222. </div>
  223. </template>
  224. </vxe-column>
  225. <!-- 数值 -->
  226. <vxe-column v-if="colItem.type === 'number'" :field="colItem.field"
  227. :title="colItem.title?colItem.title:$t(colItem.field)"
  228. :type="colItem.type"
  229. class-name="number-class"
  230. :header-class-name="colItem.required?'required-class':''"
  231. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  232. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  233. :edit-render="{autofocus: '.vxe-input--inner', autoselect: true}" :formatter="formatColumn"
  234. :params="colItem">
  235. <template #header="{ row }">
  236. <span :ref="'title_' + colItem.field ">{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
  237. <!--提示信息-->
  238. <Poptip trigger="hover" transfer placement="top-start" :content="colItem.info" v-if="colItem.info">
  239. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 14px;margin-top:-1px"
  240. color="#909399" ref="info-icon"/>
  241. </Poptip>
  242. <Poptip trigger="click" transfer @on-popper-show="popperShow(colIndex,'inputNumber')"
  243. @on-popper-hide="popperHide">
  244. <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
  245. v-if="colItem.copyVisible"/>
  246. <div slot="content">
  247. <!--点回车相当于点按钮填充-->
  248. <div style="display: flex;align-items: center;justify-content: center;">
  249. <InputNumberPop size="small" :digits="colItem.digits" v-model="inputDownValue"
  250. :ref="'pop_' + colIndex"
  251. @keydown.13.native.stop="inputDown(colItem)" :pop-visible="false"
  252. :name="colItem.field"></InputNumberPop>
  253. <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
  254. </div>
  255. </div>
  256. </Poptip>
  257. <!--冻结/解冻列-->
  258. <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
  259. v-if="freezeData && colItem.freezeFlag"
  260. type="ios-lock"
  261. @click="handleFreeze(colItem.field)"/>
  262. </template>
  263. <template #edit="{ row ,rowIndex}">
  264. <vxe-input v-model="row[colItem.field]" type="number"
  265. :ref="colItem.field+rowIndex"
  266. v-if="setCellCanInput(row,colItem)"
  267. @contextmenu.native.prevent
  268. :controls="false"
  269. @dblclick.native.stop="copyValue(row,colItem,rowIndex)"
  270. @blur="changeValue(colItem,rowIndex,row)"
  271. @keydown.native="controlNumber(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"
  272. @keyup.native="handleKeyup(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"></vxe-input>
  273. <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>{{
  274. row[colItem.field]
  275. }}
  276. </div>
  277. </template>
  278. </vxe-column>
  279. <!-- 主从多选组件-->
  280. <vxe-column v-if="colItem.type === 'multiSelect'" :field="colItem.field"
  281. :title="colItem.title?colItem.title:$t(colItem.field)"
  282. :type="colItem.type"
  283. :header-class-name="colItem.required?'required-class':''"
  284. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  285. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  286. :edit-render="{autofocus: '.vxe-input--inner'}">
  287. <template #default="{ row,rowIndex }">
  288. <div style="padding-left: 10px;">
  289. {{ row[colItem.field + '_Name'] }}
  290. </div>
  291. </template>
  292. <template #edit="{ row,rowIndex }">
  293. <MultiSelect v-model="row[colItem.field]"
  294. main-field="ownerFlag"
  295. :table-flag="true"
  296. @ok="getMultiSelect(Object.assign($event,{row,rowIndex,colItem}))"
  297. :default-value="row[colItem.field + '_Name']"
  298. :title="$t('pdtModelName')"
  299. :fromTitle="$t('staffNames')"
  300. :type="vm.$config.MagnifierType.product"
  301. ></MultiSelect>
  302. </template>
  303. </vxe-column>
  304. <!-- 下拉 -->
  305. <vxe-column v-if="colItem.type === 'select'" :field="colItem.field"
  306. :title="colItem.title?colItem.title:$t(colItem.field)"
  307. :type="colItem.type"
  308. :header-class-name="colItem.required?'required-class':''"
  309. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  310. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  311. :edit-render="{autofocus: '.vxe-input--inner'}">
  312. <template #header="{ row }">
  313. <span :ref="'title_' + colItem.field ">{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>
  314. <!--提示信息-->
  315. <Poptip trigger="hover" transfer placement="top-start" :content="colItem.info" v-if="colItem.info">
  316. <Icon type="ios-information-circle" style="cursor: pointer;font-size: 14px;margin-top:-1px"
  317. color="#909399" ref="info-icon"/>
  318. </Poptip>
  319. <Poptip trigger="click" transfer @on-popper-hide="popperHide">
  320. <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
  321. v-if="colItem.copyVisible"/>
  322. <div slot="content">
  323. <div style="display: flex;align-items: center;justify-content: center;">
  324. <!-- {{ colItem.options() }}-->
  325. <Select size="small" v-model="inputDownValue" style="width:200px" :multiple="colItem.multiple"
  326. clearable>
  327. <Option v-for="item in (typeof colItem.options === 'function'?colItem.options():colItem.options)"
  328. :key="item[colItem.valueKey]"
  329. :value="item[colItem.valueKey]"
  330. :label="item[colItem.labelKey]">
  331. {{ item[colItem.labelKey] }}
  332. </Option>
  333. </Select>
  334. <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
  335. </div>
  336. </div>
  337. </Poptip>
  338. <!--冻结/解冻列-->
  339. <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
  340. v-if="freezeData && colItem.freezeFlag"
  341. type="ios-lock"
  342. @click="handleFreeze(colItem.field)"/>
  343. </template>
  344. <template #default="{ row }">
  345. <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem)">{{
  346. row[colItem.field + '_Name']
  347. }}
  348. </div>
  349. </template>
  350. <!--多选-->
  351. <template #edit="{ row,column,rowIndex }" v-if="colItem.multiple">
  352. <vxe-select transfer v-model="row[colItem.field]" v-show="setCellCanInput( row ,colItem)"
  353. :ref="colItem.field+rowIndex"
  354. @change="changeValue(colItem,rowIndex,row)"
  355. :disabled="setCellDisabled(row,colItem)" placeholder="请选择下拉"
  356. multiple clearable>
  357. <vxe-option v-for="item in typeof colItem.options === 'function'?colItem.options():colItem.options"
  358. :key="item[colItem.valueKey]"
  359. :value="item[colItem.valueKey]"
  360. :label="item[colItem.labelKey]"></vxe-option>
  361. </vxe-select>
  362. </template>
  363. <template v-else #edit="{ row,column,rowIndex }">
  364. <TableSelect :text="row[colItem.field + '_Name']?row[colItem.field + '_Name']:row[colItem.labelKey]"
  365. v-if="setCellCanInput( row ,colItem)"
  366. :field="colItem.field" :dataType="colItem.dataType"
  367. :ref="colItem.field + rowIndex"
  368. :keyValue="colItem.valueKey"
  369. :label="colItem.labelKey"
  370. :title="colItem.title"
  371. :clearFlag="true"
  372. :options="typeof colItem.options === 'function'?colItem.options():colItem.options"
  373. :searchDataFlag="false"
  374. :search-detail-flag="false"
  375. :sortBoolean="colItem.sortBoolean"
  376. @focus="handleSelectFocus(row,rowIndex,colItem)"
  377. @change="inputChange(row,rowIndex,colItem)"
  378. @clear="clearSelect(Object.assign({column:colItem,colIndex,rowIndex,row}))"
  379. @keydown.stop="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex,row}))"
  380. @onChoose="onChoose($event,row,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"></TableSelect>
  381. <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>
  382. {{ row[colItem.field + '_Name'] }}
  383. </div>
  384. </template>
  385. </vxe-column>
  386. <!-- date -->
  387. <vxe-column v-if="colItem.type === 'date'" :params="{type:'date'}"
  388. :field="colItem.title?colItem.title:$t(colItem.field)"
  389. :type="colItem.type"
  390. :header-class-name="colItem.required?'required-class':''"
  391. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  392. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  393. :title="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}">
  394. <!-- <template #header="{ row }">-->
  395. <!-- <span>{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>-->
  396. <!-- <Poptip trigger="click" transfer @on-popper-hide="popperHide">-->
  397. <!-- <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"-->
  398. <!-- v-if="colItem.copyVisible"/>-->
  399. <!-- <div slot="content">-->
  400. <!-- <div style="display: flex;align-items: center;justify-content: center;">-->
  401. <!-- <DatePicker transfer v-model="inputDownValue" type="date"></DatePicker>-->
  402. <!-- <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>-->
  403. <!-- </div>-->
  404. <!-- </div>-->
  405. <!-- </Poptip>-->
  406. <!-- &lt;!&ndash;冻结/解冻列&ndash;&gt;-->
  407. <!-- <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "-->
  408. <!-- v-if="freezeData && colItem.freezeFlag"-->
  409. <!-- type="ios-lock"-->
  410. <!-- @click="handleFreeze(colItem.field)"/>-->
  411. <!-- </template>-->
  412. <template #default="{ row }">
  413. <span @dblclick.stop="copyValue(row,colItem)">{{ dateFormat(row[colItem.field]) }}</span>
  414. </template>
  415. <template #edit="{ row,rowIndex }">
  416. <DatePicker transfer :ref="colItem.field+rowIndex" v-model="row[colItem.field]" type="date"
  417. @on-change="changeValue(colItem,rowIndex,row)"
  418. v-show="setCellCanInput( row ,colItem)" :disabled="setCellDisabled(row,colItem)"></DatePicker>
  419. </template>
  420. </vxe-column>
  421. <!-- 选择框 -->
  422. <vxe-column v-if="colItem.type === 'checkbox'" :field="colItem.field"
  423. :header-class-name="colItem.required?'required-class':''"
  424. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  425. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  426. :tree-node="colItem.treeNode">
  427. <template #header="{ row }">
  428. <div class="checkbox-class">
  429. <vxe-checkbox :ref="colItem.field+'_header'" v-model="colItem.chooseAllFlag"
  430. @change="clickAllCheckbox(colItem)"/>
  431. </div>
  432. </template>
  433. <template #default="{ row,rowIndex }">
  434. <div class="checkbox-class">
  435. <vxe-checkbox v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
  436. :ref="colItem.field+'_default_'+rowIndex"
  437. :disabled="setCellDisabled(row,colItem)"
  438. v-model="row[colItem.field]" @change="changeValue(colItem,rowIndex,row)"/>
  439. </div>
  440. </template>
  441. <template #edit="{ row,rowIndex }">
  442. <div class="checkbox-class">
  443. <vxe-checkbox v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
  444. :ref="colItem.field+'_default_'+rowIndex"
  445. :disabled="setCellDisabled(row,colItem)"
  446. v-model="row[colItem.field]" @change="changeValue(colItem,rowIndex,row)"/>
  447. </div>
  448. </template>
  449. </vxe-column>
  450. <!-- 开关 -->
  451. <vxe-column v-if="colItem.type === 'switch'" :params="{type:'switch'}"
  452. :title="colItem.title?colItem.title:$t(colItem.field)"
  453. :type="colItem.type"
  454. :header-class-name="colItem.required?'required-class':''"
  455. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  456. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  457. :field="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}">
  458. <!-- <template #header="{ row }">-->
  459. <!-- <span>{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>-->
  460. <!-- <Poptip trigger="click" transfer @on-popper-hide="popperHide">-->
  461. <!-- <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"-->
  462. <!-- v-if="colItem.copyVisible"/>-->
  463. <!-- <div slot="content">-->
  464. <!-- <div style="display: flex;align-items: center;justify-content: center;">-->
  465. <!-- <i-switch v-model="inputDownBooleanValue"/>-->
  466. <!-- <Button type="primary" style="margin-left:10px" size="small" @click="inputDown(colItem)">-->
  467. <!-- {{ $t('filling') }}-->
  468. <!-- </Button>-->
  469. <!-- </div>-->
  470. <!-- </div>-->
  471. <!-- </Poptip>-->
  472. <!-- &lt;!&ndash;冻结/解冻列&ndash;&gt;-->
  473. <!-- <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "-->
  474. <!-- v-if="freezeData && colItem.freezeFlag"-->
  475. <!-- type="ios-lock"-->
  476. <!-- @click="handleFreeze(colItem.field)"/>-->
  477. <!-- </template>-->
  478. <template #default="{ row,rowIndex }">
  479. <!-- <span>{{ row[colItem.field] ? '是' : '否' }}</span>-->
  480. <div class="switch-class">
  481. <vxe-switch :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
  482. v-show="setCellCanInput( row ,colItem)"
  483. @change="changeValue(colItem,rowIndex,row)"
  484. :disabled="setCellDisabled(row,colItem)"/>
  485. </div>
  486. </template>
  487. <template #edit="{ row,rowIndex }">
  488. <div class="switch-class">
  489. <vxe-switch :ref="colItem.field+rowIndex" v-model="row[colItem.field]"
  490. v-show="setCellCanInput( row ,colItem)"
  491. @change="changeValue(colItem,rowIndex,row)"
  492. :disabled="setCellDisabled(row,colItem)"/>
  493. </div>
  494. </template>
  495. </vxe-column>
  496. <!-- 按钮 -->
  497. <vxe-column v-if="colItem.type === 'button'" :params="{type:'button'}"
  498. :title="colItem.title?colItem.title:$t(colItem.field)"
  499. :type="colItem.type"
  500. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  501. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  502. :field="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}">
  503. <template #default="{ row,rowIndex }">
  504. <vxe-button :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
  505. v-show="setCellCanInput( row ,colItem)"
  506. :content="row[colItem.field]"
  507. @click.native="buttonClick(colItem,rowIndex,row)"
  508. :disabled="setCellDisabled(row,colItem)"/>
  509. </template>
  510. <template #edit="{ row,rowIndex }">
  511. <vxe-button class-name="edit-button" :ref="colItem.field+'_'+rowIndex" v-model="row[colItem.field]"
  512. v-show="setCellCanInput( row ,colItem)"
  513. :content="row[colItem.field]"
  514. @click.native="buttonClick(colItem,rowIndex,row)"
  515. :disabled="setCellDisabled(row,colItem)"/>
  516. </template>
  517. </vxe-column>
  518. <!-- 文本按钮 -->
  519. <vxe-column v-if="colItem.type === 'textButton'" :params="{type:'textButton'}"
  520. :title="colItem.title?colItem.title:$t(colItem.field)"
  521. :type="colItem.type"
  522. :width="colItem.width?colItem.width:vm.$config.columnWidth"
  523. :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
  524. :field="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}">
  525. <template #default="{ row,rowIndex }">
  526. <div style="display: flex" v-show="setCellCanInput( row ,colItem)">
  527. <vxe-input :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
  528. :content="row[colItem.field]"
  529. :readonly="true"/>
  530. <vxe-button class-name="text-button-class" content="测试"
  531. @click.native="buttonClick(colItem,rowIndex,row)"></vxe-button>
  532. </div>
  533. </template>
  534. <template #edit="{ row,rowIndex }">
  535. <div style="display: flex" v-show="setCellCanInput( row ,colItem)">
  536. <vxe-input :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
  537. :content="row[colItem.field]"
  538. :readonly="true"/>
  539. <vxe-button class-name="text-button-class" content="测试" @click.native="buttonClick(colItem,rowIndex,row)"></vxe-button>
  540. </div>
  541. </template>
  542. </vxe-column>
  543. <!-- checkbox-->
  544. <!-- <vxe-column type="checkbox" width="60" v-if="colItem.type === 'checkbox'"></vxe-column>-->
  545. </div>
  546. </vxe-table>
  547. <div class="setting-class" v-if="showSettingFlag"
  548. :style="'top:' + settingTop + ';left:' + settingLeft"
  549. @click="showSetting">
  550. <Icon ref="setting" type="md-settings"/>
  551. </div>
  552. </div>
  553. </template>
  554. <script>
  555. import XEUtils from "xe-utils";
  556. import SeqButton from '@/components/sub/seq-button/index'
  557. import Sortable from "sortablejs";
  558. import TableSelect from '@/components/business/table-select'
  559. export default {
  560. name: 'EditTable',
  561. components: {SeqButton, TableSelect},
  562. props: {
  563. value: {
  564. type: Array,
  565. default: () => {
  566. }
  567. },
  568. // 表格标题
  569. title: {
  570. type: String,
  571. default: undefined,
  572. },
  573. // 标题说明
  574. titleInfo: {
  575. type: String,
  576. default: undefined,
  577. },
  578. // 数据源
  579. data: {
  580. type: Array,
  581. default: () => {
  582. }
  583. },
  584. // 列数据源
  585. columns: {
  586. type: Array,
  587. default: () => []
  588. },
  589. // 列表的高度
  590. height: {
  591. type: [String, Number],
  592. default: 300
  593. },
  594. // 列表的宽度
  595. divWidth: {
  596. type: String,
  597. default: '100%'
  598. },
  599. // 是否允许重复
  600. enabledRepeat: {
  601. type: Boolean,
  602. default: false
  603. },
  604. // 允许重复的列名称
  605. enabledRepeatId: {
  606. type: [String, Array],
  607. default: ''
  608. },
  609. //该行数据有值其他可输入单元格才能进行
  610. controlId: {
  611. type: String,
  612. default: ''
  613. },
  614. // 是否显示新增按钮
  615. addFlag: {
  616. type: Boolean,
  617. default: true
  618. },
  619. //是否显示删除按钮
  620. deleteFlag: {
  621. type: Boolean,
  622. default: true
  623. },
  624. // 控制删除按钮是否可见(外部传入的方法)
  625. canDelete: {
  626. type: Function,
  627. default: () => {
  628. return true
  629. }
  630. },
  631. // 唯一勾选的列表(用于switch,数据中只有一个勾选值)
  632. defaultField: {
  633. type: String,
  634. default: ''
  635. },
  636. //操作标识(新增、删除)是否可见
  637. operateFlag: {
  638. type: Boolean,
  639. default: true
  640. },
  641. // 是否显示新行
  642. newRowFlag: {
  643. type: Boolean,
  644. default: true
  645. },
  646. // 新增新行,不判断是否有数据
  647. newRowAlwaysFlag: {
  648. type: Boolean,
  649. default: false
  650. },
  651. //光标是否进入新增行
  652. focusFlag: {
  653. type: Boolean,
  654. default: false
  655. },
  656. //是否显示表头
  657. showHeader: {
  658. type: Boolean,
  659. default: true
  660. },
  661. //是否显示合计行
  662. showFooter: {
  663. type: Boolean,
  664. default: false
  665. },
  666. //表格名字
  667. name: {
  668. type: String,
  669. default: 'xTable'
  670. },
  671. //是否高亮显示
  672. highlightCurrentRow: {
  673. type: Boolean,
  674. default: false
  675. },
  676. requiredColumn: {
  677. type: Array,
  678. default: () => []
  679. },
  680. //主键Id
  681. majorField: {
  682. type: String,
  683. default: ''
  684. },
  685. //是否只读
  686. readonly: {
  687. type: Boolean,
  688. default: false
  689. },
  690. // 是否显示设置按钮
  691. showSettingFlag: {
  692. type: Boolean,
  693. default: true
  694. },
  695. // 是否开启冻结
  696. freeze: {
  697. type: Boolean,
  698. default: true,
  699. },
  700. // 鼠标移入进行编辑的标识
  701. mouseEnterEditFlag: {
  702. type: Boolean,
  703. default: true,
  704. },
  705. // 是否自动跳转到下一个可输入框
  706. autoNextFlag: {
  707. type: Boolean,
  708. default: true,
  709. },
  710. // 是否自动聚焦一行
  711. autoFocus: {
  712. type: Boolean,
  713. default: true,
  714. },
  715. },
  716. provide() {
  717. return {
  718. dkEditTable: this
  719. }
  720. },
  721. data() {
  722. const vm = window.vm;
  723. return {
  724. vm: vm,
  725. rowIndex: -1,
  726. colIndex: -1,
  727. existsFlag: true, // 存在标识,用于销毁内部组件
  728. visibleRows: [],// 可见的行,用于控制
  729. header: {
  730. options: [
  731. [
  732. // <!--冻结-->
  733. {
  734. code: 'freeze', name: vm.$t('freeze'), disabled: false, visible: false, children: [
  735. {code: 'colFreeze', name: vm.$t('freeze'), disabled: false, visible: true},
  736. {code: 'clearFreeze', name: vm.$t('clearFreeze'), disabled: false, visible: false},
  737. ]
  738. },
  739. // <!--定位-->
  740. {
  741. code: 'position', name: vm.$t('positionItem'), disabled: false, visible: true, children: [
  742. {code: 'rowPosition', name: vm.$t('rowPosition'), disabled: false, visible: true},
  743. {code: 'exchange', name: '替换', disabled: false, visible: true},
  744. {code: 'colPosition', name: vm.$t('colPosition'), disabled: false, visible: true},
  745. ]
  746. },
  747. // <!--自适应列宽-->
  748. {
  749. code: 'adaption', name: vm.$t('adaption'), disabled: false, visible: true, children: [
  750. {code: 'selfAdaptionOne', name: vm.$t('selfAdaptionOne'), disabled: false, visible: true},
  751. {code: 'selfAdaption', name: vm.$t('selfAdaption'), disabled: false, visible: true},
  752. ]
  753. },
  754. ]
  755. ]
  756. },
  757. freezeData: false, // 是否开启冻结
  758. enabledEdit: true, //是否启用编辑模式
  759. modal1: true,
  760. filterWrapper: true,
  761. inputDownValue: null,
  762. inputDownBooleanValue: false,
  763. tableData: [],
  764. tableDataChange: [], //改变集合
  765. isScroll: false,
  766. validRules: {}, //校验的规则
  767. deleteData: [], //删除的数据
  768. columnsData: [], //记录列
  769. currentRowIndex: 0, // 当前行
  770. settingLeft: null, // 设置图标居左的位置
  771. settingTop: null, // 设置图标居上的位置
  772. }
  773. },
  774. watch: {
  775. newRowFlag(n, o) {
  776. if (n) {
  777. this.add();
  778. } else {
  779. this.tableData = []
  780. }
  781. },
  782. data(n, o) {
  783. // 编辑
  784. if (n && n.length > 0) {
  785. this.tableData = n
  786. this.handleSelectData();
  787. } else {
  788. this.tableData = []
  789. this.tableDataChange = []
  790. if (this.newRowFlag) {
  791. //新建时增加行
  792. this.add()
  793. }
  794. }
  795. },
  796. tableData(n, o) {
  797. if (n) {
  798. this.$emit('input', n)
  799. }
  800. },
  801. },
  802. methods: {
  803. /**
  804. * @desc : 重新加载列
  805. * @author : 周兴
  806. * @date : 2023/4/4 16:24
  807. */
  808. loadColumn(columns) {
  809. if (columns) {
  810. return this.$refs[this.name].loadColumn(columns);
  811. } else {
  812. const tableColumns = this.$refs[this.name].getTableColumn();
  813. this.$refs[this.name].loadColumn(tableColumns.fullColumn);
  814. }
  815. },
  816. /**
  817. * @desc : 复制单元格
  818. * @author : 周兴
  819. * @date : 2022/6/9 9:31
  820. */
  821. copyValue(row, colItem) {
  822. let field = colItem.field;
  823. if (row && row[field]) {
  824. let value = row[field];
  825. // 如果是下拉,需要读取_Name字段的值
  826. if (colItem.type === 'select') {
  827. if (row[field + '_Name'] != undefined) {
  828. value = row[field + '_Name']
  829. }
  830. }
  831. this.$message.success(vm.$t('copySuccess') + ':' + value);
  832. //创建一个input框
  833. const input = document.createElement("input");
  834. //将指定的DOM节点添加到body的末尾
  835. document.body.appendChild(input);
  836. //设置input框的value值为直播地址
  837. input.setAttribute("value", value);
  838. //选取文本域中的内容
  839. input.select();
  840. //copy的意思是拷贝当前选中内容到剪贴板
  841. //document.execCommand()方法操纵可编辑内容区域的元素
  842. //返回值为一个Boolean,如果是 false 则表示操作不被支持或未被启用
  843. if (document.execCommand("copy")) {
  844. document.execCommand("copy");
  845. }
  846. //删除这个节点
  847. document.body.removeChild(input);
  848. }
  849. },
  850. /**
  851. * @desc : 单元格样式
  852. * @author : 周兴
  853. * @date : 2022/8/6 11:15
  854. */
  855. cellStyle({row, rowIndex, column}) {
  856. //序号居中
  857. if (column.type === 'seq' || column.field === 'seq' || column.type === 'checkbox' || column.type === 'date'
  858. || column.type === 'switch' || (column.params && column.params.type === 'disabled' && column.params.switch)) {
  859. return {textAlign: 'center'}
  860. } else if (column.type === 'number' || (column.params && column.params.type === 'disabled' && column.params.number)) {
  861. return {textAlign: 'right'}
  862. } else {
  863. return {textAlign: 'left'}
  864. }
  865. },
  866. /**
  867. * @desc : 点击右键
  868. * @author : 周兴
  869. * @date : 2022/12/19 11:12
  870. */
  871. closeAllPop(e) {
  872. this.$refs[this.name].$el.click(); //关闭表头的pop
  873. },
  874. /**
  875. * @desc : 右键菜单
  876. * @author : 沈博
  877. * @date : 2022/3/13 10:55
  878. */
  879. visibleMethod(e) {
  880. // 表格可以冻结
  881. if (this.freeze) {
  882. this.header.options[0].update({code: 'freeze', visible: true}, 'code', 'visible');
  883. }
  884. return true
  885. },
  886. /**
  887. * @desc : 获取当前行
  888. * @author : 周兴
  889. * @date : 2022/5/3 17:51
  890. */
  891. getCurrentRow() {
  892. return this.$refs[this.name].getCurrentRecord()
  893. },
  894. /**
  895. * @desc : 获取当前行号
  896. * @author : 周兴
  897. * @date : 2022/5/3 17:51
  898. */
  899. getCurrentRowIndex() {
  900. let row = this.$refs[this.name].getCurrentRecord()
  901. if (row) {
  902. return this.$refs[this.name].getRowIndex(row)
  903. }
  904. },
  905. /**
  906. * @desc : 点击右键按钮
  907. * @author : 周兴
  908. * @date : 2022/3/30 17:24
  909. */
  910. menuClick(e) {
  911. if (e.menu.code == 'selfAdaption') {
  912. this.autoWidthHandle()
  913. } else if (e.menu.code == 'selfAdaptionOne') {
  914. this.autoWidthHandle(e)
  915. } else if (e.menu.code == 'export') {
  916. this.export(e.column.property)
  917. } else if (e.menu.code == 'rowPosition' || e.menu.code == 'exchange') { // 行定位及替换
  918. this.showRowPosition(e, e.menu.code);
  919. } else if (e.menu.code == 'colPosition') { // 列定位
  920. this.showColPosition(e);
  921. } else if (e.menu.code == 'colFreeze') { // 列冻结
  922. this.handleFreeze(e);
  923. } else if (e.menu.code == 'clearFreeze') { // 解除冻结
  924. this.unFreeze(e);
  925. }
  926. },
  927. /**
  928. * @desc : 显示行定位定位框
  929. * @author : 周兴
  930. * @date : 2022/11/30 13:00
  931. */
  932. showRowPosition(e, code) {
  933. let tabValue = code == 'exchange' ? 'exchange' : 'search'
  934. this.$Position({component: this.$refs[this.name], tabValue, title: this.$t('findAndExchange')},
  935. {
  936. // 切换查询出的数据
  937. change: ({field, column, rowIndex, fields, equalFlag, searchText, noSelectAll, type}) => {
  938. // 没有查出数据
  939. if (noSelectAll) {
  940. this.changeFind(fields, equalFlag, searchText, type);// 查找下一条
  941. } else {
  942. // 定位当前行
  943. this.$refs[this.name].setCurrentRow(this.tableData[rowIndex]);
  944. // 定位当前列
  945. // this.$refs[this.name].setCurrentColumn(column);
  946. this.$nextTick(() => {
  947. this.$refs[this.name].scrollToRow(this.tableData[rowIndex]);
  948. this.$refs[this.name].scrollToColumn(column)
  949. });
  950. }
  951. },
  952. // 替换全部
  953. exchangeAll: (searchText, replaceText, fields, equalFlag) => {
  954. this.exchangeAll(searchText, replaceText, fields, equalFlag);
  955. },
  956. // 替换
  957. exchange: (searchText, replaceText, fields, equalFlag) => {
  958. this.exchange(searchText, replaceText, fields, equalFlag);
  959. },
  960. })
  961. },
  962. /**
  963. * @desc : 改变列的标题
  964. * @author : 周兴
  965. * @date : 2023/5/29 14:25
  966. */
  967. changeColumnTitle(field, title) {
  968. if (this.$refs['title_' + field] && this.$refs['title_' + field].length > 0) {
  969. this.$refs['title_' + field][0].innerText = title;
  970. }
  971. },
  972. /**
  973. * @desc : 改变查找的行
  974. * @author : 周兴
  975. * @date : 2023/2/16 13:05
  976. */
  977. changeFind(fields, equalFlag, searchText, type) {
  978. // 获取当前行
  979. let currentIndex = this.getCurrentRowIndex()
  980. if (!currentIndex && currentIndex != 0) {
  981. currentIndex = -1;
  982. }
  983. let table = this.tableData
  984. // 向下
  985. if (type === 'next') {
  986. for (let i = currentIndex + 1; i < table.length; i++) {
  987. let flag = this._changeFindItem(table[i], fields, equalFlag, searchText)
  988. if (flag) {
  989. return
  990. }
  991. }
  992. } else {
  993. // 向前
  994. for (let i = currentIndex - 1; i >= 0; i--) {
  995. let flag = this._changeFindItem(table[i], fields, equalFlag, searchText)
  996. if (flag) {
  997. return
  998. }
  999. }
  1000. }
  1001. },
  1002. /**
  1003. * @desc : desc
  1004. * @author : 周兴
  1005. * @date : 2023/2/16 13:09
  1006. */
  1007. _changeFindItem(item, fields, equalFlag, searchText) {
  1008. // 模糊查询
  1009. for (let it of fields) {
  1010. // 值等
  1011. if (equalFlag) {
  1012. if ((item[it.field] + '') == searchText) {
  1013. // 定位当前行
  1014. this.$refs[this.name].setCurrentRow(item);
  1015. this.$nextTick(() => {
  1016. this.$refs[this.name].scrollToRow(item);
  1017. });
  1018. return true;
  1019. }
  1020. } else {
  1021. // 模糊
  1022. if ((item[it.field] + '').indexOf(searchText) >= 0) {
  1023. // 定位当前行
  1024. this.$refs[this.name].setCurrentRow(item);
  1025. this.$nextTick(() => {
  1026. this.$refs[this.name].scrollToRow(item);
  1027. });
  1028. return true;
  1029. }
  1030. }
  1031. }
  1032. return false;
  1033. },
  1034. /**
  1035. * @desc : 替换全部数据
  1036. * @author : 周兴
  1037. * @date : 2023/2/15 14:49
  1038. */
  1039. exchangeAll(searchText, replaceText, fields, equalFlag) {
  1040. let table = this.tableData
  1041. let count = 0;
  1042. for (let i = 0; i < table.length; i++) {
  1043. // 模糊查询
  1044. fields.forEach(it => {
  1045. // 值等
  1046. if (equalFlag) {
  1047. if ((table[i][it.field] + '') == searchText) {
  1048. this.$set(table[i], it.field, replaceText);
  1049. this.setTableChange(table[i]); // 设置改变数据
  1050. count++;
  1051. }
  1052. } else {
  1053. // 模糊
  1054. if ((table[i][it.field] + '').indexOf(searchText) >= 0) {
  1055. let value = (table[i][it.field] + '').replaceAll(searchText, replaceText)
  1056. this.$set(table[i], it.field, value);
  1057. this.setTableChange(table[i]); // 设置改变数据
  1058. count++;
  1059. }
  1060. }
  1061. })
  1062. }
  1063. if (count > 0) {
  1064. this.$message.success("已经完成查找并进行" + count + '处替换');
  1065. }
  1066. },
  1067. /**
  1068. * @desc : 替换数据
  1069. * @author : 周兴
  1070. * @date : 2023/2/15 14:49
  1071. */
  1072. exchange(searchText, replaceText, fields, equalFlag) {
  1073. let table = this.tableData
  1074. if (!table || table.length == 0) return;
  1075. // 获取当前行
  1076. let currentIndex = this.getCurrentRowIndex()
  1077. if (!currentIndex && currentIndex != 0) {
  1078. currentIndex = 0;
  1079. }
  1080. let checkFlag = false;
  1081. // 判断当前有可以替换的数据
  1082. // 值等
  1083. if (equalFlag) {
  1084. fields.forEach(it => {
  1085. if ((table[currentIndex][it.field] + '') == searchText) {
  1086. this.$set(table[currentIndex], it.field, replaceText);
  1087. this.setTableChange(table[currentIndex]); // 设置改变数据
  1088. checkFlag = true;
  1089. }
  1090. })
  1091. } else {
  1092. // 模糊
  1093. fields.forEach(it => {
  1094. // 模糊
  1095. if ((table[currentIndex][it.field] + '').indexOf(searchText) >= 0) {
  1096. let value = (table[currentIndex][it.field] + '').replaceAll(searchText, replaceText)
  1097. this.$set(table[currentIndex], it.field, value);
  1098. this.setTableChange(table[currentIndex]); // 设置改变数据
  1099. checkFlag = true;
  1100. }
  1101. })
  1102. }
  1103. // 如果到最后一行,需要切换到第一行有数据的
  1104. if (currentIndex === table.length - 1) {
  1105. currentIndex = -1;
  1106. }
  1107. // 如果当前行没有数据,就跳转到下一行有匹配数据的行
  1108. if (!checkFlag) {
  1109. for (let i = currentIndex + 1; i < table.length; i++) {
  1110. // 模糊查询
  1111. for (let it of fields) {
  1112. // 值等
  1113. if (equalFlag) {
  1114. if ((table[i][it.field] + '') == searchText) {
  1115. // 定位当前行
  1116. this.$refs[this.name].setCurrentRow(this.tableData[i]);
  1117. this.$nextTick(() => {
  1118. this.$refs[this.name].scrollToRow(this.tableData[i]);
  1119. });
  1120. return;
  1121. }
  1122. } else {
  1123. // 模糊
  1124. if ((table[i][it.field] + '').indexOf(searchText) >= 0) {
  1125. // 定位当前行
  1126. this.$refs[this.name].setCurrentRow(this.tableData[i]);
  1127. this.$nextTick(() => {
  1128. this.$refs[this.name].scrollToRow(this.tableData[i]);
  1129. });
  1130. return;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. },
  1137. /**
  1138. * @desc : 设置改变表格
  1139. * @author : 周兴
  1140. * @date : 2023/2/15 14:56
  1141. */
  1142. setTableChange(row) {
  1143. let rows = this.tableDataChange.filter(it => it['_X_ID'] === row['_X_ID']);
  1144. //说明已经存在
  1145. if (rows && rows.length > 0) {
  1146. this.tableDataChange = this.tableDataChange.filter(it => it['_X_ID'] !== row['_X_ID']).map(it => it);
  1147. }
  1148. this.tableDataChange.push(row);
  1149. },
  1150. /**
  1151. * @desc : 显示列定位定位框
  1152. * @author : 周兴
  1153. * @date : 2022/11/30 13:00
  1154. */
  1155. showColPosition(e) {
  1156. let event = e.$event
  1157. this.$Position({left: event.clientX, top: event.clientY},
  1158. {
  1159. ok: (searchText) => {
  1160. this.handleColPosition(searchText); // 执行列定位方法
  1161. },
  1162. })
  1163. },
  1164. /**
  1165. * @author : 寇珊珊
  1166. * @date : 2022/3/23 16:29
  1167. * @desc : 自适应全部列宽
  1168. */
  1169. autoWidthHandle(e) {
  1170. if (this.tableData && this.tableData.length > 0) {
  1171. let data = this.tableData.copy();
  1172. if (e) {
  1173. // 当前列的自适应
  1174. let columnValues = data.map(it => {
  1175. if (typeof it[col.field] == 'boolean') {
  1176. return ''
  1177. } else if (it[col.field] == null || it[col.field] == undefined) {
  1178. return ''
  1179. } else {
  1180. return it[col.field]
  1181. }
  1182. });
  1183. columnValues.push(e.column.title + '占') // 把每列的表头也加进去算
  1184. let width = this.getMaxLength(columnValues) + 30 // 每列内容最大的宽度 + 表格的内间距(依据实际情况而定)
  1185. // this.$set(e.column, 'width', width)
  1186. // 取这个宽度和最小宽度的最大值
  1187. let minWidth = (e.column.minWidth + '')?.replace('px', '').toNum(0);
  1188. this.$set(e.column, 'width', [width, minWidth].max())
  1189. } else {
  1190. // 全部可见列的自适应
  1191. let columns = this.$refs[this.name].getColumns();
  1192. columns.forEach(col => {
  1193. if (col.type !== 'seq' && col.type !== 'radio' && col.type !== 'checkbox'
  1194. && col.type !== 'operate' && col.type !== 'info'
  1195. && col.type !== 'blank') {
  1196. let columnValues = data.map(it => {
  1197. if (typeof it[col.field] == 'boolean') {
  1198. return ''
  1199. } else if (it[col.field] == null || it[col.field] == undefined) {
  1200. return ''
  1201. } else {
  1202. return it[col.field]
  1203. }
  1204. });
  1205. columnValues.push(col.title + '占') // 把每列的表头也加进去算
  1206. let width = this.getMaxLength(columnValues) + 30 // 每列内容最大的宽度 + 表格的内间距(依据实际情况而定)
  1207. // this.$set(col, 'width', width)
  1208. // 取这个宽度和最小宽度的最大值
  1209. let minWidth = (col.minWidth + '')?.replace('px', '').toNum(0);
  1210. this.$set(col, 'width', [width, minWidth].max())
  1211. }
  1212. })
  1213. }
  1214. this.$nextTick(() => {
  1215. this.$refs[this.name].resetColumn({resizable: true})
  1216. this.$refs[this.name].recalculate()
  1217. })
  1218. }
  1219. },
  1220. /**
  1221. * @desc : 解除冻结
  1222. * @author : 周兴
  1223. * @date : 2022/12/1 13:30
  1224. */
  1225. unFreeze() {
  1226. const tableColumns = this.$refs[this.name].getTableColumn()
  1227. if (tableColumns && tableColumns.visibleColumn) {
  1228. tableColumns.visibleColumn.forEach(it => {
  1229. if (it.type != 'seq' && it.type != 'radio' && it.type != 'checkbox') {
  1230. it.fixed = ''
  1231. }
  1232. })
  1233. this.columnsData.forEach(it => {
  1234. it.freezeFlag = false;
  1235. })
  1236. // 清空冻结不可见
  1237. // this.header.options[0].update({code: 'clearFreeze', visible: false}, 'code', 'visible');
  1238. let filters = this.header.options[0].filter(it => it.code === 'freeze');
  1239. if (filters && filters.length > 0) {
  1240. filters[0].children.update({code: 'clearFreeze', visible: false}, 'code', 'visible');
  1241. }
  1242. this.$refs[this.name].refreshColumn();
  1243. }
  1244. },
  1245. /**
  1246. * @desc : 冻结列
  1247. * @author : 周兴
  1248. * @date : 2022/11/30 17:28
  1249. */
  1250. handleFreeze(e) {
  1251. let field = e.column.field;
  1252. const tableColumns = this.$refs[this.name].getTableColumn()
  1253. if (tableColumns && tableColumns.visibleColumn) {
  1254. let columnIndex = 0;
  1255. tableColumns.visibleColumn.forEach((it, index) => {
  1256. it.fixed = ''
  1257. if (it.field === field) {
  1258. columnIndex = index;
  1259. }
  1260. })
  1261. // 冻结该列之前的列,包括这列
  1262. for (let i = 0; i <= columnIndex; i++) {
  1263. tableColumns.visibleColumn[i].fixed = 'left'
  1264. }
  1265. // 先把所有的冻结标识都去掉
  1266. this.columnsData.forEach(it => {
  1267. it.freezeFlag = false;
  1268. })
  1269. // 找到当前列,给其赋值冻结标识
  1270. let colItems = this.columnsData.filter(it => it.field === field);
  1271. if (colItems && colItems.length > 0) {
  1272. colItems[0].freezeFlag = true;
  1273. }
  1274. // 清空冻结可见
  1275. // this.header.options[0].update({code: 'clearFreeze', visible: true}, 'code', 'visible');
  1276. let filters = this.header.options[0].filter(it => it.code === 'freeze');
  1277. if (filters && filters.length > 0) {
  1278. filters[0].children.update({code: 'clearFreeze', visible: true}, 'code', 'visible');
  1279. }
  1280. this.$refs[this.name].refreshColumn();
  1281. }
  1282. },
  1283. /**
  1284. * @desc : 下拉聚焦事件
  1285. * @author : 周兴
  1286. * @date : 2022/4/22 9:10
  1287. */
  1288. handleSelectFocus(row, rowIndex, colItem) {
  1289. this.$emit('on-select-focus', colItem.field, row, rowIndex)
  1290. },
  1291. /**
  1292. * @desc : 给下拉数据源增加Name列
  1293. * @author : 周兴
  1294. * @date : 2022/4/22 9:02
  1295. */
  1296. handleSelectData() {
  1297. let options = []
  1298. //记录下拉的列
  1299. this.columns.forEach(col => {
  1300. if (col.type === 'select') {
  1301. if (this.tableData && this.tableData.length > 0) {
  1302. //获取下拉数据源
  1303. if (typeof col.options === 'function') {
  1304. options = col.options()
  1305. }
  1306. this.tableData.forEach(row => {
  1307. if (row[col.field]) {
  1308. if (col.multiple) {
  1309. let selectVal = options.filter(it => row[col.field].includes(it[col.valueKey]));
  1310. if (selectVal) {
  1311. this.$set(row, col.field + '_Name', selectVal.map(it => {
  1312. return it[col.labelKey]
  1313. }).toString())
  1314. }
  1315. } else {
  1316. let selectVal = options.filter(it => row[col.field] === it[col.valueKey])[0];
  1317. if (selectVal) {
  1318. this.$set(row, col.field + '_Name', selectVal[col.labelKey])
  1319. }
  1320. }
  1321. }
  1322. })
  1323. }
  1324. }
  1325. })
  1326. },
  1327. /**
  1328. * @desc : 点击表格的keydown自动进入第一个单元格
  1329. * @author : 周兴
  1330. * @date : 2022/4/19 13:17
  1331. */
  1332. handleTableKeyDown(e) {
  1333. if (e.$event.key === 'Enter') {
  1334. this.$refs[this.name].setActiveCell(this.tableData[0], this.columns[0].field);
  1335. this.handleFocus(this.columns[0], 0);
  1336. }
  1337. },
  1338. /**
  1339. * @desc : 点击单元格
  1340. * @author : 周兴
  1341. * @date : 2023/5/16 9:32
  1342. */
  1343. handleCellClick(e) {
  1344. this.$emit('cell-click', e)
  1345. },
  1346. /**
  1347. * @desc : 增加当前行hover
  1348. * @author : 周兴
  1349. * @date : 2023/5/17 16:39
  1350. */
  1351. addHover(rowIndex) {
  1352. if (this.readonly) {
  1353. return;
  1354. }
  1355. if (this.operateFlag) {
  1356. // 如果行不变,不用执行
  1357. if (rowIndex != this.rowIndex) {
  1358. if (this.tableData && this.tableData.length > 0) {
  1359. this.tableData.forEach(it => {
  1360. this.$set(it, '_hover', false)
  1361. })
  1362. }
  1363. }
  1364. setTimeout(() => {
  1365. if (rowIndex >= 0 && this.tableData[rowIndex]) {
  1366. this.$set(this.tableData[rowIndex], '_hover', true)
  1367. }
  1368. }, 30)
  1369. }
  1370. },
  1371. /**
  1372. * @desc : 鼠标移入增加新增和删除按钮
  1373. * @author : 周兴
  1374. * @date : 2022/4/19 10:56
  1375. */
  1376. handleCellMouseEnter(e) {
  1377. // if (this.readonly) {
  1378. // return;
  1379. // }
  1380. // if (this.operateFlag) {
  1381. // // 如果行不变,不用执行
  1382. // if (e && (e.rowIndex != this.rowIndex)) {
  1383. // if (this.tableData && this.tableData.length > 0) {
  1384. // this.tableData.forEach(it => {
  1385. // this.$set(it, '_hover', false)
  1386. // })
  1387. // }
  1388. // }
  1389. // setTimeout(() => {
  1390. // if (e.rowIndex >= 0 && this.tableData[e.rowIndex]) {
  1391. // this.$set(this.tableData[e.rowIndex], '_hover', true)
  1392. // }
  1393. // }, 300)
  1394. // }
  1395. // // 鼠标移入后,当前行变为编辑状态
  1396. // if (e && e.row) {
  1397. // this.colIndex = e.columnIndex;
  1398. // // 鼠标移入自动进行行切换
  1399. // if (this.mouseEnterEditFlag) {
  1400. // // this.$refs[this.name].setActiveRow(e.row)
  1401. // // // console.log('ttt',e.row,e.rowIndex,this.currentRowIndex)
  1402. // // this.$refs[this.name].setCurrentRow(e.row)
  1403. // // if(this.rowIndex !== e.rowIndex){
  1404. // // this.currentChangeGetData({ oldRowIndex:this.rowIndex,rowIndex:e.rowIndex })
  1405. // // }
  1406. // }
  1407. // this.rowIndex = e.rowIndex;
  1408. // }
  1409. },
  1410. /**
  1411. * @desc : 鼠标移出删除新增和删除按钮
  1412. * @author : 周兴
  1413. * @date : 2022/4/19 10:56
  1414. */
  1415. handleCellMouseLeave(e) {
  1416. // if (this.operateFlag) {
  1417. // setTimeout(() => {
  1418. // if (e && e.rowIndex != this.rowIndex) {
  1419. // if (e.rowIndex >= 0 && this.tableData[e.rowIndex]) {
  1420. // this.$set(this.tableData[e.rowIndex], '_hover', false)
  1421. // }
  1422. // }
  1423. // }, 300)
  1424. // }
  1425. },
  1426. /**
  1427. * @desc : 开关控制
  1428. * @author : 周兴
  1429. * @date : 2022/6/23 9:09
  1430. */
  1431. switchValue(colItem, rowIndex, row) {
  1432. if (colItem.switchField) {
  1433. if (colItem.type === 'switch') {
  1434. // 如果开关开启,那么相关列修改为0
  1435. if (row[colItem.field] && this.tableData[rowIndex][colItem.switchField]) {
  1436. this.tableData[rowIndex][colItem.switchField] = 0;
  1437. // 重新计算
  1438. this.calc(colItem.switchField, rowIndex);
  1439. }
  1440. } else {
  1441. let flag = false;
  1442. // 控制开关列
  1443. if (row[colItem.field] && row[colItem.field] != 0) {
  1444. flag = false;
  1445. this.tableData[rowIndex][colItem.switchField] = false;
  1446. } else {
  1447. flag = true;
  1448. this.tableData[rowIndex][colItem.switchField] = true;
  1449. }
  1450. }
  1451. }
  1452. },
  1453. /**
  1454. * @desc : 值改变
  1455. * @author : 周兴
  1456. * @date : 2022/4/10 14:21
  1457. */
  1458. changeValue(colItem, rowIndex, row) {
  1459. let field = colItem.field;
  1460. //数值
  1461. if (colItem.type === 'number') {
  1462. // 如果是这里必须是负数,需要自动转为负数
  1463. // let neg = typeof colItem.negative == 'function' ? colItem.negative() : colItem.negative;
  1464. // if (neg && parseFloat(row[field]) > 0) {
  1465. // this.tableData[rowIndex][field] = -1 * parseFloat(row[field]);
  1466. // }
  1467. this.calc(field, rowIndex) //计算
  1468. } else if (colItem.type === 'text') { // 文本
  1469. if (colItem.field != 'remarks' && (colItem.upperFlag == undefined || colItem.upperFlag)) {
  1470. row[field] = row[field]?.toUpperCase(); // 备注默认转大写
  1471. }
  1472. } else if (colItem.type === 'select' && colItem.multiple) {
  1473. let options = typeof colItem.options === 'function' ? colItem.options() : colItem.options;
  1474. let selectVal = options.filter(it => row[field].includes(it[colItem.valueKey]));
  1475. if (selectVal) {
  1476. this.$set(row, field + '_Name', selectVal.map(it => {
  1477. return it[colItem.labelKey]
  1478. }).toString())
  1479. }
  1480. }
  1481. //开关
  1482. this.switchValue(colItem, rowIndex, row);
  1483. // 有联动,数据改变需要清空对应的列数据
  1484. this.columns.forEach(it => {
  1485. if (it.controlIds && it.controlIds.length > 0) {
  1486. //说明这列管控其他列
  1487. if (it.controlIds.includes(field)) {
  1488. row[it.field] = null;
  1489. }
  1490. }
  1491. })
  1492. // 如果勾选的是指定的列
  1493. if (this.defaultField && colItem.field === this.defaultField) {
  1494. this.changeDefaultFieldValue(row);
  1495. }
  1496. //把改变的行加入到tableDataChange中
  1497. // console.log('row',this.tableDataChange,row)
  1498. let rows = this.tableDataChange.filter(it => it['_X_ID'] === row['_X_ID']);
  1499. //说明已经存在
  1500. if (rows && rows.length > 0) {
  1501. this.tableDataChange = this.tableDataChange.filter(it => it['_X_ID'] !== row['_X_ID']).map(it => it);
  1502. }
  1503. this.tableDataChange.push(row);
  1504. this.$emit('changeValue', field, row, rowIndex);
  1505. // 更新合计行
  1506. this.$refs[this.name].updateFooter();
  1507. },
  1508. /**
  1509. * @desc : 改变值
  1510. * @author : 周兴
  1511. * @date : 2022/8/5 13:38
  1512. */
  1513. changeDefaultFieldValue(row) {
  1514. // 如果勾选这条,那么其他条要设置为不勾选
  1515. if (row[this.defaultField]) {
  1516. this.tableData.forEach(it => {
  1517. if (it['_X_ID'] !== row['_X_ID']) {
  1518. it[this.defaultField] = false;
  1519. }
  1520. })
  1521. } else {
  1522. // 如果去掉本条勾选,那么默认第一条作为勾选项
  1523. for (let i = 0; i < this.tableData.length; i++) {
  1524. if (this.tableData[i]['_X_ID'] !== row['_X_ID']) {
  1525. this.tableData[i][this.defaultField] = true;
  1526. break;
  1527. }
  1528. }
  1529. }
  1530. },
  1531. /**
  1532. * @desc : 设置单元格是否可以输入
  1533. * @author : 周兴
  1534. * @date : 2022/4/7 15:20
  1535. */
  1536. setCellCanInput(row, column) {
  1537. // 如果已经在可视范围内,不用再走
  1538. let flag = false;
  1539. if (this.controlId) {
  1540. //console.log('ttt',this.controlId,row[this.controlId],row)
  1541. //看这列是否需要进行管控
  1542. if (column.controlId && this.controlId === column.controlId) {
  1543. flag = true;
  1544. } else {
  1545. //如果该行controlId有值,不管控
  1546. if (row[this.controlId]) {
  1547. flag = true;
  1548. }
  1549. }
  1550. } else {
  1551. flag = true;
  1552. // 如果列设置了管控
  1553. if (column.controlIds && column.controlIds.length > 0) {
  1554. for (let i in column.controlIds) {
  1555. //如果有任意一个没有数据,那么就不允许
  1556. if (!row[column.controlIds[i]]) {
  1557. flag = false;
  1558. break;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. /* 除了controlId之外,还有新的校验 */
  1564. if (flag) {
  1565. if (column.editStatus) {
  1566. // console.log('订制品',column.editStatus(row),row)
  1567. flag = column.editStatus(row)
  1568. }
  1569. }
  1570. // 在disbaled中控制
  1571. if (flag && (column.type === 'select' || column.type === 'text' || column.type === 'number'
  1572. || column.type === 'button')) {
  1573. if (row['readOnly']) {
  1574. let readOnly = row['readOnly']
  1575. if (readOnly.indexOf(column.field) >= 0) {
  1576. flag = false;
  1577. }
  1578. // 如果是整行,那么就直接禁用
  1579. if (readOnly === 'all') {
  1580. flag = false;
  1581. }
  1582. }
  1583. }
  1584. return flag;
  1585. },
  1586. /**
  1587. * @desc : 控制下拉选择是否出现
  1588. * @author : 周兴
  1589. * @date : 2022/6/6 14:39
  1590. */
  1591. setCellCanTableSelect(row, column) {
  1592. //如果这列是否禁用的,就不能选择
  1593. if (this.readonly) {
  1594. return false;
  1595. } else if (typeof column.disabled === 'function' ? column.disabled() : column.disabled) {
  1596. return false;
  1597. } else {
  1598. if (this.controlId) {
  1599. //看这列是否需要进行管控
  1600. if (column.controlId) {
  1601. if (this.controlId !== column.controlId) {
  1602. return false;
  1603. }
  1604. } else {
  1605. if (!row[this.controlId]) {
  1606. return false;
  1607. }
  1608. }
  1609. }
  1610. if (row['readOnly']) {
  1611. let readOnly = row['readOnly']
  1612. if (readOnly.indexOf(column.field) >= 0) {
  1613. return false;
  1614. }
  1615. // 如果是整行,那么就直接禁用
  1616. if (readOnly === 'all') {
  1617. return false;
  1618. }
  1619. }
  1620. }
  1621. return true;
  1622. },
  1623. /**
  1624. * @desc : 设置是否只读
  1625. * @author : 周兴
  1626. * @date : 2022/4/11 14:22
  1627. */
  1628. setCellDisabled(row, column) {
  1629. // 按照行进行控制列
  1630. if (row && row.readOnly) {
  1631. let readOnly = row.readOnly
  1632. // console.log('eee',readOnly,column.field,readOnly.indexOf(column.field))
  1633. if (readOnly.indexOf(column.field) >= 0) {
  1634. return true;
  1635. }
  1636. // 如果是整行,那么就直接禁用
  1637. if (readOnly === 'all') {
  1638. return false;
  1639. }
  1640. }
  1641. return false;
  1642. },
  1643. /**
  1644. * @desc : 点击表头的checkbox全选/全不选
  1645. * @author : 周兴
  1646. * @date : 2023/5/9 13:30
  1647. */
  1648. clickAllCheckbox(colItem) {
  1649. if (this.tableData && this.tableData.length > 0) {
  1650. this.tableData.forEach(it => {
  1651. it[colItem.field] = colItem.chooseAllFlag
  1652. })
  1653. }
  1654. },
  1655. /**
  1656. * @desc : 点击按钮
  1657. * @author : 周兴
  1658. * @date : 2023/3/26 16:11
  1659. */
  1660. buttonClick(colItem, rowIndex, row) {
  1661. this.$emit('button-click', row, rowIndex, colItem)
  1662. },
  1663. /**
  1664. * @desc : 控制跳转到下一个输入格
  1665. * @author : 周兴
  1666. * @date : 2022/4/9 13:40
  1667. */
  1668. nextInputCellByKeyDown(e) {
  1669. //如果点击回车需要进入下一个可输入单元格
  1670. if (e.keyCode === 13) {
  1671. //回车的时候阻止冒泡事件
  1672. e.stopPropagation();
  1673. //如果是点击过去的,就不用再走一次
  1674. if (e.type === 'keyup') return;
  1675. //跳转到下一个可输入单元格
  1676. this.nextInputCell(e.row, e.rowIndex, e.colIndex, e.column.field, e.column);
  1677. }
  1678. },
  1679. /**
  1680. * @desc : 控制数值的输入
  1681. * @author : 周兴
  1682. * @date : 2022/4/5 22:28
  1683. */
  1684. controlNumber(e) {
  1685. this.$emit('on-keydown', e)
  1686. //回车和tab的时候阻止冒泡事件
  1687. if (e.keyCode === 13) {
  1688. e.stopPropagation();
  1689. }
  1690. //控制跳转到下一个输入格
  1691. this.nextInputCellByKeyDown(e);
  1692. //backspace,delete,enter,左右不控制
  1693. if (e.keyCode === 8 || e.keyCode === 46 || e.keyCode === 37
  1694. || e.keyCode === 39 || e.keyCode === 13) {
  1695. return;
  1696. }
  1697. // 获取小数位数
  1698. let digits = 0;
  1699. if (e.column.digits) {
  1700. digits = e.column.digits;
  1701. } else {
  1702. //如果没有设置小数位数,那么就读取商品中的计量单位
  1703. if (e.row.decimalPlaces) {
  1704. digits = e.row.decimalPlaces;
  1705. }
  1706. }
  1707. //ctrl+v,ctrl+c不控制
  1708. if ((e.key === 'v' || e.key === 'c') && e.ctrlKey) {
  1709. return;
  1710. }
  1711. //查看是否有选中数据,再输入的情况
  1712. let selectedLength = e.target.selectionEnd - e.target.selectionStart;
  1713. if (selectedLength > 0) {
  1714. return;
  1715. }
  1716. let num = e.target.value + "" + e.key;
  1717. //说明是插入到字符串中的
  1718. if (e.target.selectionEnd < e.target.value.length) {
  1719. num = this.$libaray.insertStr(e.target.value, e.target.selectionEnd, e.key)
  1720. }
  1721. // let negativeFlag = e.column.negative ? true : false;
  1722. let negativeFlag = e.column.negative ? true : false;
  1723. if (!this.$libaray.getRegex(digits, negativeFlag).test(num)) {
  1724. e.preventDefault();
  1725. } else {
  1726. //如果有最大值,需要判断不要超过最大值
  1727. let max = e.column.max ? e.column.max : this.$config.maxNumber;
  1728. if (num >= parseFloat(max)) {
  1729. e.preventDefault();
  1730. }
  1731. // 如果有最小值,需要判断不小于最小值
  1732. let min = e.column.min ? e.column.min : this.$config.minNumber;
  1733. if (num <= parseFloat(min)) {
  1734. e.preventDefault();
  1735. }
  1736. }
  1737. },
  1738. /**
  1739. * @desc : 控制数值的输入
  1740. * @author : 周兴
  1741. * @date : 2022/4/5 22:28
  1742. */
  1743. handleKeyup(e) {
  1744. // 获取小数位数
  1745. let digits = 0;
  1746. if (e.column.digits) {
  1747. digits = e.column.digits;
  1748. } else {
  1749. //如果没有设置小数位数,那么就读取商品中的计量单位
  1750. if (e.row.decimalPlaces) {
  1751. digits = e.row.decimalPlaces;
  1752. }
  1753. }
  1754. //复制时调用改变事件
  1755. if (e.key === 'v' && e.ctrlKey) {
  1756. this.changeValueByCtrlV(e, digits);
  1757. }
  1758. },
  1759. /**
  1760. * @desc : 值改变
  1761. * @author : 周兴
  1762. * @date : 2022/4/10 14:21
  1763. */
  1764. changeValueByCtrlV(e, digits) {
  1765. let value = e.target.value
  1766. if (Number.isNaN(Number(value))) {
  1767. e.target.value = null;
  1768. this.tableData[e.rowIndex][e.column.field] = null;
  1769. } else {
  1770. //正则表达式去控制输入
  1771. if (!this.$libaray.getRegex(digits).test(value)) {
  1772. value = XEUtils.toFixed(XEUtils.round(value, digits), digits);
  1773. }
  1774. //判断是否超过最大值,如果超过最大值,就取最大值
  1775. let max = e.column.max ? e.column.max : this.$config.maxNumber;
  1776. if (parseFloat(value) >= max) {
  1777. //获取最大值
  1778. let maxValue = this.$libaray.getMaxValue(max, digits);
  1779. e.target.value = maxValue;
  1780. this.tableData[e.rowIndex][e.column.field] = maxValue;
  1781. } else {
  1782. e.target.value = value;
  1783. this.tableData[e.rowIndex][e.column.field] = value;
  1784. }
  1785. }
  1786. },
  1787. /**
  1788. * @desc : 格式化列
  1789. * @author : 周兴
  1790. * @date : 2022/4/4 13:40
  1791. */
  1792. formatColumn({column, cellValue, row}) {
  1793. //默认显示空值
  1794. if (cellValue === undefined || !column.params) {
  1795. return null;
  1796. }
  1797. let param = column.params
  1798. // 只有数值类型,或者是diable类型中数值的需要进行处理
  1799. if (param.type === 'number' || param.number) {
  1800. //获取小数位数
  1801. let digits = 0;
  1802. if (param.digits || param.digits == 0) {
  1803. digits = param.digits;
  1804. } else {
  1805. //如果没有设置小数位数,那么就读取商品中的计量单位
  1806. if (row.decimalPlaces) {
  1807. digits = row.decimalPlaces;
  1808. }
  1809. }
  1810. // 数值列开启千分位过滤 (默认开启千分位)
  1811. if (param.formatThousandth == undefined || param.formatThousandth) {
  1812. if (cellValue != null) {
  1813. //没有开启千分位
  1814. return XEUtils.commafy(Number(cellValue), {digits});
  1815. }
  1816. } else {
  1817. if (cellValue != null) {
  1818. //没有开启千分位
  1819. return XEUtils.toFixed(XEUtils.round(cellValue, digits), digits);
  1820. }
  1821. }
  1822. } else {
  1823. //日期
  1824. if (param.date && cellValue != null) {
  1825. return new Date(cellValue).format('yyyy-MM-dd');
  1826. } else {
  1827. // 如果不是数值,就直接返回
  1828. return cellValue;
  1829. }
  1830. }
  1831. }
  1832. ,
  1833. /**
  1834. * @desc : 合计行运算
  1835. * @author : 周兴
  1836. * @date : 2022/3/31 11:28
  1837. */
  1838. footerMethod({data}) {
  1839. //如果不开启合计行,那么就不走该方法
  1840. if (!this.showFooter) return;
  1841. let total = this.$t('totalSum');
  1842. const sums = []
  1843. if (sums.indexOf(total) < 0) {
  1844. sums.push(total)
  1845. }
  1846. let sumCell = null;
  1847. // this.$nextTick(() => {
  1848. for (let column of this.columns) {
  1849. sumCell = null;
  1850. if ((column.type === vm.$config.columnType.number
  1851. || column.number) && column.sum) {
  1852. let digits = 0;
  1853. //小数位数
  1854. if (column.digits) {
  1855. digits = column.digits;
  1856. }
  1857. data.forEach(item => {
  1858. sumCell += Number(item[column.field] == undefined ? 0 : item[column.field])
  1859. })
  1860. //格式化金额开启(默认开启)
  1861. if (column.formatThousandth == undefined || column.formatThousandth) {
  1862. sumCell = XEUtils.commafy(Number(sumCell), {digits})
  1863. }
  1864. }
  1865. sums.push(sumCell);
  1866. }
  1867. // })
  1868. return [sums]
  1869. }
  1870. ,
  1871. /**
  1872. * @desc : poper隐藏事件
  1873. * @author : 沈博
  1874. * @date : 2022/3/13 10:10
  1875. */
  1876. popperHide() {
  1877. this.inputDownValue = null
  1878. },
  1879. /**
  1880. * @desc : poper显示事件 TODO
  1881. * @author : 周兴
  1882. * @date : 2022/4/11 11:37
  1883. */
  1884. popperShow(colIndex, type) {
  1885. // console.log('field', this.$refs['pop_' + colIndex], this.columns)
  1886. this.$nextTick(() => {
  1887. if (!type) {
  1888. this.$refs['pop_' + colIndex][0].$refs.input.focus();
  1889. } else {
  1890. this.$refs['pop_' + colIndex][0].$refs.inputNumber.focus();
  1891. }
  1892. })
  1893. },
  1894. /**
  1895. * @desc : 获取删除的数据
  1896. * @author : 周兴
  1897. * @date : 2022/6/18 16:32
  1898. */
  1899. getDeleteData() {
  1900. let table = this.deleteData ? this.deleteData.copy() : []
  1901. return table;
  1902. },
  1903. /**
  1904. * @desc : 获取数据
  1905. * @author : 周兴
  1906. * @date : 2022/4/10 11:38
  1907. */
  1908. getTableData() {
  1909. let table = this.tableData ? this.tableData.copy() : []
  1910. return table;
  1911. },
  1912. /**
  1913. * @desc : 获取过滤掉主键数据没有选择的信息
  1914. * @author : 周兴
  1915. * @date : 2022/4/10 11:39
  1916. */
  1917. getTableDataFilter() {
  1918. let table = this.tableData ? this.tableData.copy() : []
  1919. if (this.controlId) {
  1920. table = table.filter(it => it[this.controlId]);
  1921. }
  1922. return table;
  1923. },
  1924. /**
  1925. * @desc : 获取改变的数据
  1926. * @author : 周兴
  1927. * @date : 2022/4/10 11:38
  1928. */
  1929. getTableChangeData() {
  1930. let table = this.tableDataChange ? this.tableDataChange.copy() : []
  1931. return table;
  1932. },
  1933. /**
  1934. * @desc : 清除掉变化数据
  1935. * @author : 周兴
  1936. * @date : 2022/4/21 17:24
  1937. */
  1938. clearTableChangeData() {
  1939. this.tableDataChange = [];
  1940. },
  1941. /**
  1942. * @desc : 清空数据
  1943. * @author : 周兴
  1944. * @date : 2022/4/21 17:24
  1945. */
  1946. clearTable() {
  1947. this.tableData = [];
  1948. this.tableDataChange = [];
  1949. if (this.operateFlag && this.newRowFlag) {
  1950. // 新增一行
  1951. this.add();
  1952. }
  1953. },
  1954. /**
  1955. * @desc : 文本输入后执行的事件
  1956. * @author : 周兴
  1957. * @date : 2022/4/6 13:52
  1958. */
  1959. editClosed(e) {
  1960. this.$emit('editClosed', e, this.tableData)
  1961. },
  1962. /**
  1963. * @desc : 点击行执行事件
  1964. * @author : 于继渤
  1965. * @date : 2022/4/21 13:43
  1966. */
  1967. currentChangeGetData(e) {
  1968. e.oldRowIndex = this.currentRowIndex;
  1969. this.$emit('current-change', e, this.tableData);
  1970. this.currentRowIndex = e.rowIndex;
  1971. // 给当前行增加hover
  1972. this.addHover(this.currentRowIndex);
  1973. },
  1974. /**
  1975. * @desc : 根据field获取
  1976. * @author : 周兴
  1977. * @date : 2022/6/16 8:44
  1978. */
  1979. getColumnByField(field) {
  1980. for (let i = 0; i < this.columns.length; i++) {
  1981. if (this.columns[i].field === field) {
  1982. return this.columns[i];
  1983. }
  1984. }
  1985. },
  1986. /**
  1987. * @desc : 根据field获取
  1988. * @author : 周兴
  1989. * @date : 2022/6/16 8:44
  1990. */
  1991. getColumnIndexByField(columns, field) {
  1992. for (let i = 0; i < columns.length; i++) {
  1993. if (columns[i].property === field) {
  1994. return i;
  1995. }
  1996. }
  1997. },
  1998. /**
  1999. * @desc : 设置主从数据赋值
  2000. * @author : 周兴
  2001. * @date : 2023/5/9 15:53
  2002. */
  2003. getMultiSelect(e) {
  2004. if (this.tableData[e.rowIndex]) {
  2005. this.$set(this.tableData[e.rowIndex], e.colItem.field, e.rows)
  2006. this.$set(this.tableData[e.rowIndex], e.colItem.field + '_Name', e.display)
  2007. }
  2008. },
  2009. /**
  2010. * @desc : 跳转到下一个可输入单元格
  2011. * @author : 周兴
  2012. * @date : 2022/4/7 15:36
  2013. */
  2014. nextInputCell(row, rowIndex, columnIndex, field, colItem) {
  2015. //如果下拉选择数据没有选择,点回车光标不离开 用columnIndex去查不对,因为位置可能会移动,并且column的列也可能跟列表的顺序不一致
  2016. let filterColumn = this.getColumnByField(field);
  2017. if (filterColumn && filterColumn.controlId && row[field] === null) {
  2018. this.$refs[this.name].setActiveCell(this.tableData[rowIndex], field);
  2019. this.handleFocus(filterColumn, rowIndex);
  2020. return;
  2021. }
  2022. let visibleColumns = this.$refs[this.name].getTableColumn().visibleColumn;
  2023. this.isScroll = true;
  2024. let currentColumnIndex = columnIndex;
  2025. //如果是最后一列那么跳转到下一行
  2026. if (field === visibleColumns[visibleColumns.length - 1].field) {
  2027. rowIndex = parseInt(rowIndex) + 1
  2028. columnIndex = 0;
  2029. } else {
  2030. // 根据field后去列的顺序
  2031. columnIndex = this.getColumnIndexByField(visibleColumns, field) + 1;
  2032. }
  2033. //设置单元格激活状态
  2034. for (let i = rowIndex; i < this.tableData.length; i++) {
  2035. for (let j = columnIndex; j < visibleColumns.length; j++) {
  2036. filterColumn = this.getColumnByField(visibleColumns[j].field);
  2037. //列只读以及行单元格只读
  2038. if (filterColumn && filterColumn.type !== 'disabled' && filterColumn.type !== 'switch') {
  2039. // 不能从同一个controlId的列跳转到下一列
  2040. if (filterColumn.controlId && colItem.controlId
  2041. && filterColumn.controlId === colItem.controlId) {
  2042. continue;
  2043. } else {
  2044. // console.log('bbb',rowIndex,visibleColumns[j].field,filterColumn)
  2045. this.$refs[this.name].setActiveRow(this.tableData[i])
  2046. this.$refs[this.name].setCurrentRow(this.tableData[i])
  2047. this.$refs[this.name].setActiveCell(this.tableData[i], visibleColumns[j].field);
  2048. // 焦点落在各控件上
  2049. this.handleFocus(filterColumn, i);
  2050. }
  2051. // 如果是第一列,需要设置滚动,不然不会回到第一个列的位置
  2052. if (j === 0) {
  2053. this.$refs[this.name].scrollTo(0, 0);
  2054. }
  2055. // 延迟更新不然就会让 滚动先执行
  2056. setTimeout(() => {
  2057. this.isScroll = false;
  2058. }, 500)
  2059. return;
  2060. }
  2061. }
  2062. }
  2063. this.isScroll = false;
  2064. },
  2065. /**
  2066. * @desc : 单元格编辑结束后,光标停留在对应的位置
  2067. * @author : 周兴
  2068. * @date : 2022/4/10 14:02
  2069. */
  2070. handleFocus(column, rowIndex) {
  2071. setTimeout(() => {
  2072. // console.log(e)
  2073. if (column.type) {
  2074. switch (column.type) {
  2075. case 'date':
  2076. this.$refs[column.field + rowIndex][0].focus()
  2077. this.$refs[column.field + rowIndex][0].$refs['input'].focus()
  2078. break;
  2079. case 'switch':
  2080. this.$refs[column.field + rowIndex][0].$el.focus()
  2081. break;
  2082. // case 'select':
  2083. // console.log('res',column.field + rowIndex)
  2084. // // this.$refs[column.field + rowIndex][0].focus()
  2085. // this.$refs[column.field + rowIndex][0].isActivated = true
  2086. // this.$refs[column.field + rowIndex][0].$refs.input.focus()
  2087. // break;
  2088. case 'tableSelect':
  2089. case 'select':
  2090. if (this.$refs[column.field + rowIndex] && this.$refs[column.field + rowIndex].length > 0) {
  2091. if (this.$refs[column.field + rowIndex][0].$refs['input']) {
  2092. this.$refs[column.field + rowIndex][0].$refs['input'].$el.click()
  2093. this.$refs[column.field + rowIndex][0].$refs['input'].focus()
  2094. }
  2095. if (this.$refs[column.field + rowIndex][0].$refs['table']) {
  2096. this.$refs[column.field + rowIndex][0].$refs['table'].focus()
  2097. }
  2098. }
  2099. break;
  2100. }
  2101. }
  2102. }, 200)
  2103. },
  2104. /**
  2105. * @desc : 计算
  2106. * @author : 周兴
  2107. * @date : 2022/4/6 13:59
  2108. */
  2109. calc(field, rowIndex) {
  2110. // console.log('e', e)
  2111. //获取当前列的名
  2112. let currentColumn = this.columns.filter(col => col.field === field);
  2113. if (!currentColumn) return;
  2114. let formula = currentColumn[0].formula;
  2115. //如果没有公式就推出
  2116. if (!formula || !Object.keys(formula)) {
  2117. return;
  2118. }
  2119. let row = this.tableData[rowIndex]
  2120. let key = Object.keys(formula)[0];
  2121. //获取需要计算的列
  2122. let countColumn = this.columns.filter(col => col.field === key);
  2123. if (!countColumn) return;
  2124. let values = formula[key];
  2125. // console.log('dd1', values)
  2126. if (values && values.length > 0) {
  2127. let formu = values[0];
  2128. for (let i = 1; i < values.length; i++) {
  2129. if (row[values[i]]) {
  2130. formu = formu.replace(values[i], row[values[i]]);
  2131. } else {
  2132. // 如果不是非标,面积要进行替换为1
  2133. if (values[i] == 'nonStandardArea') {
  2134. formu = formu.replace('nonStandardArea', 1);
  2135. } else {
  2136. formu = formu.replace(values[i], 0);
  2137. }
  2138. // formu = formu.replace(values[i], 0);
  2139. }
  2140. }
  2141. try {
  2142. //用eval进行计算
  2143. let tValue = eval(formu)
  2144. //说明除数为0,那么金额清空
  2145. if ('Infinity' == tValue || '-Infinity' == tValue || isNaN(tValue)) {
  2146. // row[key] = null;
  2147. } else {
  2148. // 获取小数位数
  2149. let digits = 0;
  2150. if (countColumn[0].digits) {
  2151. digits = countColumn[0].digits
  2152. }
  2153. // console.log('countColumn',countColumn,digits)
  2154. //对计算出来的数据进行处理
  2155. row[key] = XEUtils.toFixed(XEUtils.round(tValue, digits), digits);
  2156. }
  2157. } catch (err) {
  2158. // row[key] = 0
  2159. }
  2160. }
  2161. },
  2162. /**
  2163. * @desc : 表格向下{{ $t('filling') }}
  2164. * @author : 沈博
  2165. * @date : 2022/3/13 9:56
  2166. */
  2167. inputDown(column) {
  2168. let field = column.field
  2169. //获取当前列的名
  2170. let currentColumn = this.columns.filter(col => col.field === field);
  2171. if (!currentColumn) return;
  2172. //console.log('d',currentColumn,column.type)
  2173. // 数值
  2174. if (column.type === 'number') {
  2175. let formula = currentColumn[0].formula;
  2176. //如果没有公式就推出
  2177. if (formula && Object.keys(formula)) {
  2178. let key = Object.keys(formula)[0];
  2179. //获取需要计算的列
  2180. let countColumn = this.columns.filter(col => col.field === key);
  2181. if (countColumn) {
  2182. let values = formula[key];
  2183. if (values && values.length > 0) {
  2184. let formu = values[0];
  2185. //给你当前单元格赋值
  2186. this.tableData.forEach(it => {
  2187. // 如果有controlId,那么只能赋值有值的行
  2188. if (this.controlId && it[this.controlId]) {
  2189. formu = values[0];
  2190. for (let i = 1; i < values.length; i++) {
  2191. if (it[values[i]]) {
  2192. formu = formu.replace(values[i], it[values[i]]);
  2193. } else {
  2194. formu = formu.replace(values[i], 0);
  2195. }
  2196. }
  2197. try {
  2198. //用eval进行计算
  2199. let tValue = eval(formu)
  2200. //说明除数为0,那么金额清空
  2201. if ('Infinity' == tValue) {
  2202. this.$set(it, field, null)
  2203. } else {
  2204. // 获取小数位数
  2205. let digits = 0;
  2206. if (countColumn[0].digits) {
  2207. digits = countColumn[0].digits
  2208. } else {
  2209. //如果没有设置小数位数,那么就读取商品中的计量单位
  2210. if (it.decimalPlaces) {
  2211. digits = it.decimalPlaces;
  2212. }
  2213. }
  2214. //对计算出来的数据进行处理
  2215. this.$set(it, key, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
  2216. }
  2217. } catch (err) {
  2218. this.$set(it, key, 0)
  2219. }
  2220. }
  2221. })
  2222. }
  2223. }
  2224. } else {
  2225. //给你当前单元格赋值
  2226. // 获取小数位数
  2227. let digits = 0;
  2228. if (currentColumn[0].digits) {
  2229. digits = currentColumn[0].digits
  2230. }
  2231. this.tableData.forEach(it => {
  2232. // 如果有controlId,那么只能赋值有值的行
  2233. if ((this.controlId && it[this.controlId]) || !this.controlId) {
  2234. //如果没有设置小数位数,那么就读取商品中的计量单位
  2235. if (digits === 0) {
  2236. digits = it.decimalPlaces;
  2237. }
  2238. this.$set(it, field, XEUtils.toFixed(XEUtils.round(this.inputDownValue, digits), digits))
  2239. }
  2240. })
  2241. }
  2242. } else if (column.type === 'text') {
  2243. //文本
  2244. this.tableData.forEach(it => {
  2245. // 如果有controlId,那么只能赋值有值的行
  2246. if ((this.controlId && it[this.controlId]) || !this.controlId) {
  2247. this.$set(it, field, this.inputDownValue);
  2248. }
  2249. })
  2250. } else if (column.type === 'switch') {
  2251. this.tableData.forEach(it => {
  2252. // 如果有controlId,那么只能赋值有值的行
  2253. if ((this.controlId && it[this.controlId]) || !this.controlId) {
  2254. this.$set(it, field, this.inputDownBooleanValue);
  2255. }
  2256. })
  2257. } else if (column.type === 'select') {
  2258. this.tableData.forEach(it => {
  2259. // 如果有controlId,那么只能赋值有值的行
  2260. if ((this.controlId && it[this.controlId]) || !this.controlId) {
  2261. this.$set(it, field, this.inputDownValue);
  2262. let list = typeof column.options === 'function' ? column.options() : column.options
  2263. this.$set(it, field + '_Name', list.filter(it => it[column.valueKey] === this.inputDownValue)[0][column.labelKey]);
  2264. }
  2265. })
  2266. } else if (column.type === 'tableSelect') {
  2267. if (currentColumn && currentColumn.length > 0) {
  2268. let col = currentColumn[0]
  2269. let row = col[col.field + '_copy']
  2270. this.tableData.forEach(it => {
  2271. col.fieldUpdate.forEach(it2 => {
  2272. if (it[this.controlId] || it.controlId !== this.controlId) {
  2273. this.$set(it, it2.updateField, row[it2.valueFiled])
  2274. }
  2275. })
  2276. })
  2277. }
  2278. }
  2279. this.$refs['down-input-icon'][0].$el.click()
  2280. }
  2281. ,
  2282. /**
  2283. * @desc : 新增一行
  2284. * @author : 周兴
  2285. * @date : 2022/4/7 14:36
  2286. */
  2287. add(rowIndex) {
  2288. let obj = {};
  2289. this.columnsData.forEach(it => {
  2290. //开关时,默认是true,如果要是false需要在列中给其传值
  2291. if (it.type === 'switch') {
  2292. this.$set(obj, it.field, it.value === undefined || it.value === null ? true : it.value);
  2293. if (this.defaultField && it.field == this.defaultField) {
  2294. this.$set(obj, it.field, false);
  2295. }
  2296. } else {
  2297. // 如果是显示顺序需要自增
  2298. if (it.field === 'displayNo') {
  2299. let arr = this.tableData.map(m => m[it.field]);
  2300. let cMax = Math.max.apply(null, arr);
  2301. if (cMax && cMax != '-Infinity') {
  2302. this.$set(obj, it.field, cMax + 1);
  2303. } else {
  2304. this.$set(obj, it.field, 1);
  2305. }
  2306. } else {
  2307. //读取列的默认值,如果有设置,那么需要设置上
  2308. if (it.value && it.value != null) {
  2309. if (it.type === 'select') {
  2310. setTimeout(() => {
  2311. let options = it.options();
  2312. let filters = options.filter(item => item[it.valueKey] === it.value);
  2313. if (filters && filters.length > 0) {
  2314. this.$set(obj, it.field, it.value);
  2315. this.$set(obj, it.field + '_Name', filters[0][it.labelKey]);
  2316. }
  2317. }, rowIndex ? 0 : 300)
  2318. } else {
  2319. this.$set(obj, it.field, it.value);
  2320. }
  2321. } else {
  2322. this.$set(obj, it.field, null);
  2323. }
  2324. }
  2325. }
  2326. })
  2327. //说明是手动新增的
  2328. let curorRowIndex = 0;
  2329. if (rowIndex || rowIndex === 0) {
  2330. this.tableData.splice(rowIndex + 1, 0, obj)
  2331. curorRowIndex = rowIndex + 1;
  2332. } else {
  2333. this.tableData.push(obj)
  2334. curorRowIndex = 0;
  2335. }
  2336. //设置光标位置
  2337. if (this.focusFlag) {
  2338. this.$nextTick(() => {
  2339. for (let j in this.columnsData) {
  2340. if (this.columnsData[j].type !== 'disabled' && this.columnsData[j].type !== 'switch' &&
  2341. (!this.tableData[curorRowIndex].readOnly || this.tableData[curorRowIndex].readOnly.indexOf(this.columnsData[j].field) < 0)) {
  2342. this.$refs[this.name].setActiveCell(this.tableData[curorRowIndex], this.columnsData[j].field);
  2343. // console.log('ttt',this.focusFlag,)
  2344. this.handleFocus(this.columnsData[j], curorRowIndex);
  2345. break;
  2346. }
  2347. }
  2348. })
  2349. }
  2350. this.$emit('addRow', rowIndex)
  2351. },
  2352. /**
  2353. * @desc : 删除一行
  2354. * @author : 周兴
  2355. * @date : 2022/4/11 9:13
  2356. */
  2357. del(rowIndex) {
  2358. // console.log('del',rowIndex)
  2359. let row = {...this.tableData[rowIndex]}
  2360. // 记录删除的数据
  2361. if (this.majorField && row[this.majorField]) {
  2362. this.deleteData.push(row);
  2363. }
  2364. this.tableData = [...this.tableData.filter((it, index) => {
  2365. return index !== rowIndex
  2366. })]
  2367. //如果删完了,那么就要新增新行
  2368. if (this.operateFlag && this.newRowFlag && (!this.tableData || this.tableData.length === 0)) {
  2369. this.add(0);
  2370. }
  2371. this.$refs[this.name].reloadData(this.tableData)
  2372. this.$emit('delRow', row, rowIndex)
  2373. this.setDefaultFlag(row, true);
  2374. },
  2375. /**
  2376. * @desc : TableSelect输入框离开焦点事件
  2377. * @author : 周兴
  2378. * @date : 2022/5/26 16:40
  2379. */
  2380. handleSelectInputBlur(e, row, rowIndex, colItem, colIndex) {
  2381. // 把值恢复回去
  2382. if (this.$refs[colItem.field + rowIndex] && row[colItem.field]) {
  2383. this.$refs[colItem.field + rowIndex][0].$refs.input.$refs.input.value = row[colItem.field];
  2384. }
  2385. },
  2386. /**
  2387. * @desc : 清空选择
  2388. * @author : 周兴
  2389. * @date : 2022/9/23 17:39
  2390. */
  2391. clearSelect(e) {
  2392. if (this.tableData && this.tableData[e.rowIndex] && this.tableData[e.rowIndex][e.column.field]) {
  2393. this.tableData[e.rowIndex][e.column.field] = null;
  2394. this.tableData[e.rowIndex][e.column.field + '_Name'] = null;
  2395. }
  2396. this.$emit('clear-select', e)
  2397. },
  2398. /**
  2399. * @desc : desc
  2400. * @author : 周兴
  2401. * @date : 2022/4/10 14:22
  2402. */
  2403. inputChange(row, rowIndex, colItem, val) {
  2404. // 更新需要更新的列
  2405. this.columns.forEach((it, index) => {
  2406. //如果这里是controlId
  2407. if (this.controlId) {
  2408. if (colItem.type === 'tableSelect') {
  2409. if (colItem.controlId && it.field == colItem.field && this.controlId === colItem.controlId) {
  2410. this.tableData[rowIndex][it.field] = null;
  2411. }
  2412. }
  2413. } else {
  2414. //说明这列受管控
  2415. if (it.controlIds && it.controlIds.length > 0 && it.controlIds.includes(colItem.field)) {
  2416. this.tableData[rowIndex][it.field] = null;
  2417. if (this.tableData[rowIndex][it.field + '_Name']) {
  2418. this.tableData[rowIndex][it.field + '_Name'] = null;
  2419. }
  2420. }
  2421. }
  2422. })
  2423. this.$emit('changeValue', colItem.field, row, rowIndex, val);
  2424. },
  2425. /**
  2426. * @desc : 批量选择数据
  2427. * @author : 周兴
  2428. * @date : 2022/5/26 16:54
  2429. */
  2430. onBatchChoose(e, column, rowIndex, colIndex, fieldUpdate, colItem) {
  2431. // 单选
  2432. if (colItem.multiple !== undefined && !colItem.multiple) {
  2433. this.onChoose(e.batchRows[0], e.batchRows[0], column, rowIndex, colIndex, fieldUpdate, colItem)
  2434. } else {
  2435. // 多选
  2436. let {batchRows, batchKeys} = e;
  2437. if (batchRows && batchRows.length > 0) {
  2438. let deleteCurrentFlag = false;
  2439. let index = 0;
  2440. for (let i = 0; i < batchRows.length; i++) {
  2441. // 只有控制主键的列才会这么操作
  2442. if (colItem.controlId) {
  2443. // 判断是否重复
  2444. this.checkRepeat(batchRows[i], batchRows[i], rowIndex, colItem, false).then(isRepeat => {
  2445. // 如果重复就不进行后续
  2446. if (isRepeat) {
  2447. //只要重复就不允许删除当前行了
  2448. deleteCurrentFlag = true;
  2449. // index = index + 1;
  2450. } else {
  2451. // 如果第一行是新行,那么就要把deleteCurrentFlag设置为true,不然第二行就要删除掉之前的数据
  2452. if (i === 0 && this.controlId && !this.tableData[rowIndex][this.controlId]) {
  2453. deleteCurrentFlag = true;
  2454. }
  2455. //如果当前行有值,先删除当前行 (当前行只能删除一次)
  2456. if (!deleteCurrentFlag && this.controlId && this.tableData[rowIndex][this.controlId]) {
  2457. // 记录删除的数据
  2458. if (this.majorField && colItem.field == this.majorField && this.tableData[rowIndex][this.majorField]) {
  2459. this.deleteData.push(this.tableData[rowIndex]);
  2460. }
  2461. //删除当前数据
  2462. this.tableData = this.tableData.filter((it, cIndex) => {
  2463. return cIndex !== rowIndex
  2464. })
  2465. deleteCurrentFlag = true;
  2466. }
  2467. //新增行(判断行是否是新行,新行要新增
  2468. this.addNewRow(rowIndex + index);
  2469. // 设置需要更新的数据
  2470. this.setTableData(batchRows[i], batchRows[i], rowIndex + index, colItem, fieldUpdate);
  2471. index = index + 1;
  2472. }
  2473. });
  2474. }
  2475. }
  2476. if (this.autoNextFlag) {
  2477. // 跳转到第一行的可输入单元格
  2478. this.nextInputCell(batchRows[0], rowIndex, colIndex, colItem.field, colItem);
  2479. }
  2480. // this.$emit('onBatchChoose', batchRows, rowIndex)
  2481. this.$emit('chooseData', batchRows, rowIndex, colItem)
  2482. }
  2483. }
  2484. },
  2485. /**
  2486. * @desc : 批量赋值
  2487. * @author : 周兴
  2488. * @date : 2022/11/15 13:04
  2489. */
  2490. onBatchChooseCopy(e, colItem, type) {
  2491. let row = type === 'batch' ? e.batchRows[0] : e
  2492. // this.tableData.forEach(it => {
  2493. // colItem.fieldUpdate.forEach(it2 => {
  2494. // if (it[this.controlId] || it.controlId !== this.controlId) {
  2495. // this.$set(it, it2.updateField, row[it2.valueFiled])
  2496. // }
  2497. // })
  2498. // })
  2499. this.$set(colItem, colItem.field + '_copy', row)
  2500. },
  2501. /**
  2502. * @desc : 增加新行(【批量选择数据后增加】)
  2503. * @author : 周兴
  2504. * @date : 2022/5/27 9:13
  2505. */
  2506. addNewRow(rowIndex) {
  2507. // console.log('ttt',rowIndex)
  2508. if (!this.tableData[rowIndex]) {
  2509. this.add(rowIndex);
  2510. } else {
  2511. // 如果多行增加时,这行有值,需要增加
  2512. if (this.controlId && this.tableData[rowIndex][this.controlId]) {
  2513. this.add(rowIndex);
  2514. }
  2515. }
  2516. },
  2517. /**
  2518. * @desc : 选择数据
  2519. * @author : 周兴
  2520. * @date : 2022/4/7 16:02
  2521. */
  2522. onChoose(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem) {
  2523. this.chooseData(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem, true);
  2524. setTimeout(() => {
  2525. if (this.autoNextFlag) {
  2526. this.$refs[this.name].clearActived()
  2527. // 跳转到下一个可输入单元格
  2528. this.nextInputCell(row, rowIndex, columnIndex, colItem.field, colItem);
  2529. }
  2530. }, 300)
  2531. },
  2532. /**
  2533. * @desc : 设置默认标识
  2534. * @author : 周兴
  2535. * @date : 2022/8/5 9:28
  2536. */
  2537. setDefaultFlag(row, deleteFlag) {
  2538. if (this.defaultField && row) {
  2539. // 删除
  2540. if (deleteFlag) {
  2541. // 如果删除的是默认行,那么需要指定第一行为默认
  2542. if (row[this.defaultField] && this.tableData && this.tableData.length > 0) {
  2543. this.$set(this.tableData[0], this.defaultField, true);
  2544. }
  2545. } else {
  2546. // 判断是否有标识已经勾选上了
  2547. let filterRows = this.tableData.filter(it => it[this.defaultField]);
  2548. if (!filterRows || filterRows.length == 0) {
  2549. this.$set(row, this.defaultField, true);
  2550. } else {
  2551. this.$set(row, this.defaultField, false);
  2552. }
  2553. }
  2554. }
  2555. },
  2556. /**
  2557. * @desc : 选择数据(私有方法)
  2558. * @author : 周兴
  2559. * @date : 2022/5/26 16:39
  2560. */
  2561. chooseData(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem, showMessage) {
  2562. let eRow = e == null ? row : e;
  2563. // 判断是否重复
  2564. this.checkRepeat(eRow, row, rowIndex, colItem, showMessage).then(res => {
  2565. if (res) {
  2566. return;
  2567. }
  2568. //记录删除的行
  2569. if (this.majorField && colItem.field == this.majorField && row[this.majorField]) {
  2570. this.deleteData.push(row);
  2571. }
  2572. // 设置需要更新的数据
  2573. this.setTableData(eRow, row, rowIndex, colItem, fieldUpdate);
  2574. this.$emit('chooseData', row, rowIndex, colItem)
  2575. });
  2576. },
  2577. /**
  2578. * @desc : 设置需要更新的数据
  2579. * @author : 周兴
  2580. * @date : 2022/5/27 8:48
  2581. */
  2582. setTableData(eRow, row, rowIndex, colItem, fieldUpdate) {
  2583. //说明是下拉,需要赋值
  2584. if (colItem.valueKey) {
  2585. //先把labelKey赋值给field,方便显示
  2586. if (eRow[colItem.valueKey]) {
  2587. this.$set(this.tableData[rowIndex], colItem.field, eRow[colItem.valueKey].toString())
  2588. this.$set(this.tableData[rowIndex], colItem.field + '_Name', eRow[colItem.labelKey])
  2589. // this.tableData[rowIndex][colItem.field] = eRow[colItem.valueKey].toString();
  2590. // this.tableData[rowIndex][colItem.field + '_Name'] = eRow[colItem.labelKey];
  2591. }
  2592. } else {
  2593. // 更新需要更新的列
  2594. if (fieldUpdate) {
  2595. fieldUpdate.forEach(it => {
  2596. this.$set(this.tableData[rowIndex], it.updateField, eRow[it.valueFiled])
  2597. // this.tableData[rowIndex][it.updateField] = eRow[it.valueFiled]
  2598. })
  2599. }
  2600. // 设置默认值
  2601. this.setDefaultFlag(this.tableData[rowIndex]);
  2602. }
  2603. // 给id赋值
  2604. // this.tableData[rowIndex]['id'] = eRow['id']
  2605. //把改变的行加入到tableDataChange中
  2606. let rows = this.tableDataChange.filter(it => it['_X_ID'] === row['_X_ID']);
  2607. //说明已经存在
  2608. if (rows && rows.length > 0) {
  2609. this.tableDataChange = this.tableDataChange.filter(it => it['_X_ID'] !== row['_X_ID']).map(it => it);
  2610. }
  2611. this.tableDataChange.push(row);
  2612. },
  2613. /**
  2614. * @desc : 判断是否重复
  2615. * @author : 周兴
  2616. * @date : 2022/5/27 8:46
  2617. */
  2618. checkRepeat(eRow, row, rowIndex, colItem, showMessage) {
  2619. return new Promise(resolve => {
  2620. //如果需要进行唯一性判断
  2621. if (!this.enabledRepeat && this.enabledRepeatId) {
  2622. //不是数组
  2623. if (!Array.isArray(this.enabledRepeatId)) {
  2624. //判断是否有重复的数据
  2625. let tmpRows = this.tableData.filter(it => it[this.controlId] == eRow[this.enabledRepeatId]);
  2626. // console.log('3343', this.enabledRepeat, this.tableData, this.enabledRepeatId, eRow)
  2627. if (tmpRows && tmpRows.length > 0) {
  2628. //判断是否是同一行的
  2629. if (row['_X_ID'] != tmpRows[0]['_X_ID']) {
  2630. //提示信息重复
  2631. if (showMessage) {
  2632. this.$Message.warning(vm.$t('W_018'))
  2633. }
  2634. resolve(true);
  2635. }
  2636. }
  2637. } else {
  2638. let data = [...this.tableData];
  2639. let currentRow = data[rowIndex];
  2640. for (let col = 0; col < this.enabledRepeatId.length; col++) {
  2641. // for (let col in this.enabledRepeatId) {
  2642. data = this.filterData(data, eRow, this.enabledRepeatId[col], currentRow, colItem);
  2643. // 说明没有重复
  2644. if (!data || data.length === 0) {
  2645. break;
  2646. }
  2647. }
  2648. if (data && data.length > 0) {
  2649. //提示信息重复
  2650. if (showMessage) {
  2651. this.$Message.warning(vm.$t('W_018'))
  2652. }
  2653. resolve(true);
  2654. }
  2655. }
  2656. }
  2657. resolve(false);
  2658. })
  2659. },
  2660. /**
  2661. * @desc : 过滤数据
  2662. * @author : 周兴
  2663. * @date : 2022/5/13 16:27
  2664. */
  2665. filterData(data, eRow, col, currentRow, column) {
  2666. //说明是当前列,当前列从下拉中取值
  2667. if (column.field === col) {
  2668. if (column.valueKey) {
  2669. return data.filter(it => it[col] == eRow[column.valueKey]);
  2670. }
  2671. } else {
  2672. if (currentRow && currentRow[col]) {
  2673. return data.filter(it => it[col] == currentRow[col] && it['_X_ID'] != currentRow['_X_ID']);
  2674. }
  2675. }
  2676. return null;
  2677. },
  2678. /**
  2679. * @desc : 校验数据
  2680. * @author : 周兴
  2681. * @date : 2022/4/7 16:02
  2682. */
  2683. validCheck() {
  2684. return new Promise((resolve, reject) => {
  2685. const $table = this.$refs[this.name]
  2686. $table.fullValidate(true).then(() => {
  2687. resolve(true)
  2688. }).catch(errMap => {
  2689. resolve(false)
  2690. })
  2691. })
  2692. },
  2693. /**
  2694. * @desc : 日期格式
  2695. * @author : 周兴
  2696. * @date : 2022/4/24 17:13
  2697. */
  2698. dateFormat(val) {
  2699. if (!val) {
  2700. return ''
  2701. }
  2702. return val.format('yyyy-MM-dd')
  2703. },
  2704. /**
  2705. * @desc : 单元格编辑结束后,光标停留在对应的位置
  2706. * @author : 周兴
  2707. * @date : 2022/4/10 14:02
  2708. */
  2709. editMethod(e) {
  2710. },
  2711. /**
  2712. * @desc : 滚动就隐藏pop
  2713. * @author : 周兴
  2714. * @date : 2022/4/19 9:21
  2715. */
  2716. handleScroll(e) {
  2717. if (!this.isScroll) {
  2718. if (e.isY) {
  2719. this.$refs[this.name].clearActived(); //关闭行激活状态
  2720. }
  2721. this.$refs[this.name].$el.click(); //关闭表头的pop
  2722. }
  2723. },
  2724. /**
  2725. * @desc : 移动行
  2726. * @author : 周兴
  2727. * @date : 2022/12/15 16:28
  2728. */
  2729. rowDrop() {
  2730. this.$nextTick(() => {
  2731. let xTable = this.$refs[this.name];
  2732. this.sortable = Sortable.create(
  2733. xTable.$el.querySelector(".body--wrapper>.vxe-table--body tbody"),
  2734. {
  2735. handle: ".vxe-body--row",
  2736. animation: 150,
  2737. onEnd: ({newIndex, oldIndex}) => {
  2738. let tableData = this.tableData.copy();
  2739. tableData.splice(newIndex, 0, tableData.splice(oldIndex, 1)[0]);
  2740. let newArray = tableData.slice(0);
  2741. this.tableData = [];
  2742. this.$nextTick(function () {
  2743. this.tableData = newArray;
  2744. });
  2745. },
  2746. }
  2747. );
  2748. });
  2749. },
  2750. /**
  2751. * @desc : 表格设置
  2752. * @author : 周兴
  2753. * @date : 2022/12/1 15:11
  2754. */
  2755. showSetting(e) {
  2756. const tableColumns = this.$refs[this.name].getTableColumn()
  2757. if (tableColumns) {
  2758. let columns = tableColumns.fullColumn
  2759. columns = columns.filter(it => it.type != 'seq' && it.type != 'blank' && it.type != 'info')
  2760. this.$TableFilter({tableData: columns},
  2761. {
  2762. ok: (val) => {
  2763. // this.unFreeze();
  2764. // 去掉选择的标题
  2765. let filterRows = val.filter(it => it.type == 'checkbox' || it.type == 'radio');
  2766. if (filterRows && filterRows.length > 0) {
  2767. filterRows.forEach(it => {
  2768. it.title = '';
  2769. })
  2770. }
  2771. // 加入序号
  2772. val.splice(0, 0, tableColumns.fullColumn[0])
  2773. // 加入校验信息
  2774. val.splice(1, 0, tableColumns.fullColumn[1])
  2775. // 加入blank
  2776. val.push(tableColumns.fullColumn[tableColumns.fullColumn.length - 1])
  2777. // 加载列
  2778. this.$refs[this.name].loadColumn(val);
  2779. },
  2780. })
  2781. }
  2782. },
  2783. /**
  2784. * @desc : 根据requiredColumn进行validRules设置
  2785. * @author : 周兴
  2786. * @date : 2022/4/25 15:13
  2787. */
  2788. setRequiredColumn() {
  2789. if (this.requiredColumn && this.requiredColumn.length > 0) {
  2790. let validRules = {}
  2791. this.requiredColumn.forEach(col => {
  2792. let tempCol = this.columns.filter(it => it.field === col);
  2793. if (tempCol && tempCol.length > 0) {
  2794. tempCol[0].required = true;
  2795. }
  2796. // if (tempCol) {
  2797. // validRules[col] = [{
  2798. // required: true,
  2799. // // message: vm.$t('inputWords', {'search-name': tempCol[0].title ? tempCol[0].title : vm.$t(tempCol[0].field)})
  2800. // }]
  2801. // }
  2802. })
  2803. console.log('b', this.columns)
  2804. // this.validRules = validRules;
  2805. }
  2806. },
  2807. /**
  2808. * @desc : 刷新表的列
  2809. * @author : 周兴
  2810. * @date : 2023/3/17 14:41
  2811. */
  2812. refreshTableColumns(columns) {
  2813. this.columnsData = []
  2814. //如果列中没有序号要加上
  2815. let filterColumns = columns.filter(it => it.field === 'seq');
  2816. if (!filterColumns || filterColumns.length === 0) {
  2817. columns.splice(0, 0, {type: 'seq', field: 'seq', fixed: 'left'})
  2818. columns.splice(1, 0, {type: 'info', field: 'info', fixed: 'left', width: '15'})
  2819. columns.splice(0, 0, {type: 'blank', field: 'blank', width: '1'})
  2820. }
  2821. this.columnsData = columns;
  2822. },
  2823. /**
  2824. * @desc : 初始化列
  2825. * @author : 周兴
  2826. * @date : 2022/6/11 10:42
  2827. */
  2828. initColumn() {
  2829. let columns = [...this.columns]
  2830. //如果列中没有序号要加上
  2831. let filterColumns = columns.filter(it => it.field === 'seq');
  2832. if (!filterColumns || filterColumns.length === 0) {
  2833. columns.splice(0, 0, {type: 'seq', field: 'seq', fixed: 'left'})
  2834. columns.splice(1, 0, {type: 'info', field: 'info', fixed: 'left', width: '15'})
  2835. columns.splice(0, 0, {type: 'blank', field: 'blank', width: '1'})
  2836. }
  2837. this.columnsData = columns;
  2838. },
  2839. /**
  2840. * @desc : 固定列
  2841. * @author : 周兴
  2842. * @date : 2022/6/8 20:29
  2843. */
  2844. toggleFixedColumn() {
  2845. const xTable = this.$refs[this.name]
  2846. if (!xTable) return;
  2847. const tableColumns = xTable.getTableColumn()
  2848. if (tableColumns && tableColumns.visibleColumn
  2849. && tableColumns.visibleColumn.length > 0) {
  2850. let refreshFlag = false;
  2851. for (let i in this.columnsData) {
  2852. // 查看是否有列设置了固定
  2853. if (this.columnsData[i].fixed) {
  2854. let col = tableColumns.visibleColumn.filter(it => it.property === this.columnsData[i].field)
  2855. if (col && col.length > 0) {
  2856. col[0].fixed = this.columnsData[i].fixed;
  2857. refreshFlag = true;
  2858. }
  2859. }
  2860. }
  2861. if (refreshFlag) {
  2862. // 刷新列
  2863. xTable.refreshColumn();
  2864. }
  2865. }
  2866. },
  2867. /**
  2868. * @desc : 改变设置的位置
  2869. * @author : 周兴
  2870. * @date : 2023/1/29 16:55
  2871. */
  2872. changeSettingLocation() {
  2873. let self = this;
  2874. this.$nextTick(() => {
  2875. setTimeout(() => {
  2876. self.settingLeft = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetWidth + self.$refs[self.name].$el.offsetLeft - 26) + 'px' : 0// 设置图标居左的位置
  2877. self.settingTop = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetTop + 1) + 'px' : 0; // 设置图标居上的位置
  2878. }, 700)
  2879. })
  2880. },
  2881. },
  2882. mounted() {
  2883. let self = this;
  2884. setTimeout(() => {
  2885. self.toggleFixedColumn(); // 冻结列
  2886. }, 300)
  2887. self.rowDrop(); //行移动
  2888. //监听窗口变化
  2889. window.addEventListener('resize', self.changeSettingLocation)
  2890. self.handleSelectData()
  2891. self.changeSettingLocation();
  2892. },
  2893. beforeDestroy() {
  2894. if (this.sortable) {
  2895. this.sortable.destroy();
  2896. }
  2897. this.sortable = null;
  2898. window.removeEventListener('resize', this.changeSettingLocation)
  2899. this.existsFlag = null
  2900. },
  2901. created() {
  2902. // 初始化列
  2903. this.initColumn();
  2904. this.tableData = this.data;
  2905. //设置新行
  2906. if (!this.data || this.data.length === 0 || this.newRowAlwaysFlag) {
  2907. this.tableData = []
  2908. this.tableDataChange = []
  2909. if (this.newRowFlag) {
  2910. //新建时增加行
  2911. this.add()
  2912. }
  2913. // 聚焦到第一行
  2914. if (this.autoFocus) {
  2915. setTimeout(() => {
  2916. this.$refs[this.name]?.setActiveRow(this.tableData[0])
  2917. }, 300)
  2918. }
  2919. }
  2920. // 根据列表是否只读,判断是否开启编辑模式
  2921. if (this.readonly) {
  2922. this.enabledEdit = false;
  2923. }
  2924. // 设置必须输入项
  2925. this.setRequiredColumn();
  2926. this.freezeData = this.freeze;
  2927. }
  2928. }
  2929. </script>
  2930. <style scoped>
  2931. /deep/ .vxe-cell {
  2932. display: flex;
  2933. align-items: center;
  2934. padding-left: 0 !important;
  2935. padding-right: 0 !important;
  2936. }
  2937. /deep/ .vxe-cell--label {
  2938. padding-left: 10px !important;
  2939. padding-right: 10px !important;
  2940. }
  2941. .edit-div-class {
  2942. padding-left: 10px !important;
  2943. padding-right: 10px !important;
  2944. overflow: hidden !important;
  2945. text-overflow: ellipsis !important;
  2946. white-space: nowrap !important;
  2947. }
  2948. /deep/ .vxe-footer--row .vxe-cell {
  2949. justify-content: left !important;
  2950. }
  2951. /deep/ .vxe-input {
  2952. width: 100%;
  2953. border: 1px solid #dcdee2;
  2954. border-radius: 2px;
  2955. }
  2956. /deep/ .vxe-input :hover {
  2957. /*border: 1px solid #57a3f3 !important;*/
  2958. /*border-radius: 2px;*/
  2959. }
  2960. /deep/ .vxe-input > input:focus {
  2961. /*border-color: #57a3f3 !important;*/
  2962. /*border-radius: 2px;*/
  2963. /*-webkit-box-shadow: 0 0 0 1px rgba(45, 140, 240, .2) !important;*/
  2964. box-shadow: 0 0 0 2px rgba(45, 140, 240, 0.2);
  2965. }
  2966. /deep/ .col--valid-error .vxe-input > input {
  2967. border-color: red !important;
  2968. }
  2969. /deep/ .vxe-cell--title {
  2970. line-height: 0;
  2971. }
  2972. /*
  2973. * @desc : TODO 不好使
  2974. * @author : 周兴
  2975. * @date : 2022/4/5 16:35
  2976. */
  2977. .number-class .vxe-cell {
  2978. justify-content: right !important;
  2979. }
  2980. /deep/ .vxe-input--number-prev-icon {
  2981. display: none;
  2982. }
  2983. /deep/ .vxe-input--number-next-icon {
  2984. display: none;
  2985. }
  2986. /deep/ .vxe-input .vxe-input--extra-suffix {
  2987. display: none;
  2988. }
  2989. .setting-class {
  2990. position: absolute;
  2991. z-index: 300;
  2992. width: 25px;
  2993. height: 28px;
  2994. background: #F8F8F9;
  2995. justify-content: center;
  2996. display: flex;
  2997. align-items: center;
  2998. cursor: pointer;
  2999. }
  3000. .freeze-class {
  3001. margin-top: 4px;
  3002. margin-left: 5px;
  3003. cursor: pointer;
  3004. font-size: 14px;
  3005. color: #c0c4cc;
  3006. }
  3007. .freezed-class {
  3008. margin-top: 4px;
  3009. margin-left: 5px;
  3010. cursor: pointer;
  3011. font-size: 14px;
  3012. }
  3013. .table-title {
  3014. padding: 4px 0 4px 0;
  3015. font-size: 14px;
  3016. font-weight: bold;
  3017. }
  3018. .edit-button {
  3019. border-color: #57a3f3 !important;
  3020. }
  3021. .switch-class {
  3022. height: calc(100% - 3px) !important;
  3023. display: flex !important;
  3024. align-items: center !important;
  3025. justify-content: center !important;
  3026. }
  3027. .checkbox-class {
  3028. height: 100% !important;
  3029. display: flex !important;
  3030. align-items: center !important;
  3031. justify-content: center !important;
  3032. }
  3033. .checkbox-class label {
  3034. margin-bottom: 0 !important;
  3035. }
  3036. /deep/ .close-div-class .ivu-input-group {
  3037. top: 3px !important
  3038. }
  3039. /deep/ .required-class .vxe-cell--edit-icon {
  3040. color: red !important;
  3041. }
  3042. /deep/ .vxe-cell--edit-icon {
  3043. margin-top: 1px !important;
  3044. }
  3045. .text-button-class {
  3046. margin-left: 0 !important;
  3047. width: 65px !important;
  3048. background-color: #17a2b8 !important;
  3049. color: white !important;
  3050. }
  3051. .vxe-table--render-default .vxe-body--row.row--current .vxe-body--column .vxe-cell .text-button-class {
  3052. background-color: #17a2b8 !important;
  3053. color: white !important;
  3054. }
  3055. .vxe-table--render-default .vxe-body--row.row--checked, .vxe-table--render-default .vxe-body--row.row--radio .vxe-body--column .vxe-cell .text-button-class {
  3056. background-color: #17a2b8 !important;
  3057. color: white !important;
  3058. }
  3059. </style>