华西海圻ELN前端工程
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.

205 lines
6.1 KiB

  1. G<template>
  2. <div>
  3. <!-- 新增试验间弹窗 -->
  4. <el-dialog :title="$t('page.business.study.studyMethod.scff')" :visible.sync="open" width="400px" append-to-body
  5. :close-on-click-modal="false">
  6. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  7. <el-row>
  8. <el-col :span="24">
  9. <el-form-item :label="$t('page.business.study.studyMethod.mc')" prop="ffmc">
  10. <el-input type="text" v-model="form.ffmc" maxlength="20"
  11. :placeholder="$t('form.placeholderInput')" />
  12. </el-form-item>
  13. </el-col>
  14. </el-row>
  15. <el-row>
  16. <!-- 方法 -->
  17. <el-col :span="24">
  18. <el-form-item :label="$t('page.business.study.studyMethod.ff')" prop="fileUlr">
  19. <el-upload class="upload-demo" :before-upload="handleBeforeUpload" :on-error="handleUploadError"
  20. :on-exceed="handleExceed" :on-success="handleUploadSuccess" :show-file-list="true" :headers="headers"
  21. :on-remove="handleRemove" :action="uploadFileUrl" accept=".pdf" :limit="1" :file-list="fileList">
  22. <el-button size="small" type="primary">{{ $t('page.business.study.studyMethod.scwj') }}</el-button>
  23. <div slot="tip" class="el-upload__tip">{{ $t('page.business.study.studyMethod.wjm') }}</div>
  24. </el-upload>
  25. </el-form-item>
  26. </el-col>
  27. </el-row>
  28. <el-row>
  29. <el-col :span="24">
  30. <el-form-item :label="$t('form.qmyy')" prop="qmyy">
  31. <el-input type="text" :value="form.qmyy" maxlength="50" disabled
  32. :placeholder="$t('form.placeholderInput')" />
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row>
  37. <el-col :span="24">
  38. <el-form-item :label="$t('form.remark')" prop="qmbz">
  39. <el-input type="textarea" v-model="form.qmbz" :rows="2" maxlength="500"
  40. :placeholder="$t('form.placeholderInput')">
  41. </el-input>
  42. </el-form-item>
  43. </el-col>
  44. </el-row>
  45. <el-row>
  46. <el-col :span="24">
  47. <el-form-item :label="$t('form.signer')">
  48. <el-input type="text" v-model="nickName" maxlength="50" disabled
  49. :placeholder="$t('form.placeholderInput')" />
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-row>
  54. <el-col :span="24">
  55. <el-form-item :label="$t('form.password')" prop="qmrmm">
  56. <el-input type="password" v-model="form.qmrmm" maxlength="20"
  57. :placeholder="$t('form.placeholderInput')" />
  58. </el-form-item>
  59. </el-col>
  60. </el-row>
  61. </el-form>
  62. <div slot="footer" class="dialog-footer">
  63. <el-button type="primary" @click="save">{{ $t('form.confirm') }}</el-button>
  64. <el-button @click="cancel">{{ $t('form.cancel') }}</el-button>
  65. </div>
  66. </el-dialog>
  67. </div>
  68. </template>
  69. <script>
  70. import { studyMethod_save } from "@/api/business/study/studyMethod"
  71. import { mapGetters } from 'vuex'
  72. import { getToken } from "@/utils/auth"
  73. export default {
  74. name: "XzSyj",
  75. components: {},
  76. data() {
  77. return {
  78. open: false,
  79. form: {
  80. mc: '',
  81. fileUrl: '',
  82. fileName: ''
  83. },
  84. uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload",
  85. headers: {
  86. Authorization: "Bearer " + getToken(),
  87. },
  88. fileList: [],
  89. rules: {
  90. ffmc: [{
  91. required: true,
  92. message: ' ',
  93. trigger: 'blur'
  94. }],
  95. fileUrl: [{
  96. required: true,
  97. message: ' ',
  98. trigger: 'blur'
  99. }],
  100. qmrmm: [{
  101. required: true,
  102. message: ' ',
  103. trigger: 'blur'
  104. }],
  105. }
  106. }
  107. },
  108. computed: {
  109. ...mapGetters([
  110. 'nickName','name'
  111. ]),
  112. },
  113. created() {
  114. },
  115. methods: {
  116. cancel() {
  117. this.open = false
  118. },
  119. reset() {
  120. this.form = {
  121. ffmc: null,
  122. fileUrl: '',
  123. fileName: '',
  124. qmrmm: null,
  125. kssyyl: '',
  126. qmyy: '上传文件',
  127. bjbz: ''
  128. }
  129. this.fileList = []
  130. this.resetForm("form")
  131. },
  132. show(study) {
  133. this.reset()
  134. this.form.studyId = study.id
  135. this.form.studySubjectId = study.studySubjectId
  136. this.open = true
  137. },
  138. save() {
  139. this.$refs["form"].validate(valid => {
  140. if (valid) {
  141. studyMethod_save(this.form).then(response => {
  142. this.open = false
  143. this.$emit('callback')
  144. })
  145. }
  146. })
  147. },
  148. // 上传前校检格式和大小
  149. handleBeforeUpload(file) {
  150. let fileType = ['pdf']
  151. // 校检文件类型
  152. if (fileType) {
  153. const fileName = file.name.split('.')
  154. const fileExt = fileName[fileName.length - 1]
  155. const isTypeOk = fileType.indexOf(fileExt) >= 0
  156. if (!isTypeOk) {
  157. this.$modal.msgError('文件格式不正确,请上传pdf格式文件!')
  158. return false
  159. }
  160. }
  161. // 校检文件名是否包含特殊字符
  162. if (file.name.includes(',')) {
  163. this.$modal.msgError('文件名不正确,不能包含英文逗号!')
  164. return false
  165. }
  166. this.$modal.loading("正在上传文件,请稍候...")
  167. this.number++
  168. return true
  169. },
  170. // 文件个数超出
  171. handleExceed() {
  172. this.$modal.msgError('上传文件数量不能超过1个!')
  173. },
  174. // 上传失败
  175. handleUploadError(err) {
  176. this.$modal.msgError("上传文件失败,请重试")
  177. this.$modal.closeLoading()
  178. },
  179. // 上传成功回调
  180. handleUploadSuccess(res, file) {
  181. console.log(res)
  182. if (res.code === 200) {
  183. this.form.fileUrl = res.data.url
  184. this.form.fileName = res.data.name
  185. this.fileList.push({ name: res.data.name, url: res.data.url })
  186. this.$modal.closeLoading()
  187. } else {
  188. this.number--
  189. this.$modal.closeLoading()
  190. this.$modal.msgError(res.msg)
  191. this.$refs.fileUpload.handleRemove(file)
  192. }
  193. },
  194. handleRemove() {
  195. this.form.fileUrl = ''
  196. this.form.fileName = ''
  197. this.fileList = []
  198. }
  199. }
  200. }
  201. </script>