spotCheckList.vue 4.0 KB

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