AddForm.vue 4.7 KB

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