CardOptionDialog.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. @upload-error="uplaodError"
  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. examTaskId: "",
  106. paperType: "",
  107. courseCode: "",
  108. courseName: "",
  109. cardRuleId: "",
  110. cardId: "",
  111. makeMethod: "",
  112. // 考务规则
  113. customCard: false
  114. };
  115. export default {
  116. name: "card-option-dialog-view",
  117. props: {
  118. data: {
  119. type: Object,
  120. default() {
  121. return {};
  122. }
  123. }
  124. },
  125. components: { UploadFileView },
  126. data() {
  127. return {
  128. modalIsShow: false,
  129. isSubmit: false,
  130. modalForm: { ...initModalForm },
  131. rules: {
  132. cardId: [
  133. {
  134. required: true,
  135. message: "请选择已选题卡",
  136. trigger: "change"
  137. }
  138. ]
  139. },
  140. onlySelect: false,
  141. cards: [],
  142. cardSourceTypes: [],
  143. CARD_SOURCE_TYPE,
  144. // apply-customer
  145. applyModalForm: {
  146. title: "",
  147. custAttachmentId: ""
  148. },
  149. applyRules: {
  150. title: [
  151. {
  152. required: true,
  153. message: "请输入文件标题",
  154. trigger: "change"
  155. },
  156. {
  157. message: "文件标题不能超过100个字",
  158. max: 100,
  159. trigger: "change"
  160. }
  161. ],
  162. custAttachmentId: [
  163. {
  164. required: true,
  165. message: "请上传样卷或试卷结构文件",
  166. trigger: "change"
  167. }
  168. ]
  169. },
  170. // upload
  171. format: ["pdf"],
  172. maxSize: 20 * 1024 * 1024,
  173. uploadUrl: "/api/admin/common/file/upload",
  174. uploadData: {
  175. type: "PAPER"
  176. }
  177. };
  178. },
  179. methods: {
  180. visibleChange() {
  181. this.getCardSourceTypes();
  182. this.modalForm = this.$objAssign(initModalForm, this.data);
  183. this.modalForm.makeMethod =
  184. this.data.makeMethod || this.cardSourceTypes[0].type;
  185. this.getCardList();
  186. },
  187. getCardSourceTypes() {
  188. let cardSourceTypes = [];
  189. Object.keys(CARD_SOURCE_TYPE).forEach(key => {
  190. // 自助创建 =>
  191. // 若题卡规则为专卡,命题人可即时创建专卡;
  192. // 若题卡规则为全部通卡,则不显示该制卡方式;
  193. // 申请客服制卡 =>
  194. // 若题卡规则为专卡,命题人可即时创建专卡;
  195. // 若题卡规则为全部通卡,则不显示该制卡方式;
  196. if (this.data.cardRuleId === COMMON_CARD_RULE_ID && key !== "SELECT")
  197. return;
  198. // 考务规则中未开启客服制卡时,不显示客服制卡选项
  199. if (!this.data.customCard && key === "CUST") return;
  200. cardSourceTypes.push({
  201. type: key,
  202. name: CARD_SOURCE_TYPE[key]
  203. });
  204. });
  205. this.cardSourceTypes = cardSourceTypes;
  206. },
  207. async getCardList() {
  208. // 选择已有题卡 =>
  209. // 若题卡规则为专卡,选择已有题卡时,下拉列表将显示适用的专卡和通卡;
  210. // 若题卡规则为“全部通卡”,则下拉列表中只显示适用的通卡模板;
  211. const data = await cardForSelectList({
  212. courseCode: this.modalForm.courseCode,
  213. paperType: this.modalForm.paperType,
  214. cardRuleId: this.modalForm.cardRuleId
  215. });
  216. this.cards = data || [];
  217. },
  218. cancel() {
  219. this.modalIsShow = false;
  220. },
  221. open() {
  222. this.modalIsShow = true;
  223. },
  224. uplaodError(errorData) {
  225. this.$notify.error({ title: "错误提示", message: errorData.message });
  226. },
  227. uploadSuccess(data) {
  228. this.$message.success("上传成功!");
  229. this.applyModalForm.custAttachmentId = data.id;
  230. this.$refs.ApplyModalForm.validateField("custAttachmentId");
  231. },
  232. async confirm() {
  233. // 客服制卡
  234. if (this.modalForm.makeMethod === "CUST") {
  235. this.$emit("draft-task");
  236. const valid = await this.$refs.ApplyModalForm.validate().catch(
  237. () => {}
  238. );
  239. if (!valid) return;
  240. if (this.isSubmit) return;
  241. this.isSubmit = true;
  242. // 创建题卡
  243. const result = await applyCustomerCard({
  244. status: "STAGE",
  245. examTaskId: this.modalForm.examTaskId,
  246. courseCode: this.modalForm.courseCode,
  247. courseName: this.modalForm.courseName,
  248. makeMethod: "CUST",
  249. type: "CUSTOM",
  250. ...this.applyModalForm
  251. }).catch(() => {});
  252. this.isSubmit = false;
  253. if (!result) return;
  254. this.$message.success("申请成功!");
  255. this.$emit("confirm", {
  256. cardId: result,
  257. makeMethod: this.modalForm.makeMethod
  258. });
  259. this.cancel();
  260. return;
  261. }
  262. // 自主创建
  263. if (this.modalForm.makeMethod === "SELF") {
  264. this.$emit("draft-task");
  265. this.$ls.set("prepareTcPCard", {
  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. });
  274. // 打开题卡编辑页,创建题卡,并预设需要绑定的任务
  275. this.$router.push({
  276. name: "CardEdit"
  277. });
  278. return;
  279. }
  280. // 选择已有题卡
  281. if (this.modalForm.makeMethod === "SELECT") {
  282. if (!this.modalForm.cardId) {
  283. this.$message.error("请选择已有的题卡!");
  284. return;
  285. }
  286. this.$emit("confirm", {
  287. cardId: this.modalForm.cardId,
  288. makeMethod: this.modalForm.makeMethod
  289. });
  290. this.cancel();
  291. }
  292. },
  293. toPreview() {
  294. if (!this.modalForm.cardId) {
  295. this.$message.error("请先选择题卡!");
  296. return;
  297. }
  298. window.open(
  299. this.getRouterPath({
  300. name: "CardPreview",
  301. params: {
  302. cardId: this.modalForm.cardId,
  303. viewType: "view"
  304. }
  305. })
  306. );
  307. }
  308. }
  309. };
  310. </script>
  311. <style scoped>
  312. .card-option-body {
  313. color: #878787;
  314. }
  315. .card-type {
  316. margin: 32px 0;
  317. }
  318. .card-select {
  319. margin-bottom: 10px;
  320. }
  321. .card-view {
  322. display: inline-block;
  323. margin-left: 10px;
  324. color: rgba(35, 196, 185, 1);
  325. cursor: pointer;
  326. }
  327. .card-view:hover {
  328. color: rgba(28, 208, 161, 1);
  329. }
  330. </style>