SupervisorList.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.push(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. icon:'none'
  77. })
  78. self.getDataList()
  79. self.$emit('success')
  80. })
  81. }
  82. }
  83. });
  84. }
  85. },
  86. onSubmit(item){
  87. this.$refs.form.validate().then(res=>{
  88. let submitFx=item.supervisorId?dangerApi.updateSupervisor:dangerApi.createSupervisor
  89. submitFx({dangerId:this.dangerId,...item}).then(()=>{
  90. uni.showToast({
  91. icon:"none",
  92. title:"成功!!"
  93. })
  94. this.getDataList()
  95. this.$emit('success')
  96. })
  97. }).catch(err =>{
  98. uni.showToast({
  99. icon:"none",
  100. title:"请检查填写信息!"
  101. })
  102. })
  103. },
  104. getDataList(){
  105. dangerApi.getSupervisorListById(this.dangerId).then((res)=>{
  106. this.form=res.data||[]
  107. })
  108. },
  109. show(item){
  110. this.resetForm()
  111. this.dangerId=item.dangerId
  112. this.dangerTitle=item.dangerTitle
  113. this.getDataList()
  114. this.$refs.drawer.open()
  115. },
  116. close(){
  117. this.$refs.drawer.close()
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. .head{
  124. height: 80rpx;
  125. display: flex;
  126. justify-content: space-between;
  127. align-items: center;
  128. padding:0 10rpx;
  129. background-color: #f5f5f5;
  130. .name{
  131. font-size: 30rpx;
  132. color: #222222;
  133. font-weight: 500;
  134. line-height: 1;
  135. padding-left: 30rpx;
  136. }
  137. .close{
  138. height: 100%;
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. padding:0 30rpx;
  143. }
  144. }
  145. .scroll-view {
  146. height: calc(100% - 130rpx);
  147. padding:0 20rpx 20rpx;
  148. box-sizing: border-box;
  149. .add{
  150. padding: 10rpx 30rpx;
  151. }
  152. .form-wrap{
  153. padding:40rpx 20rpx;
  154. .handle-container{
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. padding-bottom: 10rpx;
  159. button{
  160. width: 160rpx;
  161. padding: 20rpx 16rpx;
  162. line-height: 1;
  163. font-size: 28rpx;
  164. &.save{
  165. background-color: #007aff;
  166. }
  167. &.del{
  168. background-color: #f56c6c;
  169. color: #fff;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. </style>