ProjectTemplate.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <section class="content" style="margin-top: 20px;">
  3. <div class="box box-info">
  4. <!-- 正文信息 -->
  5. <div class="box-body">
  6. <el-form
  7. :model="formSearch"
  8. :inline="true"
  9. label-position="right"
  10. label-width="100px"
  11. >
  12. <el-form-item label="学校">
  13. <el-select
  14. v-model="formSearch.orgId"
  15. placeholder="请选择"
  16. clearable
  17. @change="loadExamList(formSearch.orgId)"
  18. >
  19. <el-option
  20. v-for="item in orgList"
  21. :label="item.orgName"
  22. :value="item.orgId"
  23. :key="item.orgId"
  24. ></el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="考试">
  28. <el-select
  29. v-model="formSearch.examId"
  30. @change="searchRecords"
  31. placeholder="请选择"
  32. >
  33. <el-option
  34. v-for="item in examList"
  35. :label="item.examName"
  36. :value="item.examId"
  37. :key="item.examId"
  38. ></el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button
  43. size="small"
  44. type="primary"
  45. icon="el-icon-search"
  46. @click="searchRecords"
  47. >查询
  48. </el-button>
  49. </el-form-item>
  50. </el-form>
  51. <!-- 数据列表 -->
  52. <el-table
  53. v-loading="loading"
  54. :data="tableData"
  55. element-loading-text="数据加载中"
  56. style="width:100%;"
  57. border
  58. >
  59. <el-table-column label="序号" type="index" width="50">
  60. </el-table-column>
  61. <el-table-column label="类别" prop="typeName" />
  62. <el-table-column label="上传">
  63. <template slot-scope="scope">
  64. <el-upload
  65. :action="uploadAction"
  66. :headers="uploadHeaders"
  67. :file-list="uploadFileList"
  68. :disabled="!hasPermit"
  69. :before-upload="file => beforeUpload(file, scope.row)"
  70. :on-success="
  71. (response, file, fileList) =>
  72. uploadSuccess(response, file, fileList, scope.row)
  73. "
  74. :on-error="uploadError"
  75. :show-file-list="false"
  76. :auto-upload="true"
  77. :multiple="false"
  78. >
  79. <el-button
  80. size="mini"
  81. icon="el-icon-upload"
  82. :disabled="!hasPermit"
  83. >上传</el-button
  84. >
  85. </el-upload>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="下载">
  89. <template slot-scope="scope">
  90. <el-button
  91. size="mini"
  92. icon="el-icon-download"
  93. :disabled="checkEmptyStr(scope.row.fileName)"
  94. @click="download(scope.row)"
  95. >下载
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. </div>
  101. </div>
  102. </section>
  103. </template>
  104. <script>
  105. import { PRINT_API } from "@/constants/constants";
  106. import {} from "../constants/constants.js";
  107. import { mapState } from "vuex";
  108. import { checkEmptyStr, checkEmptyNumber } from "../utils/common.js";
  109. export default {
  110. data() {
  111. return {
  112. formSearch: {
  113. orgId: "",
  114. examId: ""
  115. },
  116. curUserRole: {},
  117. hasPermit: false,
  118. loading: false,
  119. tableData: [],
  120. orgList: [],
  121. examList: [],
  122. templateForm: {
  123. orgId: "",
  124. examId: "",
  125. templateType: "",
  126. fileUrl: ""
  127. },
  128. uploadFileList: [],
  129. uploadAction: PRINT_API + "/common/upload",
  130. uploadHeaders: {
  131. key: "",
  132. token: ""
  133. },
  134. rules: {}
  135. };
  136. },
  137. methods: {
  138. searchRecords() {
  139. /* 查询记录列表 */
  140. let orgId = this.formSearch.orgId;
  141. if (checkEmptyNumber(orgId)) {
  142. this.$notify({
  143. title: "提示",
  144. message: "请选择学校!",
  145. type: "warning"
  146. });
  147. return;
  148. }
  149. let examId = this.formSearch.examId;
  150. if (checkEmptyNumber(examId)) {
  151. this.$notify({
  152. title: "提示",
  153. message: "请选择考试!",
  154. type: "warning"
  155. });
  156. return;
  157. }
  158. this.loading = true;
  159. let url = PRINT_API + "/project/template/" + orgId + "/" + examId;
  160. this.$http.post(url, this.formSearch).then(
  161. response => {
  162. this.tableData = response.data;
  163. this.loading = false;
  164. },
  165. error => {
  166. console.log(error);
  167. this.loading = false;
  168. }
  169. );
  170. },
  171. selectDefault() {
  172. if (this.orgList.length > 0) {
  173. let firstOrgId = this.orgList[0].orgId;
  174. this.formSearch.orgId = firstOrgId;
  175. this.loadExamList(firstOrgId);
  176. }
  177. },
  178. loadOrgList() {
  179. /* 查询学校列表 */
  180. let url = PRINT_API + "/printing/project/org/list";
  181. this.$http.post(url).then(
  182. response => {
  183. this.orgList = response.data;
  184. this.selectDefault();
  185. },
  186. error => {
  187. console.log(error.response);
  188. // ignore
  189. }
  190. );
  191. },
  192. loadExamList(orgId) {
  193. /* 查询考试列表 */
  194. this.formSearch.examId = "";
  195. this.examList = [];
  196. this.tableData = [];
  197. if (checkEmptyNumber(orgId)) {
  198. return;
  199. }
  200. let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
  201. this.$http.post(url).then(response => {
  202. this.examList = response.data;
  203. if (this.examList.length > 0) {
  204. this.formSearch.examId = this.examList[0].examId;
  205. this.searchRecords();
  206. }
  207. });
  208. },
  209. beforeUpload(file, row) {
  210. const isLimit = file.size / 1024 / 1024 < 50;
  211. if (!isLimit) {
  212. this.$notify({
  213. title: "提示",
  214. message: "上传文件大小不能超过50MB!",
  215. type: "warning"
  216. });
  217. return false;
  218. }
  219. let index = file.name.lastIndexOf(".");
  220. let ext = file.name.substring(index).toLowerCase();
  221. console.log("templateType:" + row.templateType + " ext:" + ext);
  222. if (row.templateType == 1 || row.templateType == 2) {
  223. /* 考生数据表(1)、考场数据表(2) */
  224. if (!new RegExp("(.xls|.xlsx)$").test(ext)) {
  225. this.$notify({
  226. title: "提示",
  227. message: "请选择后缀为.xls或.xlsx的文件!",
  228. type: "warning"
  229. });
  230. return false;
  231. }
  232. } else if (row.templateType == 8) {
  233. /* 试卷袋样式(8) */
  234. if (!new RegExp("(.jpg|.png)$").test(ext)) {
  235. this.$notify({
  236. title: "提示",
  237. message: "请选择后缀为.jpg或.png的文件!",
  238. type: "warning"
  239. });
  240. return false;
  241. }
  242. } else {
  243. /* 卷袋贴模板(3)、签到表模板(4)、常规题卡模板(5)、特殊题卡模板(6)、备份卷贴模板(7) */
  244. if (!new RegExp("(.pdf)$").test(ext)) {
  245. this.$notify({
  246. title: "提示",
  247. message: "请选择后缀为.pdf的文件!",
  248. type: "warning"
  249. });
  250. return false;
  251. }
  252. }
  253. return true;
  254. },
  255. uploadSuccess(response, file, fileList, row) {
  256. /* 上传模板 */
  257. if (response.code == "PRT-000200") {
  258. this.templateForm.orgId = this.formSearch.orgId;
  259. this.templateForm.examId = this.formSearch.examId;
  260. this.templateForm.templateType = row.templateType;
  261. this.templateForm.fileUrl = response.data;
  262. this.$http
  263. .post(PRINT_API + "/project/template/save", this.templateForm)
  264. .then(
  265. () => {
  266. this.$notify({
  267. title: "提示",
  268. message: "上传模板成功!",
  269. type: "success"
  270. });
  271. this.searchRecords();
  272. },
  273. error => {
  274. console.log(error.response);
  275. this.$notify({
  276. title: "错误",
  277. type: "error",
  278. message: error.response.data.desc
  279. });
  280. }
  281. );
  282. }
  283. },
  284. uploadError(response) {
  285. console.log(response);
  286. this.$notify({
  287. title: "错误",
  288. message: "上传文件失败!",
  289. type: "error"
  290. });
  291. },
  292. preview(row) {
  293. /* 预览模板 */
  294. let url = row.fileUrl;
  295. if (!url) {
  296. this.$notify({
  297. title: "提示",
  298. message: "当前模板不存在!",
  299. type: "warning"
  300. });
  301. return;
  302. }
  303. window.open(url);
  304. },
  305. download(row) {
  306. /* 下载模板 */
  307. let filePath = row.fileName;
  308. if (!filePath) {
  309. this.$notify({
  310. title: "提示",
  311. message: "当前模板不存在!",
  312. type: "warning"
  313. });
  314. return;
  315. }
  316. let url = PRINT_API + "/common/download?filePath=" + filePath;
  317. window.location.href = url;
  318. },
  319. checkEmptyStr: checkEmptyStr
  320. },
  321. computed: {
  322. ...mapState({ user: state => state.user })
  323. },
  324. created() {
  325. this.loadOrgList();
  326. this.loadUserRole(this.user);
  327. if (this.curUserRole.isSuperLeader || this.curUserRole.isPM) {
  328. this.hasPermit = true;
  329. } else {
  330. this.hasPermit = false;
  331. }
  332. this.uploadHeaders = {
  333. key: this.user.key,
  334. token: this.user.token
  335. };
  336. }
  337. };
  338. </script>
  339. <style scoped>
  340. .page {
  341. margin-top: 10px;
  342. }
  343. .pull-right {
  344. float: right;
  345. }
  346. .pull-left {
  347. float: left;
  348. }
  349. .w220 {
  350. width: 220px;
  351. }
  352. </style>