setInputTPT.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div>
  3. <div class="setInputcss">
  4. <el-row :span="24">
  5. <el-col :span="3.3" style="line-height: 40px">
  6. 元素坐标:
  7. </el-col>
  8. <el-col :span="18">
  9. <avue-input v-model="htmlData.name" placeholder="请输入内容" :disabled='true'></avue-input>
  10. </el-col>
  11. </el-row>
  12. <el-row :span="24">
  13. <el-col :span="3.3" style="line-height: 40px">
  14. 文本格式:
  15. </el-col>
  16. <el-col :span="18">
  17. <el-select style="width:100%;" v-model="from.type" clearable placeholder="请选择">
  18. <el-option v-for="item in kjtype" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey">
  19. </el-option>
  20. </el-select>
  21. </el-col>
  22. </el-row>
  23. <el-row :span="24" v-if="from.type==='date'||from.type==='daterange'">
  24. <el-col :span="3.8" style="line-height: 40px">
  25. 日期:
  26. </el-col>
  27. <el-col :span="8">
  28. <el-checkbox-group v-model="checkDateList" style="margin-top: 10px;margin-left: 10px;" size="large" @change="changeDate">
  29. <el-checkbox v-for="item in yearList" :label="item.value">{{ item.name }}</el-checkbox>
  30. </el-checkbox-group>
  31. </el-col>
  32. <el-col :span="3.8" style="line-height: 40px">
  33. 分隔符:
  34. </el-col>
  35. <el-col :span="8" style="margin-left: 10px;">
  36. <el-select
  37. style="width:100%;"
  38. v-model="from.divide_y"
  39. clearable
  40. placeholder="请选择"
  41. >
  42. <el-option
  43. label="文本"
  44. value="文本"
  45. >
  46. </el-option>
  47. <el-option
  48. label="-"
  49. value="-"
  50. >
  51. </el-option>
  52. <el-option
  53. label="/"
  54. value="/"
  55. >
  56. </el-option>
  57. </el-select>
  58. </el-col>
  59. </el-row>
  60. <el-row :span="24" v-if="from.type==='date'||from.type==='daterange'">
  61. <el-col :span="3.8" style="line-height: 40px">
  62. 时间:
  63. </el-col>
  64. <el-col :span="8">
  65. <el-checkbox-group v-model="checkTimeist" style="margin-top: 10px;margin-left: 10px;" size="large" @change="changeTime">
  66. <el-checkbox v-for="item in timeList" :label="item.value">{{ item.name }}</el-checkbox>
  67. </el-checkbox-group>
  68. </el-col>
  69. <el-col :span="3.8" style="line-height: 40px">
  70. 分隔符:
  71. </el-col>
  72. <el-col :span="8" style="margin-left: 10px;">
  73. <el-select
  74. style="width:100%;"
  75. v-model="from.divide_h"
  76. clearable
  77. placeholder="请选择"
  78. >
  79. <el-option
  80. label="文本"
  81. value="文本"
  82. >
  83. </el-option>
  84. <el-option
  85. label=":"
  86. value=":"
  87. >
  88. </el-option>
  89. <el-option
  90. label="/"
  91. value="/"
  92. >
  93. </el-option>
  94. </el-select>
  95. </el-col>
  96. </el-row>
  97. <el-row :span="24" v-if="from.type==='daterange'">
  98. <el-col :span="3.3" style="line-height: 40px">
  99. 中间分隔符:
  100. </el-col>
  101. <el-col :span="18" style="margin-left: 10px;">
  102. <el-select
  103. style="width:100%;"
  104. v-model="from.divide_c"
  105. clearable
  106. placeholder="请选择"
  107. >
  108. <el-option
  109. label="至"
  110. value='至'
  111. >
  112. </el-option>
  113. <el-option
  114. label="-"
  115. value="-"
  116. >
  117. </el-option>
  118. <el-option
  119. label="~"
  120. value="~"
  121. >
  122. </el-option>
  123. </el-select>
  124. </el-col>
  125. </el-row>
  126. </div>
  127. <!-- 添加框 -->
  128. <div style="border: 1px dotted rgb(187, 187, 187);box-sizing: border-box;padding: 0px 15px;"
  129. class="martop20 marbottom10" v-show="from.type == 'select' || from.type == 'radio' || from.type == 'checkbox'">
  130. <table class="table" width='100%' border='1px' cellpadding='2px' bordercolor="#E5E5E5">
  131. <thead cellpadding='2px' height='40px'>
  132. <tr>
  133. <th width='15%'>序号</th>
  134. <th width='65%'>默认值</th>
  135. <th width='20%'>操作</th>
  136. </tr>
  137. </thead>
  138. <tbody height='36px'>
  139. <tr v-for="(item, key) in setInputTable" :key="key">
  140. <td align="center">{{ key + 1 }}</td>
  141. <td>
  142. <el-input v-model="setInputTable[key].dictValue" size="mini" placeholder="请输入内容"></el-input>
  143. </td>
  144. <td align="center">
  145. <el-link type="warning" @click="deleteTable(key)">删除</el-link>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. <div class="martop20 flexEnd marbottom10"><i
  151. style="padding-bottom: 10px;color:rgb(10, 134, 217);font-size:24px;cursor: pointer;" class="el-icon-circle-plus"
  152. @click="addTable()"></i></div>
  153. </div>
  154. <el-row style="text-align: center">
  155. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="saveType()">保存设置</el-button>
  156. &nbsp;&nbsp;
  157. <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="saveType()">继续保存</el-button>
  158. </el-row>
  159. </div>
  160. </template>
  161. <script>
  162. import { dictionary, saveInput, getColByTabId } from "@/api/manager/AdjustForm";
  163. import { getExcelHtml } from '@/api/exctab/excelmodel'
  164. export default {
  165. props: ['pkeyId', 'htmlData'],
  166. computed: {
  167. myHtmlData: function () {
  168. return this.htmlData;
  169. }
  170. },
  171. watch: {
  172. myHtmlData: function (newV) {
  173. //console.log(newV)
  174. if (newV.type) {
  175. if (newV.type == 'checkbox') {
  176. this.from.type = 'checkbox';
  177. this.setInputTable = newV.checkLabelDatas;
  178. } else if (newV.type == 'radio') {
  179. this.from.type = 'radio';
  180. this.setInputTable = newV.radioDatas;
  181. } else if (newV.type == 'select') {
  182. this.from.type = 'select';
  183. this.setInputTable = newV.selectDatas;
  184. }
  185. } else {
  186. // this.from.type = '';
  187. this.setInputTable = [];
  188. }
  189. }
  190. },
  191. data() {
  192. return {
  193. elementName: [],
  194. kjtype: [],//框架类型
  195. from: {
  196. type: '',
  197. value: '',
  198. divide_c:'至'
  199. },
  200. setInputTable: [],//数据体
  201. disabled: false,
  202. yearList:[
  203. {name:'年',value:'YYYY',sort:1},
  204. {name:'月',value:'MM',sort:2},
  205. {name:'日',value:'DD',sort:3},
  206. ],
  207. yearSort:[],
  208. TimeSort:[],
  209. timeList:[
  210. {name:'时',value:'HH',sort:4},
  211. {name:'分',value:'mm',sort:5},
  212. {name:'秒',value:'ss',sort:6},
  213. ],
  214. checkDateList: [],
  215. checkTimeist:[],
  216. }
  217. },
  218. methods: {
  219. addTable() {//添加table表
  220. this.setInputTable.push({ dictValue: '' })
  221. },
  222. deleteTable(key) {//删除数据
  223. this.setInputTable.splice(key, 1)
  224. },
  225. saveType() {//保存设置按钮
  226. if (this.htmlData.tr === '' || this.htmlData.td === '') {
  227. this.$message({
  228. type: "warning",
  229. message: "请先选择元素"
  230. });
  231. return;
  232. }
  233. this.disabled = true
  234. if (this.from.type) {
  235. let ks = false
  236. if (this.from.type == 'select' | this.from.type == 'radio' | this.from.type == 'checkbox') {
  237. if (this.setInputTable) {
  238. this.setInputTable.forEach(val => {
  239. if (!val.dictValue) {
  240. ks = true
  241. }
  242. })
  243. }
  244. if (ks) {
  245. this.$message({
  246. type: "error",
  247. message: "请填写完枚举值"
  248. });
  249. this.disabled = false
  250. } else {
  251. this.saveInput({
  252. trIndex: this.htmlData.tr,
  253. tdIndex: this.htmlData.td,
  254. tableId: this.pkeyId,
  255. textId: this.from.type,
  256. type: '1',
  257. textInfo: this.setInputTable
  258. })
  259. }
  260. } else if(this.from.type == 'daterange'|this.from.type == 'date'){
  261. let c = this.yearSort.concat(this.TimeSort);//c=[1,2,3,4,5,6]
  262. console.log(c,'c');
  263. let isAdd=this.IncreasingFn(c)
  264. console.log(isAdd,'isAdd');
  265. if(isAdd){
  266. let dateFormat=[]
  267. this.yearList.forEach((ele)=>{
  268. this.checkDateList.forEach((ele1)=>{
  269. if(ele.value===ele1){
  270. dateFormat.push(
  271. ele
  272. )
  273. }
  274. })
  275. })
  276. this.timeList.forEach((ele)=>{
  277. this.checkTimeist.forEach((ele1)=>{
  278. if(ele.value===ele1){
  279. dateFormat.push(
  280. ele
  281. )
  282. }
  283. })
  284. })
  285. if(this.from.divide_y){
  286. dateFormat.push({
  287. divide_y:this.from.divide_y
  288. })
  289. }
  290. if(this.from.divide_h){
  291. dateFormat.push({
  292. divide_h:this.from.divide_h
  293. })
  294. }
  295. if(this.from.divide_c&&this.from.type==='daterange'){
  296. dateFormat.push({
  297. divide_c:this.from.divide_c
  298. })
  299. }
  300. console.log(dateFormat,'dateFormat');
  301. this.saveInput({
  302. trIndex: this.htmlData.tr,
  303. tdIndex: this.htmlData.td,
  304. tableId: this.pkeyId,
  305. textId: this.from.type,
  306. type: '1',
  307. textInfo: this.setInputTable,
  308. dateFormat:dateFormat
  309. })
  310. }else{
  311. this.$message.warning('请按年月日时分秒顺序选择,不要跨越选择')
  312. }
  313. }
  314. else {
  315. this.saveInput({
  316. trIndex: this.htmlData.tr,
  317. tdIndex: this.htmlData.td,
  318. tableId: this.pkeyId,
  319. textId: this.from.type,
  320. type: '1',
  321. textInfo: []
  322. })
  323. }
  324. } else {
  325. this.disabled = false
  326. this.$message({
  327. type: "warning",
  328. message: "请选择文本格式"
  329. });
  330. }
  331. },
  332. async dictionary() {//获取文本类型接口
  333. const { data: res } = await dictionary()
  334. console.log(res);
  335. if (res.code === 200) {
  336. this.kjtype = res.data
  337. }
  338. },
  339. async saveInput(da) {//保存设置文本接口
  340. const { data: res } = await saveInput(da)
  341. console.log(res);
  342. this.checkDateList=[]
  343. this.checkTimeist=[]
  344. this.from.divide_y=''
  345. this.from.divide_h=''
  346. this.yearSort=[]
  347. this.TimeSort=[]
  348. if (res.code == 200) {
  349. this.setInputTable = []
  350. this.disabled = false
  351. this.getExcelHtml()
  352. }
  353. },
  354. // async getColByTabId () {//获取字段信息
  355. // const { data: res } = await getColByTabId({ tabId: this.pkeyId })
  356. // console.log(res);
  357. // if (res.code === 200) {
  358. // this.elementName = res.data
  359. // }
  360. // },
  361. async getExcelHtml() {
  362. const { data: res } = await getExcelHtml({ pkeyId: this.pkeyId })
  363. console.log(res);
  364. if (res.code === 200) {
  365. this.htmlData.name = ''
  366. // this.from.type = ''
  367. this.htmlData.tr = ''
  368. this.htmlData.td = ''
  369. this.setInputTable = []
  370. localStorage.setItem('excelHtml', res.data)
  371. this.$emit('cop')
  372. }
  373. },
  374. // 判断是否是是
  375. IncreasingFn(array) {
  376. let IncreasingFn = false
  377. let arrayCount = array.length - 1
  378. // console.log(arrayCount,'现在是?');
  379. for (var i = 0; i < arrayCount; i++) {
  380. let currentArr = Number(array[i]) + 1
  381. let nestArr = Number(array[i + 1])
  382. if (i < 1 == arrayCount) {
  383. console.log('执行')
  384. currentArr = Number(array[i])
  385. nestArr = Number(array[i])
  386. }
  387. if (currentArr != nestArr) {
  388. IncreasingFn = false
  389. break
  390. } else {
  391. IncreasingFn = true
  392. }
  393. }
  394. return IncreasingFn
  395. },
  396. changeDate(val){
  397. this.yearSort=[]
  398. this.yearList.forEach((ele)=>{
  399. val.forEach((ele1)=>{
  400. if(ele.value===ele1){
  401. this.yearSort.push(ele.sort)
  402. }
  403. })
  404. })
  405. },
  406. changeTime(val){
  407. this.TimeSort=[]
  408. this.timeList.forEach((ele)=>{
  409. val.forEach((ele1)=>{
  410. if(ele.value===ele1){
  411. this.TimeSort.push(ele.sort)
  412. }
  413. })
  414. })
  415. }
  416. },
  417. created() {
  418. this.dictionary() //获取文本类型接口
  419. // this.getColByTabId()
  420. },
  421. }
  422. </script>
  423. <style lang="scss" scoped>
  424. .table {
  425. margin-top: 20px;
  426. border-radius: 5px;
  427. color: #101010;
  428. font-size: 14px;
  429. }
  430. .setInputcss {
  431. width: 90%;
  432. height: 100%;
  433. }
  434. </style>