AddForm.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="modal" :class="showModal?'show':''">
  3. <view class="head">
  4. <view class="name">{{title}}</view>
  5. <view class="clear-bt" @click="showModal=false">
  6. <uni-icons type="clear" size="30"></uni-icons>
  7. </view>
  8. </view>
  9. <view class="form-wrap" >
  10. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  11. <uni-forms-item label="值班岗" name="posId">
  12. <uni-data-select v-model="form.posId" :localdata="dutyList" placeholder="请选择值班岗" :clear="false" ></uni-data-select>
  13. </uni-forms-item>
  14. <uni-forms-item label="值班人员" name="accountId">
  15. <uni-data-select v-model="form.accountId" :localdata="userList" placeholder="请选择值班人员" :clear="false"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="职责说明" name="remark">
  18. <uni-easyinput type="textarea" :maxlength="30" v-model="form.remark" placeholder="请输入职责说明"></uni-easyinput>
  19. </uni-forms-item>
  20. </uni-forms>
  21. <view class="handle-container">
  22. <button class="save" type="primary" @click="onSubmit">保存</button>
  23. <button class="cancel" type="default" @click="showModal=false">取消</button>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import dutyApi from '@/api/duty.js'
  30. export default{
  31. name:'DutyAddForm',
  32. computed:{
  33. dutyList(){
  34. let dutyList=uni.getStorageSync('dutys')
  35. if(!dutyList)return[]
  36. return dutyList.map(item=>{return{...item,value:item.posId,text:item.posName}})
  37. },
  38. userList(){
  39. let groupUser=uni.getStorageSync('groupUser')
  40. if(!groupUser)return[]
  41. let userList=[]
  42. groupUser.map((item,index)=>{
  43. userList.push({...item,value:`root-${index+1}`,text:item.name,disable:true})
  44. if(Array.isArray(item.children)&&item.children.length>0){
  45. userList=userList.concat(item.children.map(item=>{return{...item,value:item.accountId,text:item.accountName}}))
  46. }
  47. })
  48. return userList
  49. }
  50. },
  51. data(){
  52. return{
  53. showModal:false,
  54. type:undefined,
  55. title:'',
  56. rules:{
  57. posId:{
  58. rules:[
  59. {
  60. required: true,
  61. errorMessage: '请选择值班岗'
  62. }
  63. ],
  64. validateTrigger:'submit'
  65. },
  66. accountId:{
  67. rules:[
  68. {
  69. required: true,
  70. errorMessage: '请选择值班人员',
  71. }
  72. ],
  73. validateTrigger:'submit'
  74. }
  75. },
  76. form:{
  77. year:"",
  78. week:'',
  79. dutyType: undefined,
  80. groupId: 0,
  81. groupName: '',
  82. posId: undefined,
  83. posName: '',
  84. accountId: undefined,
  85. accountName: '',
  86. positionId: 0,
  87. positionName: '',
  88. remark: '',
  89. }
  90. }
  91. },
  92. methods:{
  93. show({type,params}){
  94. this.type=type
  95. if(type==='add'){this.resetForm()}
  96. if(params)this.form={...this.form,...params};
  97. this.showModal=true;
  98. this.title=type==='add'?'新增周记录':'更新周记录'
  99. },
  100. resetForm(){
  101. this.form={
  102. year:"",
  103. week:'',
  104. dutyType: undefined,
  105. groupId: 0,
  106. groupName: '',
  107. posId: undefined,
  108. posName: '',
  109. accountId: undefined,
  110. accountName: '',
  111. positionId: 0,
  112. positionName: '',
  113. remark: ''
  114. }
  115. },
  116. onSubmit(){
  117. this.$refs.form.validate().then(res=>{
  118. let user=this.userList.find(item=>this.form.accountId===item.accountId)
  119. let params={
  120. year: this.form.year,
  121. week: this.form.week,
  122. dutyType:this.form.dutyType,
  123. posId: this.form.posId,
  124. remark: this.form.remark,
  125. accountId: user.accountId,
  126. accountName: user.accountName,
  127. positionId: user.positionId,
  128. positionName: user.positionName,
  129. oAccountId: 0,
  130. }
  131. let submitFx=this.type==='add'?dutyApi.createWeekRecord:dutyApi.createWeekRecord
  132. submitFx(params).then(()=>{
  133. uni.showToast({
  134. icon:"none",
  135. title:"成功!!"
  136. })
  137. this.$emit('success')
  138. this.showModal=false;
  139. })
  140. }).catch(err =>{
  141. uni.showToast({
  142. icon:"none",
  143. title:"请检查填写信息!"
  144. })
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .modal{
  152. position: fixed;
  153. left: 100%;
  154. top: 0;
  155. right: 0;
  156. bottom: 0;
  157. background-color: #fff;
  158. z-index: 999;
  159. box-sizing: border-box;
  160. transition: 0.26s;
  161. overflow-x: hidden;
  162. overflow-y: auto;
  163. &.show{
  164. left: 0;
  165. }
  166. .head{
  167. display: flex;
  168. justify-content: space-between;
  169. align-items: center;
  170. padding: 20rpx;
  171. background-color: #f5f5f5;
  172. .name{
  173. font-size: 32rpx;
  174. font-weight: 500;
  175. color: #222222;
  176. }
  177. }
  178. .form-wrap{
  179. padding:40rpx 20rpx;
  180. .handle-container{
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. button{
  185. width: 160rpx;
  186. padding: 20rpx 16rpx;
  187. line-height: 1;
  188. font-size: 28rpx;
  189. &.save{
  190. background-color: #007aff;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. </style>