BaseFormMeasureInStore.vue 14 KB

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