centerManage.vue 14 KB

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