DocGeneratorSelected.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <div class="flex-container-2">
  3. <div class="flex-content-2 table-fix-head-2">
  4. <table
  5. class="fixed-table table-striped table-bordered"
  6. :width="tableWidth"
  7. height="40px"
  8. >
  9. <thead>
  10. <tr height="40px">
  11. <th
  12. width="50px"
  13. class="fixed-cell"
  14. >
  15. 序号
  16. </th>
  17. <th
  18. width="50px"
  19. class="fixed-cell"
  20. >
  21. 操作
  22. </th>
  23. <th
  24. v-for="infoGridField in infoGridFields"
  25. v-show="infoGridField.isShow"
  26. :key="infoGridField.fieldName"
  27. :width="infoGridField.width + 'px'"
  28. @click="onSort(infoGridField)"
  29. >
  30. <div
  31. :id="'infoGridFieldId_' + infoGridField.fieldName"
  32. class="rz-handle"
  33. draggable="true"
  34. @dragstart="ondragstart($event, infoGridField)"
  35. @drag="ondrag($event, infoGridField)"
  36. @dragend="ondragend($event, infoGridField)"
  37. />
  38. <div class="td-max">
  39. {{ infoGridField.name }}
  40. </div>
  41. </th>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. <tr
  46. v-for="(rowData, index) in dataList"
  47. :key="rowData.id"
  48. height="40px"
  49. >
  50. <td class="fixed-cell">
  51. {{ index + 1 }}
  52. </td>
  53. <td class="fixed-cell">
  54. <span
  55. class="label label-danger"
  56. style="cursor: pointer;"
  57. @click="removeRow(rowData)"
  58. >删除</span>
  59. </td>
  60. <td
  61. v-for="infoGridField in infoGridFields"
  62. :key="infoGridField.fieldName + '_' + rowData.id"
  63. >
  64. <input
  65. v-if="infoGridField.simpleDisplayType == 'TextEditor'"
  66. autocomplete="off"
  67. type="text"
  68. class="form-control"
  69. :value="getDisplayValue(rowData, infoGridField)"
  70. @keyup="valueChange($event, rowData, infoGridField)"
  71. />
  72. <input
  73. v-if="infoGridField.simpleDisplayType == 'NumberEditor'"
  74. autocomplete="off"
  75. type="number"
  76. class="form-control"
  77. :value="getDisplayValue(rowData,infoGridField)"
  78. @keyup="valueChange($event, rowData, infoGridField)"
  79. />
  80. <span v-if="infoGridField.simpleDisplayType == undefined">
  81. {{ rowData.data[infoGridField.fieldName]==undefined?"":rowData.data[infoGridField.fieldName].displayValue[0] }}
  82. </span>
  83. </td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. </div>
  88. <div
  89. class="flex-footer-2"
  90. style="margin-top: 10px;"
  91. >
  92. <div class="pull-left">
  93. <span>
  94. 共计 {{ dataList.length }} 条
  95. </span>
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. var Common = require('../../common/Common.js').default;
  102. var Notify = require('../../common/Notify.js').default;
  103. var InfoUtil = require('./InfoUtil.js').default;
  104. export default {
  105. components: {
  106. },
  107. props: {
  108. // 查询窗口编号
  109. 'infoWindowNo': {
  110. type: String,
  111. default: null,
  112. },
  113. // 表格字段
  114. 'infoGridFields': {
  115. type: Object,
  116. default: null,
  117. },
  118. },
  119. emits: ['selectChanged'],
  120. data: function () {
  121. return {
  122. dataList: [],
  123. sortStyle: '',
  124. sortClause: '',
  125. };
  126. },
  127. computed: {
  128. /**
  129. * 自动计算表格的宽度
  130. */
  131. tableWidth: function () {
  132. var totalWidth = 50;
  133. if (this.infoGridFields !== undefined) {
  134. this.infoGridFields.forEach(function (infoGridField) {
  135. if (infoGridField.width !== undefined
  136. && infoGridField.width !== null
  137. && infoGridField.width !== '') {
  138. totalWidth += Number(infoGridField.width);
  139. }
  140. });
  141. }
  142. return totalWidth + 'px';
  143. },
  144. },
  145. methods: {
  146. /**
  147. * 列开始拖动
  148. * @author YangZhiJie 20210909
  149. */
  150. ondragstart: function (event, gridFieldItem) {
  151. var _self = this;
  152. _self.startX = event.pageX;
  153. _self.startWidth = Number(gridFieldItem.width);
  154. },
  155. /**
  156. * 列拖动
  157. * @author YangZhiJie 20210909
  158. */
  159. ondrag: function (event, gridFieldItem) {
  160. var _self = this;
  161. gridFieldItem.width = _self.startWidth + (event.pageX - _self.startX);
  162. },
  163. /**
  164. * 列结束拖动
  165. * @author YangZhiJie 20210909
  166. */
  167. ondragend: function (event, gridFieldItem, index) {
  168. var _self = this;
  169. var gridFieldItemClone = {
  170. 'id': gridFieldItem.id,
  171. 'index': index,
  172. 'isShow': gridFieldItem.isShow,
  173. 'width': gridFieldItem.width,
  174. 'sortNo': gridFieldItem.sortNo,
  175. 'fieldName': gridFieldItem.fieldName,
  176. };
  177. gridFieldItemClone.width = _self.startWidth + (event.pageX - _self.startX);
  178. if (gridFieldItemClone.width < 50) {
  179. gridFieldItemClone.width = 50;
  180. }
  181. gridFieldItem.width = gridFieldItemClone.width;
  182. InfoUtil.saveInfoGridField(_self.infoWindowNo, gridFieldItemClone);
  183. InfoUtil.restoreInfoGridField(_self.infoWindowNo, _self.infoGridFields);
  184. },
  185. /**
  186. * 排序
  187. * @author YangZhiJie 20210909
  188. */
  189. onSort: function (infoGridField) {
  190. var _self = this;
  191. var fieldName = null;
  192. if (infoGridField.sortFieldName != undefined && infoGridField.sortFieldName != '') {
  193. fieldName = infoGridField.sortFieldName;
  194. } else {
  195. fieldName = infoGridField.fieldName;
  196. }
  197. _self.sortClause = fieldName + _self.sortStyle;
  198. _self.sortStyle = ((_self.sortStyle === ' ASC') ? ' DESC' : ' ASC');
  199. console.warn('暂时不支持排序。');
  200. },
  201. /**
  202. * 冻结表头
  203. * @author YangZhiJie 20210909
  204. */
  205. fixedTableHeader: function () {
  206. let _self = this;
  207. _self.$nextTick(function () {
  208. var $th = $('.table-fix-head-2').find('thead');
  209. var $fixedCell = $('.table-fix-head-2').find('.fixed-cell');
  210. $('.table-fix-head-2').on('scroll', function () {
  211. $th.css('transform', 'translateY(' + this.scrollTop + 'px)');
  212. $fixedCell.css('transform', 'translateX(' + this.scrollLeft + 'px)');
  213. });
  214. });
  215. },
  216. /**
  217. * 表格中填写的值发生了改变
  218. * @author YangZhiJie 20210909
  219. */
  220. valueChange: function (event, rowData, infoGridField) {
  221. var _self = this;
  222. var value = event.target.value;
  223. const fieldName = infoGridField.fieldName;
  224. if (rowData.data[fieldName] == undefined) {
  225. var tempFieldValue = {
  226. displayValue: [value],
  227. };
  228. rowData.data[fieldName] = tempFieldValue;
  229. } else {
  230. rowData.data[fieldName].displayValue[0] = value;
  231. }
  232. rowData.checked = true;
  233. },
  234. /**
  235. * 获取显示的值
  236. * @author YangZhiJie 20210909
  237. */
  238. getDisplayValue(rowData, infoGridField) {
  239. let fieldValue = rowData.data[infoGridField.fieldName];
  240. if (fieldValue === undefined || fieldValue === null) {
  241. return '';
  242. } else {
  243. return fieldValue.displayValue[0];
  244. }
  245. },
  246. /**
  247. * 设置dataList数据
  248. * @author YangZhiJie 20210908
  249. */
  250. parseDataList: function (dataList) {
  251. let _self = this;
  252. if (dataList === null || dataList === undefined) {
  253. return;
  254. }
  255. if (!Array.isArray(dataList)) {
  256. console.error('参数异常,参数不是数组类型。');
  257. console.error(dataList);
  258. return;
  259. }
  260. const tempDataList = JSON.parse(JSON.stringify(dataList));
  261. for (let index = 0, length = tempDataList.length; index < length; index++) {
  262. let tempData = tempDataList[index];
  263. let rowData = this.getRowDataById(tempData.id);
  264. if(tempData.checked === true){
  265. if(rowData === null){
  266. this.dataList[this.dataList.length]=tempData;
  267. } else {
  268. let dataListIndex = this.dataList.indexOf(rowData);
  269. this.dataList[dataListIndex]=tempData;
  270. }
  271. } else if(tempData.checked === false){
  272. if(rowData !== null){
  273. let dataListIndex = this.dataList.indexOf(rowData);
  274. this.dataList.splice(dataListIndex, 1);
  275. }
  276. }
  277. }
  278. this.$nextTick(function(){
  279. _self.fixedTableHeader();
  280. });
  281. },
  282. /**
  283. * 删除用户行
  284. * @param rowData 行数据
  285. * @author YangZhiJie 2021-09-08
  286. */
  287. removeRow: function(rowData){
  288. let index = this.dataList.indexOf(rowData);
  289. if(index >= 0){
  290. this.dataList.splice(index, 1);
  291. }
  292. this.$emit('selectChanged');
  293. },
  294. /**
  295. * 根据id获取行数据
  296. * @author YangZhiJie 20210909
  297. */
  298. getRowDataById: function(id){
  299. for (let index = 0, length = this.dataList.length; index < length; index++) {
  300. if(this.dataList[index].id === id){
  301. return this.dataList[index];
  302. }
  303. }
  304. return null;
  305. },
  306. /**
  307. * 根据id判断数据是否被选中
  308. * 供外部接口调用
  309. * @author YangZhiJie 20210909
  310. */
  311. isSelectedById: function(id){
  312. let rowData = this.getRowDataById(id);
  313. return rowData === null ? false : true;
  314. },
  315. /**
  316. * 获取选中的数据
  317. * 供外部接口调用
  318. * @author YangZhiJie 20210909
  319. */
  320. getSelectedData: function(){
  321. return this.dataList;
  322. },
  323. },
  324. };
  325. </script>
  326. <style scoped>
  327. .flex-container-2 {
  328. display: flex;
  329. flex-direction: column;
  330. width: 100%;
  331. height: calc(100% - 10px);
  332. }
  333. .flex-content-2 {
  334. flex: 1;
  335. overflow: auto;
  336. width: 100%;
  337. margin-top: 5px;
  338. }
  339. .flex-footer-2 {
  340. height: 35px;
  341. /*放大缩小比例为0 */
  342. flex: 0 0 35px;
  343. }
  344. </style>
  345. <style scoped>
  346. .fixed-table {
  347. table-layout: fixed;
  348. }
  349. .fixed-cell{
  350. text-align: center;
  351. }
  352. table.fixed-table th {
  353. position: relative;
  354. min-width: 10px;
  355. }
  356. table.fixed-table tr td:first-child,
  357. table.fixed-table tr th:first-child {
  358. text-align: center;
  359. }
  360. table.fixed-table th,
  361. table.fixed-table td {
  362. text-align: left;
  363. overflow: hidden;
  364. white-space: nowrap;
  365. text-overflow: ellipsis;
  366. padding: 0.1em;
  367. border-right: 1px solid rgba(0, 0, 0, 0.05);
  368. background-color: white;
  369. }
  370. table.fixed-table th .rz-handle {
  371. width: 10px;
  372. height: 100%;
  373. position: absolute;
  374. top: 0;
  375. right: 0;
  376. background: repeating-linear-gradient(
  377. 45deg,
  378. transparent,
  379. transparent 2px,
  380. rgba(0, 0, 0, 0.05) 2px,
  381. rgba(0, 0, 0, 0.05) 4px
  382. );
  383. cursor: ew-resize !important;
  384. }
  385. table.fixed-table th .rz-handle.rz-handle-active {
  386. border-right: 1px dotted #000;
  387. }
  388. </style>