form.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  4. <uni-forms-item label="是否通过" required>
  5. <text class="status-item"
  6. :class="form.status==1?'active':''"
  7. @click="form.status=1"
  8. >通过</text>
  9. <text class="status-item"
  10. :class="form.status==2?'active':''"
  11. @click="form.status=2"
  12. >不通过</text>
  13. </uni-forms-item>
  14. <uni-forms-item label="整改人" name="user" required>
  15. <uni-data-select
  16. v-model="form.user"
  17. :localdata="users"
  18. ></uni-data-select>
  19. </uni-forms-item>
  20. <uni-forms-item label="描述" name="desc" required>
  21. <uni-easyinput type="textarea" autoHeight v-model="form.desc" placeholder="请输入描述"></uni-easyinput>
  22. </uni-forms-item>
  23. <uni-forms-item label="附件">
  24. <div class="upload-container">
  25. <image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
  26. <p class="tip">注:单个附件上传不超过10M,附件累计不超过20M</p>
  27. </div>
  28. <view class="preview" v-if="form.attachList.length>0">
  29. <image :src="attach.path" mode="widthFix" v-for="(attach,index) in form.attachList" :key="index"></image>
  30. </view>
  31. </uni-forms-item>
  32. </uni-forms>
  33. <view class="footer" @click="onSubmit">提交</view>
  34. </div>
  35. </template>
  36. <script>
  37. import {uploadFile,uploadFiles,uploadApi} from '@/api/upload.js'
  38. export default {
  39. data() {
  40. return {
  41. status: [
  42. { value: 0, text: "否" },
  43. { value: 1, text: "是" }
  44. ],
  45. users:[
  46. { value: 0, text: "张三" },
  47. { value: 1, text: "李四" }
  48. ],
  49. rules:{
  50. user:{
  51. rules:[
  52. {
  53. required: true,
  54. errorMessage: '请选择整改人',
  55. },
  56. ],
  57. },
  58. desc:{
  59. rules:[
  60. {
  61. required: true,
  62. errorMessage: '请填写描述',
  63. },
  64. ]
  65. }
  66. },
  67. form:{
  68. status:1,
  69. password:"",
  70. desc:"",
  71. attachList:[]
  72. }
  73. }
  74. },
  75. methods: {
  76. upload(){
  77. uni.chooseImage({
  78. success: (files) => {
  79. const tempFilePaths = files.tempFilePaths;
  80. const tempFiles = files.tempFiles
  81. const formData = new FormData()
  82. formData.append('file', tempFilePaths)
  83. // uploadApi({
  84. // formData
  85. // })
  86. }
  87. });
  88. },
  89. onSubmit(){
  90. this.$refs.form.validate().then(res=>{
  91. console.log('表单数据信息:', res);
  92. }).catch(err =>{
  93. console.log('表单错误信息:', err);
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .body{
  101. height: 100vh;
  102. box-sizing: border-box;
  103. padding:21rpx 16rpx;
  104. background-color: #F3F5FB;
  105. .status-item{
  106. padding: 22rpx 32rpx;
  107. background-color: #fff;
  108. font-size: 28rpx;
  109. line-height: 1;
  110. display: inline-block;
  111. color: #434343;
  112. margin-right: 20rpx;
  113. border-radius: 2px;
  114. &.active{
  115. background: rgba(22, 141, 236, 0.16);
  116. color:#168DEC ;
  117. }
  118. }
  119. ::v-deep .uni-forms-item__content{
  120. .uni-easyinput,.uni-select{
  121. background-color: #fff;
  122. }
  123. }
  124. .upload-container{
  125. .upload{
  126. width: 216rpx;
  127. display: block;
  128. }
  129. .tip{
  130. font-size: 24rpx;
  131. line-height: 28rpx;
  132. color: #999999;
  133. padding-top: 20rpx;
  134. }
  135. }
  136. .footer{
  137. width: 100%;
  138. height: 136upx;
  139. background: #FFFFFF;
  140. border-radius: 16upx 16upx 0px 0px;
  141. position: fixed;
  142. left: 0;
  143. bottom: 0;
  144. text-align: center;
  145. color: #168DEC;
  146. font-size: 32upx;
  147. padding-top: 20upx;
  148. letter-spacing: 2px;
  149. }
  150. }
  151. </style>