阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
16 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="des-form">
  3. <el-form ref="form" :model="form" :rules="rules" :hide-required-asterisk="isDisabled" size="small" label-width="80px">
  4. <el-row>
  5. <el-col :span="16">
  6. <el-form-item label="字段名称" prop="fieldCnName">
  7. <el-input v-model="form.fieldCnName" :disabled="isDisabled" />
  8. </el-form-item>
  9. <el-form-item label="字段标识" prop="fieldName" class="inline-error-item" :inline-message="true">
  10. <el-input v-if="isDisabled" v-model="form.fieldName" disabled />
  11. <el-input v-else v-model="form.fieldName" :disabled="!isAdd" />
  12. </el-form-item>
  13. <el-form-item label="字段类型" prop="isDataType">
  14. <el-input v-if="isDisabled" v-model="form.isDataTypeTxt" disabled />
  15. <el-select v-else v-model="form.isDataType" placeholder="" :disabled="!isAdd">
  16. <el-option v-for="item in dataTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="字段长度" prop="isColumnLength">
  20. <el-input v-if="isDisabled" v-model="form.isColumnLength" type="number" placeholder="" disabled />
  21. <el-input v-else v-model.number="form.isColumnLength" type="number" placeholder="" :disabled="!isAdd" />
  22. </el-form-item>
  23. <el-form-item label="著录形式" prop="isInputClass">
  24. <el-input v-if="isDisabled" v-model="form.isInputClassTxt" disabled />
  25. <el-select v-else v-model="form.isInputClass" placeholder="" @change="selectInputClass">
  26. <el-option v-for="item in inputClassOptions" :key="item.value" :label="item.label" :value="item.value" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="对应数据" prop="dictionaryConfigId">
  30. <el-input v-if="isDisabled" v-model="form.dictionaryConfigId.dicName" disabled />
  31. <!-- @change="selectDictionary" -->
  32. <div v-else class="dictionary-selected">
  33. <el-select v-model="form.mateData" class="dictionary-left" placeholder="" value-key="id" :disabled="form.isInputClass !== 'select' && form.isInputClass !== 'popover'" @change="changeDictType">
  34. <el-option v-for="item in dataOptions" :key="item.value" :label="item.label" :value="item.value" />
  35. </el-select>
  36. <el-select v-model="form.dictionaryConfigId.id" class="dictionary-right" placeholder="" value-key="id" :disabled="form.mateData !== 3">
  37. <el-option v-for="item in dictionaryData" :key="item.id" :label="item.dictionaryName" :value="item.id" />
  38. </el-select>
  39. </div>
  40. </el-form-item>
  41. <el-form-item label="显示长度" prop="editLength">
  42. <!-- :min="46" :max="510" -->
  43. <el-input v-model="form.editLength" type="number" :disabled="isDisabled" @keyup.enter.native="changEditLength" @blur="changEditLength" />
  44. </el-form-item>
  45. <el-form-item label="默认值" prop="isDefaultValue">
  46. <el-input v-model="form.isDefaultValue" :disabled="isDisabled" />
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="8">
  50. <el-form-item class="checkbox-item">
  51. <span>整行显示</span>
  52. <el-checkbox v-model="form.isLine" name="isLine" :disabled="isDisabled" @change="changeIsLine" />
  53. </el-form-item>
  54. <el-form-item class="checkbox-item">
  55. <span>输入字段</span>
  56. <el-checkbox v-model="form.isInput" name="isInput" :disabled="isDisabled" />
  57. </el-form-item>
  58. <el-form-item class="checkbox-item">
  59. <span>必填字段</span>
  60. <el-checkbox v-model="form.isRequired" name="isRequired" :disabled="isDisabled" />
  61. </el-form-item>
  62. <el-form-item class="checkbox-item">
  63. <span>自动生成</span>
  64. <el-checkbox v-model="form.isAutomatic" name="isAutomatic" :disabled="isDisabled" @change="changeAuto" />
  65. </el-form-item>
  66. <el-form-item class="checkbox-item">
  67. <span>值不重复</span>
  68. <el-checkbox v-model="form.isRepeat" name="isRepeat" :disabled="isDisabled" />
  69. </el-form-item>
  70. <el-form-item class="checkbox-item">
  71. <span>自动补零</span>
  72. <el-checkbox v-model="form.isFilling" name="isFilling" :disabled="isDisabled || form.isInputClass !=='number'" @change="changeSupplement" />
  73. </el-form-item>
  74. <el-form-item class="input-num" label="位数" prop="fillingDigit">
  75. <el-input v-if="isDisabled || !form.isFilling" v-model="form.fillingDigit" disabled />
  76. <!-- <el-input v-model="form.fillingDigit" type="number" :min="1" :disabled="isDisabled || !form.isSupplement" /> -->
  77. <el-input-number v-else v-model="form.fillingDigit" controls-position="right" :min="1" :disabled="isDisabled || !form.isFilling" />
  78. <span></span>
  79. </el-form-item>
  80. </el-col>
  81. </el-row>
  82. </el-form>
  83. </div>
  84. </template>
  85. <script>
  86. import { FetchDictionaryTree } from '@/api/system/dict'
  87. import { getNoFormatField } from '@/api/system/category/fileNoFormat'
  88. export default {
  89. name: 'SettingForm',
  90. components: {},
  91. props: {
  92. isDisabled: {
  93. type: Boolean,
  94. required: true
  95. },
  96. isAdd: {
  97. type: Boolean,
  98. required: true
  99. },
  100. thisFields: {
  101. type: Object,
  102. required: true
  103. }
  104. },
  105. data() {
  106. var checkMaxLength = (rule, value, callback) => {
  107. if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
  108. callback(new Error('请输入正整数数字值'))
  109. } else {
  110. if (this.form.isDataType === 1 && value > 2000) {
  111. callback(new Error('字符最大长度不能超过2000位'))
  112. } else if (this.form.isDataType === 2 && value > 11) {
  113. callback(new Error('数字最大长度不能超过11位'))
  114. } else {
  115. callback()
  116. }
  117. }
  118. }
  119. var checkFieldName = (rule, value, callback) => {
  120. const reg = /^(([A-Za-z][A-Za-z_]*[a-zA-Z])|([A-Za-z]))$/
  121. if (reg.test(value)) {
  122. callback()
  123. } else {
  124. callback(new Error('字段标识只能由字母、字符“_”组成,并且必须以字母开头和结尾'))
  125. }
  126. }
  127. // 显示长度限制
  128. var checkEditLength = (rule, value, callback) => {
  129. if (this.form.editLength && this.form.editLength > 578) {
  130. callback(new Error('显示长度最大578'))
  131. } else if (this.form.editLength && this.form.editLength < 46) {
  132. callback(new Error('显示长度最小46'))
  133. } else {
  134. callback()
  135. }
  136. }
  137. // 对应字典必填判断
  138. var checkDictionaryConfigId = (rule, value, callback) => {
  139. if ((this.form.isInputClass === 'select' || this.form.isInputClass === 'popover') && !this.form.dictionaryConfigId.id && this.form.mateData === 3) {
  140. callback(new Error('对应字典项不可为空!'))
  141. } else {
  142. callback()
  143. }
  144. }
  145. // 选择'自动补零',位数必填
  146. var checkFillingDigit = (rule, value, callback) => {
  147. if (this.form.isFilling && !this.form.fillingDigit) {
  148. callback(new Error('请填写位数!'))
  149. } else {
  150. callback()
  151. }
  152. }
  153. var getRules = () => {
  154. const rules = {
  155. fieldCnName: [
  156. { required: true, message: '请输入中文名称', trigger: 'blur' },
  157. { max: 7, message: '最大长度7个字符', trigger: 'blur' }
  158. ],
  159. fieldName: [
  160. { required: true, message: '请选择字段标识', trigger: 'blur' },
  161. { validator: checkFieldName, trigger: 'blur' }
  162. ],
  163. isDataType: [
  164. { required: true, message: '请选择数据类型', trigger: 'blur' }
  165. ],
  166. isColumnLength: [
  167. { required: true, message: '请输入字段长度', trigger: 'blur' },
  168. { validator: checkMaxLength, trigger: 'blur' }
  169. ],
  170. editLength: [
  171. { validator: checkEditLength, trigger: 'blur' }
  172. ],
  173. dictionaryConfigId: [
  174. { validator: checkDictionaryConfigId, trigger: 'blur' }
  175. ],
  176. fillingDigit: [
  177. { validator: checkFillingDigit, trigger: 'blur' }
  178. ]
  179. }
  180. if (this.isDisabled) {
  181. delete rules.isDataType
  182. }
  183. return rules
  184. }
  185. return {
  186. form: {
  187. dictionaryConfigId: {
  188. id: null
  189. }
  190. },
  191. rules: getRules(),
  192. // 字段类型
  193. dataTypeOptions: [
  194. { value: 1, label: '字符' },
  195. { value: 2, label: '数字' }
  196. ],
  197. // 著录形式
  198. inputClassOptions: [
  199. { value: 'select', label: '下拉框' },
  200. { value: 'popover', label: '弹出框' },
  201. { value: 'text', label: '文本框' },
  202. { value: 'number', label: '数字框' },
  203. { value: 'date', label: '日期框' },
  204. { value: 'textarea', label: '文本域' }
  205. ],
  206. // 对应字典
  207. dictionaryData: [],
  208. dataOptions: [
  209. { value: 1, label: '全宗' },
  210. { value: 2, label: '档案分类' },
  211. { value: 3, label: '字典' }
  212. ]
  213. // dictionaryId: null
  214. }
  215. },
  216. watch: {
  217. thisFields(value) {
  218. this.form = value
  219. if (!this.isAdd) {
  220. this.getForm()
  221. }
  222. }
  223. },
  224. mounted() {
  225. this.$nextTick(() => {
  226. this.form = this.thisFields
  227. console.log(this.form)
  228. if (!this.isAdd) {
  229. this.getForm()
  230. }
  231. })
  232. },
  233. methods: {
  234. getForm() {
  235. // 初始化
  236. this.form.isFilling = !!this.form.isFilling
  237. this.form.isLine = !!this.form.isLine
  238. this.form.isInput = !!this.form.isInput
  239. this.form.isRequired = !!this.form.isRequired
  240. this.form.isAutomatic = !!this.form.isAutomatic
  241. if (this.form.mateData !== 3) {
  242. this.dictionaryData = []
  243. this.form.dictionaryConfigId.id = null
  244. }
  245. // 字段类型
  246. if (this.form.isDataType === 1) {
  247. this.form.isDataTypeTxt = '字符'
  248. } else if (this.form.isDataType === 2) {
  249. this.form.isDataTypeTxt = '数字'
  250. }
  251. // 初始化 - 著录形式
  252. switch (this.form.isInputClass) {
  253. case 'select':
  254. this.form.isInputClassTxt = '下拉框'
  255. break
  256. case 'popover':
  257. this.form.isInputClassTxt = '弹出框'
  258. break
  259. case 'text':
  260. this.form.isInputClassTxt = '文本框'
  261. break
  262. case 'number':
  263. this.form.isInputClassTxt = '数字框'
  264. break
  265. case 'date':
  266. this.form.isInputClassTxt = '日期框'
  267. break
  268. case 'textarea':
  269. this.form.isInputClassTxt = '文本域'
  270. break
  271. }
  272. if (!this.isDisabled) {
  273. // 初始化 - 著录形式 - 对应字典
  274. if (this.form.isInputClass === 'select' || this.form.isInputClass === 'popover') {
  275. this.getDictrionaryList()
  276. } else {
  277. this.dictionaryData = []
  278. this.form.dictionaryConfigId.id = null
  279. }
  280. }
  281. },
  282. // 获取对应字典list
  283. getDictrionaryList() {
  284. FetchDictionaryTree().then(res => {
  285. this.dictionaryData = res
  286. })
  287. },
  288. // selectDictionary(value) {
  289. // this.dictionaryId = value
  290. // },
  291. changeDictType(value) {
  292. this.form.dictionaryConfigId.id = null
  293. },
  294. // 著录形式为'下拉框'、'弹出框'的,对应字典不为空,反之为空
  295. selectInputClass(value) {
  296. if (value === 'select' || value === 'popover') {
  297. this.getDictrionaryList()
  298. } else {
  299. this.dictionaryData = []
  300. this.form.mateData = null
  301. this.form.dictionaryConfigId.id = null
  302. }
  303. // 字段类型为数字型,且默认著录类型为数字框不可更改
  304. if (this.form.isDataType === 2 && this.form.isInputClass !== 'number') {
  305. this.form.isInputClass = 'number'
  306. this.$message.error('字段类型为数字型,默认著录类型为数字框且不能修改')
  307. }
  308. },
  309. // 显示长度 input.value>200,则自动勾选上“显示一整行”
  310. changEditLength(e) {
  311. const value = e.target.value
  312. // if (value < 46) {
  313. // this.$message.error('显示长度最小46')
  314. // this.form.editLength = 46
  315. // }
  316. if (value > 225) {
  317. this.form.isLine = true
  318. }
  319. // if (value > 510) {
  320. // this.$message.error('显示长度最大510')
  321. // this.form.editLength = 510
  322. // }
  323. },
  324. changeIsLine() {
  325. if (!this.form.isLine) {
  326. if (this.form.editLength > 225) {
  327. this.form.editLength = 225
  328. }
  329. }
  330. },
  331. // '自动补零' false - 补零位数清空
  332. changeSupplement() {
  333. if (!this.form.isFilling) {
  334. this.form.fillingDigit = undefined
  335. }
  336. if (this.form.isFilling) {
  337. // '字段类型'为数字型时,'自动补零'不可操作
  338. if (this.form.isDataType === 2) {
  339. this.form.isFilling = false
  340. this.$message.error('字段类型必须为字符型才可操作!')
  341. }
  342. // 著录形式必须-数字框
  343. if (this.form.isInputClass !== 'number') {
  344. this.form.isFilling = false
  345. this.$message.error('著录形式必须为数字框才可操作!')
  346. }
  347. if (this.form.isDataType !== 2 && this.form.isInputClass === 'number') {
  348. this.form.fillingDigit = 1
  349. }
  350. }
  351. },
  352. // 自动生成 - 规则出自“档案规则设置”页面,著录形式为“文本框”才可
  353. changeAuto(value) {
  354. if (this.form.isAutomaticField === 1) {
  355. this.form.isAutomatic = false
  356. this.$message.error('已经为档号组成项,不可设置为自动生成')
  357. } else if (this.form.isInputClass !== 'text') {
  358. this.form.isAutomatic = false
  359. this.$message.error('著录形式必须为文本框才可操作!')
  360. } else if (value) {
  361. console.log(this.form)
  362. getNoFormatField({ categoryId: this.form.categoryId }).then((res) => {
  363. const repeatIndex = res.findIndex((item) => {
  364. return item.dictionaryId === this.form.id
  365. })
  366. if (repeatIndex >= 0) {
  367. this.form.isAutomatic = false
  368. this.$message.error('已经为档号组成项,不能设为自动生成!')
  369. }
  370. })
  371. }
  372. },
  373. // submitForm(formName) {
  374. // // 对应字典必填判断
  375. // if (this.form.isInputClass === 'select' || this.form.isInputClass === 'popover') {
  376. // if (!this.form.dictionaryConfigId.id) {
  377. // this.$message.error('对应字典项不可为空!')
  378. // return
  379. // }
  380. // }
  381. // // 选择'自动补零',位数必填
  382. // if (this.form.isFilling) {
  383. // if (!this.form.fillingDigit) {
  384. // this.$message.error('请填写位数!')
  385. // return
  386. // }
  387. // }
  388. // // 显示长度限制
  389. // if (this.form.editLength) {
  390. // if (this.form.editLength > 510) {
  391. // this.$message.error('显示长度最大510')
  392. // return
  393. // }
  394. // }
  395. // this.$refs[formName].validate((valid) => {
  396. // if (valid) {
  397. // alert('submit!')
  398. // } else {
  399. // console.log('error submit!!')
  400. // return false
  401. // }
  402. // })
  403. // },
  404. resetForm(formName) {
  405. // this.$refs[formName].resetFields()
  406. // console.log(this.thisFields)
  407. }
  408. }
  409. }
  410. </script>
  411. <style lang="scss" scoped>
  412. .dictionary-selected{
  413. display: flex;
  414. justify-content: space-between;
  415. width: 264px;
  416. .dictionary-left{
  417. width: 104px;
  418. ::v-deep .el-input__inner{
  419. width: 104px !important;
  420. }
  421. }
  422. .dictionary-right{
  423. width: 150px;
  424. ::v-deep .el-input__inner{
  425. width: 150px !important;
  426. }
  427. }
  428. }
  429. </style>