form_dialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div>
  3. <!-- 表格导入-->
  4. <el-dialog v-model='showImport'
  5. append-to-body
  6. center
  7. title="数据表格导入"
  8. @close="close"
  9. width="45%">
  10. <div class='flex flex-center flex-col'>
  11. <div class="flex flex-center full-width flex-justify-start">
  12. <span class="bold mr-20">文件上传</span>
  13. <div>
  14. <uploads ref='upload' max="9" btn-text="点击进行文件上传" @before="before" @success="upload"
  15. @error='loading = false'
  16. :loading='loading'
  17. :data='dept'
  18. :action='action'
  19. accept=".xlsx"/>
  20. </div>
  21. <div>
  22. <span class='bold ml-10 mr-10'>是否是汇总表</span>
  23. <el-switch v-model='gather'/>
  24. </div>
  25. <div class='flex flex-center' v-if='gather === false'>
  26. <span class='bold ml-10 mr-10'>项目所属机构:</span>
  27. <div>
  28. <el-autocomplete
  29. v-model='deptName'
  30. clearable
  31. placeholder="快速搜索机构"
  32. prefix-icon="Search"
  33. :trigger-on-focus="false"
  34. :fetch-suggestions="querySearchDept"
  35. @select="handleSelectDept"
  36. />
  37. </div>
  38. </div>
  39. </div>
  40. <div class="flex flex-justify-start full-width">
  41. <span class="font-12 mt-10"
  42. style="color:#E24141">注意:文件格式需要为Excel表格,表格必须要有项目名称及责任单位名称两项内容,才能确保系统成功解析文件。</span>
  43. </div>
  44. </div>
  45. <el-divider/>
  46. <div class="hide-scrollbar full-width" style="height: 20vh;overflow-x: scroll" v-loading='loading'>
  47. <div v-if='attaches.length === 0' class='full-width flex flex-center '>
  48. <el-empty image-size='100'/>
  49. </div>
  50. <div class="flex flex-justify-between flex-center mt-5" v-for="item in attaches" :key="item">
  51. <span class="blue">{{ item.name }}</span>
  52. <el-icon color="#DCAE64" size="16px" @click="removeFile(item)">
  53. <CircleCloseFilled/>
  54. </el-icon>
  55. </div>
  56. </div>
  57. <div class="flex flex-center mt-20 mb-5">
  58. <base-button title="重置" type="0" icon="Refresh"/>
  59. <base-button class="ml-15" title="导入" icon="el-icon-upload" @click='importExcel'/>
  60. </div>
  61. </el-dialog>
  62. <!-- 表格导出-->
  63. <el-dialog v-model='showExport'
  64. append-to-body
  65. center
  66. @close="close"
  67. title="数据表格导出"
  68. width="75%">
  69. <div class="flex flex-col">
  70. <el-autocomplete
  71. v-model="keyWords"
  72. clearable
  73. placeholder="字段信息快速搜索"
  74. prefix-icon="Search"
  75. :trigger-on-focus="false"
  76. :fetch-suggestions="querySearch"
  77. @select="handleSelect"
  78. />
  79. <div class="flex flex-wrap flex-align-center">
  80. <div class="flex flex-center padding radius box-shadow mr-20 mt-20 pointer"
  81. v-for="(item,index) in fieldType" :key='item.id'
  82. :class="item.count > 0 ? 'box-s' : 'box'"
  83. @click='switchTab(item,index)'>
  84. <div class="flex flex-col flex-center">
  85. <span class="bold font-16 text-center">{{ item.dictValue }}</span>
  86. <div class="flex flex-center">
  87. <el-icon color="#81D0B2">
  88. <SuccessFilled/>
  89. </el-icon>
  90. <span class="grey-9 font-12">已选{{ item.count }}项目</span>
  91. </div>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <el-divider/>
  97. <div v-loading='loading' class="hide-scrollbar full-width">
  98. <!-- <div v-if='attaches.length === 0' class='full-width flex flex-center '>-->
  99. <!-- <el-empty image-size='100'/>-->
  100. <!-- </div>-->
  101. <div class="flex flex-justify-start flex-center">
  102. <span class="bold grey ml-5 ">字段选择</span>
  103. <el-checkbox class='ml-20' @change='allChange'>全 选</el-checkbox>
  104. <div class='flex flex-center' v-if='selectIndex === 2'>
  105. <div class='bold ml-10 text-right' style='width: 80px'>筛选:</div>
  106. <el-select
  107. v-model="year"
  108. clearable
  109. placeholder="选择年份"
  110. style="width: 200px"
  111. >
  112. <el-option
  113. v-for="item in years"
  114. :key="item + `年`"
  115. :label="item + `年`"
  116. :value="item"
  117. />
  118. </el-select>
  119. <el-select
  120. v-model="season"
  121. clearable
  122. class='ml-20 mr-20'
  123. placeholder="选择季度"
  124. style="width: 200px"
  125. >
  126. <el-option
  127. v-for="item in seasons"
  128. :key="item.value"
  129. :label="item.name"
  130. :value="item.value"
  131. />
  132. </el-select>
  133. <el-select
  134. v-if='season === "" '
  135. v-model="month"
  136. clearable
  137. placeholder="选择月份"
  138. style="width: 200px"
  139. >
  140. <el-option
  141. v-for="item in 12"
  142. :key="item + `月`"
  143. :label="item + `月`"
  144. :value="item"
  145. />
  146. </el-select>
  147. <el-button icon='el-icon-search' class='ml-20' type='primary' @click='search'>搜 索</el-button>
  148. <el-button icon='el-icon-delete' class='ml-20' type='primary' plain @click='resetKey'>清 空</el-button>
  149. </div>
  150. </div>
  151. <div class="flex flex-wrap" v-if='selectIndex !== -1' style="height: 300px;overflow-x: scroll">
  152. <div v-for="(item,index) in fieldType[selectIndex].params" :key='item.id'
  153. class="flex padding pointer">
  154. <el-checkbox v-model=item.checked :label="item.code" size="large" @change='change(selectIndex,index)'>
  155. {{ item.dictValue }}
  156. </el-checkbox>
  157. </div>
  158. </div>
  159. <el-empty v-else description='点击上方按钮,选择字段'/>
  160. </div>
  161. <div class="flex flex-center mt-20 mb-5">
  162. <base-button title="重置" @click='resetParams' type="0" icon="Refresh"/>
  163. <base-button class="ml-15" title="导出表格" icon="el-icon-download" @click='exportExcel'/>
  164. </div>
  165. </el-dialog>
  166. </div>
  167. </template>
  168. <script>
  169. import BaseButton from '@/components/base-button.vue'
  170. import uploads from '@/components/uploads.vue'
  171. import { useStore } from '@/store/user.js'
  172. export default {
  173. name: 'form_dialog',
  174. components: { BaseButton, uploads },
  175. setup () {
  176. const user = useStore()
  177. return { user }
  178. },
  179. props: {
  180. dialogType: {
  181. type: String,
  182. default: -1
  183. }
  184. },
  185. watch: {
  186. dialogType: {
  187. handler (val) {
  188. if (val === 0) {
  189. this.showImport = true
  190. } else if (val === 1) {
  191. this.getDict('params_type')
  192. this.showExport = true
  193. } else {
  194. this.showExport = false
  195. this.showImport = false
  196. this.loading = false
  197. this.deptName = ''
  198. this.attaches = []
  199. }
  200. },
  201. immediate: true
  202. },
  203. season: {
  204. handler (val) {
  205. if (val.length > 0) {
  206. this.month = ''
  207. }
  208. }
  209. }
  210. },
  211. data () {
  212. return {
  213. deptName: '',
  214. deptList: [],
  215. dept: null,
  216. loading: false,
  217. active: 0,
  218. checked: true,
  219. showImport: false,
  220. showExport: false,
  221. attaches: [],
  222. gather: false,
  223. action: '/api/wutong-parse-file/import-excel/v1/parse-excel',
  224. keyWords: '',
  225. code: '',
  226. fieldType: [],
  227. paramsList: [],
  228. checkList: [],
  229. selectIndex: -1,
  230. resultParams: [],
  231. inspectList: [],
  232. page: {
  233. current: 1,
  234. size: 10
  235. },
  236. years: [],
  237. year: '',
  238. seasons: [
  239. {
  240. name: '第一季度',
  241. value: 1
  242. },
  243. {
  244. name: '第二季度',
  245. value: 2
  246. },
  247. {
  248. name: '第三季度',
  249. value: 3
  250. },
  251. {
  252. name: '第四季度',
  253. value: 4
  254. }
  255. ],
  256. season: '',
  257. month: ''
  258. }
  259. },
  260. created () {
  261. this.init()
  262. },
  263. methods: {
  264. init () {
  265. const tmp = new Date().getFullYear()
  266. this.year = tmp
  267. for (let i = 0; i < tmp - 2018; i++) {
  268. const res = Number.parseInt(tmp) - i
  269. this.years.push(res)
  270. }
  271. },
  272. /**
  273. * 获取督查情况
  274. */
  275. getInspects (status) {
  276. const data = { status }
  277. this.$api.inspect.list(Object.assign(this.page, data)).then(res => {
  278. if (res.code === 200) {
  279. console.log(res)
  280. }
  281. })
  282. },
  283. getDict (code) {
  284. this.$api.common.dicList({ code }).then(res => {
  285. if (res.code === 200) {
  286. if (code === 'inspect_type') {
  287. this.inspectList = res.data
  288. this.getInspects(this.inspectList[0].dictKey)
  289. } else {
  290. const tmps = res.data.map(e => {
  291. e.isSelect = false
  292. e.count = 0
  293. e.parmas = []
  294. return e
  295. })
  296. this.fieldType = tmps
  297. }
  298. }
  299. })
  300. },
  301. close () {
  302. this.$emit('close')
  303. },
  304. upload (res) {
  305. this.attaches = res.fileList
  306. this.$message.success('操作成功')
  307. this.showImport = false
  308. this.loading = false
  309. this.deptName = ''
  310. this.close()
  311. },
  312. before (files) {
  313. this.attaches = files
  314. },
  315. removeFile (item) {
  316. this.attaches = this.attaches.filter(sub => sub.uid !== item.uid)
  317. },
  318. switchTab (item, index) {
  319. this.fieldType[index].isSelect = !this.fieldType[index].isSelect
  320. this.selectIndex = index
  321. if (index === 2) {
  322. this.$api.params.paramsList({
  323. type: this.fieldType[this.selectIndex].dictKey,
  324. year: this.year,
  325. season: this.season,
  326. month: this.month
  327. }).then(res => {
  328. if (res.code === 200) {
  329. this.parseList(res.data.records, index)
  330. }
  331. })
  332. return
  333. }
  334. this.$api.params.getListByKey({ type: this.fieldType[index].dictKey, export: 1 }).then(res => {
  335. if (res.code === 200) {
  336. this.parseList(res.data.records, index)
  337. }
  338. })
  339. },
  340. /**
  341. * 组装数据
  342. * @param list
  343. * @param index
  344. */
  345. parseList (list, index, reset = Boolean) {
  346. const tmps = list.map(e => {
  347. e.checked = reset ? false : this.fieldType[index].params === undefined ? false : this.fieldType[index].params.findIndex(sub => sub.id === e.id) > -1
  348. return e
  349. }).filter(sub => sub.code !== 'name')
  350. if (this.fieldType[index].params !== undefined && reset === false) {
  351. const d = tmps.filter(ele => {
  352. return this.fieldType[index].params.findIndex(sub => sub.id === ele.id) === -1
  353. })
  354. for (let i = 0; i < d.length; i++) {
  355. this.fieldType[index].params.push(d[i])
  356. }
  357. } else {
  358. this.fieldType[index].params = tmps
  359. }
  360. this.fieldType[index].count = this.fieldType[index].params.filter(e => e.checked).length
  361. },
  362. importExcel () {
  363. if (this.attaches && this.attaches.length === 0) {
  364. this.$message.error('请选择要上传的文件')
  365. return
  366. }
  367. if (this.gather) {
  368. this.action = '/api//wutong-parse-file/import-excel/v1/parse-summary-excel'
  369. } else {
  370. if (this.dept === null) {
  371. this.$message.error('请选择项目所属机构')
  372. return
  373. }
  374. this.action = '/api/wutong-parse-file/import-excel/v1/parse-excel'
  375. }
  376. this.loading = true
  377. this.$message.success('正在导入,请稍后...')
  378. if (this.user.info.viewStage === 1) {
  379. this.dept = Object.assign({}, this.dept, { isReport: 1 })
  380. } else {
  381. this.dept = Object.assign({}, this.dept, { isReport: 0 })
  382. }
  383. this.$refs.upload.submit()
  384. },
  385. change (parentIndex, index) {
  386. const tmp = this.fieldType[parentIndex].params.filter(e => e.checked)
  387. this.fieldType[parentIndex].count = tmp.length
  388. for (let i = 0; i < tmp.length; i++) {
  389. this.resultParams.push(tmp[i])
  390. }
  391. },
  392. allChange (res) {
  393. this.fieldType[this.selectIndex].params = this.fieldType[this.selectIndex].params.map(sub => {
  394. sub.checked = res
  395. return sub
  396. })
  397. const tmp = this.fieldType[this.selectIndex].params.filter(e => e.checked)
  398. this.fieldType[this.selectIndex].count = tmp.length
  399. },
  400. resetParams () {
  401. this.fieldType[this.selectIndex].params = this.fieldType[this.selectIndex].params.map(sub => {
  402. sub.checked = false
  403. return sub
  404. })
  405. this.fieldType[this.selectIndex].count = 0
  406. },
  407. exportExcel () {
  408. const params = this.fieldType.filter(sub => sub.params).map(sub => sub.params)
  409. const tmps = [].concat.apply([], params)
  410. const tmpsList = tmps.filter(sub => sub.checked)
  411. if (tmpsList && tmpsList.length > 0) {
  412. const result = tmpsList.map(sub => sub.code).join(',')
  413. this.loading = true
  414. this.$emit('export', 'name,' + result)
  415. } else {
  416. this.$message.error('未选择任何字段进行导出')
  417. }
  418. this.attaches = []
  419. },
  420. querySearchDept (key, cb) {
  421. if (key && key.length === 0) {
  422. return
  423. }
  424. setTimeout(() => {
  425. const parentId = [0, 2].includes(this.user.info.viewStage) ? this.user.info.parentDeptId : this.user.info.deptId
  426. this.$api.system.getDeptLazy({ deptName: key, parentId }).then(res => {
  427. if (res.code === 200) {
  428. const tmp = res.data.map(sub => {
  429. const item = { value: sub.deptName, label: sub.deptName, deptId: sub.id, areaCode: sub.areaCode }
  430. return item
  431. })
  432. cb(tmp)
  433. }
  434. })
  435. }, 500)
  436. },
  437. querySearch (string, cb) {
  438. if (string && string.length === 0) {
  439. return
  440. }
  441. setTimeout(() => {
  442. this.$api.params.getParamByName({ dictValue: string }).then(res => {
  443. if (res.code === 200) {
  444. const tmp = res.data.records.map(sub => {
  445. const item = { value: sub.dictValue, label: sub.dictValue }
  446. return Object.assign(sub, item)
  447. })
  448. cb(tmp)
  449. }
  450. })
  451. }, 500)
  452. },
  453. handleSelectDept (item) {
  454. this.dept = item
  455. },
  456. handleSelect (item) {
  457. const sub = item
  458. sub.search = true
  459. sub.checked = true
  460. const index = this.fieldType.findIndex(e => e.dictKey === sub.type)
  461. if (index > -1) {
  462. this.fieldType[index].count++
  463. if (this.fieldType[index].params === undefined) {
  464. this.fieldType[index].params = []
  465. this.fieldType[index].params.push(sub)
  466. } else {
  467. const subIndex = this.fieldType[index].params.findIndex(ele => ele.id === sub.id)
  468. if (subIndex > -1) {
  469. this.fieldType[index].params[subIndex].checked = true
  470. } else {
  471. this.fieldType[index].params.push(sub)
  472. }
  473. }
  474. this.$message.success(item.dictValue + '已勾选成功')
  475. this.fieldType[index].params.count = this.fieldType[index].params.filter(sub => sub.checked).length
  476. }
  477. },
  478. resetKey () {
  479. this.year = ''
  480. this.season = ''
  481. this.month = ''
  482. },
  483. search () {
  484. this.$api.params.paramsList({
  485. type: this.fieldType[this.selectIndex].dictKey,
  486. year: this.year,
  487. season: this.season,
  488. month: this.month
  489. }).then(res => {
  490. if (res.code === 200) {
  491. this.parseList(res.data.records, this.selectIndex, true)
  492. }
  493. })
  494. }
  495. }
  496. }
  497. </script>
  498. <style lang="scss" scoped>
  499. .pic {
  500. width: 196px;
  501. height: 154px;
  502. margin-top: -20px;
  503. }
  504. .box-s {
  505. border: 1px solid #AC9A7C;
  506. width: 120px;
  507. height: 50px;
  508. color: #D1A55F;
  509. }
  510. .box {
  511. width: 120px;
  512. height: 50px;
  513. border: 1px solid transparent;
  514. background: #F1F2F7;
  515. color: #707070;
  516. }
  517. </style>