TeamForm.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <uni-drawer ref="drawer" mode="left" :mask-click="false" width="85%" :maskClick='true'>
  3. <scroll-view class="scroll-view" scroll-y="true">
  4. <view class="form-wrap" >
  5. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  6. <uni-forms-item label="队伍名称" name="teamName" required>
  7. <uni-easyinput v-model="form.teamName" placeholder="请输入队伍名称" :clearable="false" />
  8. </uni-forms-item>
  9. <uni-forms-item label="队伍类别" name="teamCatId" required>
  10. <uni-data-select v-model="form.teamCatId" :localdata="teamCats" placeholder="请选择值班人员" :clear="false"></uni-data-select>
  11. </uni-forms-item>
  12. <uni-forms-item label="职责说明">
  13. <uni-easyinput type="textarea" :maxlength="1000" v-model="form.teamDuty" placeholder="请输入职责说明" autoHeight ></uni-easyinput>
  14. <view class="word-limit">{{form.teamDuty.length||0}}/1000</view>
  15. </uni-forms-item>
  16. <uni-forms-item label="说明">
  17. <uni-easyinput type="textarea" :maxlength="500"
  18. v-model="form.teamDesc" autoHeight
  19. placeholder="请输入职责说明"></uni-easyinput>
  20. <view class="word-limit">{{form.teamDesc.length||0}}/500</view>
  21. </uni-forms-item>
  22. <uni-forms-item label="排序" v-model="form.sortNo">
  23. <uni-number-box :min="1"></uni-number-box>
  24. </uni-forms-item>
  25. </uni-forms>
  26. <view class="handle-container">
  27. <button class="save" type="primary" @click="onSubmit">保存</button>
  28. <button class="cancel" type="default" @click="close">取消</button>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </uni-drawer>
  33. </template>
  34. <script>
  35. import teamApi from '@/api/team.js'
  36. export default{
  37. name:"TeamForm",
  38. computed:{
  39. teamCats(){
  40. let teamCats=uni.getStorageSync('teamCat')
  41. return teamCats.map(item=>{
  42. return{
  43. value:item.teamCatId,
  44. text:item.teamCatTitle
  45. }
  46. })
  47. }
  48. },
  49. data(){
  50. return{
  51. type:undefined,
  52. rules:{
  53. teamName:{
  54. rules:[
  55. {
  56. required: true,
  57. errorMessage: '请输入队伍名称'
  58. }
  59. ],
  60. validateTrigger:'submit'
  61. },
  62. teamCatId:{
  63. rules:[
  64. {
  65. required: true,
  66. errorMessage: '请选择队伍类别',
  67. }
  68. ],
  69. validateTrigger:'submit'
  70. },
  71. },
  72. form:{
  73. teamId: 0,
  74. teamName: '',
  75. teamType: 1,
  76. teamCatId: 1,
  77. teamDuty: '',
  78. teamDesc: '',
  79. sortNo: 1
  80. }
  81. }
  82. },
  83. methods:{
  84. resetForm(){
  85. this.form={
  86. teamId: 0,
  87. teamName: '',
  88. teamType: 1,
  89. teamCatId: 1,
  90. teamDuty: '',
  91. teamDesc: '',
  92. sortNo: 1
  93. }
  94. },
  95. onSubmit(){
  96. this.$refs.form.validate().then(res=>{
  97. let submitFx=this.type==='add'?teamApi.create:teamApi.update
  98. submitFx(this.form).then(()=>{
  99. uni.showToast({
  100. icon:"none",
  101. title:"成功!!"
  102. })
  103. this.$emit('success')
  104. this.close();
  105. })
  106. }).catch(err =>{
  107. uni.showToast({
  108. icon:"none",
  109. title:"请检查填写信息!"
  110. })
  111. })
  112. },
  113. show(type,item){
  114. this.resetForm()
  115. if(type==='edit'){
  116. this.form={...item}
  117. }else{
  118. this.form.teamType=item
  119. }
  120. this.type=type
  121. this.$refs.drawer.open()
  122. },
  123. close(){
  124. this.$refs.drawer.close()
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .scroll-view {
  131. height: 100%;
  132. padding: 20rpx;
  133. box-sizing: border-box;
  134. .form-wrap{
  135. padding:40rpx 20rpx;
  136. .handle-container{
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. button{
  141. width: 160rpx;
  142. padding: 20rpx 16rpx;
  143. line-height: 1;
  144. font-size: 28rpx;
  145. &.save{
  146. background-color: #007aff;
  147. }
  148. }
  149. }
  150. .word-limit{
  151. text-align: right;
  152. padding: 10rpx 0;
  153. color: #999;
  154. font-size: 26rpx;
  155. }
  156. }
  157. }
  158. </style>