DocGeneratorSelected.vue 11 KB

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