index.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. <template>
  2. <div class="data-table" :style="{ marginTop: marginTop,width: tableWidth ? tableWidth : '100%',height:tableHeight ? tableHeight : '100%',padding:isAuto ? '':'24px' }">
  3. <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" class="data-table-content">
  4. <div class="flex">
  5. <div class="manageTitle">{{ pageTitle }}</div>
  6. <div>
  7. <auth-button :auth="btnAddObj" />
  8. <auth-button :auth="btnQueryObj" />
  9. </div>
  10. </div>
  11. <template v-if="tableData.length || tableCols.length">
  12. <div style="height: calc(100% - 40px);">
  13. <el-table v-el-table-infinite-scroll="load" :data="filteredTableData" :summary-method="getSummaries" :span-method="tableSpanMethod" stripe :show-summary="showSummary" border @cell-click="cellClick" :cell-class-name="cellClass" ref="table" :height="tableHeight ? tableHeight : minHeight - 8 + 'vh'" class="table infinite-list" style=" overflow: auto" :style="{width: tableWidth ? tableWidth : '100%'}" @select="selectHandler">
  14. <el-table-column v-for="(item, index) in tableColsCopy" :sortable="item.needSort ? true : false" :key="index" :prop="item.columnName" :label="item.columnLabel" :show-overflow-tooltip="showOverflowTooltip" :formatter="formatter">
  15. <template #header>
  16. <span class="colTips">
  17. <el-tooltip :content="item.columnDescribe" placement="top">
  18. <span>{{ item.columnLabel }}</span>
  19. </el-tooltip>
  20. </span>
  21. <span v-if="item.needFilters">
  22. <el-popover placement="bottom" trigger="click" @show="popoverShowHandler(item.columnName)" @hide="popoverHideHandler">
  23. <i slot="reference" :class="[
  24. 'filter-arrow',
  25. 'el-icon-arrow-down',
  26. arrowClass(item.columnName),
  27. ]" />
  28. <el-form>
  29. <el-form-item :label="item.columnLabel">
  30. <el-select v-model="filterValues[item.columnName]" size="small" placeholder="筛选" default-first-option filterable clearable>
  31. <el-option v-for="(option, optionIndex) in tableDataFilters[
  32. item.columnName
  33. ]" :key="option.value + optionIndex" :value="option.value" :label="option.text" />
  34. </el-select>
  35. </el-form-item>
  36. </el-form>
  37. </el-popover>
  38. </span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column v-if="authBtns.length" fixed="right" label="操作" :width="fixedWidth">
  42. <template slot-scope="scope">
  43. <div class="hd-td">
  44. <auth-button v-for="(item,index) in authBtns" :key="index" :auth="item" :row="scope.row" />
  45. </div>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </div>
  50. </template>
  51. <template v-else>
  52. <NoData image-width="auto" image-height="100%" />
  53. </template>
  54. </div>
  55. <div class="data-table-dialog">
  56. <!--新增/编辑-->
  57. <Dialog :width="width" :isBody="isBody" :flag="flag">
  58. <div class="dialog-content">
  59. <div class="title">{{ tableTitle }}</div>
  60. <div style="max-height:580px;overflow-y: scroll;" class="contents">
  61. <el-form ref="ruleForm" :model="tableForm" :label-width="labelWidth">
  62. <el-row :gutter="20">
  63. <el-col v-for="(item, index) in tableColsCopy" :key="index" :span="rows">
  64. <el-form-item :label="item.columnLabel">
  65. <template v-if="
  66. item.listqueryTemplateID ||
  67. item.listqueryTemplateID == 0
  68. ">
  69. <el-select class="input-shadow" size="small" filterable default-first-option style="width: 100%" v-model="tableForm[item.columnName]" @change="changeSelect(item.columnName, item)" placeholder="请选择" clearable @clear="tableForm[item.columnName] = ''">
  70. <el-option v-for="item in tableOptions[item.columnName]" :key="item.v ? item.v : item.planDepartureApt" :label="item.k ? item.k : item.planDepartureApt" :value="
  71. item.setlabel === 'positionDescribe'
  72. ? item.v
  73. : item.v != undefined
  74. ? item.v
  75. : item.planDepartureApt
  76. ">
  77. </el-option>
  78. </el-select>
  79. </template>
  80. <template v-else-if="fromDataType(item.dataType) == 'text'">
  81. <el-input size="small" :rows="1" type="textarea" @change="inputChangeHandler(item.columnName)" v-model="tableForm[item.columnName]"></el-input>
  82. </template>
  83. <template v-else-if="fromDataType(item.dataType) == 'date'">
  84. <el-date-picker class="datetimes" value-format="yyyy-MM-dd" v-model="tableForm[item.columnName]" type="date" placeholder="选择日期" @change="inputChangeHandler(item.columnName)">
  85. </el-date-picker>
  86. </template>
  87. <template v-else-if="fromDataType(item.dataType) == 'datetime'">
  88. <el-date-picker class="datetimes" value-format="yyyy-MM-dd HH:mm:ss" v-model="tableForm[item.columnName]" type="datetime" placeholder="选择日期时间" @change="inputChangeHandler(item.columnName)">
  89. </el-date-picker>
  90. </template>
  91. <template v-else-if="fromDataType(item.dataType) == 'int' || fromDataType(item.dataType) == 'tinyint'">
  92. <el-input size="small" v-model.number="tableForm[item.columnName]" onkeyup="value=value.replace(/[^1-9]/g,'')" @change="inputChangeHandler(item.columnName)"></el-input>
  93. </template>
  94. <template v-else>
  95. <el-input size="small" v-model="tableForm[item.columnName]" @change="inputChangeHandler(item.columnName)"></el-input>
  96. </template>
  97. </el-form-item>
  98. </el-col>
  99. </el-row>
  100. </el-form>
  101. </div>
  102. <div class="foot right">
  103. <el-button size="medium" @click="handleOk" class="r24" type="primary">确定</el-button>
  104. <el-button @click="eledite" size="medium">取消</el-button>
  105. </div>
  106. </div>
  107. </Dialog>
  108. <!--删除-->
  109. <Dialog :isBody="isBody" :flag="rmFlag">
  110. <div class="airportInfoDialog">
  111. <div class="title del-title">删除</div>
  112. <div class="content del-content">
  113. <span class="el-icon-error error r10"></span>您是否确认删除<span class="error l10">{{ rmTitle }}</span>
  114. </div>
  115. <div class="foot right Delfoot">
  116. <el-button size="medium" class="r24" @click="tableRemove" type="danger">删除</el-button>
  117. <el-button size="medium" @click="rmFlag = false">取消</el-button>
  118. </div>
  119. </div>
  120. </Dialog>
  121. <!--高级查询-->
  122. <Dialog :flag="dialogFlag" width="852px">
  123. <AdvanceQuery :tableColMunt="tableCols" @getColData="getColData" @dialogHide="dialogHide" />
  124. </Dialog>
  125. </div>
  126. </div>
  127. </template>
  128. <script>
  129. import { setTableFilters } from "@/utils/table";
  130. import Dialog from "@/layout/components/Dialog/index.vue";
  131. import NoData from "@/components/nodata";
  132. import AdvanceQuery from './components/advanceQuery.vue';
  133. import AuthButton from './components/authButton.vue';
  134. import { translateDataToTreeAllTreeMsg, getAuthData } from "@/utils/validate";
  135. import { Query, newData, modifyData, moveData, abnormalDataRecovery } from "@/api/webApi";
  136. import { getToken } from '@/utils/auth';
  137. export default {
  138. name: "DataTable",
  139. props: {
  140. dataContent: {
  141. type: Object,
  142. default: () => ({}),
  143. },
  144. //弹框宽度
  145. width: {
  146. type: String,
  147. default: "630px",
  148. },
  149. //弹框是否显示在body上
  150. isBody: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. //弹框表单-行数
  155. rows: {
  156. type: Number,
  157. default: 24,
  158. },
  159. //弹框-表单文字宽度
  160. labelWidth: {
  161. type: String,
  162. default: "120px",
  163. },
  164. minHeight: {
  165. type: Number,
  166. default: 89,
  167. },
  168. // 是否显示合计行
  169. showSummary: {
  170. type: Boolean,
  171. default: false,
  172. },
  173. marginTop: {
  174. type: String,
  175. default: "0px",
  176. },
  177. // 不换行,溢出隐藏
  178. showOverflowTooltip: {
  179. type: Boolean,
  180. default: true,
  181. },
  182. //操作列宽度
  183. fixedWidth: {
  184. type: String,
  185. default: "180px",
  186. },
  187. },
  188. components: { Dialog, NoData, AdvanceQuery, AuthButton },
  189. data () {
  190. return {
  191. pageTitle: '',
  192. asShow: true,
  193. loading: false,
  194. flag: false,
  195. serviceId: null,
  196. rmFlag: false,
  197. rowTitle: "",
  198. page: 0,
  199. pageSize: 20,
  200. noMore: false,
  201. tableCols: [], //表头数据
  202. tableData: [], //表格数据
  203. tableColsCopy: [], //表头数据缓存
  204. tableDataFilters: {}, //表头-下拉数据
  205. filterValues: {}, //表头-下拉-选中数据
  206. tableDataCopy: [], //缓存table数据
  207. tableGroups: [], //表格分组数据
  208. colShowFilter: "", //表头-下拉-箭头
  209. spanArr: [], //表格分组数据缓存
  210. pos: 0, //表格分组计数
  211. tableTitle: "新增", //弹框标题
  212. tableType: "add", //弹框类型=新增/编辑
  213. tableForm: {}, //弹框表单
  214. rmTitle: "", //弹框-删除-标题
  215. tableObj: {}, //增/删/改数据缓存
  216. tableOptions: {}, //弹框-下来数据缓存
  217. tableArrs: [], //重组table-表头下拉
  218. proAll: false, //重组时-所有请求是否都完成
  219. roles: JSON.parse(sessionStorage.getItem("userAuthList")) ?? [],
  220. tableOptionscp: {},
  221. tabledatacopy: {},
  222. queryId: '',
  223. tableOther: {},
  224. tableHeight: '',
  225. tableWidth: '',
  226. btnQueryObj: {},
  227. btnAddObj: {},
  228. btnEditObj: {},
  229. btnDelObj: {},
  230. btnRecordObj: {},
  231. isAuto: false,
  232. dialogFlag: false,
  233. authBtns: [],
  234. authBtnCol: [],
  235. authBtnColName: [],
  236. urlParams: {},
  237. authId: ''
  238. };
  239. },
  240. computed: {
  241. dataTableContentStyle () {
  242. const style = {};
  243. if (this.minHeight) {
  244. style["min-height"] = this.minHeight;
  245. }
  246. if (this.tableHeight) {
  247. style["height"] = this.tableHeight;
  248. }
  249. return style;
  250. },
  251. //设置表头-下拉-箭头样式
  252. arrowClass () {
  253. return function (prop) {
  254. let classString = "";
  255. if (this.colShowFilter === prop) {
  256. return "arrow-active";
  257. }
  258. if (
  259. Object.entries(this.tableDataFilters).find(
  260. ([key, arr]) => this.filterValues[prop]
  261. )
  262. ) {
  263. classString += "arrow-blue";
  264. }
  265. return classString;
  266. };
  267. },
  268. //设置新增修改表单类型
  269. fromDataType () {
  270. return function (type) {
  271. if (type) {
  272. return type.replace(/\([^\)]*\)/g, "");
  273. }
  274. }
  275. },
  276. //设置表头-下拉-选中数据
  277. filteredTableData () {
  278. if (this.isTree) {
  279. this.tableData = translateDataToTreeAllTreeMsg(
  280. this.tableData,
  281. "parentID",
  282. "companyID"
  283. );
  284. }
  285. return this.tableData.filter((item) => {
  286. let flag = true;
  287. Object.entries(this.filterValues).forEach(([key, value]) => {
  288. if (value !== "" && item[key] !== value) {
  289. flag = false;
  290. }
  291. });
  292. return flag;
  293. });
  294. },
  295. },
  296. mounted () {
  297. const { query } = this.$route
  298. const { title, auth_id } = this.$route.meta
  299. const { arrs } = getAuthData(auth_id)
  300. const table = arrs.filter(item => item.auth_type == 4)
  301. this.urlParams = query
  302. if (table && table.length) {
  303. const obj = table[0]
  304. const { arrs } = getAuthData(obj.auth_id)
  305. this.isAuto = true
  306. this.tableOther = obj
  307. this.pageTitle = obj.auth_name;
  308. this.authId = obj.auth_id
  309. this.queryId = obj.queryTemplateID;
  310. this.authBtns = arrs.filter(item => Number(item.service_type) > 2 && Number(item.service_type) < 6)
  311. this.authBtnCol = arrs.filter(item => Number(item.service_type) == 6)
  312. if (this.authBtnCol.length) {
  313. this.authBtnCol.forEach(item => {
  314. this.authBtnColName.push(item.relation_data)
  315. })
  316. }
  317. if (arrs && arrs.length) {
  318. arrs.forEach(item => {
  319. this.autoBtnObj(item)
  320. })
  321. }
  322. this.getColumnData(obj.auth_id);
  323. } else {
  324. this.pageTitle = title;
  325. if (auth_id) {
  326. this.queryId = auth_id;
  327. this.authId = auth_id
  328. this.getColumnData(auth_id);
  329. }
  330. }
  331. },
  332. updated () {
  333. if (Object.keys(this.tableOther).length) {
  334. this.tableHeight = this.tableOther.table_height
  335. this.tableWidth = `${this.tableOther.table_width}`.includes('%') ? this.tableOther.table_width + 'px' : this.tableOther.table_width + 'px'
  336. }
  337. this.$refs["table"]?.doLayout();
  338. // this.$refs['table'].style.width = this.tableOther.table_width
  339. },
  340. methods: {
  341. //获取表头数据
  342. async getColumnData (id) {
  343. try {
  344. const { code, returnData } = await Query({
  345. serviceId: SERVICE_ID.sysUserAuthId,
  346. dataContent: [
  347. {
  348. user_id: getToken('userid'),
  349. auth_id: id
  350. }
  351. ],
  352. });
  353. if (code == 0) {
  354. if (returnData && returnData.length) {
  355. const titleColumn = returnData.find(
  356. (item) => item.needShow === 1
  357. );
  358. if (titleColumn) {
  359. this.rowTitle = titleColumn.columnName;
  360. }
  361. this.$store.dispatch('auth/changeAuthMsg', returnData)
  362. this.tableCols = returnData;
  363. if (Object.keys(this.urlParams).length) {
  364. this.getQuery(this.queryId, this.urlParams);
  365. } else {
  366. this.getQuery(this.queryId);
  367. }
  368. }
  369. } else {
  370. this.$message.error("获取表头数据失败");
  371. }
  372. } catch (error) {
  373. console.log(error)
  374. }
  375. },
  376. autoBtnObj (item) {
  377. switch (item.service_type) {
  378. case '1':
  379. this.btnQueryObj = item
  380. break;
  381. case '2':
  382. this.btnAddObj = item
  383. break;
  384. case '3':
  385. if (item.open_method != "1") {
  386. this.btnEditObj = item
  387. }
  388. else {
  389. this.btnRecordObj = item
  390. }
  391. break;
  392. case '4':
  393. this.btnDelObj = item
  394. break;
  395. default:
  396. break;
  397. }
  398. },
  399. autoBtnClick (id, url) {
  400. switch (id) {
  401. case '1':
  402. this.$message.warning('平铺功能开发中')
  403. break;
  404. case '2':
  405. this.$router.push(url)
  406. break;
  407. default:
  408. break;
  409. }
  410. },
  411. handleQuery () {
  412. const { open_method, route_info } = this.btnQueryObj
  413. if (open_method) {
  414. if (open_method != 3) {
  415. this.autoBtnClick(open_method, route_info)
  416. } else {
  417. this.dialogFlag = true
  418. }
  419. }
  420. },
  421. eledite () {
  422. this.flag = false;
  423. const arrbegin = _.cloneDeep(this.tableOptionscp);
  424. this.tableOptions = arrbegin;
  425. },
  426. load () {
  427. //
  428. if (!this.isTree) {
  429. if (this.noMore || this.loading) {
  430. return;
  431. }
  432. if (Object.keys(this.urlParams).length) {
  433. this.getQuery(this.queryId, this.urlParams);
  434. } else {
  435. this.getQuery(this.queryId);
  436. }
  437. }
  438. },
  439. resetTable () {
  440. this.page = 0;
  441. this.noMore = false;
  442. this.tableData = [];
  443. },
  444. changeSelect (data, name) {
  445. if (this.tableForm[data] === "") {
  446. this.tableForm[data] = null;
  447. }
  448. this.tableForm[this.tableOptions[data][0].setvalue] =
  449. this.tableForm[data];
  450. const arrbegin = _.cloneDeep(this.tabledatacopy);
  451. if (this.tableForm.beginNode) {
  452. this.tableOptions.beginPosition = arrbegin.beginPosition.filter(
  453. (i) => i.nodeCode === this.tableForm.beginNode
  454. );
  455. arrbegin.beginPosition.forEach((element) => {
  456. if (element.v === this.tableForm.beginPosition) {
  457. if (element.nodeCode !== this.tableForm.beginNode) {
  458. this.tableForm.beginPosition = "";
  459. }
  460. }
  461. });
  462. // let arr = [];
  463. // this.tableOptions.beginPosition.forEach((element) => {
  464. // arr.push(element.nodeCode);
  465. // });
  466. // if (
  467. // !arr.includes(this.tableForm.beginPosition) &&
  468. // this.tableForm.beginNode
  469. // ) {
  470. // this.tableForm.beginPosition = null;
  471. // }
  472. this.asShow = false;
  473. this.asShow = true;
  474. }
  475. if (this.tableForm.beginPosition && !this.tableForm.beginNode) {
  476. arrbegin.beginPosition.forEach((element) => {
  477. if (this.tableForm.beginPosition === element.v) {
  478. this.tableForm.beginNode = element.nodeCode;
  479. }
  480. });
  481. }
  482. if (this.tableForm.endNode) {
  483. this.tableOptions.endPosition = arrbegin.endPosition.filter(
  484. (i) => i.nodeCode === this.tableForm.endNode
  485. );
  486. arrbegin.endPosition.forEach((element) => {
  487. if (element.v === this.tableForm.endPosition) {
  488. if (element.nodeCode !== this.tableForm.endNode) {
  489. this.tableForm.endPosition = "";
  490. }
  491. }
  492. });
  493. this.asShow = false;
  494. this.asShow = true;
  495. }
  496. if (this.tableForm.endPosition && !this.tableForm.endNode) {
  497. arrbegin.endPosition.forEach((element) => {
  498. if (this.tableForm.endPosition === element.v) {
  499. this.tableForm.endNode = element.nodeCode;
  500. }
  501. });
  502. }
  503. },
  504. inputChangeHandler (data) {
  505. if (this.tableForm[data] === "") {
  506. this.tableForm[data] = null;
  507. }
  508. },
  509. //获取高级查询条件
  510. getColData (val) {
  511. const arr = [...val]
  512. if (arr && arr.length) {
  513. arr.forEach(item => {
  514. item.value = item.value.replace(/\s*/g, "")
  515. })
  516. }
  517. this.resetTable()
  518. this.getQuery(this.queryId, arr);
  519. },
  520. //获取表格数据
  521. async getQuery (id, dataContent = this.dataContent) {
  522. try {
  523. this.loading = true;
  524. const { code, returnData } = await Query({
  525. serviceId: id,
  526. page: ++this.page,
  527. pageSize: this.pageSize,
  528. dataContent,
  529. authId: this.authId
  530. });
  531. if (code == 0) {
  532. if (returnData.length === 0) {
  533. this.page--;
  534. this.noMore = true;
  535. this.loading = false;
  536. }
  537. this.tableData.push(...returnData);
  538. // this.tableCols = columnset;
  539. this.serviceId = id;
  540. setTimeout(() => {
  541. this.initTableData();
  542. this.loading = false;
  543. }, 100);
  544. } else {
  545. this.page--;
  546. this.loading = false;
  547. this.$message.error("获取表格数据失败");
  548. }
  549. } catch (error) {
  550. this.page--;
  551. this.loading = false;
  552. }
  553. },
  554. //表格-增/删/改
  555. async generalDataReception (event, data) {
  556. try {
  557. const params = {
  558. serviceId: this.serviceId,
  559. dataContent: data,
  560. event: `${event}`,
  561. };
  562. const { code } =
  563. event == 1
  564. ? await newData(params)
  565. : event == 2
  566. ? await modifyData(params)
  567. : await moveData(params);
  568. if (code == 0) {
  569. this.$message.success("操作成功");
  570. this.resetTable();
  571. this.getQuery(this.queryId);
  572. this.flag = false;
  573. this.rmFlag = false;
  574. this.tableObj = {};
  575. this.tableForm = {};
  576. // this.$router.go(0);
  577. } else {
  578. this.$message.error("操作失败");
  579. this.flag = false;
  580. this.rmFlag = false;
  581. this.tableObj = {};
  582. this.tableForm = {};
  583. }
  584. } catch (error) {
  585. this.flag = false;
  586. this.rmFlag = false;
  587. this.tableObj = {};
  588. this.tableForm = {};
  589. }
  590. },
  591. // 表格勾选
  592. toggleRowSelection (row, isSelected) {
  593. this.$refs["table"].toggleRowSelection(row, isSelected);
  594. },
  595. // 表格初始勾选
  596. selectTableRows (tableData, selectFlagName) {
  597. tableData.forEach((row) => {
  598. this.$refs["table"].toggleRowSelection(row, !!row[selectFlagName]);
  599. });
  600. this.$emit("selectionAll", this.$refs.table.selection);
  601. },
  602. //初始化表格
  603. initTableData () {
  604. this.tableColsCopy = this.tableCols.filter((item) => item.needShow);
  605. this.tableColsCopy = _.orderBy(this.tableColsCopy, ['orderNumber'], ['asc']);
  606. this.tableDataCopy = _.cloneDeep(this.tableData);
  607. const datas = _.cloneDeep(this.tableColsCopy);
  608. // const reqUts = [];
  609. datas.forEach(async (item) => {
  610. this.tableDataFilters[item.columnName] = [];
  611. if (item.needGroup) {
  612. this.tableGroups.push(item.columnName);
  613. }
  614. if (item.listqueryTemplateID || item.listqueryTemplateID == 0) {
  615. this.tableArrs.push(item.columnName);
  616. // const reqUt = this.getSelectData(item.listqueryTemplateID)
  617. // reqUts.push(reqUt)
  618. if (!this.tableOptions[item.columnName]) {
  619. //开始位置beginPosition 结束位置endPosition (区分开始结束位置必须传null)
  620. if (
  621. item.columnName !== "beginPosition" &&
  622. item.columnName !== "endPosition"
  623. ) {
  624. this.tableOptions[item.columnName] = await this.getSelectData(
  625. item.listqueryTemplateID
  626. );
  627. } else {
  628. this.tableOptions[item.columnName] = await this.getSelectData(
  629. item.listqueryTemplateID,
  630. null
  631. );
  632. this.tabledatacopy[item.columnName] = _.cloneDeep(
  633. this.tableOptions[item.columnName]
  634. );
  635. }
  636. } else {
  637. if (
  638. item.columnName === "beginPosition" ||
  639. item.columnName === "endPosition"
  640. ) {
  641. this.tableOptions[item.columnName] = await this.getSelectData(
  642. item.listqueryTemplateID,
  643. null
  644. );
  645. }
  646. }
  647. //
  648. }
  649. // this.filterValues[item.columnName] = ''
  650. });
  651. setTableFilters(this.tableData, this.tableDataFilters);
  652. this.tableGroup(this.tableData);
  653. // this.selectTableRows(this.tableData, "DeployID");
  654. this.tableOptionscp = _.cloneDeep(this.tableOptions);
  655. const arrbegin = _.cloneDeep(this.tableOptions);
  656. if (arrbegin) {
  657. setTimeout(() => {
  658. this.tableData.forEach((element) => {
  659. if (this.tableOptions.beginNode) {
  660. arrbegin.beginNode.forEach((res) => {
  661. if (res.v === element.beginNode) {
  662. element.beginNode = res.k;
  663. }
  664. });
  665. arrbegin.endNode.forEach((res) => {
  666. if (res.v == element.endNode) {
  667. element.endNode = res.k;
  668. }
  669. });
  670. arrbegin.calculationBasis.forEach((res) => {
  671. if (res.v == element.calculationBasis) {
  672. element.calculationBasis = res.k;
  673. }
  674. });
  675. //位置
  676. this.tabledatacopy.beginPosition.forEach((res) => {
  677. if (res.v == element.beginPosition) {
  678. element.beginPosition = res.k;
  679. }
  680. });
  681. this.tabledatacopy.endPosition.forEach((res) => {
  682. if (res.v == element.endPosition) {
  683. element.endPosition = res.k;
  684. }
  685. });
  686. }
  687. });
  688. }, 100);
  689. }
  690. // this.getSelectDataAll(reqUts)
  691. },
  692. //获取所有获取弹框-下拉数据-请求状态
  693. getSelectDataAll (reqUts) {
  694. Promise.all(reqUts)
  695. .then((res) => {
  696. this.proAll = true;
  697. })
  698. .catch((err) => {
  699. this.proAll = false;
  700. });
  701. },
  702. //获取弹框-下拉数据
  703. async getSelectData (id, name) {
  704. // name ? [name] : name === null ? [null]: [],
  705. const { code, returnData } = await Query({
  706. id,
  707. dataContent: name ? [name] : name === null ? [null] : [],
  708. });
  709. if (code == 0) {
  710. return returnData.listValues;
  711. } else {
  712. return [];
  713. }
  714. },
  715. //重组table-显示名称
  716. setTable () {
  717. this.tableArrs.forEach((item) => {
  718. this.tableOptions[item].forEach((p) => {
  719. this.tableDataCopy.forEach((msg) => {
  720. if (msg[item] == p.v) {
  721. msg[item] = p.k;
  722. }
  723. });
  724. this.tableDataFilters[item].forEach((cap) => {
  725. if (cap.value == p.v) {
  726. cap.text = p.k;
  727. cap.value = p.k;
  728. }
  729. });
  730. });
  731. });
  732. this.tableData = this.tableDataCopy;
  733. },
  734. //分组
  735. tableGroup (tableData) {
  736. const spanArr = [];
  737. let pos = 0;
  738. let ifYj = this.tableGroups[0];
  739. for (let i = 0; i < tableData.length; i++) {
  740. if (i === 0) {
  741. spanArr.push(1);
  742. } else {
  743. if (tableData[i][ifYj] === tableData[i - 1][ifYj]) {
  744. spanArr[pos] += 1;
  745. spanArr.push(0);
  746. } else {
  747. spanArr.push(1);
  748. pos = i;
  749. }
  750. }
  751. }
  752. this.spanArr = spanArr;
  753. this.pos = pos;
  754. },
  755. popoverShowHandler (prop) {
  756. this.colShowFilter = prop;
  757. },
  758. popoverHideHandler () {
  759. this.colShowFilter = "";
  760. },
  761. //分组
  762. tableSpanMethod ({ row, column, rowIndex, columnIndex }) {
  763. if (this.tableGroups.includes(column["property"])) {
  764. const _row = this.spanArr[rowIndex];
  765. const _col = _row > 0 ? 1 : 0;
  766. return {
  767. rowspan: _row,
  768. colspan: _col,
  769. };
  770. }
  771. },
  772. //合计
  773. getSummaries (param) {
  774. const { columns, data } = param;
  775. const sums = [];
  776. columns.forEach((column, index) => {
  777. this.tableColsCopy.forEach((p) => {
  778. if (column.property == p.columnName && p.needCount) {
  779. const values = data.map((item) => Number(item[column.property]));
  780. if (!values.every((value) => isNaN(value))) {
  781. sums[index] = values.reduce((prev, curr) => {
  782. const value = Number(curr);
  783. if (!isNaN(value)) {
  784. return prev + curr;
  785. } else {
  786. return prev;
  787. }
  788. }, 0);
  789. sums[index] += "";
  790. }
  791. }
  792. });
  793. });
  794. return sums;
  795. },
  796. //弹框-确定
  797. handleOk () {
  798. this.submitClickHandler();
  799. },
  800. //滚动
  801. tableLoad () { },
  802. //表格-新增
  803. handleAdd () {
  804. const { open_method, route_info } = this.btnAddObj
  805. if (open_method) {
  806. if (open_method != 3) {
  807. this.autoBtnClick(open_method, route_info)
  808. } else {
  809. this.flag = true;
  810. this.tableType = "add";
  811. this.tableTitle = "新增";
  812. this.tableForm = {};
  813. }
  814. }
  815. },
  816. //表格-编辑
  817. async handleEdit (row) {
  818. const { open_method, route_info } = this.btnEditObj
  819. if (open_method) {
  820. if (open_method != 3) {
  821. this.autoBtnClick(open_method, route_info)
  822. } else {
  823. this.flag = true;
  824. this.tableType = "edit";
  825. this.tableTitle = "编辑";
  826. this.tableForm = _.cloneDeep(row);
  827. }
  828. }
  829. },
  830. //表格-其他类型按钮操作
  831. handleOther (row, auth) {
  832. const { open_method, route_info } = auth
  833. if (open_method) {
  834. if (open_method != 3) {
  835. this.autoBtnClick(open_method, route_info)
  836. } else {
  837. console.log(row)
  838. }
  839. }
  840. },
  841. //表格-数据恢复
  842. async handleRecord (row) {
  843. const { open_method, route_info } = this.btnRecordObj
  844. console.log(code)
  845. const params = {
  846. "serviceId": row.serviceId,
  847. "dataObjectId": row.dataObjectId
  848. }
  849. const { code } = await abnormalDataRecovery(params)
  850. console.log(code)
  851. },
  852. // 新增/编辑-确认
  853. submitClickHandler () {
  854. this.$refs["ruleForm"].validate((valid) => {
  855. if (valid) {
  856. if (this.tableType == "add") {
  857. this.tableForm.event = 1;
  858. } else {
  859. this.tableForm.event = 2;
  860. }
  861. this.generalDataReception(this.tableForm.event, this.tableForm);
  862. } else {
  863. return false;
  864. }
  865. });
  866. },
  867. //表格-删除
  868. handleRemove (row) {
  869. const { open_method, route_info } = this.btnDelObj
  870. if (open_method) {
  871. if (open_method != 3) {
  872. this.autoBtnClick(open_method, route_info)
  873. } else {
  874. this.rmFlag = true;
  875. this.rmTitle = row[this.rowTitle];
  876. this.tableObj = row;
  877. }
  878. }
  879. },
  880. //表格-删除-确认
  881. tableRemove () {
  882. this.generalDataReception(3, this.tableObj);
  883. },
  884. // 表格-选中行
  885. selectHandler (selection, row) {
  886. this.$emit("selection-change", selection, row);
  887. },
  888. // 表格-查询模板预览
  889. handlePreview (row) {
  890. this.$emit("preview", row);
  891. },
  892. //高级查询关闭
  893. dialogHide () {
  894. this.dialogFlag = false
  895. },
  896. //表格-单元格点击
  897. cellClick (row, column) {
  898. const dataBtns = this.authBtnCol
  899. if (dataBtns && dataBtns.length) {
  900. const clickBtn = dataBtns.filter(item => item.relation_data == column.property)[0]
  901. if (clickBtn) {
  902. const { open_method, route_info, pass_parameters } = clickBtn
  903. if (open_method == 2) {
  904. if (pass_parameters) {
  905. const query = pass_parameters.split(',')
  906. const obj = {}
  907. query.forEach(item => {
  908. obj[item] = row[item]
  909. })
  910. this.$router.push({
  911. path: route_info,
  912. query: obj
  913. })
  914. } else {
  915. this.autoBtnClick(open_method, route_info)
  916. }
  917. }
  918. }
  919. }
  920. },
  921. //表格-设置单元格样式
  922. cellClass ({ row, column, rowIndex, columnIndex }) {
  923. if (this.authBtnColName.includes(column.property)) {
  924. return 'is-click-btn'
  925. }
  926. },
  927. formatter(row, column, cellValue, index) {
  928. const sameColumn = this.tableCols.find(col => col.columnName === column.property)
  929. if (sameColumn && this.fromDataType(sameColumn.dataType) === 'datetime') {
  930. return (cellValue ?? '').replace('T', ' ')
  931. }
  932. return cellValue
  933. }
  934. },
  935. };
  936. </script>
  937. <style lang="scss" scoped>
  938. @import "./css/index.scss";
  939. </style>