form.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="wrap">
  3. <uni-section :title="point?point.pointContent:''" type="line">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" :label-width="300" label-position="top">
  5. <uni-forms-item label="检查结果" name="checkResult" required>
  6. <view class="uni-data-checkbox-wrap">
  7. <uni-data-checkbox v-model="formData.checkResult" :localdata="checkResults" />
  8. </view>
  9. </uni-forms-item>
  10. <uni-forms-item label="备注" name="remark">
  11. <uni-easyinput v-model="formData.remark" type="textarea" :maxlength="-1" autoHeight placeholder="备注" />
  12. </uni-forms-item>
  13. <uni-file-picker v-model="formData.attachList"
  14. fileMediatype="image"
  15. title="请上传附件"
  16. limit="1"
  17. @select="uploadSuccess"
  18. @delete="deleteFile"></uni-file-picker>
  19. </uni-forms>
  20. </uni-section>
  21. <view class="tip">还剩<text class="word">{{handles.length+1}}</text></view>
  22. <button type="primary" @click="onSubmit" class="submit-BT">下一步</button>
  23. </view>
  24. </template>
  25. <script>
  26. import {upload} from '@/api/system/upload.js'
  27. import {updateChecklistPoint,getchecklistRecord,checklistComplete} from '@/api/aqpt/checklistPoint.js'
  28. export default {
  29. data() {
  30. return {
  31. checkResults:[
  32. {text:"通过",value:1},
  33. {text:"不通过",value:-1},
  34. ],
  35. formData:{
  36. checkResult:1,
  37. remark:"",
  38. attachList:[]
  39. },
  40. rules:{},
  41. point:{},
  42. handles:[],
  43. itemList:[]
  44. }
  45. },
  46. onLoad() {
  47. this.init()
  48. },
  49. methods: {
  50. init(){
  51. let point=uni.getStorageSync('point');
  52. this.point=point;
  53. this.getchecklistRecord()
  54. this.getLocation()
  55. },
  56. getchecklistRecord(){
  57. let {checklistId,recordId}=uni.getStorageSync('point');
  58. if(!checklistId)return
  59. getchecklistRecord(checklistId,recordId).then((res)=>{
  60. let itemList=res.data.itemList
  61. let point=null
  62. let points=[]
  63. for(let i=0;i<itemList.length;i++){
  64. if(itemList[i].children){
  65. itemList[i].children.map(child=>{
  66. child.recordList.map(pointitem=>{
  67. points.push(pointitem)
  68. })
  69. })
  70. }else{
  71. itemList[i].recordList.map(pointitem=>{
  72. points.push(pointitem)
  73. })
  74. }
  75. }
  76. this.itemList=points
  77. this.handles=points.filter(item=>(!item.checkResult&&item.pointId!==this.point.pointId))
  78. })
  79. },
  80. getLocation(){
  81. const self=this;
  82. uni.getLocation({
  83. type: 'wgs84',
  84. success: function (res) {
  85. self.formData.dutyLongitude=res.longitude
  86. self.formData.dutyLatitude=res.latitude
  87. }
  88. });
  89. },
  90. async onSubmit() {
  91. let point=uni.getStorageSync('point')
  92. let attachList=[]
  93. for(let i=0;i<this.formData.attachList.length;i++){
  94. let filePath=this.formData.attachList[i].url
  95. let fileresq=await upload({filePath,formData:{
  96. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  97. }}).catch(()=>{
  98. uni.showToast({
  99. icon:'none',
  100. title:"提交失败!"
  101. })
  102. })
  103. if(fileresq.includes('html')){
  104. uni.showToast({
  105. icon:'none',
  106. title:"图片上传异常"
  107. })
  108. return
  109. }
  110. fileresq=JSON.parse(fileresq)
  111. attachList.push(fileresq.data)
  112. }
  113. await updateChecklistPoint({
  114. recordId:point.recordId,
  115. checklistId:point.checklistId,
  116. itemId:point.itemId,
  117. pointId:point.pointId,
  118. checkResult:this.formData.checkResult,
  119. remark:this.formData.remark,
  120. attachList,
  121. }).catch(()=>{
  122. uni.showToast({
  123. icon:'none',
  124. title:"提交失败!"
  125. })
  126. })
  127. // uni.showToast({
  128. // icon:'none',
  129. // title:"提交成功!",
  130. // duration:1000,
  131. // complete() {
  132. // uni.redirectTo({
  133. // url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  134. // })
  135. // }
  136. // })
  137. // this.goOnNext();
  138. let idx=this.itemList.findIndex(item=>item.pointId===point.pointId)
  139. this.itemList[idx].checkResult=this.formData.checkResult
  140. this.batchHandle()
  141. },
  142. // 批量处理未处理的
  143. batchHandle(){
  144. let point=uni.getStorageSync('point')
  145. const rid=point.recordId;
  146. const cid=point.checklistId;
  147. if(this.handles.length<1){
  148. const key=this.itemList.find(item=>item.checkResult===-1)
  149. checklistComplete(point.recordId,point.checklistId).then(()=>{
  150. if(!key){
  151. uni.$emit('type',1)
  152. uni.switchTab({
  153. url:'/pages/history/history'
  154. })
  155. }else{
  156. uni.showModal({
  157. title: '提示',
  158. content: '本次检查有未通过项,是否需要登记隐患?',
  159. success: function (res) {
  160. if (res.confirm) {
  161. uni.reLaunch({
  162. url:`/pages/app_views/danger/submit/submit?rid=${rid}&cid=${cid}&type=point`
  163. })
  164. } else if (res.cancel) {
  165. uni.$emit('type',1)
  166. uni.switchTab({
  167. url:'/pages/history/history'
  168. })
  169. }
  170. }
  171. });
  172. }
  173. }).catch(()=>{
  174. uni.showToast({
  175. icon:"none",
  176. title:"操作失败"
  177. })
  178. })
  179. }
  180. let nextPoint=this.handles[0]
  181. this.formData={
  182. checkResult:1,
  183. remark:"",
  184. attachList:[]
  185. }
  186. this.handles.shift()
  187. uni.setStorageSync('point',nextPoint);
  188. this.point=nextPoint;
  189. },
  190. // 批量处理未处理的【按顺序走到最后一个】
  191. goOnNext(){
  192. let point=uni.getStorageSync('point')
  193. let pointIdex=this.itemList.findIndex(item=>point.pointId===item.pointId)
  194. let handles=this.itemList.slice(pointIdex+1);
  195. let nextPointIdx=handles.findIndex(item=>(!item.checkResult))
  196. nextPointIdx=nextPointIdx+pointIdex
  197. if(handles.length<1||nextPointIdx<0){
  198. uni.showToast({
  199. icon:'none',
  200. title:"处理完毕",
  201. duration:1000,
  202. complete() {
  203. uni.redirectTo({
  204. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  205. })
  206. }
  207. })
  208. return
  209. }
  210. this.formData={
  211. checkResult:1,
  212. remark:"",
  213. attachList:[]
  214. }
  215. let nextPoint=this.itemList[nextPointIdx+1]
  216. uni.setStorageSync('point',nextPoint);//防止测试刷新数据丢失
  217. this.point=nextPoint;
  218. },
  219. uploadSuccess(e){
  220. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  221. attachList.push(e.tempFiles[0])
  222. this.formData.attachList=attachList
  223. },
  224. deleteFile(e){
  225. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  226. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  227. this.formData.attachList=attachList
  228. },
  229. },
  230. onUnload() {
  231. uni.removeStorageSync('point')
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .wrap{
  237. padding: 20rpx;
  238. .tip{
  239. padding: 20rpx 10rpx 10rpx;
  240. text-align: right;
  241. color: #666;
  242. .word{
  243. font-weight: bold;
  244. color: #222;
  245. padding: 0 10rpx;
  246. }
  247. }
  248. .submit-BT {
  249. width: 750rpx;
  250. color: #4D73FF;
  251. text-align: center;
  252. font-size: 32rpx;
  253. padding-bottom: 68rpx;
  254. background-color: #fff;
  255. position: fixed;
  256. left: 0;
  257. bottom: 0;
  258. z-index: 99;
  259. box-shadow: 0px 0px 12px 0px #0000000A;
  260. border-radius: 8px 8px 0px 0px
  261. }
  262. ::v-deep .uni-forms-item{
  263. .uni-forms-item__content{
  264. .uni-data-checkbox-wrap{
  265. height: 100%;
  266. display: flex;
  267. align-items: center;
  268. }
  269. }
  270. }
  271. }
  272. </style>