equipment-add-or-update.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="!id ? '新增': display ? '点检记录' : '修改'"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible">
  8. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  9. <el-row class="my-row">
  10. <el-col :span="8">
  11. <el-form-item label="编码" prop="code">
  12. <el-input v-model="dataForm.code" :disabled="display || !id" placeholder="系统自动生成,无需填写"></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="8" style="padding-left: 10px">
  16. <el-form-item label="名称" prop="name">
  17. <el-input v-model="dataForm.name" :disabled="display" placeholder="名称"></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8" style="padding-left: 10px">
  21. <el-form-item label="型号规格" prop="specifications">
  22. <el-input v-model="dataForm.specifications" :disabled="display" placeholder="型号规格"></el-input>
  23. </el-form-item>
  24. </el-col>
  25. </el-row>
  26. <el-row class="my-row">
  27. <el-col :span="8">
  28. <el-form-item label="制造商" prop="manufacturers">
  29. <el-input v-model="dataForm.manufacturers" :disabled="display" placeholder="制造商"></el-input>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="8" style="padding-left: 10px">
  33. <el-form-item label="检定日期" prop="verificationDate">
  34. <el-date-picker
  35. :disabled="display"
  36. v-model="dataForm.verificationDate"
  37. value-format="yyyy-MM-dd"
  38. type="date">
  39. </el-date-picker>
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8" style="padding-left: 10px">
  43. <el-form-item label="检定有效期" prop="validityDate">
  44. <el-date-picker
  45. :disabled="display"
  46. v-model="dataForm.validityDate"
  47. value-format="yyyy-MM-dd"
  48. type="date">
  49. </el-date-picker>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-row class="my-row">
  54. <el-col :span="8">
  55. <el-form-item label="设备责任人" prop="responsibilityUser">
  56. <el-input v-if="display" v-model="dataForm.responsibilityUserName" disabled></el-input>
  57. <user-component v-else v-model="dataForm.responsibilityUser"/>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="8" style="padding-left: 20px">
  61. <el-form-item label="操作人" prop="userOf">
  62. <el-input v-if="display" v-model="dataForm.userOfName" disabled></el-input>
  63. <user-component v-else v-model="dataForm.userOf"/>
  64. </el-form-item>
  65. </el-col>
  66. </el-row>
  67. <el-row class="my-row">
  68. <upload-component :display="display" :title="'使用说明书'" :accept="'*'" :file-obj-list="fileList" @uploadSuccess="uploadSuccess"/>
  69. </el-row>
  70. <el-row class="my-row" style="margin-top: 20px">
  71. <el-form-item label="备注" prop="notes">
  72. <el-input type="textarea" v-model="dataForm.notes" :disabled="display" placeholder="备注"></el-input>
  73. </el-form-item>
  74. </el-row>
  75. </el-form>
  76. <span slot="footer" class="dialog-footer">
  77. <el-button @click="visible = false">取消</el-button>
  78. <el-button v-if="!display" type="primary" @click="dataFormSubmit()">确定</el-button>
  79. </span>
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script>
  84. import { getEquipmentDetail } from '@/api/production'
  85. import UserComponent from '../common/user-component'
  86. import uploadComponent from '../common/upload-component'
  87. export default {
  88. name: 'equipment-add-or-update',
  89. components: {
  90. UserComponent, uploadComponent
  91. },
  92. data () {
  93. return {
  94. visible: false,
  95. display: false,
  96. dataList: [],
  97. fileList: [],
  98. id: 0,
  99. dataForm: {},
  100. optionsType: [],
  101. optionsApplier: [],
  102. materialDetails: [],
  103. addMaterialVisible: false,
  104. totalAmount: 0,
  105. dataRule: {
  106. name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
  107. specifications: [{ required: true, message: '型号规格不能为空', trigger: 'blur' }],
  108. manufacturers: [{ required: true, message: '制造商不能为空', trigger: 'blur' }],
  109. verificationDate: [{ required: true, message: '检定日期不能为空', trigger: 'change' }],
  110. validityDate: [{ required: true, message: '检定有效期不能为空', trigger: 'change' }]
  111. }
  112. }
  113. },
  114. methods: {
  115. async init (id, display) {
  116. this.materialDetails = []
  117. this.dataForm = {
  118. payType: '0'
  119. }
  120. this.visible = true
  121. this.id = id || 0
  122. this.display = display
  123. if (!id) return
  124. await getEquipmentDetail(this.id).then(({data}) => {
  125. if (data && data.code === '200') {
  126. this.dataForm = data.data
  127. // 文件列表
  128. this.fileList = []
  129. if (data.data.attachList) {
  130. data.data.attachList.forEach((item) => {
  131. this.fileList.push({
  132. name: item.fileName,
  133. url: item.url,
  134. id: item.url
  135. })
  136. })
  137. }
  138. }
  139. })
  140. },
  141. validateField (type) {
  142. this.$refs.dataForm.validateField(type)
  143. },
  144. // 表单提交
  145. dataFormSubmit () {
  146. this.$refs['dataForm'].validate((valid) => {
  147. if (valid) {
  148. // 添加附件
  149. let fList = this.fileList
  150. if (fList.length > 0) {
  151. this.dataForm.attachList = []
  152. for (let i = 0; i < fList.length; i++) {
  153. this.dataForm.attachList.push({
  154. fileName: fList[i].name,
  155. url: fList[i].url
  156. })
  157. }
  158. }
  159. this.$http({
  160. url: !this.id ? this.$http.adornUrl(`/biz-service/equipment/save`) : this.$http.adornUrl(`/biz-service/equipment/update`),
  161. method: 'post',
  162. data: this.$http.adornData(this.dataForm)
  163. }).then(({data}) => {
  164. if (data && data.code === '200') {
  165. this.$message({
  166. message: '操作成功',
  167. type: 'success',
  168. duration: 1500,
  169. onClose: () => {
  170. this.visible = false
  171. this.$emit('refreshDataList')
  172. }
  173. })
  174. } else {
  175. this.$message.error(data.msg)
  176. }
  177. })
  178. }
  179. })
  180. },
  181. uploadSuccess (fileList) {
  182. this.fileList = fileList
  183. }
  184. }
  185. }
  186. </script>
  187. <style scoped>
  188. </style>