spotCheckList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="pageInfo">
  3. <!-- 任务列表 -->
  4. <view v-for="item in list" :key="item.id" class="itemInfo">
  5. <view class="itemName">
  6. <span class="name">{{ item.name }}</span>
  7. <u-switch size="40" @change="changeItem(item)" v-model="item.status == 1"></u-switch>
  8. </view>
  9. <view class="itemName">
  10. <span>{{ item.startDate }} 至 {{ item.endDate }}</span>
  11. <span>
  12. <u-button type="success" size="mini" style="margin-right: 15upx;" @click="handetail(item)">查看</u-button>
  13. <u-button v-if="item.status == 0&&item.taskGenerateFlag==0" type="primary" size="mini" style="margin-right: 15upx;" @click="handedit(item)">编辑</u-button>
  14. <u-button v-if="item.status == 0&&item.taskGenerateFlag==0" type="error" size="mini" @click="handelete(item)">删除</u-button>
  15. </span>
  16. </view>
  17. </view>
  18. <view style="padding-top: 30vh;">
  19. <u-empty :text="noDataText" v-if="list.length == 0 && status != 'loading'" mode="list"></u-empty>
  20. </view>
  21. <view style="padding: 20upx;">
  22. <u-loadmore v-if="total > pageSize || status == 'loading'" :status="status" />
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {clzConfirm} from '@/libs/tools.js'
  28. import { getCheckTaskConfigList, delCheckTaskConfig, enableCheckTaskConfig } from '@/api/checkTaskConfig.js';
  29. export default {
  30. data() {
  31. return {
  32. status: 'loadmore',
  33. noDataText: '暂无数据',
  34. list: [],
  35. pageNo: 1,
  36. pageSize: 10,
  37. total: 0
  38. };
  39. },
  40. onLoad() {
  41. this.getList();
  42. uni.$on("updateCheckTaskConfigList",()=>{
  43. this.pageNo = 1;
  44. this.list = []
  45. this.getList();
  46. })
  47. },
  48. // 新增
  49. onNavigationBarButtonTap() {
  50. uni.navigateTo({
  51. url: '/pages/spotCheckConfigure/addSpotCheck'
  52. });
  53. },
  54. // 上拉分页
  55. onReachBottom() {
  56. console.log('onReachBottom');
  57. if(this.list.length< this.total){
  58. this.pageNo++
  59. this.getList()
  60. }else {
  61. uni.showToast({
  62. title: '已经到底了',
  63. icon: 'none'
  64. })
  65. this.status = "nomore"
  66. }
  67. },
  68. methods: {
  69. // 获取列表
  70. getList() {
  71. let _this = this;
  72. let params = {
  73. pageNo: this.pageNo,
  74. pageSize: this.pageSize,
  75. };
  76. this.status = 'loading';
  77. getCheckTaskConfigList(params).then(res => {
  78. if (res.status == 200) {
  79. let list = res.data.list;
  80. if(_this.pageNo>1){
  81. _this.list = _this.list.concat(list);
  82. }else{
  83. _this.list = list
  84. }
  85. _this.total = res.data.count;
  86. } else {
  87. uni.showToast({
  88. title: res.message,
  89. icon: 'none'
  90. });
  91. _this.noDataText = res.message;
  92. }
  93. _this.status = 'loadmore';
  94. });
  95. },
  96. // 启用禁用
  97. changeItem(item){
  98. let _this = this
  99. let status = item.status == 1 ? 0 : 1
  100. enableCheckTaskConfig({id:item.id,flag: status}).then(res=>{
  101. if(res.status == 200){
  102. console.log(_this.list,status)
  103. let i = _this.list.findIndex(a=>a.id == item.id)
  104. console.log(i)
  105. _this.list[i].status = status
  106. _this.list.splice()
  107. }
  108. uni.showToast({
  109. title: res.message,
  110. icon: 'none'
  111. })
  112. })
  113. },
  114. // 查看详情
  115. handetail(item) {
  116. uni.navigateTo({
  117. url: '/pages/spotCheckConfigure/spotCheckDetail/spotCheckDetail?id='+item.id
  118. });
  119. },
  120. // 编辑
  121. handedit(item) {
  122. uni.navigateTo({
  123. url: '/pages/spotCheckConfigure/addSpotCheck?id='+item.id
  124. });
  125. },
  126. // 删除
  127. handelete(item) {
  128. const _this = this;
  129. clzConfirm({
  130. title: '提示',
  131. content: '确认删除,删除后数据将无法恢复?',
  132. success: function(res) {
  133. if (res.confirm || res.index == 0) {
  134. delCheckTaskConfig({id:item.id}).then(ret=>{
  135. if(ret.status == 200){
  136. let i = _this.list.findIndex(a=>a.id == item.id)
  137. _this.list.splice(i,1)
  138. }
  139. uni.showToast({
  140. title: ret.message,
  141. icon: 'none'
  142. })
  143. })
  144. }
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss">
  152. page {
  153. background: #f8f8f8;
  154. height: auto;
  155. }
  156. .itemInfo {
  157. margin: 20upx;
  158. background-color: #fff;
  159. border-radius: 3px;
  160. .itemName {
  161. padding: 25upx 35upx;
  162. display: flex;
  163. justify-content: space-between;
  164. }
  165. .itemName:first-child {
  166. border-bottom: 1px solid #f8f8f8;
  167. }
  168. }
  169. </style>