centerManage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <section >
  3. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  4. <el-form :inline="true">
  5. <el-form-item :label="user.timeType.customDegreeName + '管理'">
  6. </el-form-item>
  7. <!-- <el-link type="primary" :underline="false" @click="intoCenterRatio" class="tanjia">批量导入{{user.timeType.customDegreeName}}</el-link>
  8. <el-link icon="el-icon-circle-plus-outline" type="primary" :underline="false" class="tanjia" @click="addNewSubProject()">添加{{user.timeType.customDegreeName}}</el-link>
  9. <el-link type="primary" :underline="false" @click="batchDelete" class="tanjia">批量删除{{user.timeType.customDegreeName}}</el-link> -->
  10. <el-link type="primary" :underline="false" @click="batchDelete" class="tanjia">批量删除</el-link>
  11. <el-link type="primary" :underline="false" @click="outoCenterRatio" class="tanjia">数据导出</el-link>
  12. <el-link type="primary" :underline="false" @click="intoCenterRatio" class="tanjia">批量导入</el-link>
  13. <el-link icon="el-icon-circle-plus-outline" type="primary" :underline="false" class="tanjia" @click="addNewSubProject()">新增</el-link>
  14. </el-form>
  15. </el-col>
  16. <el-table :data="subProjectList" highlight-current-row v-loading="listLoading" :height="heightDoms" style="width: 100%;" @selection-change="selectionChange">
  17. <el-table-column type="selection"></el-table-column>
  18. <el-table-column prop="id" width="200" label="序号" align="center">
  19. <template slot-scope="scope" >
  20. {{scope.$index + 1}}
  21. </template>
  22. </el-table-column>
  23. <el-table-column prop="name" label="名称" min-width="120" show-overflow-tooltip></el-table-column>
  24. <el-table-column prop="projects" label="相关项目" min-width="180" show-overflow-tooltip></el-table-column>
  25. <el-table-column label="操作" width="170">
  26. <template slot-scope="scope" >
  27. <el-button size="small" type="primary" @click="addNewSubProject(scope.row)">编辑</el-button>
  28. <el-button size="small" type="danger" @click="deleteSubPro(scope.row)">删除</el-button>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. <el-dialog title="新增/修改维护数据" v-if="addSubProject" :visible.sync="addSubProject" :close-on-click-modal="false" customClass="customWidth" width="500px">
  33. <el-form ref="form2" :model="addfm" :rules="ruless" label-width="100px">
  34. <el-form-item label="名称" prop="name">
  35. <el-input v-model="addfm.name" placeholder="请输入名称" clearable></el-input>
  36. </el-form-item>
  37. </el-form>
  38. <div slot="footer" class="dialog-footer">
  39. <el-button @click.native="addSubProject = false">取消</el-button>
  40. <el-button type="primary" @click="submitInsertSubProject" :loading="addLoading">提交</el-button>
  41. </div>
  42. </el-dialog>
  43. <!-- 导入结果说明 -->
  44. <el-dialog title="导入结果" v-if="showImportResult" :visible.sync="showImportResult" customClass="customWidth" width="500px">
  45. <div>
  46. <span>{{importResultMsg}}</span>
  47. </div>
  48. <span slot="footer" class="dialog-footer">
  49. <el-button type="primary" @click="showImportResult=false">确定</el-button>
  50. </span>
  51. </el-dialog>
  52. <el-dialog :title="`导入${user.timeType.customDegreeName}数据`" v-if="intoCenterDialog" :visible.sync="intoCenterDialog" customClass="customWidth" width="500px">
  53. <p>1. 下载
  54. <el-link type="primary" style="margin-left:5px;" :underline="false" href="./upload/研究中心导入模板.xlsx" :download="`${user.timeType.customDegreeName}导入模板.xlsx`">{{user.timeType.customDegreeName}}导入模板.xlsx</el-link>
  55. </p>
  56. <!-- <p>2. 填写excel模板,请确保模板中的项目和人员已添加到系统中。</p> -->
  57. <p style="display: flex;justify-content: center;padding:1em 0">
  58. <el-upload ref="upload" action="#" :limit="1" :http-request="batchImportData" :show-file-list="false">
  59. <el-button type="primary" :underline="false" :loading="importingData">开始导入</el-button>
  60. </el-upload>
  61. </p>
  62. </el-dialog>
  63. </section>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. user: JSON.parse(sessionStorage.getItem("user")),
  70. subProjectList: [],//子项目列表
  71. listLoading: false,
  72. addfm: {
  73. name: '',
  74. },
  75. addSubProject: false,
  76. ruless: {
  77. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  78. },
  79. heightDoms: document.documentElement.clientHeight - 140,
  80. intoCenterDialog:false,
  81. importingData: false,
  82. importResultMsg:null,
  83. showImportResult:false,
  84. selectionArr: []
  85. };
  86. },
  87. methods: {
  88. // 批量删除
  89. selectionChange(selection){
  90. this.selectionArr = selection
  91. console.log(this.selectionArr);
  92. },
  93. batchDelete(){
  94. if(this.selectionArr.length == 0){
  95. this.$message('请选择要删除的' + this.user.timeType.customDegreeName + '数据')
  96. return
  97. }else{
  98. let nametext = ''
  99. for(let i in this.selectionArr){
  100. nametext += this.selectionArr[i].name + '、'
  101. }
  102. nametext = nametext.substring(0,nametext.length - 1)
  103. this.$confirm('确定要批量删除' + this.user.timeType.customDegreeName + '数据:' + nametext + '\u3000吗?','删除',{
  104. confirmButtonText: '确定',
  105. cancelButtonText: '取消',
  106. type: 'warning'
  107. }).then(()=>{
  108. let batchIds = ''
  109. for(let m in this.selectionArr){
  110. batchIds += this.selectionArr[m].id + ','
  111. }
  112. batchIds = batchIds.substring(0,batchIds.length - 1)
  113. this.http.post('/report-extra-degree/batchDelete',{
  114. batchIds
  115. },res => {
  116. if(res.code == 'ok'){
  117. this.$message({
  118. message: '删除成功',
  119. type: 'success'
  120. })
  121. this.getSub()
  122. }else {
  123. this.$message({
  124. message: res.msg,
  125. type: 'error'
  126. })
  127. }
  128. },err => {
  129. this.$message({
  130. message: err,
  131. type: 'error'
  132. })
  133. })
  134. })
  135. }
  136. },
  137. intoCenterRatio(){
  138. this.intoCenterDialog=true;
  139. },
  140. outoCenterRatio(){
  141. this.http.post('/report-extra-degree/exportData',{},
  142. res => {
  143. if(res.code == 'ok'){
  144. let filePath = res.data;
  145. let fileName = filePath.split('/upload/')[1]
  146. const a = document.createElement('a'); // 创建a标签
  147. a.setAttribute('download', fileName);// download属性
  148. a.setAttribute('href', filePath);// href链接
  149. a.click(); //自执行点击事件
  150. a.remove();
  151. }else{
  152. this.$message({
  153. message: res.msg,
  154. type: 'error'
  155. })
  156. }
  157. },err => {
  158. this.$message({
  159. message: err,
  160. type: 'error'
  161. })
  162. })
  163. },
  164. batchImportData(item) {
  165. //首先判断文件类型
  166. let str = item.file.name.split(".");
  167. let format = str[str.length - 1];
  168. if (format != "xls" && format != "xlsx") {
  169. this.$message({
  170. message: "请选择.xls或.xlsx文件",
  171. type: "error"
  172. });
  173. } else {
  174. this.importingData = true;
  175. let formData = new FormData();
  176. formData.append("file", item.file);
  177. this.http.uploadFile('/report-extra-degree/importData', formData,
  178. res => {
  179. this.$refs.upload.clearFiles();
  180. this.importingData = false;
  181. this.showImportResult = true;
  182. if (res.code == "ok") {
  183. //换成弹出框,以免有人等了半天回来啥也没看到
  184. this.importResultMsg = "成功导入/更新"+res.data+"条客户数据。"+(res.msg?res.msg:"");
  185. this.getSub();
  186. } else {
  187. this.importResultMsg = "导入失败:"+res.msg;
  188. }
  189. },
  190. error => {
  191. this.$refs.upload.clearFiles();
  192. this.importingData = false;
  193. this.$message({
  194. message: error,
  195. type: "error"
  196. });
  197. });
  198. }
  199. },
  200. getSub() {
  201. this.listLoading = true;
  202. this.http.post('/report-extra-degree/getAll ',{withProjects:1},
  203. res => {
  204. this.listLoading = false;
  205. if (res.code == "ok") {
  206. console.log(res, '看看')
  207. this.subProjectList = res.data
  208. } else {
  209. this.$message({
  210. message: res.msg,
  211. type: "error"
  212. });
  213. }
  214. },
  215. error => {
  216. this.listLoading = false;
  217. this.$message({
  218. message: error,
  219. type: "error"
  220. });
  221. }
  222. );
  223. },
  224. addNewSubProject(subProject) {
  225. // console.log(1234)
  226. // if (subProject == null) {
  227. // this.addForm = {projectId: this.currentProject.id, level:1}
  228. // }
  229. // else {
  230. // this.addForm = subProject;
  231. // }
  232. if(subProject) {
  233. this.addfm.name = subProject.name
  234. this.addfm.id = subProject.id
  235. }
  236. this.addSubProject = true;
  237. },
  238. deleteSubPro(subProject) {
  239. this.$confirm("确定要删除这条" + subProject.name + "数据吗?","删除", {
  240. confirmButtonText: "确定",
  241. cancelButtonText: "取消",
  242. type: "warning"
  243. })
  244. .then(() => {
  245. this.listLoading = true;
  246. this.http.post('/report-extra-degree/delete',{
  247. id: subProject.id
  248. },
  249. res => {
  250. this.listLoading = false;
  251. if (res.code == "ok") {
  252. this.$message({
  253. message: "删除成功",
  254. type: "success"
  255. });
  256. this.getSub();
  257. } else {
  258. this.$message({
  259. message: res.msg,
  260. type: "error"
  261. });
  262. }
  263. },
  264. error => {
  265. this.listLoading = false;
  266. this.$message({
  267. message: error,
  268. type: "error"
  269. });
  270. }
  271. );
  272. })
  273. .catch(() => {});
  274. },
  275. submitInsertSubProject() {
  276. this.$refs.form2.validate(valid => {
  277. if (valid) {
  278. var slp = this.addfm
  279. this.http.post('/report-extra-degree/addOrMod',slp,
  280. res => {
  281. this.listLoading = false;
  282. if (res.code == "ok") {
  283. this.$message({
  284. message: '成功',
  285. type: "success"
  286. });
  287. this.addfm = {name: ''}
  288. this.addSubProject = false
  289. this.getSub()
  290. } else {
  291. this.$message({
  292. message: res.msg,
  293. type: "error"
  294. });
  295. }
  296. },
  297. error => {
  298. this.listLoading = false;
  299. this.$message({
  300. message: error,
  301. type: "error"
  302. });
  303. }
  304. );
  305. }
  306. })
  307. },
  308. },
  309. created() {
  310. this.getSub()
  311. },
  312. mounted() {
  313. }
  314. };
  315. </script>
  316. <style lang="scss" scoped>
  317. .addNode {
  318. cursor:pointer;
  319. }
  320. .addNode:hover {
  321. color:#20a0ff;
  322. }
  323. .panel {
  324. padding:30px 15px ;box-shadow: 0 2px 4px rgba(3, 3, 3, 0.12), 0 0 6px rgba(0, 0, 0, .04);
  325. }
  326. .sample {
  327. margin-top:30px;
  328. color: #999;
  329. }
  330. .tip {
  331. margin-left:10px; color:gray;
  332. }
  333. .tanjia {
  334. float: right;
  335. box-sizing: border-box;
  336. margin: 10px 28px;
  337. }
  338. </style>
  339. <style>
  340. .el-tooltip__popper{
  341. max-width: 600px;
  342. }
  343. </style>