SupervisorList.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <uni-drawer ref="drawer" mode="left" :mask-click="false" width="100%" :maskClick='true'>
  3. <view class="head">
  4. <view class="name">{{dangerTitle}}</view>
  5. <view class="close" @click="close()">
  6. <uni-icons type="closeempty" size="24" color="#999" @click="close"></uni-icons>
  7. </view>
  8. </view>
  9. <scroll-view class="scroll-view" scroll-y="true">
  10. <uni-section title="隐患责任主体" type="line">
  11. <template v-slot:right>
  12. <view class="add" @click="create">
  13. <uni-icons type="plusempty" size="20" color="#ccc"></uni-icons>
  14. </view>
  15. </template>
  16. </uni-section>
  17. <view class="form-wrap" >
  18. <uni-forms ref="form" :model="form" :label-width="100">
  19. <uni-card padding="2px 0" margin="5px 0" v-for="(item,index) in form" :key="index">
  20. <uni-forms-item label ="责任部门">
  21. <uni-easyinput v-model="item.supervisorGroupName" placeholder="请输入责任部门" :clearable="false" />
  22. </uni-forms-item>
  23. <uni-forms-item label="责任人员">
  24. <uni-easyinput v-model="item.supervisorName" placeholder="请输入责任人员" :clearable="false" />
  25. </uni-forms-item>
  26. <uni-forms-item label="联系电话">
  27. <uni-easyinput v-model="item.supervisorPhone" type="number" placeholder="请输入联系电话" :clearable="false" />
  28. </uni-forms-item>
  29. <view class="handle-container">
  30. <button class="save" type="primary" @click="onSubmit(item)">保存</button>
  31. <button class="del" type="default" @click="delItem(index,item)">删除</button>
  32. </view>
  33. </uni-card>
  34. </uni-forms>
  35. </view>
  36. </scroll-view>
  37. </uni-drawer>
  38. </template>
  39. <script>
  40. import dangerApi from '@/api/danger.js'
  41. export default{
  42. name:"SupervisorList",
  43. data(){
  44. return{
  45. dangerId:undefined,
  46. dangerTitle:undefined,
  47. form:{},
  48. }
  49. },
  50. methods:{
  51. resetForm(){
  52. this.form={}
  53. },
  54. create(){
  55. let item={
  56. dangerId:this.dangerId,
  57. supervisorGroupName: '',
  58. supervisorName: '',
  59. supervisorPhone: '',
  60. }
  61. this.form.unshift(item)
  62. },
  63. delItem(index,item){
  64. if(!item.supervisorId){
  65. this.form=this.form.filter((item,idx)=>index!==idx)
  66. }else{
  67. const self=this;
  68. uni.showModal({
  69. title: '提示',
  70. content: '是否确定删除',
  71. success: function (res) {
  72. if (res.confirm) {
  73. dangerApi.deleteSupervisorById(item.dangerId,item.supervisorId).then(()=>{
  74. uni.showToast({
  75. title:'删除成功!',
  76. duration:1500,
  77. icon:'none'
  78. })
  79. setTimeout(()=>{
  80. self.getDataList()
  81. self.$emit('success')
  82. },1500)
  83. })
  84. }
  85. }
  86. });
  87. }
  88. },
  89. onSubmit(item){
  90. this.$refs.form.validate().then(res=>{
  91. let submitFx=item.supervisorId?dangerApi.updateSupervisor:dangerApi.createSupervisor
  92. submitFx({dangerId:this.dangerId,...item}).then(()=>{
  93. uni.showToast({
  94. title:'操作成功!',
  95. duration:1500,
  96. icon:'none'
  97. })
  98. setTimeout(()=>{
  99. this.getDataList()
  100. this.$emit('success')
  101. },1500)
  102. })
  103. }).catch(err =>{
  104. uni.showToast({
  105. icon:"none",
  106. title:"请检查填写信息!"
  107. })
  108. })
  109. },
  110. getDataList(){
  111. dangerApi.getSupervisorListById(this.dangerId).then((res)=>{
  112. this.form=res.data||[]
  113. })
  114. },
  115. show(item){
  116. this.resetForm()
  117. this.dangerId=item.dangerId
  118. this.dangerTitle=item.dangerTitle
  119. this.getDataList()
  120. this.$refs.drawer.open()
  121. },
  122. close(){
  123. this.$refs.drawer.close()
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .head{
  130. height: 80rpx;
  131. display: flex;
  132. justify-content: space-between;
  133. align-items: center;
  134. padding:0 10rpx;
  135. background-color: #f5f5f5;
  136. .name{
  137. font-size: 30rpx;
  138. color: #222222;
  139. font-weight: 500;
  140. line-height: 1;
  141. padding-left: 30rpx;
  142. }
  143. .close{
  144. height: 100%;
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. padding:0 30rpx;
  149. }
  150. }
  151. .scroll-view {
  152. height: calc(100% - 130rpx);
  153. padding:0 20rpx 20rpx;
  154. box-sizing: border-box;
  155. .add{
  156. padding: 10rpx 30rpx;
  157. }
  158. .form-wrap{
  159. padding:40rpx 20rpx;
  160. .handle-container{
  161. display: flex;
  162. justify-content: center;
  163. align-items: center;
  164. padding-bottom: 10rpx;
  165. button{
  166. width: 160rpx;
  167. padding: 20rpx 16rpx;
  168. line-height: 1;
  169. font-size: 28rpx;
  170. &.save{
  171. background-color: #007aff;
  172. }
  173. &.del{
  174. background-color: #f56c6c;
  175. color: #fff;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. </style>