ProjectTemplate.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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="fileList"
  68. :disabled="!hasPermit"
  69. :on-success="
  70. (response, file, fileList) =>
  71. uploadSuccess(response, file, fileList, scope.row)
  72. "
  73. :on-error="uploadError"
  74. :show-file-list="false"
  75. :auto-upload="true"
  76. :multiple="false"
  77. >
  78. <el-button
  79. size="mini"
  80. icon="el-icon-upload"
  81. :disabled="!hasPermit"
  82. >上传</el-button
  83. >
  84. </el-upload>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="下载">
  88. <template slot-scope="scope">
  89. <el-button
  90. size="mini"
  91. icon="el-icon-download"
  92. :disabled="checkEmptyStr(scope.row.fileName)"
  93. @click="download(scope.row);"
  94. >下载
  95. </el-button>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="预览">
  99. <template slot-scope="scope">
  100. <el-button
  101. size="mini"
  102. icon="el-icon-view"
  103. :disabled="checkEmptyStr(scope.row.fileUrl)"
  104. @click="preview(scope.row);"
  105. >预览
  106. </el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. </div>
  111. </div>
  112. </section>
  113. </template>
  114. <script>
  115. import { PRINT_API } from "@/constants/constants";
  116. import {} from "../constants/constants.js";
  117. import { mapState } from "vuex";
  118. import { checkEmptyStr, checkEmptyNumber } from "../utils/common.js";
  119. export default {
  120. data() {
  121. return {
  122. formSearch: {
  123. orgId: "",
  124. examId: ""
  125. },
  126. curUserRole: {},
  127. hasPermit: false,
  128. loading: false,
  129. tableData: [],
  130. orgList: [],
  131. examList: [],
  132. templateForm: {
  133. orgId: "",
  134. examId: "",
  135. templateType: "",
  136. fileUrl: ""
  137. },
  138. fileList: [],
  139. uploadAction: PRINT_API + "/common/upload",
  140. uploadHeaders: {
  141. key: "",
  142. token: ""
  143. },
  144. rules: {}
  145. };
  146. },
  147. methods: {
  148. searchRecords() {
  149. /* 查询记录列表 */
  150. let orgId = this.formSearch.orgId;
  151. if (checkEmptyNumber(orgId)) {
  152. this.$notify({
  153. message: "请选择学校!",
  154. type: "warning"
  155. });
  156. return;
  157. }
  158. let examId = this.formSearch.examId;
  159. if (checkEmptyNumber(examId)) {
  160. this.$notify({
  161. message: "请选择考试!",
  162. type: "warning"
  163. });
  164. return;
  165. }
  166. this.loading = true;
  167. let url = PRINT_API + "/project/template/" + orgId + "/" + examId;
  168. this.$http.post(url, this.formSearch).then(
  169. response => {
  170. this.tableData = response.data;
  171. this.loading = false;
  172. },
  173. error => {
  174. console.log(error);
  175. this.loading = false;
  176. }
  177. );
  178. },
  179. selectDefault() {
  180. if (this.orgList.length > 0) {
  181. let firstOrgId = this.orgList[0].orgId;
  182. this.formSearch.orgId = firstOrgId;
  183. this.loadExamList(firstOrgId);
  184. }
  185. },
  186. loadOrgList() {
  187. /* 查询学校列表 */
  188. let url = PRINT_API + "/printing/project/org/list";
  189. this.$http.post(url).then(
  190. response => {
  191. this.orgList = response.data;
  192. this.selectDefault();
  193. },
  194. error => {
  195. console.log(error);
  196. }
  197. );
  198. },
  199. loadExamList(orgId) {
  200. /* 查询考试列表 */
  201. this.formSearch.examId = "";
  202. this.examList = [];
  203. this.tableData = [];
  204. if (checkEmptyNumber(orgId)) {
  205. return;
  206. }
  207. let url = PRINT_API + "/printing/project/exam/list?orgId=" + orgId;
  208. this.$http.post(url).then(response => {
  209. this.examList = response.data;
  210. if (this.examList.length > 0) {
  211. this.formSearch.examId = this.examList[0].examId;
  212. this.searchRecords();
  213. }
  214. });
  215. },
  216. uploadSuccess(response, file, fileList, row) {
  217. /* 上传模板 */
  218. if (response.code == "PRT-000200") {
  219. this.templateForm.orgId = this.formSearch.orgId;
  220. this.templateForm.examId = this.formSearch.examId;
  221. this.templateForm.templateType = row.templateType;
  222. this.templateForm.fileUrl = response.data;
  223. this.$http
  224. .post(PRINT_API + "/project/template/save", this.templateForm)
  225. .then(
  226. () => {
  227. this.$notify({
  228. message: "上传模板成功!",
  229. type: "success"
  230. });
  231. this.searchRecords();
  232. },
  233. () => {
  234. this.$notify({
  235. message: "上传模板失败!",
  236. type: "error"
  237. });
  238. }
  239. );
  240. }
  241. },
  242. uploadError(response) {
  243. console.log(response);
  244. this.$notify({
  245. message: "上传文件失败!",
  246. type: "error"
  247. });
  248. },
  249. preview(row) {
  250. /* 预览模板 */
  251. let url = row.fileUrl;
  252. if (!url) {
  253. this.$notify({
  254. message: "当前模板不存在!",
  255. type: "warning"
  256. });
  257. return;
  258. }
  259. window.open(url);
  260. },
  261. download(row) {
  262. /* 下载模板 */
  263. let filePath = row.fileName;
  264. if (!filePath) {
  265. this.$notify({
  266. message: "当前模板不存在!",
  267. type: "warning"
  268. });
  269. return;
  270. }
  271. let url = PRINT_API + "/common/download?filePath=" + filePath;
  272. window.location.href = url;
  273. },
  274. checkEmptyStr: checkEmptyStr
  275. },
  276. computed: {
  277. ...mapState({ user: state => state.user })
  278. },
  279. created() {
  280. this.loadOrgList();
  281. this.loadUserRole(this.user);
  282. if (this.curUserRole.isSuperLeader || this.curUserRole.isPM) {
  283. this.hasPermit = true;
  284. } else {
  285. this.hasPermit = false;
  286. }
  287. this.uploadHeaders = {
  288. key: this.user.key,
  289. token: this.user.token
  290. };
  291. }
  292. };
  293. </script>
  294. <style scoped>
  295. .page {
  296. margin-top: 10px;
  297. }
  298. .pull-right {
  299. float: right;
  300. }
  301. .pull-left {
  302. float: left;
  303. }
  304. .w220 {
  305. width: 220px;
  306. }
  307. </style>