form.vue 6.8 KB

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