index.vue 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339
  1. <template>
  2. <el-card shadow="always" :body-style="{ padding: '10px' }">
  3. <div class="app-container">
  4. <el-dialog
  5. :title="upload.title"
  6. :visible.sync="upload.open"
  7. width="400px"
  8. append-to-body
  9. >
  10. <el-upload
  11. ref="upload"
  12. :limit="1"
  13. accept=".xlsx, .xls"
  14. :headers="upload.headers"
  15. :action="
  16. upload.url +
  17. '?updateSupport=' +
  18. upload.updateSupport +
  19. '&tableName=' +
  20. tableName +
  21. '&sqlKey=' +
  22. tableKey
  23. "
  24. v-loading="upload.isUploading"
  25. :disabled="upload.isUploading"
  26. :on-progress="handleFileUploadProgress"
  27. :on-success="handleFileSuccess"
  28. :auto-upload="false"
  29. :onChange="handleChange"
  30. drag
  31. >
  32. <i class="el-icon-upload"></i>
  33. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  34. <div class="el-upload__tip text-center" slot="tip">
  35. <!-- <div class="el-upload__tip" slot="tip">-->
  36. <!-- <el-checkbox v-model="upload.updateSupport"/>-->
  37. <!-- 是否更新已经存在的用户数据-->
  38. <!-- </div>-->
  39. <span>仅允许导入xls、xlsx格式文件。</span>
  40. <el-link
  41. type="primary"
  42. :underline="false"
  43. style="font-size: 12px; vertical-align: baseline"
  44. @click="importTemplate"
  45. >下载模板
  46. </el-link>
  47. </div>
  48. </el-upload>
  49. <div slot="footer" class="dialog-footer">
  50. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  51. <el-button @click="upload.open = false">取 消</el-button>
  52. </div>
  53. </el-dialog>
  54. <Queryfrom
  55. v-if="QueryfromLoading"
  56. :formVals="templateInfo.where"
  57. :statisticList="statisticList"
  58. :showCount="showCount"
  59. :showSearch="showSearch"
  60. @getList="getList"
  61. ref="mychild"
  62. />
  63. <div class="mb8 btn-wrap">
  64. <!-- 按钮行 start -->
  65. <btn-menu-list
  66. @topBtnHandler="topBtnHandler"
  67. :topBtnArr="topBtnArr"
  68. :selection="selection"
  69. >
  70. <el-button
  71. :disabled="!selection.length"
  72. type="info"
  73. icon="el-icon-s-help"
  74. size="mini"
  75. @click="handleAuto"
  76. >自动排产</el-button
  77. >
  78. </btn-menu-list>
  79. <!-- 按钮行 end -->
  80. <!-- <template v-else>
  81. <el-col :span="1.5">
  82. <el-button
  83. type="primary"
  84. plain
  85. icon="el-icon-plus"
  86. size="mini"
  87. @click="handleAdd"
  88. >新增
  89. </el-button>
  90. </el-col>
  91. <el-col :span="1.5" v-if="false">
  92. <el-button
  93. type="success"
  94. plain
  95. icon="el-icon-edit"
  96. size="mini"
  97. :disabled="single"
  98. @click="handleUpdate"
  99. >修改
  100. </el-button>
  101. </el-col>
  102. <el-col :span="1.5">
  103. <el-button
  104. type="danger"
  105. plain
  106. icon="el-icon-delete"
  107. size="mini"
  108. :disabled="multiple"
  109. @click="handleBatchDelete"
  110. >删除
  111. </el-button>
  112. </el-col>
  113. <el-col :span="1.5">
  114. <el-button
  115. plain
  116. icon="el-icon-upload2"
  117. size="mini"
  118. @click="upload.open = true"
  119. >导入
  120. </el-button>
  121. </el-col>
  122. <el-col :span="1.5">
  123. <el-button
  124. type="warning"
  125. plain
  126. icon="el-icon-download"
  127. size="mini"
  128. @click="handleExport"
  129. >导出
  130. </el-button>
  131. </el-col>
  132. </template> -->
  133. <right-toolbar
  134. :showCount.sync="showCount"
  135. :showSearch.sync="showSearch"
  136. :counts="true"
  137. @queryTable="pageList"
  138. ></right-toolbar>
  139. </div>
  140. <el-table
  141. v-loading="loading"
  142. :data="tableList"
  143. @selection-change="handleSelectionChange"
  144. ref="tableRef"
  145. :cell-style="cellStyle"
  146. :reserve-selection="true"
  147. :row-key="getRowKey"
  148. >
  149. <el-table-column
  150. type="selection"
  151. width="55"
  152. reserve-selection
  153. align="center"
  154. >
  155. </el-table-column>
  156. <!-- <span v-for="(key, val) in columns" :key="key">
  157. <el-table-column :label="key" align="center" :prop="val" />
  158. </span> -->
  159. <el-table-column
  160. v-for="item in columns"
  161. :key="item.key"
  162. :label="item.value"
  163. align="center"
  164. :prop="item.key"
  165. >
  166. <template slot-scope="scope">
  167. <!-- 存在字段样式或字典样式 -->
  168. <template
  169. v-if="
  170. scope.row.styleFieldObj != undefined &&
  171. scope.row.styleFieldObj[item.key]
  172. "
  173. >
  174. <!-- 字段样式 -->
  175. <template v-if="scope.row.styleFieldObj[item.key].styleType == 1">
  176. <!-- 一般字体样式 -->
  177. <template
  178. v-if="scope.row.styleFieldObj[item.key].fieldStyleType == 0"
  179. >
  180. <span
  181. :style="`color:${
  182. scope.row.styleFieldObj[item.key].fontColor
  183. }`"
  184. >{{ scope.row[item.key] }}</span
  185. >
  186. </template>
  187. <!-- 标签字体样式 -->
  188. <template
  189. v-else-if="
  190. scope.row.styleFieldObj[item.key].fieldStyleType == 1
  191. "
  192. >
  193. <el-tag
  194. :type="scope.row.styleFieldObj[item.key].tagType"
  195. :effect="
  196. scope.row.styleFieldObj[item.key].isTagFullBg
  197. ? 'dark'
  198. : 'light'
  199. "
  200. >
  201. {{ scope.row[item.key] }}
  202. </el-tag>
  203. </template>
  204. </template>
  205. <!-- 字典样式 -->
  206. <template
  207. v-else-if="scope.row.styleFieldObj[item.key].styleType == 2"
  208. >
  209. <span
  210. v-if="
  211. scope.row.styleFieldObj[item.key].listClass == '' ||
  212. scope.row.styleFieldObj[item.key].listClass == 'default'
  213. "
  214. >{{ scope.row.styleFieldObj[item.key].dictLabel }}</span
  215. >
  216. <el-tag
  217. v-else
  218. :type="
  219. scope.row.styleFieldObj[item.key].listClass == 'primary'
  220. ? ''
  221. : scope.row.styleFieldObj[item.key].listClass
  222. "
  223. >{{ scope.row.styleFieldObj[item.key].dictLabel }}
  224. </el-tag>
  225. </template>
  226. </template>
  227. <!-- 显示默认值 -->
  228. <template v-else>
  229. {{ scope.row[item.key] }}
  230. </template>
  231. </template>
  232. </el-table-column>
  233. <el-table-column
  234. v-if="isShowExcuteCol"
  235. label="操作"
  236. align="center"
  237. class-name="small-padding fixed-width"
  238. >
  239. <template slot-scope="scope">
  240. <Menu
  241. :row="scope.row"
  242. v-for="btnObj in excuteBtnArr"
  243. :key="btnObj.id"
  244. :listAll="btnObj"
  245. @excuteHandler="excuteHandler"
  246. ></Menu>
  247. </template>
  248. </el-table-column>
  249. </el-table>
  250. <pagination
  251. v-show="total > 0"
  252. :total="total"
  253. :page.sync="queryParams.pageNum"
  254. :limit.sync="queryParams.pageSize"
  255. @pagination="pageList"
  256. />
  257. <!-- 添加或修改 -->
  258. <el-dialog :title="title" :visible.sync="open" append-to-body>
  259. <!-- <iframe
  260. :src="iframeUrl"
  261. width="100%"
  262. height="600px"
  263. style="border: none"
  264. scrolling="no"
  265. >
  266. </iframe> -->
  267. <!-- <template v-else> -->
  268. <div
  269. v-show="formType == 'dragFormGroup' && !formListShow"
  270. class="dialog_loading"
  271. >
  272. <i class="el-icon-loading"></i>
  273. </div>
  274. <template>
  275. <!-- :style="{ opacity: formListShow ? 1 : 0 }" -->
  276. <FormList
  277. v-show="formType == 'dragFormGroup' && formListShow && !isLayout"
  278. ref="formGroupRef"
  279. :formList="formList"
  280. ></FormList>
  281. <LayoutIndex
  282. v-show="formType == 'dragFormGroup' && formListShow && isLayout"
  283. ref="formGroupLayoutRef"
  284. :layoutData="layoutData"
  285. ></LayoutIndex>
  286. <!-- <div v-show="times" class="times">
  287. <i class="el-icon-loading" style="font-size: 30px"></i>
  288. </div> -->
  289. <!-- <el-button @click="showValue">test</el-button> -->
  290. </template>
  291. <template>
  292. <k-form-build
  293. v-if="jsonData && formType == 'dragForm'"
  294. class="formBuild"
  295. ref="addFromRef"
  296. :dynamicData="dynamicData"
  297. :defaultValue="defaultValue"
  298. @submit="tempSubBtn"
  299. @change="formChangeHandler"
  300. :value="jsonData"
  301. :tableData="tableTempList"
  302. />
  303. </template>
  304. <div slot="footer" class="dialog-footer">
  305. <el-button type="primary" @click="editConfirmHandler"
  306. >确 定
  307. </el-button>
  308. <el-button @click="cancel">取 消</el-button>
  309. </div>
  310. </el-dialog>
  311. <!-- 绑定按钮dialog -->
  312. <el-dialog
  313. title="提示"
  314. :visible.sync="btnDialogVisible"
  315. :before-close="handleClose"
  316. >
  317. <DialogTemplate
  318. ref="dialogRef"
  319. :groupKey="groupKey"
  320. :rowobj="rowobj"
  321. :subCount="subCount"
  322. :tableCount="tableCount"
  323. :subTableName="subTableName"
  324. @addList="addListHandler"
  325. >
  326. </DialogTemplate>
  327. <span slot="footer" class="dialog-footer">
  328. <el-button @click="btnDialogVisible = false">取 消</el-button>
  329. <el-button type="primary" @click="btnComfirm">确 定</el-button>
  330. </span>
  331. </el-dialog>
  332. <!-- 自定义弹窗 -->
  333. <el-dialog
  334. title="提示"
  335. :visible.sync="btnDialogVisible"
  336. :before-close="handleClose"
  337. >
  338. <DialogTemplate
  339. ref="dialogRef"
  340. :groupKey="groupKey"
  341. :rowobj="rowobj"
  342. :subCount="subCount"
  343. :tableCount="tableCount"
  344. :subTableName="subTableName"
  345. @addList="addListHandler"
  346. >
  347. </DialogTemplate>
  348. <span slot="footer" class="dialog-footer">
  349. <el-button @click="btnDialogVisible = false">取 消</el-button>
  350. <el-button type="primary" @click="btnComfirm">确 定</el-button>
  351. </span>
  352. </el-dialog>
  353. <!-- 打印弹窗 -->
  354. <el-dialog title="打印" :visible.sync="printShow" width="30%">
  355. <div ref="detailTable" id="detail"></div>
  356. <span slot="footer" class="dialog-footer">
  357. <el-button @click="printShow = false">取 消</el-button>
  358. <el-button type="primary" @click="confirmPrint">打 印</el-button>
  359. </span>
  360. </el-dialog>
  361. <!-- 消息提示弹窗 -->
  362. <el-dialog title="提示" :visible.sync="toastShow" width="30%">
  363. <span>
  364. <i :class="`el-icon-info ${toastType}`"></i>
  365. {{ toastMsg || "暂无提示信息" }}
  366. </span>
  367. <template #footer>
  368. <span>
  369. <el-button type="primary" @click="toastShow = false"
  370. >确认</el-button
  371. >
  372. </span>
  373. </template>
  374. </el-dialog>
  375. <!-- 自动排产 -->
  376. <el-dialog title="自动排产" :visible.sync="autoShow" width="30%">
  377. <el-form
  378. :model="autoForm"
  379. ref="autoForm"
  380. :rules="autoFormRules"
  381. label-width="80px"
  382. :inline="false"
  383. size="normal"
  384. >
  385. <el-form-item label="排产类型" prop="planType">
  386. <!-- <el-input v-model="form.planType"></el-input> -->
  387. <el-select
  388. v-model="autoForm.planType"
  389. placeholder="请选择排产类型"
  390. clearable
  391. filterable
  392. >
  393. <el-option
  394. v-for="item in dict.type.schedule_type"
  395. :key="item.value"
  396. :label="item.label"
  397. :value="item.value"
  398. >
  399. </el-option>
  400. </el-select>
  401. </el-form-item>
  402. </el-form>
  403. <template #footer>
  404. <span>
  405. <el-button type="info" @click="autoShow = false">取消</el-button>
  406. <el-button type="primary" @click="autoShow = false">确认</el-button>
  407. </span>
  408. </template>
  409. </el-dialog>
  410. <div id="printDom"></div>
  411. </div>
  412. </el-card>
  413. </template>
  414. <script>
  415. import {
  416. delTableData,
  417. dragTableInfo,
  418. listTable,
  419. unionListTableData,
  420. getInfoBySqlKey,
  421. btnCommonApi,
  422. addTableData,
  423. batchEdit,
  424. getStatisticList,
  425. } from "@/api/tablelist/commonTable";
  426. import { listData } from "@/api/system/tenant/data";
  427. import { getToken } from "@/utils/auth";
  428. import Queryfrom from "@/views/tablelist/commonTable/queryfrom.vue";
  429. import { camelCase, toUnderline } from "@/utils";
  430. import { inputDisableComplete } from "@/utils/other";
  431. import Menu from "@/views/tablelist/commonTable/BtnMenu.vue";
  432. import BtnMenuList from "@/views/tablelist/commonTable/BtnMenuList.vue";
  433. import { checkRole } from "@/utils/permission";
  434. import DialogTemplate from "@/views/dialogTemplate/components/index.vue";
  435. import FormList from "@/components/FormGroup/formList.vue";
  436. import { v4 as uuidv4 } from "uuid";
  437. import printHtml from "@/views/tablelist/commonTable/print";
  438. import LayoutIndex from "@/views/tablelist/components/FormGroupLayout/LayoutIndex.vue";
  439. // let times = 2; //请求次数
  440. export default {
  441. name: "listInfo",
  442. dicts: ["schedule_type"],
  443. components: {
  444. Queryfrom,
  445. Menu,
  446. DialogTemplate,
  447. FormList,
  448. BtnMenuList,
  449. LayoutIndex,
  450. },
  451. data() {
  452. return {
  453. // 自动排产数据 start
  454. autoShow: false,
  455. autoForm: {
  456. planType: "",
  457. },
  458. autoFormRules: {
  459. planType: [
  460. { required: true, message: "请选择排产类型", trigger: "change" },
  461. ],
  462. },
  463. // 自动排产数据 end
  464. QueryfromLoading: false,
  465. layoutData: "", //表单组布局数据
  466. times: 1, //请求次数
  467. formListShow: false, //控制表单组是否显示
  468. // 提示信息 start
  469. toastMsg: "",
  470. toastShow: false,
  471. toastType: "",
  472. // 提示信息 end
  473. // 顶部按钮数据
  474. topBtnArr: [], //顶部按钮数据
  475. selection: [], //选中数组
  476. printShow: false, //打印页面
  477. printHtml: "", //打印的html
  478. // 自动生成字段
  479. theAutoField: [
  480. "id",
  481. "createBy",
  482. "createById",
  483. "createTime",
  484. "delFlag",
  485. "updateBy",
  486. "updateById",
  487. "updateTime",
  488. "del_flag",
  489. "create_by",
  490. "create_by_id",
  491. "create_time",
  492. "data_approval_status",
  493. "update_by",
  494. "update_by_id",
  495. "update_time",
  496. ],
  497. // 绑定按钮dialog
  498. btnDialogVisible: false,
  499. // 绑定修改dialog
  500. groupKey: "",
  501. // 遮罩层
  502. loading: true,
  503. // 选中数组
  504. ids: [],
  505. // 非单个禁用
  506. single: true,
  507. // 非多个禁用
  508. multiple: true,
  509. // 显示统计
  510. showCount: true,
  511. // 显示搜索条件
  512. showSearch: true,
  513. // 总条数
  514. total: 0,
  515. // 用户表格数据
  516. tableList: [],
  517. // 弹出层标题
  518. title: "",
  519. // 日期范围
  520. dateRange: [],
  521. // 表单参数
  522. form: {},
  523. rules: {},
  524. // cru 弹窗
  525. open: false,
  526. // excel共通导入数据
  527. upload: {
  528. // 是否显示弹出层
  529. open: false,
  530. // 弹出层标题(
  531. title: "",
  532. // 是否禁用上传
  533. isUploading: false,
  534. // 是否更新已经存在的数据
  535. updateSupport: 0,
  536. // 设置上传的请求头部
  537. headers: { Authorization: "Bearer " + getToken() },
  538. // 上传的地址
  539. url: process.env.VUE_APP_BASE_API1 + "common/uploadData",
  540. },
  541. // 排序方式 默认降序
  542. sortOrder: true,
  543. // 共通查询参数接受子组件的参数
  544. queryParams: {
  545. pageNum: 1, // 第几页
  546. pageSize: 10, // 每页大小
  547. orderByColumn: "", // 根据某列排序
  548. isAsc: "", // desc(降序)或 asc(升序)
  549. // 基本查询参数
  550. basicMap: {
  551. tableName: "",
  552. },
  553. // 当前表字段筛选参数
  554. queryMap: {
  555. // 当前查询基本参数
  556. // ... key : value 当前页面的筛选条件
  557. // 超级查询的唯一值
  558. queryCriteriaValue: "",
  559. },
  560. },
  561. // 列信息
  562. columns: {},
  563. // 当前模版信息
  564. templateInfo: {},
  565. // 查询条件
  566. queryFromWhere: {},
  567. // 当前table唯一标识
  568. tableKey: null,
  569. // 当前表名称
  570. tableName: null,
  571. //存放html代码块
  572. iframeUrl: "",
  573. //存放表单渲染数据
  574. jsonData: {},
  575. // 回显表格数据,
  576. defaultValue: {},
  577. // 统计card
  578. statisticList: [],
  579. // 样式表
  580. styleList: [],
  581. // 字典样式对象
  582. dictStyleObj: {},
  583. // 操作列 按钮数据
  584. excuteBtnArr: [],
  585. // 下拉框动态数据
  586. dynamicData: {},
  587. // 当前点击按钮的数据
  588. currentBtnData: {},
  589. // 修改选中行
  590. rowobj: {},
  591. // 该行的统计信息
  592. subCount: [],
  593. tableCount: [],
  594. // 弹窗新增数据
  595. addLists: [],
  596. subTableName: "",
  597. // 当前点击行的数据
  598. currentRow: {},
  599. // 操作列是否显示隐藏
  600. isShowExcuteCol: false,
  601. // 表单组数据
  602. formList: [],
  603. formType: "dragFormGroup",
  604. FormNameList: [], //表单组中表格名称
  605. FormListDefaultValue: {}, //表单组的默认表单数据
  606. // 临时测试数据
  607. tableTempList: [
  608. {
  609. id: "1",
  610. user_name: "张三",
  611. },
  612. {
  613. id: "2",
  614. user_name: "李四",
  615. },
  616. {
  617. id: "3",
  618. user_name: "王五",
  619. },
  620. ],
  621. };
  622. },
  623. created() {
  624. // 得到当前展示的table的唯一标识
  625. this.tableKey = this.$route.query.tableKey;
  626. // 优化共通模版查询调用逻辑 (Don't fucking change it)
  627. this.getList(this.queryParams);
  628. },
  629. mounted() {
  630. // this.initFormGroupDialog();
  631. },
  632. methods: {
  633. // 自动排产回调
  634. handleAuto() {
  635. console.log(this.selection);
  636. this.autoShow = true;
  637. },
  638. // 预加载一次表单组数据;
  639. async initFormGroupDialog() {
  640. this.loading = true;
  641. console.log(this.excuteBtnArr.children);
  642. let targetMenuList = this.excuteBtnArr?.children?.filter((item) => {
  643. return item.btnFormType == "dragFormGroup";
  644. });
  645. console.log(targetMenuList, this.tableList);
  646. if (targetMenuList?.length > 0 && this.tableList.length > 0) {
  647. for (let i = 0; i < targetMenuList.length; i++) {
  648. this.excuteHandler(targetMenuList[i], this.tableList[0]);
  649. }
  650. }
  651. this.loading = false;
  652. },
  653. showValue() {
  654. this.$refs.formGroupRef.setDefaultValue();
  655. },
  656. // 计算操作列的显示与隐藏
  657. calcuteExcuteCol() {
  658. if (!this.excuteBtnArr || !this.excuteBtnArr.length) {
  659. this.isShowExcuteCol = false;
  660. } else {
  661. this.isShowExcuteCol = !this.excuteBtnArr?.every(
  662. (arr) => arr.children.length == 0
  663. );
  664. }
  665. },
  666. // 获取row-key
  667. getRowKey(row) {
  668. return row[
  669. camelCase(this.tableName + "_" + this.templateInfo.template?.primaryKey)
  670. ];
  671. },
  672. /** 查询列表 */
  673. getList(queryParams) {
  674. this.loading = true;
  675. // 序列化当前查询参数列表
  676. queryParams &&
  677. (this.queryParams.queryMap = Object.assign({}, queryParams.queryMap));
  678. if (typeof queryParams.queryMap.timehorizon != "undefined") {
  679. // timehorizon 时间范围转换字符串回传后台
  680. this.queryParams.queryMap.timehorizon = JSON.stringify(
  681. Object.assign({}, queryParams.queryMap.timehorizon)
  682. );
  683. }
  684. // 获取当前表单结构信息
  685. dragTableInfo({ queryMap: { tableKey: this.tableKey } })
  686. .then((res) => {
  687. // 得到当前模版信息 --- sql columns queryWhere
  688. this.templateInfo = res.data.resultMap;
  689. this.QueryfromLoading = true; // 加载查询组件
  690. this.styleList = res.data.resultMap.style?.map((item) => {
  691. item.styleField = camelCase(
  692. item.styleField.replace(".", "_") || ""
  693. );
  694. return item;
  695. });
  696. // 获取操作列的按钮数据
  697. this.excuteBtnArr = res.data.resultMap.button?.filter(
  698. (item) => item.btnGroupType == "right"
  699. );
  700. this.topBtnArr =
  701. res.data.resultMap.button?.filter(
  702. (item) => item.btnGroupType == "top"
  703. ) || [];
  704. this.calcuteExcuteCol();
  705. this.$nextTick(() => this.$refs.tableRef.doLayout());
  706. this.queryParams.orderByColumn =
  707. res.data.resultMap.querySql.orderByColumn;
  708. this.sortOrder = JSON.parse(res.data.resultMap.querySql.sortOrder);
  709. // 根据拖拽时设置当前列表排列顺序
  710. this.queryParams.isAsc = this.sortOrder ? "DESC" : "ASC";
  711. this.tableName = this.templateInfo.template.dtTableName;
  712. // 得到查询条件
  713. this.queryFromWhere = res.data.resultMap.where;
  714. // 得到当前列表信息
  715. this.columns = this.columnsHandler(
  716. JSON.parse(this.templateInfo.template.dtColumnName)
  717. );
  718. })
  719. .finally((fes) => {
  720. // 调用子组件中查询条件顺序处理事件
  721. this.$refs.mychild.handlerFormVals();
  722. if (this.templateInfo == {}) return;
  723. // 调用查询需要携带当前table的唯一标识
  724. this.queryParams.queryMap.sqlkey = this.templateInfo.template.sqlKey;
  725. this.queryParams.orderByColumn = camelCase(
  726. this.queryParams.orderByColumn || ""
  727. );
  728. // 根据sql语句查询当前表数据 ->得到列表数据
  729. unionListTableData(this.queryParams).then(async (res) => {
  730. this.tableList = [];
  731. res.rows.forEach((item) => this.tableList.push(item.resultMap));
  732. // 驼峰转换
  733. let tempTableList = [];
  734. tempTableList = this.tableList.map((item) => {
  735. let kv = {};
  736. for (let itemKey in item) kv[camelCase(itemKey)] = item[itemKey];
  737. return kv;
  738. });
  739. this.tableList = await this.setFieldStyleData(tempTableList);
  740. this.total = res.total;
  741. this.loading = false;
  742. });
  743. // 查询统计信息
  744. getStatisticList({
  745. queryMap: {
  746. tableKey: this.templateInfo.template.tableKey,
  747. queryCriteriaValue: this.queryParams.queryMap.queryCriteriaValue,
  748. },
  749. }).then((res) => {
  750. this.statisticList = res.data;
  751. });
  752. });
  753. },
  754. isUpperCase(char) {
  755. return char === char.toUpperCase();
  756. },
  757. // 下划线命名转驼峰命名
  758. toUnderScoreCase(str) {
  759. if (str === null) {
  760. return null;
  761. }
  762. let sb = "";
  763. // 前置字符是否大写
  764. let preCharIsUpperCase = true;
  765. // 当前字符是否大写
  766. let curreCharIsUpperCase = true;
  767. // 下一字符是否大写
  768. let nexteCharIsUpperCase = true;
  769. for (let i = 0; i < str.length; i++) {
  770. let c = str.charAt(i);
  771. if (i > 0) {
  772. preCharIsUpperCase = isUpperCase(str.charAt(i - 1));
  773. } else {
  774. preCharIsUpperCase = false;
  775. }
  776. curreCharIsUpperCase = isUpperCase(c);
  777. if (i < str.length - 1) {
  778. nexteCharIsUpperCase = isUpperCase(str.charAt(i + 1));
  779. }
  780. if (
  781. preCharIsUpperCase &&
  782. curreCharIsUpperCase &&
  783. !nexteCharIsUpperCase
  784. ) {
  785. sb += SEPARATOR;
  786. } else if (i !== 0 && !preCharIsUpperCase && curreCharIsUpperCase) {
  787. sb += SEPARATOR;
  788. }
  789. sb += c.toLowerCase();
  790. }
  791. return sb;
  792. },
  793. // 处理列表信息
  794. columnsHandler(columns) {
  795. let resArr = [];
  796. columns.forEach((item) => {
  797. for (const key in item) {
  798. let tempObj = {};
  799. tempObj.key = camelCase(key);
  800. tempObj.value = item[key];
  801. resArr.push(tempObj);
  802. }
  803. });
  804. return resArr;
  805. },
  806. // 取消按钮
  807. cancel() {
  808. this.open = false;
  809. // this.reset();
  810. },
  811. // 分页查询
  812. pageList(row) {
  813. // 调用子组件-》携带子组件参数请求后台
  814. this.$refs.mychild.pageList(
  815. row == undefined
  816. ? {
  817. limit: this.queryParams.pageSize,
  818. page: this.queryParams.pageNum,
  819. }
  820. : row
  821. );
  822. },
  823. // 多选框选中数据
  824. handleSelectionChange(selection) {
  825. this.ids = selection.map(
  826. (item) =>
  827. item[
  828. camelCase(
  829. this.tableName + "_" + this.templateInfo.template?.primaryKey
  830. )
  831. ]
  832. );
  833. this.selection = selection;
  834. this.single = selection.length != 1;
  835. this.multiple = !selection.length;
  836. },
  837. // 更多操作触发
  838. handleCommand(command, row) {
  839. switch (command) {
  840. case "handleResetPwd":
  841. this.handleResetPwd(row);
  842. break;
  843. case "handleAuthRole":
  844. this.handleAuthRole(row);
  845. break;
  846. default:
  847. break;
  848. }
  849. },
  850. /** 新增按钮操作 */
  851. handleAdd(row) {
  852. // this.reset();
  853. this.defaultValue = {};
  854. this.formType = "dragForm";
  855. let payLoad = {
  856. basicMap: {
  857. btnType: this.currentBtnData.btnType,
  858. btnKey: this.currentBtnData.btnKey,
  859. visible: "false",
  860. sqlKey: this.templateInfo.template.sqlKey,
  861. tableName: this.tableName,
  862. },
  863. };
  864. // getInfoBySqlKey(this.templateInfo.template.sqlKey)
  865. btnCommonApi(payLoad).then(({ data }) => {
  866. if (!data || !data.dfVueTemplate) {
  867. this.jsonData = false;
  868. this.$message.error("当前表格未绑定表单!");
  869. return;
  870. }
  871. if (data.dfFormSql) {
  872. let dynamicData = JSON.parse(data.dfFormSql);
  873. Object.assign(this.dynamicData, dynamicData);
  874. }
  875. this.jsonData = JSON.parse(data.dfVueTemplate);
  876. this.open = true;
  877. this.title = "添加信息";
  878. this.form.password = this.initPassword;
  879. this.$nextTick(() => {
  880. this.$refs.addFromRef.reset();
  881. inputDisableComplete();
  882. });
  883. });
  884. },
  885. longestCommonSubstring(strs) {
  886. if (!strs || strs.includes("")) return "";
  887. let str1_Length = strs[0].length;
  888. let str_Nums = strs.length;
  889. let flag = 0;
  890. for (let i = 0; i < str1_Length && flag == 0; i++) {
  891. let char = strs[0][i];
  892. for (var j = 1; j < str_Nums; j++) {
  893. if (char !== strs[j][i] || i == strs[j].length) {
  894. return strs[1].substring(0, i);
  895. }
  896. }
  897. }
  898. return strs[0];
  899. },
  900. // 绑定dialog对话框关闭
  901. handleClose() {
  902. this.btnDialogVisible = false;
  903. },
  904. getLastUppercaseWord(text) {
  905. const pattern = /\b[A-Z][a-z]*\b/g;
  906. const matches = [...text.matchAll(pattern)];
  907. if (matches.length > 0) {
  908. const lastMatch = matches[matches.length - 1][0];
  909. return lastMatch;
  910. } else {
  911. return null;
  912. }
  913. },
  914. // 延迟
  915. sleep(ms) {
  916. var unixtime_ms = new Date().getTime();
  917. while (new Date().getTime() < unixtime_ms + ms) {}
  918. return "";
  919. },
  920. /** 修改按钮操作 */
  921. async handleUpdate(row, btnData) {
  922. let nameTable = this.templateInfo.template.dtTableName;
  923. this.rowobj = {};
  924. let obj = {};
  925. this.formList = [];
  926. for (let key in row) {
  927. let modifiedTable = key
  928. .replace(/[A-Z]/g, (match) => `_${match}`)
  929. .toLowerCase();
  930. this.rowobj[modifiedTable] = row[key];
  931. let str = modifiedTable.substring(nameTable.length + 1);
  932. obj[str] = row[key];
  933. }
  934. // getInfoBySqlKey(this.templateInfo.template.sqlKey).then(({ data }) => {
  935. // if (!data || !data.dfVueTemplate) {
  936. // this.$message.error("当前表格未绑定表单!");
  937. // return;
  938. // }});
  939. // 新的修改请求
  940. try {
  941. let { btnFormType, btnGroupType } = btnData;
  942. // this.formType = btnFormType;
  943. let payLoad = {};
  944. let primary = camelCase(
  945. this.tableName + "_" + this.templateInfo.template?.primaryKey
  946. );
  947. // if (btnFormType == "dragFormGroup") {
  948. // payLoad.updateCommonEntityList = {
  949. // basicMap: {
  950. // btnType: this.currentBtnData.btnType,
  951. // btnKey: this.currentBtnData.btnKey,
  952. // visible: "false",
  953. // sqlKey: this.templateInfo.template.sqlKey,
  954. // tableName: this.tableName,
  955. // },
  956. // conditionMap: {},
  957. // };
  958. // payLoad.updateCommonEntityList.conditionMap[
  959. // this.templateInfo.template?.primaryKey
  960. // ] = row[primary];
  961. // } else {
  962. payLoad = {
  963. basicMap: {
  964. btnType: this.currentBtnData.btnType,
  965. btnKey: this.currentBtnData.btnKey,
  966. visible: "false",
  967. sqlKey: this.templateInfo.template.sqlKey,
  968. tableName: this.tableName,
  969. },
  970. conditionMap: {},
  971. };
  972. payLoad.conditionMap[this.templateInfo.template?.primaryKey] =
  973. row[primary];
  974. // }
  975. let res = await btnCommonApi(payLoad);
  976. // 判断是否绑定dialog弹窗
  977. if (!this.currentBtnData.btnTableFormGroupKey) {
  978. if (
  979. btnGroupType == "right" &&
  980. (!res.data || !res.data.template) &&
  981. !res.data?.mainForm
  982. ) {
  983. //右侧判定逻辑
  984. this.$message.error("当前按钮未绑定表单!");
  985. return;
  986. }
  987. if (
  988. btnGroupType == "top" &&
  989. (!res.data || !res.data.dfVueTemplate) &&
  990. !res.data?.mainForm
  991. ) {
  992. //顶部判定逻辑
  993. this.$message.error("当前按钮未绑定表单!");
  994. return;
  995. }
  996. if (btnFormType == "dragFormGroup") {
  997. //表单组
  998. if (res.code == 200) {
  999. if (res.data.mainForm) {
  1000. //表单组
  1001. // 判断是否有布局数据
  1002. this.isLayout =
  1003. res.data.layoutJson &&
  1004. JSON.parse(res.data.layoutJson)?.list.length > 0;
  1005. this.transformDataFormat(res.data);
  1006. if (this.isLayout) {
  1007. //自定义布局
  1008. this.layoutData = JSON.parse(JSON.stringify(res.data));
  1009. }
  1010. } else {
  1011. this.formList = res.data;
  1012. }
  1013. this.open = true;
  1014. if (btnData.btnFormType == "dragFormGroup") {
  1015. if (this.times) {
  1016. this.times = 0;
  1017. // debugger;
  1018. this.$nextTick(async () => {
  1019. // debugger;
  1020. setTimeout(() => {
  1021. this.handleUpdate(row, btnData).then((res) => {
  1022. this.formListShow = true;
  1023. });
  1024. // setTimeout(() => {
  1025. // this.times = 0;
  1026. // }, 1000);
  1027. }, 1000);
  1028. });
  1029. }
  1030. }
  1031. if (this.isLayout) {
  1032. //布局样式
  1033. this.$nextTick(() => {
  1034. // 手动触发布局组件的数据处理函数
  1035. this.$refs.formGroupLayoutRef?.initLayoutData(
  1036. JSON.parse(JSON.stringify(res.data))
  1037. );
  1038. });
  1039. }
  1040. // this.$nextTick(() => {
  1041. // this.open = false;
  1042. // this.$nextTick(() => {
  1043. // this.open = true;
  1044. // });
  1045. // });
  1046. // this.$nextTick(() => {
  1047. // if (res.data.mainForm) {
  1048. // this.$refs.formGroupRef.setDefaultValue();
  1049. // }
  1050. // });
  1051. } else {
  1052. this.$message.error("网络异常,请稍后再试");
  1053. }
  1054. } else {
  1055. let optionsData = "",
  1056. templateData = "";
  1057. if (btnGroupType == "top") {
  1058. optionsData = res.data.dfFormSql;
  1059. templateData = res.data.dfVueTemplate;
  1060. } else {
  1061. //修改
  1062. optionsData = res.data.template.dfFormSql;
  1063. templateData = res.data.template.dfVueTemplate;
  1064. this.addRealFieldName(res.data.result.resultMap);
  1065. let resultMap = res.data.result.resultMap;
  1066. Object.assign(this.defaultValue, resultMap);
  1067. }
  1068. //单个表单
  1069. optionsData && (this.dynamicData = JSON.parse(optionsData));
  1070. this.jsonData = JSON.parse(templateData);
  1071. this.open = true;
  1072. this.title = btnGroupType == "top" ? "新增信息" : "修改信息";
  1073. if (btnGroupType == "top") {
  1074. //新增 重置表单
  1075. this.$nextTick(() => {
  1076. this.$refs.addFromRef.reset();
  1077. });
  1078. }
  1079. this.form.password = this.initPassword;
  1080. if (btnGroupType == "right") {
  1081. this.$nextTick(() => {
  1082. this.$refs.addFromRef.setData(res.data.result.resultMap);
  1083. });
  1084. }
  1085. }
  1086. } else {
  1087. this.subTableName = res.data.result.dragTables[1].dtTableName;
  1088. this.btnDialogVisible = true;
  1089. this.groupKey = this.currentBtnData.btnTableFormGroupKey;
  1090. this.$nextTick(() => {
  1091. let refChild = this.$refs.dialogRef;
  1092. refChild.getLists(this.groupKey);
  1093. });
  1094. let tablesubKey = res.data.result.dragTables[1].tableKey;
  1095. // 查询统计信息
  1096. getStatisticList({
  1097. queryMap: {
  1098. tableKey: tablesubKey,
  1099. },
  1100. }).then((res) => {
  1101. this.subCount = res.data;
  1102. });
  1103. let prmKey = this.templateInfo.template.primaryKey;
  1104. let pkey = prmKey.replace(/_([a-z])/g, (match, p1) =>
  1105. p1.toUpperCase()
  1106. );
  1107. let data = {
  1108. queryMap: {
  1109. tableKey: res.data.result.dragTables[2].tableKey,
  1110. },
  1111. };
  1112. let key =
  1113. "#{" +
  1114. this.templateInfo.template.dtTableName +
  1115. "." +
  1116. this.templateInfo.template.primaryKey;
  1117. data.queryMap[key] =
  1118. "'" + obj[this.templateInfo.template.primaryKey] + "'";
  1119. getStatisticList(data).then((res) => {
  1120. this.tableCount = res.data;
  1121. });
  1122. }
  1123. } catch (error) {
  1124. console.log(error);
  1125. this.$message.error("网络异常,请稍后再试");
  1126. }
  1127. console.log(this.times);
  1128. return;
  1129. },
  1130. // 将表单组数据转换成符合单个表单的数据格式
  1131. transformDataFormat(data) {
  1132. this.FormNameList = [];
  1133. let { mainForm, subFormList } = data;
  1134. this.formList = [];
  1135. let showValue = null;
  1136. if (mainForm.showValue) {
  1137. showValue = mainForm.showValue[0]?.resultMap;
  1138. }
  1139. if (showValue) {
  1140. for (const key of Object.keys(showValue)) {
  1141. if (key != "remark") {
  1142. showValue[toUnderline(key)] = showValue[key];
  1143. // delete showValue[key];
  1144. if (toUnderline(key) != key) {
  1145. delete showValue[key];
  1146. }
  1147. }
  1148. }
  1149. mainForm.showTemplate.resultMap = [showValue];
  1150. }
  1151. this.formList.push({
  1152. template: mainForm.showTemplate,
  1153. tableName: mainForm.mainFormTable,
  1154. });
  1155. this.FormNameList.push({
  1156. tableName: mainForm.mainFormTable,
  1157. formItem: mainForm.mainFormItem,
  1158. relateFormItem: null,
  1159. isMainForm: true,
  1160. formType: mainForm.showTemplate.spare == "2" ? "batch" : "normal",
  1161. defaultValue: mainForm.showValue ? mainForm.showValue[0].resultMap : {},
  1162. });
  1163. if (subFormList && subFormList.length > 0) {
  1164. subFormList.forEach((item) => {
  1165. let showValue = null;
  1166. if (item.showValue) {
  1167. showValue = item.showValue[0];
  1168. }
  1169. let defaultValue = {};
  1170. if (showValue) {
  1171. if (item.showTemplate.spare == "2") {
  1172. //动态表格表单
  1173. let batch = {},
  1174. tableName = item.formItem?.split(".")?.[0];
  1175. batch[tableName] = item.showValue.map((item) => item.resultMap);
  1176. defaultValue = JSON.parse(JSON.stringify(batch));
  1177. // 所有字段驼峰转下划线
  1178. batch[tableName].forEach((i) => {
  1179. for (const key of Object.keys(i)) {
  1180. i[toUnderline(key)] = i[key];
  1181. if (toUnderline(key) != key) {
  1182. delete i[key];
  1183. }
  1184. }
  1185. });
  1186. item.showTemplate.resultMap = [
  1187. {
  1188. batch,
  1189. },
  1190. ];
  1191. } else {
  1192. for (const key of Object.keys(item.showValue[0].resultMap)) {
  1193. item.showValue[0].resultMap[toUnderline(key)] =
  1194. item.showValue[0].resultMap[key];
  1195. if (toUnderline(key) != key) {
  1196. delete item.showValue[0].resultMap[key];
  1197. }
  1198. }
  1199. item.showTemplate.resultMap = [item.showValue[0].resultMap];
  1200. }
  1201. }
  1202. this.formList.push({
  1203. template: item.showTemplate,
  1204. tableName: item.formItem?.split(".")?.[0],
  1205. });
  1206. this.FormNameList.push({
  1207. tableName: item.formItem?.split(".")?.[0],
  1208. formItem: item.formItem,
  1209. relateFormItem: item.relateMainItem,
  1210. formType: item.showTemplate.spare == "2" ? "batch" : "normal",
  1211. defaultValue,
  1212. insertMap: item.insertMap,
  1213. isMainForm: false,
  1214. });
  1215. });
  1216. }
  1217. },
  1218. // 格式化表单组布局数据
  1219. formateLayout(data) {
  1220. let { layoutJson, mainForm, subFormList } = data;
  1221. },
  1222. // 添加真正的字段名
  1223. addRealFieldName(row) {
  1224. let fieldList = Object.keys(row);
  1225. // let tableName = this.longestCommonSubstring(fieldList);
  1226. let tableName = camelCase(this.tableName);
  1227. fieldList.forEach((field) => {
  1228. let realField = field.replace(tableName, "");
  1229. realField = realField[0].toLocaleLowerCase() + realField.substring(1);
  1230. row[realField] = row[field];
  1231. });
  1232. },
  1233. /** 提交按钮 */
  1234. submitForm: function () {
  1235. this.$refs["form"].validate((valid) => {
  1236. if (valid) {
  1237. if (this.form.userId != undefined) {
  1238. updateUser(this.form).then((response) => {
  1239. this.$modal.msgSuccess("修改成功");
  1240. this.open = false;
  1241. // ⚠️⚠️⚠️调用查询组件中查询函数-》handleQuery回调getList();
  1242. this.$refs.mychild.handleQuery();
  1243. });
  1244. } else {
  1245. addUser(this.form).then((response) => {
  1246. this.$modal.msgSuccess("新增成功");
  1247. this.open = false;
  1248. // ⚠️⚠️⚠️调用查询组件中查询函数-》handleQuery回调getList();
  1249. this.$refs.mychild.handleQuery();
  1250. });
  1251. }
  1252. }
  1253. });
  1254. },
  1255. /** 删除按钮操作
  1256. *
  1257. * 删除提示信息语句(标识)
  1258. * */
  1259. handleDelete(row, btnData) {
  1260. let delIds = this.ids;
  1261. let primary = camelCase(this.templateInfo.template?.primaryKey);
  1262. // let realyKey=
  1263. this.addRealFieldName(row);
  1264. if (row[primary] != undefined && row[primary] != null) {
  1265. delIds = [];
  1266. delIds.push(row[primary]);
  1267. }
  1268. let data = {
  1269. basicMap: {
  1270. btnType: btnData.btnType,
  1271. btnKey: btnData.btnKey,
  1272. tableName: this.tableName,
  1273. },
  1274. conditionMap: {
  1275. // id: delIds,
  1276. },
  1277. btnParametersMap: {},
  1278. };
  1279. if (this.currentBtnData.btnParams) {
  1280. let btnParams =
  1281. JSON.parse(this.currentBtnData.btnParams)?.commonFieldData || [];
  1282. let conditionData =
  1283. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1284. conditionData.forEach((item) => {
  1285. data.conditionMap[item.fieldName.split(".")[1]] = item.fieldValue
  1286. ? item.fieldValue
  1287. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1288. });
  1289. btnParams.forEach((item) => {
  1290. data.btnParametersMap[item.fieldName.split(".")[1]] = item.fieldValue
  1291. ? item.fieldValue
  1292. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1293. });
  1294. }
  1295. // data.conditionMap[this.templateInfo.template?.primaryKey] = delIds;
  1296. this.$modal
  1297. .confirm('是否确认删除"' + delIds + '"的数据项?')
  1298. .then(function () {
  1299. // return delTableData(data);
  1300. return btnCommonApi(data);
  1301. })
  1302. .then(() => {
  1303. // 调用子组件查询方法 目的是携带上子组件中的查询参数
  1304. this.$refs.mychild.pageList();
  1305. this.$modal.msgSuccess("删除成功");
  1306. })
  1307. .catch(() => {});
  1308. },
  1309. // 批量删除接口
  1310. handleBatchDelete() {
  1311. let delIds = this.ids;
  1312. let primary = camelCase(this.templateInfo.template?.primaryKey);
  1313. // if (row && row[primary] != undefined && row[primary] != null) {
  1314. // delIds = [];
  1315. // delIds.push(row[primary]);
  1316. // }
  1317. let data = {
  1318. basicMap: {
  1319. tableName: this.tableName,
  1320. },
  1321. conditionMap: {
  1322. // id: delIds,
  1323. },
  1324. };
  1325. // if (this.currentBtnData.btnParams) {
  1326. // let btnParams = JSON.parse(this.currentBtnData.btnParams);
  1327. // btnParams.forEach((item) => {
  1328. // data.btnParametersMap[
  1329. // this.formatField(item.fieldName, camelCase(this.tableName))
  1330. // ] = item.fieldValue
  1331. // ? item.fieldValue
  1332. // : this.currentRow[item.fieldName];
  1333. // });
  1334. // }
  1335. data.conditionMap[this.templateInfo.template?.primaryKey] = delIds;
  1336. this.$modal
  1337. .confirm('是否确认删除"' + delIds + '"的数据项?')
  1338. .then(function () {
  1339. return delTableData(data);
  1340. // return btnCommonApi(data);
  1341. })
  1342. .then(() => {
  1343. // 调用子组件查询方法 目的是携带上子组件中的查询参数
  1344. this.$refs.mychild.pageList();
  1345. this.$modal.msgSuccess("删除成功");
  1346. })
  1347. .catch(() => {});
  1348. },
  1349. /** 导出按钮操作 */
  1350. handleExport() {
  1351. let primary = camelCase(this.templateInfo.template?.primaryKey);
  1352. let realyKey = camelCase(this.tableName + "_" + primary);
  1353. if (this.ids.length > 0) {
  1354. this.queryParams["execlMap"] = [];
  1355. this.ids.forEach((item) => {
  1356. this.queryParams.execlMap.push(
  1357. this.tableList.find((ttem) => {
  1358. return ttem[realyKey] === item;
  1359. })
  1360. );
  1361. });
  1362. }
  1363. // else {
  1364. // this.$message.warning("请至少勾选一条导出数据");
  1365. // return;
  1366. // }
  1367. this.queryParams.execlMap = JSON.stringify(this.queryParams.execlMap);
  1368. this.download(
  1369. process.env.VUE_APP_BASE_API1 + "common/export",
  1370. {
  1371. ...this.queryParams,
  1372. },
  1373. `文件名称_${new Date().getTime()}.xlsx`
  1374. );
  1375. },
  1376. /** 导入按钮操作 */
  1377. handleImport() {
  1378. this.upload.title = "当前导入";
  1379. this.upload.open = true;
  1380. },
  1381. /** 下载模板操作 */
  1382. importTemplate() {
  1383. this.download(
  1384. process.env.VUE_APP_BASE_API1 +
  1385. `common/exportTemplate?tableName=${this.tableName}&sqlkey=${this.templateInfo.template.sqlKey}`,
  1386. {},
  1387. `下载模版名称${new Date().getTime()}.xlsx`
  1388. );
  1389. },
  1390. // 文件上传中处理
  1391. handleFileUploadProgress(event, file, fileList) {
  1392. this.upload.isUploading = true;
  1393. },
  1394. // 文件上传成功处理
  1395. handleFileSuccess(response, file, fileList) {
  1396. this.upload.open = false;
  1397. this.upload.isUploading = false;
  1398. this.$refs.upload.clearFiles();
  1399. this.$alert(
  1400. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  1401. response.msg +
  1402. "</div>",
  1403. "导入结果",
  1404. { dangerouslyUseHTMLString: true }
  1405. );
  1406. this.$refs.mychild.pageList({
  1407. limit: this.queryParams.pageSize,
  1408. page: this.queryParams.pageNum,
  1409. });
  1410. },
  1411. //重点在这里
  1412. handleChange(file, fileList) {
  1413. file.name = this.tableName + "." + file.name.split(".")[1];
  1414. fileList.forEach((item) => {
  1415. item.name = this.tableName + "." + file.name.split(".")[1];
  1416. });
  1417. let newFile = new File(
  1418. [file],
  1419. this.tableName + "." + file.name.split(".")[1]
  1420. ); //创建出来也是不可编辑的file对象
  1421. },
  1422. // 提交上传文件
  1423. submitFileForm() {
  1424. this.$refs.upload.submit();
  1425. },
  1426. // 弹窗新增的数
  1427. addListHandler(val) {
  1428. this.addLists.push(...val);
  1429. },
  1430. // 绑定弹窗Dialog确定按钮
  1431. btnComfirm() {
  1432. // let data = {
  1433. // addListMap:[],
  1434. // basicMap:{
  1435. // btnType: 10,
  1436. // tableName: this.subTableName,
  1437. // visible: true,
  1438. // },
  1439. // commMap: {},
  1440. // conditionMap: {},
  1441. // }
  1442. // // data.addListMap =
  1443. // btnCommonApi(data).then(res => {
  1444. // })
  1445. },
  1446. // 去掉表名 开头字母小写
  1447. formatField(field = "", tableName) {
  1448. let temp = field.replace(tableName, "");
  1449. return toUnderline(temp[0].toLowerCase() + temp.slice(1));
  1450. },
  1451. // 处理 动态表单 动态表格 新增数据
  1452. getInsertBatchData(values, data) {
  1453. if (Object.keys(values.batch).length == 0) return data;
  1454. let tableName = Object.keys(values.batch)[0];
  1455. data.basicMap.tableName = tableName;
  1456. data.addListMap = values.batch[tableName].map((item) => {
  1457. delete item.key;
  1458. return item;
  1459. });
  1460. return data;
  1461. },
  1462. // 添加插入的数据
  1463. addInsertData(insertMap, result, res) {
  1464. result.addListMap.forEach((i) => {
  1465. insertMap.forEach((j) => {
  1466. i[j.fieldName?.split(".")[1]] = res.find(
  1467. (k) => k.tableName == j.tableName
  1468. )?.data[j.relaField.split(".")[1]];
  1469. });
  1470. });
  1471. },
  1472. // 处理 动态表单 动态表格 修改数据
  1473. getEditBatchData(values, data) {},
  1474. // 处理 表单组 含有动态表格 新增数据
  1475. getFormGroupBatchData(values, index, result) {
  1476. let tableName = Object.keys(values.data.batch)[0];
  1477. let res = {
  1478. basicMap: {
  1479. tableName,
  1480. },
  1481. addListMap: [],
  1482. };
  1483. let { formItem, relateFormItem } = values;
  1484. res.addListMap = values.data.batch[tableName].map((item) => {
  1485. delete item.key;
  1486. item[formItem.split(".")[1]] =
  1487. result[0].data[relateFormItem.split(".")[1]]; //将主表单的关联值赋值给从表单
  1488. return item;
  1489. });
  1490. return res;
  1491. },
  1492. //提交编辑结果按钮回调
  1493. async editConfirmHandler() {
  1494. if (this.$refs.addFromRef && this.formType == "dragForm") {
  1495. this.$refs.addFromRef
  1496. .getData()
  1497. .then(async (values) => {
  1498. for (const key of Object.keys(values)) {
  1499. values[key] =
  1500. typeof values[key] == "undefined" ? "" : values[key];
  1501. }
  1502. let data = {
  1503. basicMap: {
  1504. tableName: this.tableName,
  1505. // btnKey: btnData.btnKey,
  1506. btnKey: this.currentBtnData.btnKey,
  1507. },
  1508. addListMap: [values],
  1509. conditionMap: {},
  1510. commMap: {},
  1511. btnParametersMap: {},
  1512. };
  1513. if (this.currentBtnData.btnParams) {
  1514. let btnParams =
  1515. JSON.parse(this.currentBtnData.btnParams)?.commonFieldData ||
  1516. [];
  1517. let conditionData =
  1518. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1519. // let
  1520. btnParams.forEach((item) => {
  1521. data.btnParametersMap[item.fieldName.split(".")[1]] =
  1522. item.fieldValue
  1523. ? item.fieldValue
  1524. : this.currentRow[
  1525. camelCase(item.fieldName.replace(".", "_"))
  1526. ];
  1527. });
  1528. conditionData.forEach((item) => {
  1529. data.conditionMap[item.fieldName.split(".")[1]] =
  1530. item.fieldValue
  1531. ? item.fieldValue
  1532. : this.currentRow[
  1533. camelCase(item.fieldName.replace(".", "_"))
  1534. ];
  1535. });
  1536. }
  1537. if (Object.keys(this.defaultValue).length) {
  1538. //修改
  1539. // data.conditionMap[this.templateInfo.template?.primaryKey] =
  1540. // this.defaultValue[this.templateInfo.template?.primaryKey];
  1541. if (values.batch) {
  1542. //动态表单的修改
  1543. data = this.getEditBatchData(values, data);
  1544. } else {
  1545. Object.keys(values).map((k) => {
  1546. data.commMap[k] = values[k];
  1547. });
  1548. }
  1549. data.basicMap.btnType = this.currentBtnData.btnType;
  1550. data.basicMap.visible = true;
  1551. } else {
  1552. // 处理 动态表格
  1553. // start
  1554. if (values.batch) {
  1555. data = this.getInsertBatchData(values, data);
  1556. }
  1557. // end
  1558. //新增
  1559. data.basicMap.btnType = "INSERT";
  1560. data.basicMap.visible = true;
  1561. }
  1562. try {
  1563. let res = await btnCommonApi(data);
  1564. if (res.code == 200) {
  1565. this.$message.success("操作成功");
  1566. } else {
  1567. this.$message.error("网络异常,请稍后再试");
  1568. }
  1569. } catch (error) {
  1570. this.$message.error("网络异常,请稍后再试");
  1571. }
  1572. // ⚠️⚠️⚠️调用查询组件中查询函数-》handleQuery回调getList();
  1573. this.$refs.mychild.handleQuery();
  1574. this.defaultValue = {};
  1575. this.open = false;
  1576. })
  1577. .catch((res) => {
  1578. console.log("res", res);
  1579. this.$modal.msgError("表单校验失败,请规范填写数据");
  1580. });
  1581. } else if (this.formType == "dragFormGroup") {
  1582. //无布局
  1583. let promiseArray = [];
  1584. if (this.isLayout) {
  1585. let res = await this.$refs.formGroupLayoutRef.getFormData();
  1586. res.forEach((item) => {
  1587. promiseArray.push(...item);
  1588. });
  1589. } else {
  1590. promiseArray = this.FormNameList.map((item) => {
  1591. return this.$refs.formGroupRef?.getFormData(item);
  1592. });
  1593. }
  1594. Promise.all(promiseArray).then(async (res) => {
  1595. // console.log("res", res);
  1596. // return;
  1597. // 获取到所有表单数据
  1598. let mainForm = res.find((item) => item.isMainForm);
  1599. let mainFormData = mainForm.data;
  1600. let data = {
  1601. basicMap: {
  1602. tableName: this.tableName,
  1603. // btnKey: btnData.btnKey,
  1604. btnKey: this.currentBtnData.btnKey,
  1605. BpmRunNodeFormDateVo: {},
  1606. },
  1607. conditionMap: {},
  1608. commMap: {},
  1609. btnParametersMap: {},
  1610. };
  1611. let btnParams =
  1612. JSON.parse(this.currentBtnData.btnParams)?.commonFieldData || [];
  1613. let conditionData =
  1614. JSON.parse(this.currentBtnData.btnParams)?.conditionData || [];
  1615. Object.keys(mainFormData).map((k) => {
  1616. data.commMap[k] = mainFormData[k];
  1617. });
  1618. btnParams.forEach((item) => {
  1619. data.btnParametersMap[item.fieldName.split(".")[1]] =
  1620. item.fieldValue
  1621. ? item.fieldValue
  1622. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1623. });
  1624. conditionData.forEach((item) => {
  1625. data.conditionMap[item.fieldName.split(".")[1]] = item.fieldValue
  1626. ? item.fieldValue
  1627. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1628. });
  1629. data.basicMap.btnType = this.currentBtnData.btnType;
  1630. data.basicMap.visible = true;
  1631. let payLoad = {
  1632. insertCommonEntityList: [],
  1633. updateCommonEntityList: [],
  1634. deleteCommonEntityList: [],
  1635. };
  1636. if (this.currentBtnData.btnType == "UPDATE") {
  1637. // 准备删除数据
  1638. res.forEach((item, index) => {
  1639. let result = {};
  1640. if (index == 0) {
  1641. //主表 主表不会是动态表格
  1642. result = {
  1643. basicMap: {
  1644. tableName: item.tableName,
  1645. },
  1646. commMap: {
  1647. ...item.data,
  1648. },
  1649. conditionMap: {},
  1650. };
  1651. //主表条件
  1652. let conditionData =
  1653. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1654. conditionData.forEach((item) => {
  1655. result.conditionMap[item.fieldName.split(".")[1]] =
  1656. item.fieldValue
  1657. ? item.fieldValue
  1658. : this.currentRow[
  1659. camelCase(item.fieldName.replace(".", "_"))
  1660. ];
  1661. });
  1662. payLoad.updateCommonEntityList.push(result);
  1663. } else {
  1664. // 从表条件
  1665. let {
  1666. formItem,
  1667. relateFormItem,
  1668. formType,
  1669. defaultValue,
  1670. tableName,
  1671. } = item;
  1672. if (formType == "batch") {
  1673. //动态表格的修改
  1674. let result = {};
  1675. // 准备删除数据
  1676. if (defaultValue[tableName]?.length) {
  1677. let ids = defaultValue[tableName].map((item) => item.id);
  1678. result = {
  1679. basicMap: {
  1680. tableName,
  1681. },
  1682. conditionMap: {
  1683. id: ids,
  1684. },
  1685. };
  1686. payLoad.deleteCommonEntityList.push(result);
  1687. }
  1688. // 准备新增数据
  1689. result = this.getFormGroupBatchData(item, index, res);
  1690. if (item.insertMap.length) {
  1691. this.addInsertData(item.insertMap, result, res);
  1692. }
  1693. // 去除未修改数据的自动生成字段
  1694. this.removeAutoField(result);
  1695. payLoad.insertCommonEntityList.push(result);
  1696. } else {
  1697. //普通表格的修改
  1698. result = {
  1699. basicMap: {
  1700. tableName: item.tableName,
  1701. },
  1702. commMap: {
  1703. ...item.data,
  1704. },
  1705. conditionMap: {},
  1706. };
  1707. let fieldName = formItem.split(".")[1];
  1708. let value =
  1709. this.currentRow[
  1710. camelCase(relateFormItem.replace(".", "_"))
  1711. ];
  1712. result.conditionMap[fieldName] = value;
  1713. payLoad.updateCommonEntityList.push(result);
  1714. }
  1715. }
  1716. });
  1717. } else if (this.currentBtnData.btnType == "INSERT") {
  1718. // 新增
  1719. let uuid = uuidv4().replace("-", "");
  1720. payLoad.insertCommonEntityList = res.map((item, index) => {
  1721. let result = {};
  1722. if (item.data.batch) {
  1723. //动态表格
  1724. result = this.getFormGroupBatchData(item, index, res);
  1725. } else {
  1726. result = {
  1727. basicMap: {
  1728. tableName: item.tableName,
  1729. },
  1730. addListMap: [
  1731. {
  1732. ...item.data,
  1733. },
  1734. ],
  1735. };
  1736. let { formItem, relateFormItem } = item;
  1737. if (index == 0) {
  1738. //主表单
  1739. // 添加新增数据的关联条件
  1740. let mainFormKey = mainForm.data[formItem.split(".")[1]];
  1741. if (mainFormKey) {
  1742. result.addListMap[0][formItem.split(".")[1]] = mainFormKey;
  1743. } else {
  1744. mainForm.data[formItem.split(".")[1]] = uuid;
  1745. result.addListMap[0][formItem.split(".")[1]] = uuid;
  1746. }
  1747. } else {
  1748. //子表单
  1749. result.addListMap[0][formItem.split(".")[1]] =
  1750. mainForm.data[relateFormItem?.split(".")[1]];
  1751. }
  1752. }
  1753. if (item.insertMap?.length) {
  1754. this.addInsertData(item.insertMap, result, res);
  1755. }
  1756. return result;
  1757. });
  1758. } else if (this.currentBtnData.btnType == "INITIATED") {
  1759. // 按照单独的表单投产逻辑收集主表单数据
  1760. // let mainFormData = res[0].data;//主表单数据
  1761. // payLoad = {
  1762. // basicMap: {
  1763. // tableName: this.tableName,
  1764. // // btnKey: btnData.btnKey,
  1765. // btnKey: this.currentBtnData.btnKey,
  1766. // },
  1767. // addListMap: mainFormData,
  1768. // conditionMap: {},
  1769. // commMap: {},
  1770. // btnParametersMap: {},
  1771. // };
  1772. // if (this.currentBtnData.btnParams) {
  1773. // let btnParams =
  1774. // JSON.parse(this.currentBtnData.btnParams)?.commonFieldData ||
  1775. // [];
  1776. // let conditionData =
  1777. // JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1778. // // let
  1779. // btnParams.forEach((item) => {
  1780. // payLoad.btnParametersMap[item.fieldName.split(".")[1]] =
  1781. // item.fieldValue
  1782. // ? item.fieldValue
  1783. // : this.currentRow[
  1784. // camelCase(item.fieldName.replace(".", "_"))
  1785. // ];
  1786. // });
  1787. // conditionData.forEach((item) => {
  1788. // payLoad.conditionMap[item.fieldName.split(".")[1]] =
  1789. // item.fieldValue
  1790. // ? item.fieldValue
  1791. // : this.currentRow[
  1792. // camelCase(item.fieldName.replace(".", "_"))
  1793. // ];
  1794. // });
  1795. // }
  1796. // if (Object.keys(this.defaultValue).length) {
  1797. // // data.conditionMap[this.templateInfo.template?.primaryKey] =
  1798. // // this.defaultValue[this.templateInfo.template?.primaryKey];
  1799. // Object.keys(mainFormData).map((k) => {
  1800. // data.commMap[k] = mainFormData[k];
  1801. // });
  1802. // data.basicMap.btnType = this.currentBtnData.btnType;
  1803. // data.basicMap.visible = true;
  1804. // } else {
  1805. // data.basicMap.btnType = "INSERT";
  1806. // data.basicMap.visible = true;
  1807. // }
  1808. // 添加表单组数据处理逻辑
  1809. payLoad.updateCommonEntityList = res.map((item, index) => {
  1810. let result = {
  1811. basicMap: {
  1812. tableName: item.tableName,
  1813. },
  1814. commMap: {
  1815. ...item.data,
  1816. },
  1817. conditionMap: {},
  1818. };
  1819. if (index == 0) {
  1820. //主表条件
  1821. let conditionData =
  1822. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1823. conditionData.forEach((item) => {
  1824. result.conditionMap[item.fieldName.split(".")[1]] =
  1825. item.fieldValue
  1826. ? item.fieldValue
  1827. : this.currentRow[
  1828. camelCase(item.fieldName.replace(".", "_"))
  1829. ];
  1830. });
  1831. } else {
  1832. // 从表条件
  1833. let { formItem, relateFormItem } = item;
  1834. let fieldName = formItem.split(".")[1];
  1835. let value =
  1836. this.currentRow[camelCase(relateFormItem.replace(".", "_"))];
  1837. result.conditionMap[fieldName] = value;
  1838. }
  1839. return result;
  1840. });
  1841. }
  1842. data.basicMap.BpmRunNodeFormDateVo = payLoad;
  1843. // return;
  1844. try {
  1845. let res = await btnCommonApi(data);
  1846. if (res.code == 200) {
  1847. this.$message.success("操作成功");
  1848. // ⚠️⚠️⚠️调用查询组件中查询函数-》handleQuery回调getList();
  1849. this.$refs.mychild.handleQuery();
  1850. this.defaultValue = {};
  1851. this.open = false;
  1852. } else {
  1853. this.$message.error("网络异常,请稍后再试");
  1854. }
  1855. } catch (error) {
  1856. this.$message.error("网络异常,请稍后再试");
  1857. }
  1858. });
  1859. } else {
  1860. // 没有绑定表单
  1861. let data = {
  1862. basicMap: {
  1863. tableName: this.tableName,
  1864. // btnKey: btnData.btnKey,
  1865. btnKey: this.currentBtnData.btnKey,
  1866. btnType: this.currentBtnData.btnType,
  1867. visible: true,
  1868. },
  1869. addListMap: [],
  1870. conditionMap: {},
  1871. commMap: {},
  1872. btnParametersMap: {},
  1873. };
  1874. if (this.currentBtnData.btnParams) {
  1875. let btnParams =
  1876. JSON.parse(this.currentBtnData.btnParams)?.commonFieldData || [];
  1877. let conditionData =
  1878. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  1879. conditionData.forEach((item) => {
  1880. data.conditionMap[item.fieldName.split(".")[1]] = item.fieldValue
  1881. ? item.fieldValue
  1882. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1883. });
  1884. btnParams.forEach((item) => {
  1885. data.btnParametersMap[item.fieldName.split(".")[1]] =
  1886. item.fieldValue
  1887. ? item.fieldValue
  1888. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  1889. });
  1890. }
  1891. // data.basicMap.btnType = this.currentBtnData.btnType;
  1892. // data.basicMap.visible = true;
  1893. try {
  1894. let res = await btnCommonApi(data);
  1895. if (res.code == 200) {
  1896. this.$message.success("操作成功");
  1897. } else {
  1898. this.$message.error("网络异常,请稍后再试");
  1899. }
  1900. } catch (error) {
  1901. this.$message.error("网络异常,请稍后再试");
  1902. }
  1903. // ⚠️⚠️⚠️调用查询组件中查询函数-》handleQuery回调getList();
  1904. this.$refs.mychild.handleQuery();
  1905. this.defaultValue = {};
  1906. this.open = false;
  1907. }
  1908. },
  1909. // 去除多余字段
  1910. removeAutoField(result) {
  1911. result.addListMap.forEach((item) => {
  1912. this.theAutoField.forEach((field) => {
  1913. delete item[field];
  1914. });
  1915. });
  1916. },
  1917. // 使用提交数据类型的按钮获取数据
  1918. tempSubBtn(getData) {
  1919. getData()
  1920. .then((values) => {})
  1921. .catch(() => {});
  1922. },
  1923. // 判断是否生效行样式
  1924. cellStyle({ row, column, rowIndex, columnIndex }) {
  1925. let rowStyleList = this.styleList.filter((item) => item.styleType == 0);
  1926. if (!rowStyleList.length) return "";
  1927. let mainTableName = this.templateInfo.querySql.tableAlias; //主表名
  1928. for (let i = 0; i < rowStyleList.length; i++) {
  1929. let item = rowStyleList[i];
  1930. let judgeRes = this.determineCondition(item.styleCondtion, row);
  1931. if (judgeRes) {
  1932. let styleCode = JSON.parse(item.styleCode);
  1933. return `background-color:${styleCode.rowBgColor};`;
  1934. }
  1935. }
  1936. },
  1937. // 获取生效条件组结果
  1938. determineCondition(conditionStr, row) {
  1939. let conditionList = JSON.parse(conditionStr);
  1940. if (!conditionList.length) return false;
  1941. return conditionList.every((item) => this.judgeOneCondition(item, row));
  1942. },
  1943. // 获取单个判断条件结果
  1944. judgeOneCondition(item, row) {
  1945. let fullField = camelCase(item.tableName + "_" + item.fieldName);
  1946. switch (item.condition) {
  1947. case 1:
  1948. return row[fullField] > item.flagValue;
  1949. case 2:
  1950. return row[fullField] < item.flagValue;
  1951. case 3:
  1952. return row[fullField] == item.flagValue;
  1953. case 4:
  1954. return row[fullField] >= item.flagValue;
  1955. case 5:
  1956. return row[fullField] <= item.flagValue;
  1957. default:
  1958. return true; //默认为true
  1959. }
  1960. },
  1961. // 设置表格字段样式
  1962. async setFieldStyleData(tableList) {
  1963. let fieldConditionList = this.styleList.filter(
  1964. (item) => item.styleType == 1 || item.styleType == 2
  1965. );
  1966. if (!fieldConditionList.length) return tableList;
  1967. let res = await this.setDictStyleData();
  1968. this.dictStyleObj = res.reduce((pre, item) => {
  1969. return {
  1970. ...pre,
  1971. ...item,
  1972. };
  1973. }, {});
  1974. tableList.forEach((row) => {
  1975. // if (!row.styleFieldObj) row.styleFieldObj = {};
  1976. for (let i = 0; i < fieldConditionList.length; i++) {
  1977. let item = fieldConditionList[i];
  1978. if (item.styleType == 1) {
  1979. //字段样式
  1980. let judgeRes = this.determineCondition(item.styleCondtion, row);
  1981. if (judgeRes) {
  1982. let styleCode = JSON.parse(item.styleCode);
  1983. if (!row.styleFieldObj) row.styleFieldObj = {};
  1984. row.styleFieldObj[item.styleField] = {
  1985. styleType: item.styleType,
  1986. fieldStyleType: styleCode.fieldStyleType,
  1987. fontColor: styleCode.fontColor,
  1988. isTagFullBg: styleCode.isTagFullBg,
  1989. tagType: styleCode.tagType,
  1990. };
  1991. // row.styleField = item.styleField; //样式生效字段
  1992. // row.styleType = item.styleType; //0:行样式 1:字段样式 2:字典样式
  1993. // row.fieldStyleType = styleCode.fieldStyleType; //0:文本 1:标签
  1994. // row.fontColor = styleCode.fontColor;
  1995. // row.isTagFullBg = styleCode.isTagFullBg; //true/false
  1996. // row.tagType = styleCode.tagType; //string
  1997. }
  1998. } else {
  1999. //字典样式
  2000. let dicStyle = this.dictStyleObj[item.styleField]?.find((dict) => {
  2001. return dict.dictValue == row[item.styleField];
  2002. });
  2003. if (dicStyle) {
  2004. if (!row.styleFieldObj) row.styleFieldObj = {};
  2005. row.styleFieldObj[item.styleField] = dicStyle; //设置该字段应该显示的字典样式
  2006. row.styleFieldObj[item.styleField].styleType = 2;
  2007. }
  2008. }
  2009. }
  2010. });
  2011. return tableList;
  2012. },
  2013. //设置表格字典相关数据
  2014. setDictStyleData() {
  2015. let fieldConditionList = this.styleList.filter(
  2016. (item) => item.styleType == 2
  2017. );
  2018. if (!fieldConditionList.length) return;
  2019. let PromiseList = fieldConditionList.map((item) => {
  2020. return new Promise((resolve, reject) => {
  2021. let temp = {};
  2022. try {
  2023. listData({
  2024. isEnablePaging: false,
  2025. dictType: item.styleCondtion,
  2026. }).then((res) => {
  2027. temp[item.styleField] = res.rows;
  2028. resolve(temp);
  2029. });
  2030. } catch (error) {
  2031. reject(error);
  2032. }
  2033. });
  2034. });
  2035. return Promise.all(PromiseList);
  2036. },
  2037. // 页面跳转
  2038. routerHandler(btnData, type) {
  2039. let { url, commonFieldData } = JSON.parse(btnData.btnParams);
  2040. let tempArr = [];
  2041. if (commonFieldData) {
  2042. let queryArr = JSON.parse(commonFieldData);
  2043. tempArr = queryArr.map((item) => {
  2044. let key = this.formatField(item.fieldName, camelCase(this.tableName));
  2045. let value = item.fieldValue
  2046. ? item.fieldValue
  2047. : this.currentRow[item.fieldName];
  2048. return key + "=" + value;
  2049. });
  2050. }
  2051. if (tempArr.length) {
  2052. url += "?" + tempArr.join("&");
  2053. }
  2054. if (type == "INNERLINK") {
  2055. this.$router.push(url);
  2056. } else {
  2057. window.open("http://" + url, "_blank");
  2058. }
  2059. },
  2060. // 操作列回调
  2061. excuteHandler(btnData, row) {
  2062. console.log("btnData, row", btnData, row);
  2063. let { btnType, btnParams, btnFormType } = btnData;
  2064. this.formType = btnFormType;
  2065. this.currentBtnData = btnData;
  2066. this.currentRow = JSON.parse(JSON.stringify(row));
  2067. // 无表单
  2068. if (
  2069. btnFormType == "noNeed" &&
  2070. btnType != "UPDATE" &&
  2071. btnType != "INNERLINK" &&
  2072. btnType != "OUTLINK"
  2073. ) {
  2074. this.noNeedHandler(btnData, row);
  2075. return;
  2076. }
  2077. if (btnData.btnFormType == "dragFormGroup") {
  2078. this.times = 1; //重置请求次数
  2079. this.formListShow = false;
  2080. }
  2081. switch (btnType) {
  2082. case "INNERLINK": //内链
  2083. this.routerHandler(btnData, btnType);
  2084. break;
  2085. case "OUTLINK":
  2086. this.routerHandler(btnData, btnType);
  2087. break;
  2088. case "UPDATE":
  2089. this.handleUpdate(row, btnData);
  2090. break;
  2091. case "EXECUTE":
  2092. this.handleUpdate(row, btnData);
  2093. break;
  2094. case "INITIATED":
  2095. this.handleUpdate(row, btnData);
  2096. break;
  2097. case "DELETE":
  2098. this.handleDelete(row, btnData);
  2099. break;
  2100. case "INSERT":
  2101. this.handleUpdate(row, btnData);
  2102. break;
  2103. case "PRINT":
  2104. this.printHandler(btnData, row);
  2105. break;
  2106. case "TOAST":
  2107. this.showToast(btnData, row);
  2108. break;
  2109. default:
  2110. break;
  2111. }
  2112. },
  2113. // 消息提示回调
  2114. showToast(btnData, row) {
  2115. let { btnFormKey, btnFormType } = btnData;
  2116. this.toastMsg = btnFormKey;
  2117. this.toastType = btnFormType;
  2118. this.toastShow = true;
  2119. },
  2120. // 顶部按钮回调
  2121. topBtnHandler(btnData) {
  2122. let { btnType, btnParams, btnFormType } = btnData;
  2123. let row = this.selection[0] || [];
  2124. this.formType = btnFormType;
  2125. this.currentBtnData = btnData;
  2126. this.currentRow = JSON.parse(JSON.stringify(row));
  2127. // 无表单
  2128. if (
  2129. btnFormType == "noNeed" &&
  2130. btnType != "IMPORT" &&
  2131. btnType != "EXPORT" &&
  2132. btnType != "DELETE" &&
  2133. btnType != "UPDATE" &&
  2134. btnType != "INSERT" &&
  2135. btnType != "PRINT" &&
  2136. btnType != "INNERLINK" &&
  2137. btnType != "OUTLINK"
  2138. ) {
  2139. this.noNeedHandler(btnData, row);
  2140. return;
  2141. }
  2142. if (btnData.btnFormType == "dragFormGroup") {
  2143. this.times = 1; //重置请求次数
  2144. this.formListShow = false;
  2145. }
  2146. switch (btnType) {
  2147. case "INNERLINK":
  2148. this.routerHandler(btnData, btnType);
  2149. break;
  2150. case "OUTLINK":
  2151. this.routerHandler(btnData, btnType);
  2152. break;
  2153. case "UPDATE":
  2154. this.handleUpdate(row, btnData);
  2155. break;
  2156. case "EXECUTE":
  2157. this.handleUpdate(row, btnData);
  2158. break;
  2159. case "INITIATED":
  2160. this.handleUpdate(row, btnData);
  2161. break;
  2162. case "DELETE":
  2163. this.handleBatchDelete();
  2164. break;
  2165. case "INSERT":
  2166. this.handleUpdate(row, btnData);
  2167. break;
  2168. case "IMPORT":
  2169. this.upload.open = true;
  2170. break;
  2171. case "EXPORT":
  2172. this.handleExport();
  2173. break;
  2174. case "PRINT":
  2175. this.printHandler(btnData, row);
  2176. break;
  2177. default:
  2178. break;
  2179. }
  2180. },
  2181. // 打印回调
  2182. printHandler(btnData, row) {
  2183. // 发送请求获取打印数据
  2184. this.printShow = true;
  2185. this.printHtml = printHtml;
  2186. this.$nextTick(() => {
  2187. this.$refs.detailTable.innerHTML = this.printHtml;
  2188. });
  2189. },
  2190. // 确认打印回调
  2191. confirmPrint() {
  2192. document.body.innerHTML = document.getElementById("printDom").innerHTML =
  2193. this.printHtml;
  2194. window.print(); //打印
  2195. window.location.reload();
  2196. return false;
  2197. },
  2198. noNeedHandler(btnData, row) {
  2199. this.$modal
  2200. .confirm("是否确认执行该操作?")
  2201. .then(async () => {
  2202. // 获取默认参数
  2203. let data = {
  2204. basicMap: {
  2205. tableName: this.tableName,
  2206. // btnKey: btnData.btnKey,
  2207. btnKey: this.currentBtnData.btnKey,
  2208. },
  2209. conditionMap: {},
  2210. commMap: {},
  2211. btnParametersMap: {},
  2212. };
  2213. if (this.currentBtnData.btnParams) {
  2214. let conditionData =
  2215. JSON.parse(this.currentBtnData.btnParams).conditionData || [];
  2216. // let
  2217. let commonData =
  2218. JSON.parse(this.currentBtnData.btnParams).commonFieldData || [];
  2219. conditionData.forEach((item) => {
  2220. data.conditionMap[item.fieldName.split(".")[1]] = item.fieldValue
  2221. ? item.fieldValue
  2222. : this.currentRow[camelCase(item.fieldName.replace(".", "_"))];
  2223. });
  2224. commonData.forEach((item) => {
  2225. data.btnParametersMap[item.fieldName.split(".")[1]] =
  2226. item.fieldValue
  2227. ? item.fieldValue
  2228. : this.currentRow[
  2229. camelCase(item.fieldName.replace(".", "_"))
  2230. ];
  2231. });
  2232. }
  2233. data.basicMap.btnType = this.currentBtnData.btnType;
  2234. data.basicMap.visible = true;
  2235. try {
  2236. let res = await btnCommonApi(data);
  2237. if (res.code == 200) {
  2238. this.$message.success(res.msg);
  2239. } else {
  2240. console.error(res.msg);
  2241. this.$message.error("网络异常,请稍后再试");
  2242. }
  2243. } catch (error) {
  2244. console.error(error);
  2245. this.$message.error("网络异常,请稍后再试");
  2246. }
  2247. })
  2248. .then(() => {
  2249. // 调用子组件查询方法 目的是携带上子组件中的查询参数
  2250. this.$refs.mychild.pageList();
  2251. // this.$modal.msgSuccess("操作成功");
  2252. })
  2253. .catch(() => {});
  2254. },
  2255. // k-form-build表单变化回调
  2256. formChangeHandler(value, label) {},
  2257. },
  2258. };
  2259. </script>
  2260. <style scoped lang="scss">
  2261. .dialog_loading {
  2262. display: flex;
  2263. justify-content: center;
  2264. width: 100%;
  2265. font-size: 30px;
  2266. }
  2267. ::v-deep .el-dialog:not(.is-fullscreen) {
  2268. min-width: 610px !important;
  2269. }
  2270. .success {
  2271. color: #67c23a;
  2272. }
  2273. .error {
  2274. color: #f56c6c;
  2275. }
  2276. .warning {
  2277. color: #e6a23c;
  2278. }
  2279. .info {
  2280. color: #909399;
  2281. }
  2282. </style>