spotCheckList.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="pageInfo">
  3. <!-- 任务列表 -->
  4. <view v-for="item in list" :key="item.id" class="itemInfo">
  5. <view class="itemName">
  6. <view class="name">{{ item.name }}</view>
  7. <view>
  8. <switch style="transform:scale(0.9)" v-if="$hasPermissions('B_spotConfig_enable_mobile')" :checked="item.status == 1" @change="changeItem(item)" />
  9. </view>
  10. </view>
  11. <view class="itemName">
  12. <view class="date">{{ item.startDate }} 至 {{ item.endDate }}</view>
  13. <view>
  14. <u-button v-if="$hasPermissions('B_spotConfig_view_mobile')" type="success" size="mini" @click="handetail(item)">查看</u-button>
  15. <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>
  16. <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>
  17. </view>
  18. </view>
  19. </view>
  20. <view style="padding-top: 30vh;"><u-empty :text="noDataText" v-if="list.length == 0 && status != 'loading'" mode="list"></u-empty></view>
  21. <view style="padding: 20upx;"><u-loadmore v-if="total > pageSize || status == 'loading'" :status="status" /></view>
  22. </view>
  23. </template>
  24. <script>
  25. import { clzConfirm } from '@/libs/tools.js';
  26. import { getCheckTaskConfigList, delCheckTaskConfig, enableCheckTaskConfig } from '@/api/checkTaskConfig.js';
  27. export default {
  28. data() {
  29. return {
  30. status: 'loadmore',
  31. noDataText: '暂无数据',
  32. list: [],
  33. pageNo: 1,
  34. pageSize: 10,
  35. total: 0
  36. };
  37. },
  38. onLoad() {
  39. if(this.$hasPermissions("B_spotConfig_new_mobile")){
  40. // 设置标题栏按钮
  41. let currentWebview = this.$scope.$getAppWebview();
  42. currentWebview.setTitleNViewButtonStyle(0, {
  43. text: '\ue610 新增',
  44. fontSize: 16,
  45. color: '#eee',
  46. width: '80px',
  47. fontSrc: '/static/iconfont/iconfont.ttf'
  48. });
  49. }
  50. // 首次加载列表
  51. this.getList();
  52. // 刷新列表
  53. uni.$on('updateCheckTaskConfigList', () => {
  54. this.pageNo = 1;
  55. this.list = [];
  56. this.getList();
  57. });
  58. },
  59. // 新增
  60. onNavigationBarButtonTap() {
  61. uni.navigateTo({
  62. url: '/pages/spotCheckConfigure/addSpotCheck'
  63. });
  64. },
  65. // 上拉分页
  66. onReachBottom() {
  67. console.log('onReachBottom');
  68. if (this.list.length < this.total) {
  69. this.pageNo++;
  70. this.getList();
  71. } else {
  72. uni.showToast({
  73. title: '已经到底了',
  74. icon: 'none'
  75. });
  76. this.status = 'nomore';
  77. }
  78. },
  79. methods: {
  80. // 获取列表
  81. getList() {
  82. let _this = this;
  83. let params = {
  84. pageNo: this.pageNo,
  85. pageSize: this.pageSize
  86. };
  87. this.status = 'loading';
  88. getCheckTaskConfigList(params).then(res => {
  89. if (res.status == 200) {
  90. let list = res.data.list;
  91. if (_this.pageNo > 1) {
  92. _this.list = _this.list.concat(list);
  93. } else {
  94. _this.list = list;
  95. }
  96. _this.total = res.data.count;
  97. } else {
  98. uni.showToast({
  99. title: res.message,
  100. icon: 'none'
  101. });
  102. _this.noDataText = res.message;
  103. }
  104. _this.status = 'loadmore';
  105. });
  106. },
  107. // 启用禁用
  108. changeItem(item) {
  109. console.log(item)
  110. let _this = this;
  111. let status = item.status == 1 ? 0 : 1;
  112. enableCheckTaskConfig({ id: item.id, flag: status }).then(res => {
  113. if (res.status == 200) {
  114. let i = _this.list.findIndex(a => a.id == item.id);
  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. align-items: center;
  175. .date {
  176. color: #666;
  177. }
  178. > view{
  179. &:first-child{
  180. flex-grow: 1;
  181. }
  182. }
  183. }
  184. .itemName:first-child {
  185. border-bottom: 1px solid #f8f8f8;
  186. padding: 15upx 15upx 15upx 25upx;
  187. }
  188. }
  189. </style>