BaseFormMeasure.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <a-card :bordered="false" v-show="visible" class="card">
  3. <a-row :gutter="48" style="position:fixed;bottom:150px;z-index:999;display:flex; justify-content: center;width: 90%;">
  4. <a-col :md="48" :sm="48">
  5. <span>
  6. <a-button type="primary" @click="save()">保存</a-button>
  7. <a-button style="margin-left: 8px" type="default" @click="handleCancel()">返回</a-button>
  8. </span>
  9. </a-col>
  10. </a-row>
  11. <div>
  12. <div class="tables">
  13. <div style="text-align:center;padding-bottom:10px;font-size:32px;">时代思康检定表</div>
  14. <div style="display:flex; justify-content: space-between;">
  15. <div> 检定人:{{ username }}</div>
  16. </div>
  17. <table>
  18. <thead border="1px">
  19. <tr>
  20. <th width="100px">序号</th>
  21. <th width="150px">设备名称</th>
  22. <th width="150px">型号</th>
  23. <th width="150px">是否是子设备</th>
  24. <th width="350px">选择父设备</th>
  25. <th width="150px">设备位置</th>
  26. <th width="150px">设备位号</th>
  27. <th width="150px">检定周期</th>
  28. <th width="150px">检定日期</th>
  29. <th width="150px">检定单号</th>
  30. <th width="150px">检定单位</th>
  31. <th width="150px">备注</th>
  32. <th width="150px">有效期</th>
  33. <th width="150px">操作</th>
  34. </tr>
  35. <tr v-if="ListForm.length>0">
  36. <th v-for="item in ListForm[0].content" :key="item.name">{{ item.name }}</th>
  37. </tr>
  38. </thead>
  39. <tbody v-if="ListForm.length>0">
  40. <tr v-for="(item,i) in ListForm" :key="item.id">
  41. <td>{{ i+1 }}</td>
  42. <td>{{ item.sbName }}</td>
  43. <td>{{ item.sbModel }}</td>
  44. <td>{{ item.isChild === 1?'是':'否' }}</td>
  45. <td> <div v-if="item.isChild === 1" style="width:300px">
  46. <a-input
  47. disabled
  48. style="width: 50%"
  49. v-model="item.parentSbName"/>
  50. <a-button type="primary" @click="handleSbSelect(i)">选择</a-button>
  51. </div>
  52. <div v-else>无</div></td>
  53. <td><a-tree-select
  54. style="width: 150px"
  55. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  56. :treeData="treeData"
  57. :treeNodeFilterProp="'title'"
  58. :showSearch="true"
  59. v-model="item.sbPositionId"
  60. placeholder="请选择"
  61. >
  62. </a-tree-select></td>
  63. <td>
  64. <a-input v-if="item.isChild !== 1" style="width: 150px" v-model="item.sbPositionNo" />
  65. <div v-else style="width:300px">
  66. <a-input
  67. disabled
  68. style="width: 50%"
  69. v-model="item.sbPositionNo"/>
  70. <a-button type="primary" @click="handleSbNoSelect(i)">选择</a-button>
  71. </div>
  72. </td>
  73. <td><a-input v-model="item.checkPeriod" :formatter="BaseTool.Amount.formatter" :parser="BaseTool.Amount.parser"> <span slot="suffix" >月</span> </a-input></td>
  74. <td><a-date-picker
  75. placeholder="日期"
  76. style="width: 150px"
  77. :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
  78. v-model="item.lastDate" /></td>
  79. <td><a-input style="width: 150px" v-model="item.no" /></td>
  80. <td><a-input style="width: 150px" v-model="item.requirement" /></td>
  81. <td><a-input style="width: 150px" v-model="item.remark" /></td>
  82. <td>{{ validity(item.lastDate,item.checkPeriod) }}</td>
  83. <td>
  84. <a-button type="link" @click="uploadImg(item,i)">上传图片</a-button>
  85. <a-button type="link" @click="uploadFile(item,i)">上传文件</a-button>
  86. <a-modal v-model="uploadVisible" title="上传图片" :footer="null" @cancel="uploadVisible = false">
  87. <a-upload
  88. :action="uploadUrl"
  89. list-type="picture-card"
  90. :file-list="defaultApplicationFileList"
  91. @change="handleApplicationFileChange"
  92. @preview="handlePreview"
  93. accept="image/*"
  94. :headers="headers"
  95. >
  96. <div>
  97. <a-icon type="plus" />
  98. <div class="ant-upload-text">
  99. Upload
  100. </div>
  101. </div>
  102. </a-upload>
  103. </a-modal>
  104. <a-modal v-model="uploadFiledVisible" title="上传文件" :footer="null" @cancel="uploadFiledVisible = false">
  105. <a-upload
  106. :action="uploadUrl"
  107. :multiple="true"
  108. :file-list="defaultCheckFileList"
  109. @change="handleCheckFileChange"
  110. :headers="headers"
  111. >
  112. <a-button> <a-icon type="upload" /> 上传 </a-button>
  113. </a-upload>
  114. </a-modal>
  115. <a-modal :visible="previewVisible" :footer="null" @cancel="previewVisible = false" @ok="previewVisible = false">
  116. <img alt="example" style="width: 100%" :src="previewImage" />
  117. </a-modal>
  118. </td>
  119. </tr>
  120. </tbody>
  121. </table>
  122. </div>
  123. </div>
  124. <sb-info-select-modal ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
  125. <sb-position-no-modal ref="sbPositionNoModal" @selected="handleSbNoSelectd"/>
  126. </a-card>
  127. </template>
  128. <script>
  129. import { getSbPositionTree } from '@/api/sb/position'
  130. import SbInfoSelectModal from '@/views/sb/info/modules/SbInfoSelectModal'
  131. import SbPositionNoModal from '@/views/sb/info/modules/SbPositionNoModal'
  132. import { importMeasure } from '@/api/sb/info'
  133. import { uploadUrl } from '@/api/upms/file'
  134. import Vue from 'vue'
  135. import { ACCESS_TOKEN } from '@/store/mutation-types'
  136. import { status } from 'nprogress'
  137. export default {
  138. name: 'BaseFillGatherTask',
  139. components: {
  140. SbInfoSelectModal,
  141. SbPositionNoModal
  142. },
  143. data () {
  144. return {
  145. uploadUrl: uploadUrl,
  146. defaultApplicationFileList: [],
  147. defaultCheckFileList: [],
  148. checkFileList: [], // 文档
  149. applicationFileList: [],
  150. headers: {
  151. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  152. },
  153. visible: false,
  154. username: this.$store.getters.userInfo.username,
  155. uploadVisible: false,
  156. uploadFiledVisible: false,
  157. previewVisible: false,
  158. previewImage: '',
  159. treeData: [],
  160. sbParentOPt: 0,
  161. model: {},
  162. listPage: {
  163. pageNum: 1,
  164. pageSize: 10,
  165. total: 0
  166. },
  167. pagination: {
  168. pageNum: 1,
  169. pageSize: 10,
  170. total: 0
  171. },
  172. imgId: '',
  173. fileId: '',
  174. ListForm: [],
  175. id: '',
  176. updatesInfo: []
  177. // 下拉框map
  178. }
  179. },
  180. props: {
  181. },
  182. created () {
  183. // 下拉框map
  184. },
  185. methods: {
  186. validity (lastDate, checkPeriod) {
  187. if (lastDate === '') return ''
  188. lastDate = this.BaseTool.Date.formatter(lastDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN).split('-')
  189. lastDate[1] = (parseInt(lastDate[1]) + parseInt(checkPeriod)) % 12
  190. lastDate[0] = +lastDate[0] + Math.floor((parseInt(lastDate[1]) + parseInt(checkPeriod)) / 12)
  191. return lastDate.join('-')
  192. },
  193. base (record) {
  194. this.visible = true
  195. this.model = record
  196. this.ListForm = record.map(item => {
  197. const data = {
  198. sbName: item.name,
  199. sbModel: item.model,
  200. checkPeriod: item.checkPeriod,
  201. isChild: item.isChild,
  202. parentSbName: item.parentSbName,
  203. sbParentId: item.parentId,
  204. sbPositionId: item.positionId,
  205. no: '',
  206. lastDate: '',
  207. sbPositionNo: item.positionNo,
  208. requirement: '',
  209. remark: '',
  210. name: this.username,
  211. sbId: item.id,
  212. type: 1,
  213. checkImgList: [],
  214. checkFileList: []
  215. }
  216. return data
  217. })
  218. getSbPositionTree().then(res => {
  219. this.treeData = res.data
  220. })
  221. },
  222. handleSbSelect (i) {
  223. this.sbParentOPt = i
  224. this.$refs.sbInfoSelectModal.base({}, { isChild: this.DictCache.VALUE.SB_IS_CHILD.IS_PARENT })
  225. },
  226. handleSbNoSelect (i) {
  227. this.sbParentOPt = i
  228. this.$refs.sbPositionNoModal.base()
  229. },
  230. handleSbSelectd (keys, rows) {
  231. console.log(keys, rows)
  232. this.ListForm[ this.sbParentOPt ].sbParentId = keys[0]
  233. this.ListForm[ this.sbParentOPt ].parentSbName = rows[0].name
  234. },
  235. handleSbNoSelectd (keys, rows) {
  236. console.log(keys, rows)
  237. this.ListForm[ this.sbParentOPt ].sbPositionNo = rows[0].no
  238. },
  239. uploadFile (val, i) {
  240. this.uploadFiledVisible = true
  241. this.fileId = i
  242. console.log(val)
  243. this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(val.checkFileList)
  244. },
  245. uploadImg (val, i) {
  246. this.uploadVisible = true
  247. console.log(val)
  248. this.imgId = i
  249. this.defaultApplicationFileList = this.BaseTool.UPLOAD.transImg(val.checkImgList)
  250. },
  251. getBase64 (file) {
  252. return new Promise((resolve, reject) => {
  253. const reader = new FileReader()
  254. reader.readAsDataURL(file)
  255. reader.onload = () => resolve(reader.result)
  256. reader.onerror = error => reject(error)
  257. })
  258. },
  259. async handlePreview (file) {
  260. if (!file.url && !file.preview) {
  261. file.preview = await this.getBase64(file.originFileObj)
  262. }
  263. this.previewImage = file.url || file.preview
  264. this.previewVisible = true
  265. },
  266. handleApplicationFileChange (info) {
  267. this.defaultApplicationFileList = info.fileList
  268. this.applicationFileList = this.setFileList(info, 11)
  269. this.ListForm[this.imgId].checkImgList = this.applicationFileList
  270. },
  271. handleCheckFileChange (info) {
  272. this.defaultCheckFileList = info.fileList
  273. this.checkFileList = this.setFileList(info, 32)
  274. this.ListForm[this.fileId].checkFileList = this.checkFileList
  275. console.log(this.checkFileList)
  276. },
  277. setFileList (info, type) {
  278. const file = info.file
  279. const fileList = info.fileList
  280. if (file.status === 'done') {
  281. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  282. } else if (file.status === 'removed') {
  283. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  284. } else if (file.status === 'error') {
  285. this.$message.error('上传失败')
  286. return []
  287. }
  288. },
  289. save () {
  290. let status = false
  291. this.ListForm.forEach(item => {
  292. switch (true) {
  293. case item.no == '':
  294. this.$message.warning(item.sbName + '的检定单号不能为空!')
  295. status = true
  296. break
  297. case item.lastDate == '':
  298. this.$message.warning(item.sbName + '的检定日期不能为空!')
  299. status = true
  300. break
  301. }
  302. item.lastDate = item.lastDate != '' ? this.BaseTool.Date.formatter(item.lastDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN) : ''
  303. })
  304. if (status) return
  305. const params = {
  306. sbMeasureLogDTOList: this.ListForm
  307. }
  308. importMeasure(params).then(res => {
  309. this.$message.success('检定完成!')
  310. this.handleCancel()
  311. })
  312. },
  313. handleCancel () {
  314. this.visible = false
  315. this.ListForm = []
  316. this.$emit('ok')
  317. }
  318. }
  319. }
  320. </script>
  321. <style lang="less" scoped>
  322. .tables{
  323. margin: 20px 0px;
  324. width: 100%;
  325. overflow-x:auto;
  326. table {
  327. min-width:100%;
  328. margin: 0 auto;
  329. border: 1px solid #D6D6D6;
  330. border-collapse: collapse;
  331. font-size: 16px;
  332. font-weight: 400;
  333. table-layout:fixed;
  334. }
  335. th{
  336. background: #fafafa;
  337. font-weight: 500;
  338. }
  339. th,
  340. td {
  341. border: 1px solid #D6D6D6;
  342. text-align: center;
  343. padding: 5px 10px;
  344. white-space: nowrap;
  345. }
  346. }
  347. </style>