spotCheckList.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. console.log(res)
  79. if (res.status == 200) {
  80. let list = res.data.list;
  81. if(_this.pageNo>1){
  82. _this.list = _this.list.concat(list);
  83. }else{
  84. _this.list = list
  85. }
  86. _this.total = res.data.count;
  87. } else {
  88. uni.showToast({
  89. title: res.message,
  90. icon: 'none'
  91. });
  92. _this.noDataText = res.message;
  93. }
  94. _this.status = 'loadmore';
  95. });
  96. },
  97. // 启用禁用
  98. changeItem(item){
  99. let _this = this
  100. let status = item.status == 1 ? 0 : 1
  101. enableCheckTaskConfig({id:item.id,flag: status}).then(res=>{
  102. if(res.status == 200){
  103. console.log(_this.list,status)
  104. let i = _this.list.findIndex(a=>a.id == item.id)
  105. console.log(i)
  106. _this.list[i].status = status
  107. _this.list.splice()
  108. }
  109. uni.showToast({
  110. title: res.message,
  111. icon: 'none'
  112. })
  113. })
  114. },
  115. // 查看详情
  116. handetail(item) {
  117. uni.navigateTo({
  118. url: '/pages/spotCheckConfigure/spotCheckDetail/spotCheckDetail?id='+item.id
  119. });
  120. },
  121. // 编辑
  122. handedit(item) {
  123. uni.navigateTo({
  124. url: '/pages/spotCheckConfigure/addSpotCheck?id='+item.id
  125. });
  126. },
  127. // 删除
  128. handelete(item) {
  129. const _this = this;
  130. clzConfirm({
  131. title: '提示',
  132. content: '确认删除,删除后数据将无法恢复?',
  133. success: function(res) {
  134. if (res.confirm || res.index == 0) {
  135. delCheckTaskConfig({id:item.id}).then(ret=>{
  136. if(ret.status == 200){
  137. let i = _this.list.findIndex(a=>a.id == item.id)
  138. _this.list.splice(i,1)
  139. }
  140. uni.showToast({
  141. title: ret.message,
  142. icon: 'none'
  143. })
  144. })
  145. }
  146. }
  147. });
  148. }
  149. }
  150. };
  151. </script>
  152. <style lang="scss">
  153. page {
  154. background: #f8f8f8;
  155. height: auto;
  156. }
  157. .itemInfo {
  158. margin: 20upx;
  159. background-color: #fff;
  160. border-radius: 3px;
  161. .itemName {
  162. padding: 25upx 35upx;
  163. display: flex;
  164. justify-content: space-between;
  165. }
  166. .itemName:first-child {
  167. border-bottom: 1px solid #f8f8f8;
  168. }
  169. }
  170. </style>