spotCheckList.vue 4.8 KB

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