spotCheckList.vue 3.9 KB

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