ClientParamSet.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div class="client-param-set">
  3. <Row :gutter="20" type="flex">
  4. <Col span="12">
  5. <div class="part-box">
  6. <h2 class="client-param-title">科目名称设置</h2>
  7. <table class="table table-noborder">
  8. <template v-for="(subject, index) in subjects">
  9. <tr :key="index">
  10. <td>
  11. <Input
  12. v-model="subject.name"
  13. @on-blur="checkSubjectValidate(subject)"
  14. :disabled="!subject.enable"
  15. :readonly="!subject.canEdit"
  16. :clearable="subject.canEdit"
  17. :ref="subject.id"
  18. ></Input>
  19. </td>
  20. <td style="width: 220px;">
  21. <Button
  22. size="small"
  23. :disabled="!subject.enable"
  24. @click="toEdit(index)"
  25. >编辑</Button
  26. >
  27. <Button
  28. size="small"
  29. :type="subject.enable ? 'error' : 'success'"
  30. @click="toAble(index)"
  31. >
  32. {{ subject.enable ? "禁用" : "启用" }}</Button
  33. >
  34. <Button
  35. size="small"
  36. :disabled="!subject.enable"
  37. @click="toSave(subject)"
  38. >保存</Button
  39. >
  40. </td>
  41. </tr>
  42. <tr
  43. class="tr-tips-error"
  44. v-if="subject.errors"
  45. :key="index + '1'"
  46. >
  47. <td>{{ subject.errors.name }}</td>
  48. <td></td>
  49. </tr>
  50. </template>
  51. </table>
  52. </div>
  53. </Col>
  54. <Col span="12">
  55. <div class="part-box">
  56. <h2 class="client-param-title">其他设置</h2>
  57. <Form ref="modalFormComp" :model="modalForm" :label-width="120">
  58. <!-- <FormItem label="是否整包扫描:">
  59. <Select
  60. v-model="modalForm.packageScan"
  61. :disabled="!modalFormCanEdit"
  62. placeholder="是否整包扫描"
  63. >
  64. <Option
  65. v-for="(val, key) in BOOLEAN_TYPE"
  66. :key="key"
  67. :value="key * 1"
  68. :label="val"
  69. ></Option>
  70. </Select>
  71. </FormItem>
  72. <FormItem label="图片是否加密:">
  73. <Select
  74. v-model="modalForm.imageEncrypt"
  75. :disabled="!modalFormCanEdit"
  76. placeholder="图片是否加密"
  77. >
  78. <Option
  79. v-for="(val, key) in BOOLEAN_TYPE"
  80. :key="key"
  81. :value="key * 1"
  82. :label="val"
  83. ></Option>
  84. </Select>
  85. </FormItem>
  86. <FormItem label="图片命名规则:">
  87. <Select
  88. v-model="modalForm.nameRule"
  89. :disabled="!modalFormCanEdit"
  90. placeholder="请选择图片命名规则"
  91. >
  92. <Option
  93. v-for="(val, key) in IMAGE_NAME_TYPE"
  94. :key="key"
  95. :value="key * 1"
  96. :label="val"
  97. ></Option>
  98. </Select>
  99. </FormItem> -->
  100. <FormItem label="试卷档位:">
  101. <Select
  102. v-model="modalForm.paperStage"
  103. :disabled="!modalFormCanEdit"
  104. placeholder="请选择试卷档位"
  105. >
  106. <Option
  107. v-for="(val, key) in PAPER_LEVEL_KNOWN_TYPE"
  108. :key="key"
  109. :value="key * 1"
  110. :label="val"
  111. ></Option>
  112. </Select>
  113. </FormItem>
  114. <FormItem>
  115. <Button
  116. shape="circle"
  117. style="width: 80px;"
  118. @click="modalFormCanEdit = true"
  119. >编辑</Button
  120. >
  121. <Button
  122. shape="circle"
  123. type="primary"
  124. style="width: 80px;"
  125. :disabled="isSubmit"
  126. @click="toSubmit"
  127. >保存</Button
  128. >
  129. </FormItem>
  130. </Form>
  131. </div>
  132. </Col>
  133. </Row>
  134. </div>
  135. </template>
  136. <script>
  137. import {
  138. subjectList,
  139. updateSubject,
  140. enableSubject,
  141. getParamsSet,
  142. updateCollectParams
  143. } from "@/api";
  144. import {
  145. BOOLEAN_TYPE,
  146. IMAGE_NAME_TYPE,
  147. PAPER_LEVEL_KNOWN_TYPE
  148. } from "@/constants/enumerate";
  149. import schema from "async-validator";
  150. schema.warning = function() {};
  151. const initSubject = {
  152. id: "",
  153. name: "",
  154. enable: true,
  155. canEdit: false,
  156. password: ""
  157. };
  158. export default {
  159. name: "client-param-set",
  160. data() {
  161. return {
  162. BOOLEAN_TYPE,
  163. IMAGE_NAME_TYPE,
  164. PAPER_LEVEL_KNOWN_TYPE,
  165. workId: this.$route.params.workId,
  166. subjects: [],
  167. // other param
  168. isSubmit: false,
  169. initModalForm: {
  170. workId: "",
  171. packageScan: 0,
  172. imageEncrypt: 0,
  173. nameRule: 0,
  174. paperStage: 0
  175. },
  176. modalFormCanEdit: false,
  177. modalForm: {}
  178. };
  179. },
  180. mounted() {
  181. this.modalForm = { ...this.initModalForm };
  182. this.getList();
  183. this.getParamsSetInfo();
  184. },
  185. methods: {
  186. async getList() {
  187. const data = await subjectList(this.workId);
  188. this.subjects = data.map(item => {
  189. return {
  190. ...item,
  191. canEdit: false
  192. };
  193. });
  194. },
  195. toAdd() {
  196. this.subjects.push({ ...initSubject });
  197. },
  198. toEdit(index) {
  199. const row = this.subjects[index];
  200. row.canEdit = true;
  201. this.$refs[row.id][0].focus();
  202. },
  203. async toAble(index) {
  204. const row = this.subjects[index];
  205. await enableSubject(row.id);
  206. row.enable = !row.enable;
  207. },
  208. checkSubjectValidate(subject) {
  209. const descriptor = {
  210. name: [
  211. {
  212. required: true,
  213. min: 2,
  214. max: 20,
  215. message: "科目名称长度只能介于2到20之间"
  216. }
  217. ]
  218. };
  219. return new schema(descriptor)
  220. .validate(subject)
  221. .then(() => {
  222. if (subject.errors) subject.errors = null;
  223. })
  224. .catch(({ errors, fields }) => {
  225. let errorMsgs = {};
  226. errors.map(error => {
  227. errorMsgs[error.field] = error.message;
  228. });
  229. this.$set(subject, "errors", errorMsgs);
  230. return { errors };
  231. });
  232. },
  233. async toSave(row) {
  234. const result = await this.checkSubjectValidate(row);
  235. if (result) return;
  236. await updateSubject(row);
  237. row.canEdit = false;
  238. this.$Message.success("保存成功!");
  239. },
  240. // param-set
  241. async getParamsSetInfo() {
  242. const data = await getParamsSet(this.workId);
  243. this.modalForm = this.$objAssign(this.modalForm, data);
  244. },
  245. async toSubmit() {
  246. if (this.isSubmit) return;
  247. this.isSubmit = true;
  248. let result = true;
  249. await updateCollectParams(this.modalForm).catch(() => {
  250. result = false;
  251. });
  252. this.isSubmit = false;
  253. if (!result) return;
  254. this.modalFormCanEdit = false;
  255. this.$Message.success("保存成功!");
  256. }
  257. }
  258. };
  259. </script>