spotCheckList.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 class="date">{{ item.startDate }} 至 {{ item.endDate }}</span>
  11. <span>
  12. <u-button type="success" size="mini" @click="handetail(item)">查看</u-button>
  13. <u-button v-if="item.status == 0 && item.taskGenerateFlag == 0" type="primary" size="mini" style="margin-left: 15upx;" @click="handedit(item)">编辑</u-button>
  14. <u-button v-if="item.status == 0 && item.taskGenerateFlag == 0" type="error" size="mini" style="margin-left: 15upx;" @click="handelete(item)">删除</u-button>
  15. </span>
  16. </view>
  17. </view>
  18. <view style="padding-top: 30vh;"><u-empty :text="noDataText" v-if="list.length == 0 && status != 'loading'" mode="list"></u-empty></view>
  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. console.log(this.$hasPermissions("M_spotCheckConfig_list"))
  38. if(this.$hasPermissions("M_spotCheckConfig_list")){
  39. // 设置标题栏按钮
  40. let currentWebview = this.$scope.$getAppWebview();
  41. currentWebview.setTitleNViewButtonStyle(0, {
  42. text: '\ue610 新增',
  43. fontSize: 16,
  44. color: '#eee',
  45. width: '80px',
  46. fontSrc: '/static/iconfont/iconfont.ttf'
  47. });
  48. }
  49. // 首次加载列表
  50. this.getList();
  51. // 刷新列表
  52. uni.$on('updateCheckTaskConfigList', () => {
  53. this.pageNo = 1;
  54. this.list = [];
  55. this.getList();
  56. });
  57. },
  58. // 新增
  59. onNavigationBarButtonTap() {
  60. uni.navigateTo({
  61. url: '/pages/spotCheckConfigure/addSpotCheck'
  62. });
  63. },
  64. // 上拉分页
  65. onReachBottom() {
  66. console.log('onReachBottom');
  67. if (this.list.length < this.total) {
  68. this.pageNo++;
  69. this.getList();
  70. } else {
  71. uni.showToast({
  72. title: '已经到底了',
  73. icon: 'none'
  74. });
  75. this.status = 'nomore';
  76. }
  77. },
  78. methods: {
  79. // 获取列表
  80. getList() {
  81. let _this = this;
  82. let params = {
  83. pageNo: this.pageNo,
  84. pageSize: this.pageSize
  85. };
  86. this.status = 'loading';
  87. getCheckTaskConfigList(params).then(res => {
  88. if (res.status == 200) {
  89. let list = res.data.list;
  90. if (_this.pageNo > 1) {
  91. _this.list = _this.list.concat(list);
  92. } else {
  93. _this.list = list;
  94. }
  95. _this.total = res.data.count;
  96. } else {
  97. uni.showToast({
  98. title: res.message,
  99. icon: 'none'
  100. });
  101. _this.noDataText = res.message;
  102. }
  103. _this.status = 'loadmore';
  104. });
  105. },
  106. // 启用禁用
  107. changeItem(item) {
  108. let _this = this;
  109. let status = item.status == 1 ? 0 : 1;
  110. enableCheckTaskConfig({ id: item.id, flag: status }).then(res => {
  111. if (res.status == 200) {
  112. console.log(_this.list, status);
  113. let i = _this.list.findIndex(a => a.id == item.id);
  114. console.log(i);
  115. _this.list[i].status = status;
  116. _this.list.splice();
  117. }
  118. uni.showToast({
  119. title: res.message,
  120. icon: 'none'
  121. });
  122. });
  123. },
  124. // 查看详情
  125. handetail(item) {
  126. uni.navigateTo({
  127. url: '/pages/spotCheckConfigure/spotCheckDetail/spotCheckDetail?id=' + item.id
  128. });
  129. },
  130. // 编辑
  131. handedit(item) {
  132. uni.navigateTo({
  133. url: '/pages/spotCheckConfigure/addSpotCheck?id=' + item.id
  134. });
  135. },
  136. // 删除
  137. handelete(item) {
  138. const _this = this;
  139. clzConfirm({
  140. title: '提示',
  141. content: '确认删除,删除后数据将无法恢复?',
  142. success: function(res) {
  143. if (res.confirm || res.index == 0) {
  144. delCheckTaskConfig({ id: item.id }).then(ret => {
  145. if (ret.status == 200) {
  146. let i = _this.list.findIndex(a => a.id == item.id);
  147. _this.list.splice(i, 1);
  148. }
  149. uni.showToast({
  150. title: ret.message,
  151. icon: 'none'
  152. });
  153. });
  154. }
  155. }
  156. });
  157. }
  158. }
  159. };
  160. </script>
  161. <style lang="scss">
  162. page {
  163. background: #f8f8f8;
  164. height: auto;
  165. }
  166. .itemInfo {
  167. margin: 20upx;
  168. background-color: #fff;
  169. border-radius: 3px;
  170. box-shadow: 1px 1px 3px #eeeeee;
  171. .itemName {
  172. padding: 25upx;
  173. display: flex;
  174. justify-content: space-between;
  175. align-items: center;
  176. .date {
  177. color: #666;
  178. }
  179. }
  180. .itemName:first-child {
  181. border-bottom: 1px solid #f8f8f8;
  182. padding: 15upx 25upx;
  183. }
  184. }
  185. </style>