TeamForm.vue 3.8 KB

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