form.vue 2.9 KB

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