lj-win-grid-view.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <!--单据列表查询,以表格形式展示通用模板窗口-->
  2. <!--封装了数据获取请求、分页查询、高级搜索等用户交互方式-->
  3. <!--events-->
  4. <!--单元格点击cell-click,详见lj-grid-->
  5. <!--行点击row-click,详见lj-grid-->
  6. <!--高级筛选条件点击query-field-click,详见lj-query-list-->
  7. <!--高级筛选条件值改变query-field-change,详见lj-query-list-->
  8. <!--methods-->
  9. <!--打开右侧抽屉openRightDrawer()-->
  10. <!--关闭右侧抽屉closeRightDrawer()-->
  11. <!--直接设置条件的值setQueryParam(property, value)同lj-query-list-->
  12. <!--slots-->
  13. <!--header:app bar中间,默认为标题-->
  14. <!--header_right:appbar 右侧,通常为图标按钮-->
  15. <!--header_sub: appbar下方子标题,固定在顶部-->
  16. <!--footer:底部,固定-->
  17. <template>
  18. <lj-win-common :title="title" right-drawer-title="搜索" :rightDrawerInitOpen="rightDrawerInitOpen" :closeWinHandler="closeWinHandler"
  19. ref="baseWin">
  20. <slot slot="header" name="header"></slot>
  21. <mu-button v-if="columnCustomizable" icon slot="header_right"
  22. @click="openSettingWin">
  23. <i class="iconfont icon-settings"></i>
  24. </mu-button>
  25. <mu-button v-if="showFilter" icon slot="header_right" @click="openRightDrawer">
  26. <i class="iconfont icon-filter"></i>
  27. </mu-button>
  28. <slot name="header_right" slot="header_right"></slot>
  29. <div slot="body">
  30. <slot name="header_sub" :ifShowSearchbar="ifShowSearchbar" :searchtext="searchText" :search="handleSearchbar">
  31. <lj-searchbar v-if="ifShowSearchbar" ref="searchbarDom" :hint="hint" v-model="searchText" @search="handleSearchbar" />
  32. </slot>
  33. <slot name="body_grid" :loading="loading" :tableData="list" :height="gridHeight">
  34. <lj-grid :loading="loading" :table-data="list" :columns="displayColumns" :height="gridHeight"
  35. @row-click="$emit('row-click',$event)"
  36. @cell-click="$emit('cell-click',$event)"/>
  37. </slot>
  38. <mu-pagination
  39. v-if="pagination"
  40. :total="totalRowCount"
  41. :current.sync="currentPageIndex"
  42. raised
  43. @change="load"
  44. :page-count="5"
  45. :page-size="currentPageSize"
  46. style="padding: 5px 0;"
  47. ref="pagination"/>
  48. <mu-dialog :open.sync="moreDialogOpen" width="100%" scrollable>
  49. <lj-dictionary :columns="popupColumns" :data="currentRowObject"/>
  50. </mu-dialog>
  51. </div>
  52. <slot slot="footer" name="footer"></slot>
  53. <!-- 右方抽屉内容 -->
  54. <lj-query-list v-if="showFilter" slot="drawer_right" :query-fields="queryFields" :habit-key="apiName"
  55. :hard-parms="queryHardParms"
  56. :binding-parms="bindingParms"
  57. :show-scan="ifShowScan"
  58. @on-query-submit="handleQuerySubmit"
  59. @field-click="handleQueryFieldClick"
  60. @field-change="handleQueryFieldChange"
  61. @scan-click="handleClickScan"
  62. ref="queryList"/>
  63. </lj-win-common>
  64. </template>
  65. <script>
  66. import LjWinCommon from 'components/lj-win-common'
  67. import LjQueryList from "components/lj-query-list";
  68. import LjGrid from "components/lj-grid";
  69. import {Pagination} from 'muse-ui'
  70. import LjDictionary from "components/lj-dictionary";
  71. import LjSearchbar from 'components/lj-searchbar';
  72. export default {
  73. name: "lj-win-grid-view",
  74. components: {
  75. LjDictionary,
  76. LjGrid,
  77. LjQueryList,
  78. LjWinCommon,
  79. 'mu-pagination': Pagination,
  80. LjSearchbar
  81. },
  82. props: {
  83. // 标题名称
  84. title: {
  85. type: String,
  86. required: true
  87. },
  88. // 同lj-query-list的queryFields,设置后显示筛选按钮,点击弹出高级筛选框
  89. queryFields: {
  90. type: Array
  91. },
  92. // 同lj-query-list的hardParms
  93. queryHardParms: {
  94. type: Object
  95. },
  96. // 同lj-query-list的bindingParms
  97. bindingParms: {
  98. type: Object
  99. },
  100. // 获取单据列表的接口的接口
  101. apiName: {
  102. type: String,
  103. required: true
  104. },
  105. // 字段设置,详见lj-grid
  106. columns: {
  107. type: Array
  108. },
  109. // 是否分页
  110. pagination: {
  111. type: Boolean,
  112. default: true
  113. },
  114. hint: {
  115. type: String,
  116. default: "请输入关键字搜索"
  117. },
  118. rightDrawerInitOpen: {
  119. type: Boolean,
  120. default: false
  121. },
  122. columnCustomizable: {
  123. type: Boolean,
  124. default: true
  125. },
  126. ifShowSearchbar: {
  127. type: Boolean,
  128. default: false
  129. },
  130. ifShowScan: {
  131. type: Boolean,
  132. default: false
  133. },
  134. searchText:{
  135. type: String,
  136. default: ""
  137. },
  138. searchHeight:{
  139. type: Number,
  140. default: 0
  141. },
  142. useInnerMergeCustomSetting:{
  143. type: Boolean,
  144. default: true
  145. },
  146. closeWinHandler: {
  147. type: Function,
  148. },
  149. },
  150. data() {
  151. return {
  152. loadedAll: true,
  153. loading: false,
  154. moreDialogOpen: false,
  155. gridHeight: 400,
  156. dwname: "L1APP",
  157. totalPage: 1,
  158. currentRowObject: {},
  159. currentPageIndex: 1,
  160. currentPageSize: 20,
  161. currentRequestBody: {},
  162. list: [],
  163. displayColumns: [],
  164. popupColumns: [],
  165. moreColumn: {
  166. property: "more_button",
  167. label: "更多",
  168. width: 100,
  169. slot: this.moreSlotRender
  170. }
  171. //searchText: ""
  172. }
  173. },
  174. mounted() {
  175. let paginationHeight = 0;
  176. if (this.$refs.pagination) {
  177. if (this.$refs.pagination.$el) {
  178. paginationHeight = this.$refs.pagination.$el.offsetHeight;
  179. } else {
  180. paginationHeight = this.$refs.pagination.offsetHeight;
  181. }
  182. }
  183. if (!this.$slots.header_sub) {
  184. // headerSubHeight = 40;
  185. // alert(this.$slots.header_sub.offsetHeight);
  186. // alert(this.$slots.header_sub.height);
  187. // alert(this.$slots.header_sub.clientHeight);
  188. if(this.ifShowSearchbar) {
  189. let serchBarHeight = this.$refs.searchbarDom ? this.$refs.searchbarDom.$el.offsetHeight : this.searchHeight;
  190. this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight - serchBarHeight;
  191. } else {
  192. this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight;
  193. }
  194. }
  195. if(this.useInnerMergeCustomSetting){
  196. this.MergeCustomSetting();
  197. }
  198. // if (!this.showFilter) {
  199. this.refresh();
  200. // }
  201. },
  202. methods: {
  203. openRightDrawer() {
  204. this.$refs.baseWin.openRightDrawer();
  205. },
  206. closeRightDrawer() {
  207. this.$refs.baseWin.closeRightDrawer();
  208. },
  209. closeWin() {
  210. $lj.closeWin();
  211. },
  212. handleSearchbar() {
  213. this.refresh({keyword: this.searchText});
  214. },
  215. handleClickScan(){
  216. this.$emit("scan-click");
  217. },
  218. handleQuerySubmit(queryParams) {
  219. this.closeRightDrawer();
  220. this.list = [];
  221. this.refresh(queryParams);
  222. },
  223. refresh(queryParams) {
  224. this.currentPageIndex = 1;
  225. this.totalPage = 1;
  226. this.currentRequestBody = Object.assign(queryParams || this.currentRequestBody || {}, this.queryHardParms);
  227. this.load();
  228. this.$emit("refresh");
  229. },
  230. load() {
  231. this.currentRequestBody.token = $lj.getStorage("token");
  232. if (this.pagination) {
  233. this.currentRequestBody.pageindex = this.currentPageIndex;
  234. this.currentRequestBody.pagesize = this.currentPageSize;
  235. }
  236. this.loading = true;
  237. let self = this;
  238. $lj.postLJRequest(this.apiName, this.currentRequestBody, function (ret) {
  239. self.loading = false;
  240. if (ret) {
  241. self.$emit("loadedAllData",ret);
  242. for (let key in ret) {
  243. if (self.currentPageIndex >= self.totalPage) {
  244. let resultLength = ret[key].length;
  245. if (resultLength === 0 && self.currentPageIndex > 1) {
  246. self.currentPageIndex--;
  247. self.totalPage = self.currentPageIndex;
  248. $lj.toast("数据已加载完毕");
  249. return;
  250. } else if (resultLength < self.currentPageSize) {
  251. self.totalPage = self.currentPageIndex;
  252. $lj.toast("数据已加载完毕");
  253. } else {
  254. self.totalPage = self.currentPageIndex + 1;
  255. }
  256. }
  257. self.list = ret[key];
  258. self.$emit("loaded", ret[key]);
  259. return;
  260. }
  261. }
  262. })
  263. },
  264. MergeCustomSetting: function () {
  265. let userInfo = $lj.getStorage('userInfo');
  266. let empid = userInfo.empid;
  267. let requestBody = {
  268. token: $lj.getStorage("token"),
  269. empid: empid,
  270. dwname: this.dwname,
  271. itemname: this.apiName,
  272. ifcompress: 1
  273. };
  274. let self = this;
  275. this.displayColumns = [];
  276. this.popupColumns = [];
  277. $lj.postLJRequest(
  278. "GetSysUserFileString", requestBody,
  279. function (ret) {
  280. if (ret && ret.itemvalue) {
  281. let customSetting = JSON.parse(ret.itemvalue);
  282. // 构建field-style键值对
  283. let customSettingDictionary = new Map();
  284. for (let item of customSetting) {
  285. customSettingDictionary.set(item.property, item);
  286. }
  287. // 合并过滤字段,以这个字典为准,用户历史设置多删少补
  288. for (let item of self.columns) {
  289. let curField = item.property;
  290. let userStyle = customSettingDictionary.get(curField);
  291. if (userStyle) {
  292. // for (let prop in userStyle) {
  293. // item[prop] = userStyle[prop];
  294. // }
  295. item.order = userStyle.order;
  296. item.invisible = userStyle.invisible;
  297. } else {
  298. // 新增字段,暂不显示
  299. item.invisible = true;
  300. }
  301. }
  302. } else {
  303. for (let i in self.columns) {
  304. self.columns[i].order = i;
  305. }
  306. }
  307. self.columns.sort(function (object1, object2) {
  308. return object1.order - object2.order;
  309. });
  310. for (let i in self.columns) {
  311. let item = self.columns[i];
  312. item.order = i;
  313. if (item.optionid) {
  314. let optionName = $lj.getOptionValue(item.optionid);
  315. item.label = optionName ? optionName : item.label;
  316. }
  317. if (item.fixed) {
  318. self.displayColumns.push(item);
  319. } else if (!item.invisible) {
  320. self.popupColumns.push(item);
  321. }
  322. }
  323. if (self.popupColumns.length > 0) {
  324. self.displayColumns.push(self.moreColumn);
  325. }
  326. }
  327. );
  328. },
  329. openSettingWin() {
  330. let self = this;
  331. $lj.removeEventListener("grid_style_updated");
  332. $lj.addEventListener("grid_style_updated", function (ret) {
  333. if (ret.value) {
  334. if (ret.value.dwname === self.dwname && ret.value.itemname === self.apiName) {
  335. self.MergeCustomSetting();
  336. }
  337. }
  338. });
  339. $lj.openWin('grid-view-setting', {
  340. columns: this.columns,
  341. apiName: this.apiName
  342. });
  343. },
  344. moreSlotRender(h, {row, column, rowIndex}) {
  345. let self = this;
  346. return h('mu-button', {
  347. attrs: {icon: true},
  348. on: {
  349. click: function () {
  350. self.currentRowObject = self.list[rowIndex];
  351. self.moreDialogOpen = true;
  352. }
  353. }
  354. },
  355. [h('i', {class: ["iconfont", "icon-format-list-bulleted"]})]
  356. )
  357. },
  358. handleQueryFieldClick(event) {
  359. this.$emit("query-field-click", event);
  360. },
  361. handleQueryFieldChange(event){
  362. this.$emit("query-field-change", event);
  363. },
  364. setQueryParam(property, value) {
  365. this.$refs.queryList.setQueryParam(property, value);
  366. },
  367. setDisplayColumns(data){
  368. this.$nextTick(() => this.displayColumns = data);
  369. }
  370. },
  371. computed: {
  372. showFilter() {
  373. return this.queryFields && this.queryFields.length > 0;
  374. },
  375. hasLoadmoreFunction() {
  376. return this.dataLoadedCallback;
  377. },
  378. totalRowCount() {
  379. return this.totalPage * this.currentPageSize;
  380. }
  381. },
  382. watch: {
  383. searchHeight(newVal) {
  384. console.log('searchHeight 赋值新newVal :>> ', newVal);
  385. let paginationHeight = 0;
  386. if (this.$refs.pagination) {
  387. if (this.$refs.pagination.$el) {
  388. paginationHeight = this.$refs.pagination.$el.offsetHeight;
  389. } else {
  390. paginationHeight = this.$refs.pagination.offsetHeight;
  391. }
  392. }
  393. if (!this.$slots.header_sub) {
  394. if(this.ifShowSearchbar) {
  395. let serchBarHeight = this.$refs.searchbarDom ? this.$refs.searchbarDom.$el.offsetHeight : newVal;
  396. this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight - serchBarHeight;
  397. } else {
  398. this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight;
  399. }
  400. }
  401. }
  402. }
  403. }
  404. </script>
  405. <style scoped>
  406. </style>