form.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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} 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. }
  42. },
  43. onBackPress() {
  44. },
  45. onLoad() {
  46. this.init()
  47. },
  48. methods: {
  49. init(){
  50. let point=uni.getStorageSync('point');
  51. this.point=point;
  52. },
  53. getLocation(){
  54. const self=this;
  55. uni.getLocation({
  56. type: 'wgs84',
  57. success: function (res) {
  58. self.formData.dutyLongitude=res.longitude
  59. self.formData.dutyLatitude=res.latitude
  60. }
  61. });
  62. },
  63. async onSubmit() {
  64. let point=uni.getStorageSync('point')
  65. let attachList=[]
  66. for(let i=0;i<this.formData.attachList.length;i++){
  67. let filePath=this.formData.attachList[i].url
  68. fileresq=await upload({filePath,formData:{
  69. additions: `经度:${this.formData.dutyLongitude};纬度:${this.formData.dutyLatitude}`
  70. }})
  71. fileresq=JSON.parse(fileresq)
  72. attachList.push(fileresq.data)
  73. }
  74. await updateChecklistPoint({
  75. recordId:point.recordId,
  76. checklistId:point.checklistId,
  77. itemId:point.itemId,
  78. pointId:point.pointId,
  79. checkResult:this.formData.checkResult,
  80. remark:this.formData.remark,
  81. attachList,
  82. }).catch(()=>{
  83. uni.showToast({
  84. icon:'none',
  85. title:"提交失败!"
  86. })
  87. })
  88. uni.showToast({
  89. icon:'none',
  90. title:"提交成功!",
  91. complete() {
  92. uni.redirectTo({
  93. url:`/pages/app_views/checkList/index/index?type=form&id=${point.checklistId}&recordId=${point.recordId}`
  94. })
  95. }
  96. })
  97. },
  98. uploadSuccess(e){
  99. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  100. attachList.push(e.tempFiles[0])
  101. this.formData.attachList=attachList
  102. },
  103. deleteFile(e){
  104. let attachList=JSON.parse(JSON.stringify(this.formData.attachList))
  105. attachList.filter(item=>item.uuid!==e.tempFile.uuid)
  106. this.formData.attachList=attachList
  107. },
  108. },
  109. onUnload() {
  110. uni.removeStorageSync('point')
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .wrap{
  116. padding: 20rpx;
  117. .submit-BT {
  118. width: 750rpx;
  119. color: #4D73FF;
  120. text-align: center;
  121. font-size: 32rpx;
  122. padding-bottom: 68rpx;
  123. background-color: #fff;
  124. position: fixed;
  125. left: 0;
  126. bottom: 0;
  127. z-index: 99;
  128. box-shadow: 0px 0px 12px 0px #0000000A;
  129. border-radius: 8px 8px 0px 0px
  130. }
  131. ::v-deep .uni-forms-item{
  132. .uni-forms-item__content{
  133. .uni-data-checkbox-wrap{
  134. height: 100%;
  135. display: flex;
  136. align-items: center;
  137. }
  138. }
  139. }
  140. }
  141. </style>