CardOptionDialog.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div class="card-option-dialog">
  3. <el-dialog
  4. class="card-option-dialog"
  5. :visible.sync="modalIsShow"
  6. title="选择制卡方式"
  7. top="10vh"
  8. width="600px"
  9. :close-on-click-modal="false"
  10. :close-on-press-escape="false"
  11. append-to-body
  12. @open="visibleChange"
  13. >
  14. <div class="card-option-body">
  15. <p>请您选择创建题卡方式:</p>
  16. <p>1.自助创建:使用题卡工具自助设计题卡,操作简单,即刻生成;</p>
  17. <p>
  18. 2.申请客服制卡:由客服后台统一处理,处理完毕后您可查看或微调。
  19. </p>
  20. <div class="card-type">
  21. <el-radio-group v-model="modalForm.makeMethod">
  22. <el-radio
  23. v-for="item in cardSourceTypes"
  24. :key="item.type"
  25. :label="item.type"
  26. :disabled="item.disabled"
  27. >{{ item.name }}</el-radio
  28. >
  29. </el-radio-group>
  30. </div>
  31. <!-- card-select -->
  32. <div class="card-select" v-if="modalForm.makeMethod === 'SELECT'">
  33. <el-form
  34. ref="ModalForm"
  35. :model="modalForm"
  36. :rules="rules"
  37. label-width="90px"
  38. >
  39. <el-form-item prop="cardId" label="已选题卡:">
  40. <el-select
  41. v-model="modalForm.cardId"
  42. style="width: 300px;"
  43. placeholder="请选择"
  44. clearable
  45. >
  46. <el-option
  47. v-for="item in cards"
  48. :key="item.id"
  49. :value="item.id"
  50. :label="item.title"
  51. >
  52. </el-option>
  53. </el-select>
  54. <span class="card-view" @click="toPreview">预览</span>
  55. </el-form-item>
  56. </el-form>
  57. </div>
  58. <!-- apply-customer -->
  59. <div class="card-apply" v-if="modalForm.makeMethod === 'CUST'">
  60. <el-form
  61. ref="ApplyModalForm"
  62. :model="applyModalForm"
  63. :rules="applyRules"
  64. label-width="90px"
  65. >
  66. <el-form-item prop="title" label="题卡标题:">
  67. <el-input
  68. style="width:300px"
  69. v-model.trim="applyModalForm.title"
  70. placeholder="请输入题卡标题"
  71. ></el-input>
  72. </el-form-item>
  73. <el-form-item prop="custAttachmentId" label="上传文件:">
  74. <upload-file-view
  75. input-width="300px"
  76. :upload-url="uploadUrl"
  77. :upload-data="uploadData"
  78. :format="format"
  79. @valid-error="validError"
  80. @upload-success="uploadSuccess"
  81. ref="UploadFileView"
  82. ></upload-file-view>
  83. <p class="tips-info">
  84. 上传的文件只支持{{ format.join(",") }},大小不超过20M
  85. </p>
  86. </el-form-item>
  87. </el-form>
  88. </div>
  89. </div>
  90. <div slot="footer">
  91. <el-button type="primary" :disabled="isSubmit" @click="confirm"
  92. >确定</el-button
  93. >
  94. <el-button @click="cancel">返回</el-button>
  95. </div>
  96. </el-dialog>
  97. </div>
  98. </template>
  99. <script>
  100. import { cardForSelectList } from "../api";
  101. import { applyCustomerCard } from "../../customer/api";
  102. import { CARD_SOURCE_TYPE, COMMON_CARD_RULE_ID } from "@/constants/enumerate";
  103. import UploadFileView from "@/components/UploadFileView";
  104. const initModalForm = {
  105. examId: "",
  106. examTaskId: "",
  107. paperType: "",
  108. courseCode: "",
  109. courseName: "",
  110. cardRuleId: "",
  111. cardId: "",
  112. makeMethod: "",
  113. // 考务规则
  114. customCard: false
  115. };
  116. export default {
  117. name: "card-option-dialog-view",
  118. props: {
  119. data: {
  120. type: Object,
  121. default() {
  122. return {};
  123. }
  124. }
  125. },
  126. components: { UploadFileView },
  127. data() {
  128. return {
  129. modalIsShow: false,
  130. isSubmit: false,
  131. modalForm: { ...initModalForm },
  132. rules: {
  133. cardId: [
  134. {
  135. required: true,
  136. message: "请选择已选题卡",
  137. trigger: "change"
  138. }
  139. ]
  140. },
  141. onlySelect: false,
  142. cards: [],
  143. cardSourceTypes: [],
  144. CARD_SOURCE_TYPE,
  145. // apply-customer
  146. applyModalForm: {
  147. title: "",
  148. custAttachmentId: ""
  149. },
  150. applyRules: {
  151. title: [
  152. {
  153. required: true,
  154. message: "请输入文件标题",
  155. trigger: "change"
  156. },
  157. {
  158. message: "文件标题不能超过100个字",
  159. max: 100,
  160. trigger: "change"
  161. }
  162. ],
  163. custAttachmentId: [
  164. {
  165. required: true,
  166. message: "请上传样卷或试卷结构文件",
  167. trigger: "change"
  168. }
  169. ]
  170. },
  171. // upload
  172. format: ["pdf"],
  173. maxSize: 20 * 1024 * 1024,
  174. uploadUrl: "/api/admin/common/file/upload",
  175. uploadData: {
  176. type: "PAPER"
  177. }
  178. };
  179. },
  180. methods: {
  181. visibleChange() {
  182. this.getCardSourceTypes();
  183. this.modalForm = this.$objAssign(initModalForm, this.data);
  184. this.modalForm.makeMethod =
  185. this.data.makeMethod || this.cardSourceTypes[0].type;
  186. this.getCardList();
  187. },
  188. getCardSourceTypes() {
  189. let cardSourceTypes = [];
  190. Object.keys(CARD_SOURCE_TYPE).forEach(key => {
  191. // 自助创建 =>
  192. // 若题卡规则为专卡,命题人可即时创建专卡;
  193. // 若题卡规则为全部通卡,则不显示该制卡方式;
  194. // 申请客服制卡 =>
  195. // 若题卡规则为专卡,命题人可即时创建专卡;
  196. // 若题卡规则为全部通卡,则不显示该制卡方式;
  197. if (this.data.cardRuleId === COMMON_CARD_RULE_ID && key !== "SELECT")
  198. return;
  199. // 考务规则中未开启客服制卡时,不显示客服制卡选项
  200. if (!this.data.customCard && key === "CUST") return;
  201. cardSourceTypes.push({
  202. type: key,
  203. name: CARD_SOURCE_TYPE[key]
  204. });
  205. });
  206. this.cardSourceTypes = cardSourceTypes;
  207. },
  208. async getCardList() {
  209. // 选择已有题卡 =>
  210. // 若题卡规则为专卡,选择已有题卡时,下拉列表将显示适用的专卡和通卡;
  211. // 若题卡规则为“全部通卡”,则下拉列表中只显示适用的通卡模板;
  212. const data = await cardForSelectList({
  213. courseCode: this.modalForm.courseCode,
  214. paperType: this.modalForm.paperType,
  215. cardRuleId: this.modalForm.cardRuleId,
  216. examId: this.modalForm.examId
  217. });
  218. this.cards = data || [];
  219. },
  220. cancel() {
  221. this.modalIsShow = false;
  222. },
  223. open() {
  224. this.modalIsShow = true;
  225. },
  226. validError(errorData) {
  227. this.$message.error(errorData.message);
  228. },
  229. uploadSuccess(data) {
  230. this.$message.success("上传成功!");
  231. this.applyModalForm.custAttachmentId = data.id;
  232. this.$refs.ApplyModalForm.validateField("custAttachmentId");
  233. },
  234. async confirm() {
  235. // 客服制卡
  236. if (this.modalForm.makeMethod === "CUST") {
  237. const valid = await this.$refs.ApplyModalForm.validate().catch(
  238. () => {}
  239. );
  240. if (!valid) return;
  241. if (this.isSubmit) return;
  242. this.isSubmit = true;
  243. // 创建题卡
  244. const result = await applyCustomerCard({
  245. status: "STAGE",
  246. examTaskId: this.modalForm.examTaskId,
  247. courseCode: this.modalForm.courseCode,
  248. courseName: this.modalForm.courseName,
  249. makeMethod: "CUST",
  250. type: "CUSTOM",
  251. ...this.applyModalForm
  252. }).catch(() => {});
  253. this.isSubmit = false;
  254. if (!result) return;
  255. this.$message.success("申请成功!");
  256. this.$emit("confirm", {
  257. cardId: result,
  258. makeMethod: this.modalForm.makeMethod
  259. });
  260. this.cancel();
  261. return;
  262. }
  263. // 自主创建
  264. if (this.modalForm.makeMethod === "SELF") {
  265. this.$emit("confirm", {
  266. examTaskId: this.modalForm.examTaskId,
  267. courseCode: this.modalForm.courseCode,
  268. courseName: this.modalForm.courseName,
  269. schoolName: this.$ls.get("schoolName"),
  270. makeMethod: this.modalForm.makeMethod,
  271. cardRuleId: this.modalForm.cardRuleId,
  272. paperType: this.modalForm.paperType,
  273. type: "CUSTOM",
  274. createMethod: "STANDARD"
  275. });
  276. this.cancel();
  277. return;
  278. }
  279. // 选择已有题卡
  280. if (this.modalForm.makeMethod === "SELECT") {
  281. if (!this.modalForm.cardId) {
  282. this.$message.error("请选择已有的题卡!");
  283. return;
  284. }
  285. this.$emit("confirm", {
  286. cardId: this.modalForm.cardId,
  287. makeMethod: this.modalForm.makeMethod
  288. });
  289. this.cancel();
  290. }
  291. },
  292. toPreview() {
  293. if (!this.modalForm.cardId) {
  294. this.$message.error("请先选择题卡!");
  295. return;
  296. }
  297. window.open(
  298. this.getRouterPath({
  299. name: "CardPreview",
  300. params: {
  301. cardId: this.modalForm.cardId,
  302. viewType: "view"
  303. }
  304. })
  305. );
  306. }
  307. }
  308. };
  309. </script>
  310. <style scoped>
  311. .card-option-body {
  312. color: #878787;
  313. }
  314. .card-type {
  315. margin: 32px 0;
  316. }
  317. .card-select {
  318. margin-bottom: 10px;
  319. }
  320. .card-view {
  321. display: inline-block;
  322. margin-left: 10px;
  323. color: rgba(35, 196, 185, 1);
  324. cursor: pointer;
  325. }
  326. .card-view:hover {
  327. color: rgba(28, 208, 161, 1);
  328. }
  329. </style>