form.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  4. <uni-forms-item label="是否异常" name="status" required>
  5. <uni-data-select
  6. v-model="form.status"
  7. :localdata="status"
  8. ></uni-data-select>
  9. </uni-forms-item>
  10. <uni-forms-item label="评审人" name="user" required v-if="form.status===1">
  11. <view style="padding-bottom: 16rpx;">
  12. <uni-data-picker :map='groupMap'
  13. placeholder="请选择组织"
  14. popup-title="请选择组织"
  15. :localdata="groupList"
  16. @change="onchangeGroup">
  17. </uni-data-picker>
  18. </view>
  19. <uni-data-select
  20. v-model="form.user"
  21. :localdata="users"
  22. ></uni-data-select>
  23. </uni-forms-item>
  24. <uni-forms-item label="描述" name="desc" required>
  25. <uni-easyinput type="textarea" autoHeight v-model="form.desc" placeholder="请输入描述"></uni-easyinput>
  26. </uni-forms-item>
  27. <uni-forms-item label="附件">
  28. <div class="upload-container">
  29. <image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
  30. <p class="tip">注:单个附件上传不超过10M,附件累计不超过20M</p>
  31. </div>
  32. </uni-forms-item>
  33. </uni-forms>
  34. <view class="footer" @click="onSubmit">提交</view>
  35. </div>
  36. </template>
  37. <script>
  38. import { getGroupByList } from '@/api/system/groupApi'
  39. import {parseTime,packageTreeData} from '@/libs'
  40. export default {
  41. data() {
  42. return {
  43. groupList:[],
  44. groupMap:{text:"groupName",value:"groupId"},
  45. status: [
  46. { value: 0, text: "否" },
  47. { value: 1, text: "是" }
  48. ],
  49. users:[
  50. { value: 0, text: "张三" },
  51. { value: 1, text: "李四" }
  52. ],
  53. rules:{
  54. status:{
  55. rules:[
  56. {
  57. required: true,
  58. errorMessage: '请选择是否异常'
  59. }
  60. ],
  61. validateTrigger:'submit'
  62. },
  63. user:{
  64. rules:[
  65. {
  66. required: true,
  67. errorMessage: '请选择评审人',
  68. },
  69. ],
  70. },
  71. desc:{
  72. rules:[
  73. {
  74. required: true,
  75. errorMessage: '请填写描述',
  76. },
  77. ]
  78. }
  79. },
  80. form:{
  81. status:"",
  82. user:"",
  83. desc:"",
  84. attachList:[]
  85. }
  86. }
  87. },
  88. methods: {
  89. upload(){
  90. uni.chooseFile({
  91. success: (files) => {
  92. const tempFilePaths = files.tempFilePaths;
  93. uni.uploadFile({
  94. url: 'https://www.example.com/upload', //仅为示例,非真实的接口地址
  95. filePath: tempFilePaths[0],
  96. name: 'file',
  97. formData: {
  98. 'user': 'test'
  99. },
  100. success: (uploadFileRes) => {
  101. console.log(uploadFileRes.data);
  102. }
  103. });
  104. }
  105. });
  106. },
  107. onchangeGroup({detail}){
  108. let groupVal=detail.value
  109. let groupId=groupVal[groupVal.length-1].value
  110. this.getUser(groupId)
  111. },
  112. getGroup(){
  113. getGroupByList().then((res)=>{
  114. let items=packageTreeData({
  115. data:res.data,
  116. id:"groupId"
  117. })
  118. this.groupList=items
  119. })
  120. },
  121. getUser(groupId){
  122. getUserByPage({
  123. page: 1,
  124. limit: 999999,
  125. groupId
  126. }).then((res)=>{
  127. this.userList=res.data.map(item=>{
  128. return{
  129. ...item,
  130. value:item.accountId,
  131. text:item.accountName
  132. }
  133. })
  134. })
  135. },
  136. onSubmit(){
  137. this.$refs.form.validate().then(res=>{
  138. console.log('表单数据信息:', res);
  139. }).catch(err =>{
  140. console.log('表单错误信息:', err);
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .body{
  148. height: 100vh;
  149. box-sizing: border-box;
  150. padding:21rpx 16rpx;
  151. background-color: #F3F5FB;
  152. ::v-deep .uni-forms-item__content{
  153. .uni-easyinput,.uni-select{
  154. background-color: #fff;
  155. }
  156. }
  157. .upload-container{
  158. .upload{
  159. width: 216rpx;
  160. display: block;
  161. }
  162. .tip{
  163. font-size: 24rpx;
  164. line-height: 28rpx;
  165. color: #999999;
  166. padding-top: 20rpx;
  167. }
  168. }
  169. .footer{
  170. width: 100%;
  171. height: 136upx;
  172. background: #FFFFFF;
  173. border-radius: 16upx 16upx 0px 0px;
  174. position: fixed;
  175. left: 0;
  176. bottom: 0;
  177. text-align: center;
  178. color: #168DEC;
  179. font-size: 32upx;
  180. padding-top: 20upx;
  181. letter-spacing: 2px;
  182. }
  183. }
  184. </style>