form.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. })
  76. },
  77. getLocation(){
  78. const self=this;
  79. uni.getLocation({
  80. type: 'wgs84',
  81. success: function (res) {
  82. self.formData.dutyLongitude=res.longitude
  83. self.formData.dutyLatitude=res.latitude
  84. }
  85. });
  86. },
  87. async onSubmit() {
  88. let point=uni.getStorageSync('point')
  89. let attachList=[]
  90. for(let i=0;i<this.formData.attachList.length;i++){
  91. let filePath=this.formData.attachList[i].url
  92. let fileresq=await upload({filePath,formData:{
  93. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  94. }}).catch(()=>{
  95. uni.showToast({
  96. icon:'none',
  97. title:"提交失败!"
  98. })
  99. })
  100. if(fileresq.includes('html')){
  101. uni.showToast({
  102. icon:'none',
  103. title:"图片上传异常"
  104. })
  105. return
  106. }
  107. fileresq=JSON.parse(fileresq)
  108. attachList.push(fileresq.data)
  109. }
  110. await updateChecklistPoint({
  111. recordId:point.recordId,
  112. checklistId:point.checklistId,
  113. itemId:point.itemId,
  114. pointId:point.pointId,
  115. checkResult:this.formData.checkResult,
  116. remark:this.formData.remark,
  117. attachList,
  118. }).catch(()=>{
  119. uni.showToast({
  120. icon:'none',
  121. title:"提交失败!"
  122. })
  123. })
  124. this.goOnNext();
  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. },
  136. goOnNext(){
  137. let point=uni.getStorageSync('point')
  138. let pointIdex=this.itemList.findIndex(item=>point.pointId===item.pointId)
  139. let handles=this.itemList.slice(pointIdex+1);
  140. let nextPointIdx=handles.findIndex(item=>(!item.checkResult))
  141. nextPointIdx=nextPointIdx+pointIdex
  142. if(handles.length<1||nextPointIdx<0){
  143. uni.showToast({
  144. icon:'none',
  145. title:"处理完毕",
  146. duration:1000,
  147. complete() {
  148. uni.redirectTo({
  149. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  150. })
  151. }
  152. })
  153. return
  154. }
  155. this.formData={
  156. checkResult:1,
  157. remark:"",
  158. attachList:[]
  159. }
  160. let nextPoint=this.itemList[nextPointIdx+1]
  161. uni.setStorageSync('point',nextPoint);//防止测试刷新数据丢失
  162. this.point=nextPoint;
  163. },
  164. uploadSuccess(e){
  165. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  166. attachList.push(e.tempFiles[0])
  167. this.formData.attachList=attachList
  168. },
  169. deleteFile(e){
  170. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  171. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  172. this.formData.attachList=attachList
  173. },
  174. },
  175. onUnload() {
  176. uni.removeStorageSync('point')
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .wrap{
  182. padding: 20rpx;
  183. .submit-BT {
  184. width: 750rpx;
  185. color: #4D73FF;
  186. text-align: center;
  187. font-size: 32rpx;
  188. padding-bottom: 68rpx;
  189. background-color: #fff;
  190. position: fixed;
  191. left: 0;
  192. bottom: 0;
  193. z-index: 99;
  194. box-shadow: 0px 0px 12px 0px #0000000A;
  195. border-radius: 8px 8px 0px 0px
  196. }
  197. ::v-deep .uni-forms-item{
  198. .uni-forms-item__content{
  199. .uni-data-checkbox-wrap{
  200. height: 100%;
  201. display: flex;
  202. align-items: center;
  203. }
  204. }
  205. }
  206. }
  207. </style>