form.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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} 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(point)
  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. this.batchHandle()
  137. },
  138. // 批量处理未处理的
  139. batchHandle(){
  140. let point=uni.getStorageSync('point')
  141. if(this.handles.length<1){
  142. uni.showToast({
  143. icon:'none',
  144. title:"处理完毕",
  145. duration:1000,
  146. complete() {
  147. uni.redirectTo({
  148. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  149. })
  150. }
  151. })
  152. return
  153. }
  154. let nextPoint=this.handles[0]
  155. this.formData={
  156. checkResult:1,
  157. remark:"",
  158. attachList:[]
  159. }
  160. this.handles.shift()
  161. uni.setStorageSync('point',nextPoint);
  162. this.point=nextPoint;
  163. },
  164. // 批量处理未处理的【按顺序走到最后一个】
  165. goOnNext(){
  166. let point=uni.getStorageSync('point')
  167. let pointIdex=this.itemList.findIndex(item=>point.pointId===item.pointId)
  168. let handles=this.itemList.slice(pointIdex+1);
  169. let nextPointIdx=handles.findIndex(item=>(!item.checkResult))
  170. nextPointIdx=nextPointIdx+pointIdex
  171. if(handles.length<1||nextPointIdx<0){
  172. uni.showToast({
  173. icon:'none',
  174. title:"处理完毕",
  175. duration:1000,
  176. complete() {
  177. uni.redirectTo({
  178. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  179. })
  180. }
  181. })
  182. return
  183. }
  184. this.formData={
  185. checkResult:1,
  186. remark:"",
  187. attachList:[]
  188. }
  189. let nextPoint=this.itemList[nextPointIdx+1]
  190. uni.setStorageSync('point',nextPoint);//防止测试刷新数据丢失
  191. this.point=nextPoint;
  192. },
  193. uploadSuccess(e){
  194. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  195. attachList.push(e.tempFiles[0])
  196. this.formData.attachList=attachList
  197. },
  198. deleteFile(e){
  199. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  200. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  201. this.formData.attachList=attachList
  202. },
  203. },
  204. // onUnload() {
  205. // uni.removeStorageSync('point')
  206. // }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .wrap{
  211. padding: 20rpx;
  212. .submit-BT {
  213. width: 750rpx;
  214. color: #4D73FF;
  215. text-align: center;
  216. font-size: 32rpx;
  217. padding-bottom: 68rpx;
  218. background-color: #fff;
  219. position: fixed;
  220. left: 0;
  221. bottom: 0;
  222. z-index: 99;
  223. box-shadow: 0px 0px 12px 0px #0000000A;
  224. border-radius: 8px 8px 0px 0px
  225. }
  226. ::v-deep .uni-forms-item{
  227. .uni-forms-item__content{
  228. .uni-data-checkbox-wrap{
  229. height: 100%;
  230. display: flex;
  231. align-items: center;
  232. }
  233. }
  234. }
  235. }
  236. </style>