ModifyGradingUser.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <Modal
  3. class="modify-grading-user"
  4. v-model="modalIsShow"
  5. :title="title"
  6. width="540"
  7. :mask-closable="false"
  8. @on-visible-change="visibleChange"
  9. >
  10. <Form
  11. ref="modalFormComp"
  12. class="modal-form"
  13. :model="modalForm"
  14. :rules="rules"
  15. :key="modalForm.id"
  16. :label-width="80"
  17. >
  18. <FormItem prop="loginName" label="账号">
  19. <Input
  20. size="large"
  21. v-model.trim="modalForm.loginName"
  22. placeholder="请输入账号"
  23. :disabled="isEdit"
  24. clearable
  25. >
  26. <span slot="prepend" v-if="!isEdit">{{ loginNamePrepend }}</span>
  27. </Input>
  28. </FormItem>
  29. <FormItem prop="password" label="密码">
  30. <Input
  31. size="large"
  32. v-model.trim="modalForm.password"
  33. placeholder="请输入密码"
  34. disabled
  35. ></Input>
  36. </FormItem>
  37. <FormItem prop="name" label="姓名">
  38. <Input
  39. size="large"
  40. v-model.trim="modalForm.name"
  41. placeholder="请输入姓名"
  42. :disabled="isEdit"
  43. clearable
  44. ></Input>
  45. </FormItem>
  46. <FormItem prop="role" label="角色">
  47. <Select
  48. size="large"
  49. v-model="modalForm.role"
  50. :disabled="isEdit"
  51. placeholder="请选择角色"
  52. >
  53. <Option
  54. v-for="item in roleTypes"
  55. :key="item.key"
  56. :value="item.key"
  57. :label="item.val"
  58. ></Option>
  59. </Select>
  60. </FormItem>
  61. <FormItem
  62. prop="markRight"
  63. label="权限"
  64. v-if="modalForm.role === 'MARKER'"
  65. >
  66. <Select
  67. size="large"
  68. v-model="modalForm.markRight"
  69. placeholder="请选择权限"
  70. disabled
  71. >
  72. <Option
  73. v-for="(val, key) in MARKER_RIGHT_TYPE"
  74. :key="key"
  75. :value="key"
  76. :label="val"
  77. ></Option>
  78. </Select>
  79. </FormItem>
  80. <FormItem
  81. prop="weight"
  82. label="权重"
  83. v-if="
  84. modalForm.role === 'MARKER' &&
  85. modalForm.markRight &&
  86. modalForm.markRight !== 'ALLOW_SCORING'
  87. "
  88. >
  89. <InputNumber
  90. size="large"
  91. v-model.trim="modalForm.weight"
  92. :min="1"
  93. :max="100"
  94. :precision="2"
  95. placeholder="请输入权重"
  96. style="width: 120px"
  97. ></InputNumber>
  98. </FormItem>
  99. <FormItem v-if="modalForm.role === 'MARK_LEADER'">
  100. <Checkbox v-model="modalForm.oneClickLevel">是否一键定档</Checkbox
  101. ><br />
  102. <Checkbox v-model="modalForm.standardVolume">是否设立标准卷</Checkbox
  103. ><br />
  104. <Checkbox v-model="modalForm.levelCallback"
  105. >是否建议档位打回档</Checkbox
  106. >
  107. </FormItem>
  108. </Form>
  109. <div slot="footer">
  110. <Button shape="circle" type="primary" :disabled="isSubmit" @click="submit"
  111. >保存</Button
  112. >
  113. <Button shape="circle" @click="cancel">取消</Button>
  114. </div>
  115. </Modal>
  116. </template>
  117. <script>
  118. import { updateGradingUser, orgDetail } from "@/api";
  119. import { commonCode, password, numberValidator } from "@/plugins/formRules";
  120. import { ROLE_TYPE, MARKER_RIGHT_TYPE } from "@/constants/enumerate";
  121. const initModalForm = {
  122. id: "",
  123. workId: "",
  124. subject: "",
  125. loginName: "",
  126. password: "123456",
  127. name: "",
  128. role: null,
  129. markRight: "ALLOW_ALL",
  130. weight: null,
  131. oneClickLevel: false,
  132. standardVolume: false,
  133. levelCallback: false
  134. };
  135. export default {
  136. name: "modify-grading-user",
  137. props: {
  138. instance: {
  139. type: Object,
  140. default() {
  141. return {};
  142. }
  143. },
  144. subject: {
  145. type: Object,
  146. default() {
  147. return {};
  148. }
  149. }
  150. },
  151. computed: {
  152. isEdit() {
  153. return !!this.instance.id;
  154. },
  155. title() {
  156. return (this.isEdit ? "编辑" : "新增") + "账号";
  157. }
  158. },
  159. data() {
  160. return {
  161. modalIsShow: false,
  162. isSubmit: false,
  163. roleTypes: [],
  164. MARKER_RIGHT_TYPE,
  165. modalForm: { ...initModalForm },
  166. loginNamePrepend: "",
  167. orgInfo: {},
  168. rules: {
  169. loginName: commonCode({ prop: "账号" }),
  170. password,
  171. name: [
  172. {
  173. required: true,
  174. min: 2,
  175. max: 20,
  176. message: "请输入姓名,长度2-20个字符",
  177. trigger: "change"
  178. }
  179. ],
  180. role: [
  181. {
  182. required: true,
  183. message: "请选择角色",
  184. trigger: "change"
  185. }
  186. ],
  187. markRight: [
  188. {
  189. required: true,
  190. message: "请选择权限",
  191. trigger: "change"
  192. }
  193. ],
  194. weight: numberValidator("请输入权重")
  195. }
  196. };
  197. },
  198. created() {
  199. this.getOrgDetail();
  200. },
  201. methods: {
  202. initData(val) {
  203. this.$refs.modalFormComp.resetFields();
  204. this.roleTypes = Object.keys(ROLE_TYPE).map(key => {
  205. return {
  206. key,
  207. val: ROLE_TYPE[key]
  208. };
  209. });
  210. if (!this.isEdit) {
  211. this.roleTypes.filter(
  212. item => this.subject.stage === "INIT" || item.key === "MARK_LEADER"
  213. );
  214. }
  215. this.modalForm = this.$objAssign(initModalForm, val);
  216. this.loginNamePrepend = `${this.orgInfo.abbreviation.toLowerCase()}-${
  217. this.modalForm.workId
  218. }-`;
  219. },
  220. visibleChange(visible) {
  221. if (visible) {
  222. this.initData(this.instance);
  223. }
  224. },
  225. async getOrgDetail() {
  226. const organizationId = this.$ls.get("organizationId");
  227. this.orgInfo = await orgDetail(organizationId);
  228. },
  229. cancel() {
  230. this.modalIsShow = false;
  231. },
  232. open() {
  233. this.modalIsShow = true;
  234. },
  235. async submit() {
  236. const valid = await this.$refs.modalFormComp.validate();
  237. if (!valid) return;
  238. if (this.isSubmit) return;
  239. this.isSubmit = true;
  240. let result = true;
  241. const datas = { ...this.modalForm };
  242. if (!this.isEdit)
  243. datas.loginName = `${this.loginNamePrepend}${datas.loginName}`;
  244. await updateGradingUser(datas).catch(() => {
  245. result = false;
  246. });
  247. this.isSubmit = false;
  248. if (!result) return;
  249. this.$Message.success(this.title + "成功!");
  250. this.$emit("modified");
  251. this.cancel();
  252. }
  253. }
  254. };
  255. </script>