TeamForm.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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=this.cats;
  41. if(!teamCats) return[];
  42. return teamCats.map(item=>{
  43. return{
  44. value:item.teamCatId,
  45. text:item.teamCatTitle
  46. }
  47. })
  48. }
  49. },
  50. props:{
  51. cats:{
  52. type:Array,
  53. default:()=>[]
  54. }
  55. },
  56. data(){
  57. return{
  58. type:undefined,
  59. rules:{
  60. teamName:{
  61. rules:[
  62. {
  63. required: true,
  64. errorMessage: '请输入队伍名称'
  65. }
  66. ],
  67. validateTrigger:'submit'
  68. },
  69. teamCatId:{
  70. rules:[
  71. {
  72. required: true,
  73. errorMessage: '请选择队伍类别',
  74. }
  75. ],
  76. validateTrigger:'submit'
  77. },
  78. },
  79. form:{
  80. teamId: 0,
  81. teamName: '',
  82. teamType: 1,
  83. teamCatId: 1,
  84. teamDuty: '',
  85. teamDesc: '',
  86. sortNo: 1
  87. }
  88. }
  89. },
  90. methods:{
  91. resetForm(){
  92. this.form={
  93. teamId: 0,
  94. teamName: '',
  95. teamType: 1,
  96. teamCatId: 1,
  97. teamDuty: '',
  98. teamDesc: '',
  99. sortNo: 1
  100. }
  101. },
  102. onSubmit(){
  103. this.$refs.form.validate().then(res=>{
  104. let submitFx=this.type==='add'?teamApi.create:teamApi.update
  105. submitFx(this.form).then(()=>{
  106. uni.showToast({
  107. icon:"none",
  108. title:"成功!!"
  109. })
  110. this.$emit('success')
  111. this.close();
  112. })
  113. }).catch(err =>{
  114. uni.showToast({
  115. icon:"none",
  116. title:"请检查填写信息!"
  117. })
  118. })
  119. },
  120. show(type,item){
  121. this.resetForm()
  122. if(type==='edit'){
  123. this.form={...item}
  124. }else{
  125. this.form.teamType=item
  126. }
  127. this.type=type
  128. this.$refs.drawer.open()
  129. },
  130. close(){
  131. this.$refs.drawer.close()
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .scroll-view {
  138. height: 100%;
  139. padding: 20rpx;
  140. box-sizing: border-box;
  141. .form-wrap{
  142. padding:40rpx 20rpx;
  143. .handle-container{
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. button{
  148. width: 160rpx;
  149. padding: 20rpx 16rpx;
  150. line-height: 1;
  151. font-size: 28rpx;
  152. &.save{
  153. background-color: #007aff;
  154. }
  155. }
  156. }
  157. .word-limit{
  158. text-align: right;
  159. padding: 10rpx 0;
  160. color: #999;
  161. font-size: 26rpx;
  162. }
  163. }
  164. }
  165. </style>