AddForm.vue 4.7 KB

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