form.vue 3.3 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. </uni-forms-item>
  29. </uni-forms>
  30. <view class="footer" @click="onSubmit">提交</view>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. status: [
  38. { value: 0, text: "否" },
  39. { value: 1, text: "是" }
  40. ],
  41. users:[
  42. { value: 0, text: "张三" },
  43. { value: 1, text: "李四" }
  44. ],
  45. rules:{
  46. user:{
  47. rules:[
  48. {
  49. required: true,
  50. errorMessage: '请选择整改人',
  51. },
  52. ],
  53. },
  54. desc:{
  55. rules:[
  56. {
  57. required: true,
  58. errorMessage: '请填写描述',
  59. },
  60. ]
  61. }
  62. },
  63. form:{
  64. status:1,
  65. password:"",
  66. desc:""
  67. }
  68. }
  69. },
  70. methods: {
  71. upload(){
  72. uni.chooseFile({
  73. success: (files) => {
  74. const tempFilePaths = files.tempFilePaths;
  75. uni.uploadFile({
  76. url: 'https://www.example.com/upload', //仅为示例,非真实的接口地址
  77. filePath: tempFilePaths[0],
  78. name: 'file',
  79. formData: {
  80. 'user': 'test'
  81. },
  82. success: (uploadFileRes) => {
  83. console.log(uploadFileRes.data);
  84. }
  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>