maintain.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <view class="container">
  3. <!-- 关键词搜索栏:与设备台账(equipment.vue)一致,支持设备名称/编号/保养标准编号 -->
  4. <div class="bg-color-white py2">
  5. <u-search placeholder="设备名称/编号/保养标准编号" clearabled v-model="keyword" @search="search" @custom="search" @clear="search"></u-search>
  6. </div>
  7. <common-tabs :list="list" :current="current" @change="change" />
  8. <view class="p-top8">
  9. <template v-if="listData.length > 0">
  10. <view class="mx3 my2 p3 bg-color-white box p-relative" v-for="(item, index) in listData" :key="item.id"
  11. @click="handleDetail(item.id)" @longpress="showMask(item.id, $event)">
  12. <common-mask :item="item" :maskId="maskId" @hide="maskId = 0" @del="handleDel(item.id)" />
  13. <!-- 卡片标题仅显示设备名称(设备编号),右侧状态角标 -->
  14. <view class="d-flex j-between border-bottom pb-2 a-center">
  15. <view class="text-color-3 f-size-32 f-weight-bold text-overflow">{{ item.sbName }} ({{ item.sbNo }})</view>
  16. <my-badge :text="statusMap[item.status]" :status="dict[item.status]" />
  17. </view>
  18. <view class="f-size-26 text-color-6 f-weight-4 mt-2">计划执行日期:{{
  19. item.startTime
  20. }}
  21. </view>
  22. <view class="f-size-26 text-color-6 f-weight-4 mt-2">实际执行日期:{{
  23. item.actualStartTime
  24. }}
  25. </view>
  26. <!-- 与 PC 端 CheckJob 任务4保持一致:隐藏设备部位,改显示执行人/班组(checkDeptName 优先,其次 checkUserName) -->
  27. <view class="f-size-26 text-color-6 f-weight-4 mt-2">执行人/班组:{{
  28. item.checkDeptName || item.checkUserName || '-'
  29. }}
  30. </view>
  31. <view class="d-flex j-end edit-box">
  32. <!-- 与 PC 端 CheckJob 保持一致:仅未执行(1)可接收 -->
  33. <view class="text-color-3 f-size-32 edit" v-if="item.status === 1 && !startFlag">
  34. <view @click.stop="handleExecute(item)">开始</view>
  35. </view>
  36. <!-- 与 PC 端 CheckJob 保持一致:仅执行中(2)可执行/完成 -->
  37. <!-- <view class="text-color-3 f-size-32 edit" v-if="item.status === 2 && !startFlag">
  38. <view @click.stop="handleFinish(item)">执行</view>
  39. </view> -->
  40. <view class="text-color-3 f-size-32 edit" v-if="item.status === 2">
  41. <view @click.stop="submit(item)">完成</view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="py3">
  46. <u-loadmore :status="status" />
  47. </view>
  48. </template>
  49. <template v-else>
  50. <view class="empty">
  51. <u-empty text="暂无数据" mode="list"></u-empty>
  52. </view>
  53. </template>
  54. </view>
  55. <!-- <view class="p-fixed d-flex j-around a-center footer">
  56. <view class="main-color-bg text-color-white common" @tap="handleStart">{{ nums }}</view>
  57. </view> -->
  58. </view>
  59. </template>
  60. <script>
  61. import BaseTool from '../../utils/tool'
  62. export default {
  63. data() {
  64. return {
  65. list: [],
  66. current: 1,
  67. sbId: '',
  68. nums: '开始计时',
  69. // 加载更多
  70. status: 'loadmore',
  71. keyword: '',
  72. page: 1,
  73. timer: null,
  74. limit: 10,
  75. type: 1,
  76. filter: -1,
  77. searchType: null,
  78. startFlag: false,
  79. loadMore: true,
  80. listData: [],
  81. periodMap: null,
  82. statusMap: null,
  83. sbStatusMap: null,
  84. dict: null,
  85. maskId: 0,
  86. statusList: null,
  87. receiveOvertime: null,
  88. timeFlag: null
  89. }
  90. },
  91. onPullDownRefresh() {
  92. // 请求结束取消刷新
  93. this.page = 1
  94. this.loadMore = true
  95. this.listData = []
  96. this.initData()
  97. uni.stopPullDownRefresh()
  98. },
  99. onReachBottom() {
  100. if (this.loadMore) {
  101. this.page++
  102. this.initData()
  103. }
  104. },
  105. onLoad(options) {
  106. this.sbId = options.sbId
  107. this.filter = options.filter
  108. this.searchType = options.searchType
  109. this.timeFlag = options.timeFlag
  110. this.periodMap = this.$DictCache.getLabelByValueMapByType(this.$DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
  111. this.statusMap = this.$DictCache.getLabelByValueMapByType(this.$DictCache.TYPE.CHECK_JOB_STATUS)
  112. this.sbStatusMap = this.$DictCache.getLabelByValueMapByType(this.$DictCache.TYPE.CHECK_JOB_SB_STATUS)
  113. this.list = [{ label: '全部', value: '' }].concat(this.$DictCache.getChildrenList(this.$DictCache.TYPE.CHECK_JOB_STATUS))
  114. this.dict = this.$DictCache.COLOR.CHECK_JOB_STATUS
  115. },
  116. onShow() {
  117. this.page = 1
  118. this.loadMore = true
  119. this.listData = []
  120. this.initData()
  121. },
  122. onHide() {
  123. this.maskId = 0
  124. },
  125. methods: {
  126. showMask(id, e) {
  127. this.maskId = id
  128. // #ifdef H5
  129. e.preventDefault()
  130. // #endif
  131. },
  132. handleDel(id) {
  133. const that = this
  134. const params = []
  135. params.push(id)
  136. uni.showModal({
  137. title: '提示',
  138. content: '您确认删除吗?',
  139. success: res => {
  140. if (res.confirm) {
  141. this.$Http.deleteCheckJobs(params).then(res => {
  142. uni.showToast({ title: '删除成功' })
  143. this.page = 1
  144. this.loadMore = true
  145. this.listData = []
  146. this.initData()
  147. })
  148. } else if (res.cancel) {
  149. }
  150. }
  151. })
  152. },
  153. // 详情
  154. handleDetail(id) {
  155. // if (index == 0) {
  156. // uni.navigateTo({
  157. // url: '../maintain-add/maintain-add'
  158. // });
  159. // } else {
  160. // uni.navigateTo({
  161. // url: '../maintain-detail/maintain-detail'
  162. // });
  163. // }
  164. if (this.maskId !== 0) {
  165. return (this.maskId = 0)
  166. }
  167. uni.navigateTo({
  168. url: '/pages/maintain-detail/maintain-detail?detailId=' + id + '&filter=' + this.filter + '&searchType=' + this.searchType
  169. })
  170. },
  171. handleExecute(item) {
  172. this.$Http.execute(item).then(res => {
  173. item.status = this.$DictCache.VALUE.CHECK_JOB_STATUS.EXECUTING
  174. this.current = this.$DictCache.VALUE.CHECK_JOB_STATUS.EXECUTING
  175. this.change(this.current, this.current)
  176. uni.showToast({ title: '已开始,请及时完成任务' })
  177. })
  178. },
  179. handleFinish(item) {
  180. uni.navigateTo({
  181. url: '/pages/maintain-add/maintain-add?detailId=' + item.id + '&filter=' + this.filter + '&searchType=' + this.searchType
  182. })
  183. },
  184. // tab
  185. change(index, value) {
  186. this.current = index
  187. console.log(index)
  188. this.statusList = null
  189. this.receiveOvertime = null
  190. if (index === 0) {
  191. this.type = ''
  192. } else if (value === 4) {
  193. // 已过期与 PC 端逾期页(PollingCheckJobOverTime)一致:receiveOvertime + 不限状态
  194. this.type = null
  195. this.statusList = []
  196. this.receiveOvertime = true
  197. } else {
  198. this.type = value
  199. }
  200. this.page = 1
  201. this.loadMore = true
  202. this.listData = []
  203. this.initData()
  204. },
  205. handleStart() {
  206. clearInterval(this.timer)
  207. uni.showToast({
  208. title: '已开始计时'
  209. })
  210. this.startFlag = true
  211. uni.setStorageSync('check-job-start-' + this.sbId, this.$BaseTool.Date.formatter(new Date(), BaseTool.Date.PICKER_NORM_DATETIME_PATTERN))
  212. var hour, minute, second // 时 分 秒
  213. hour = minute = second = 0 // 初始化
  214. var millisecond = 0 // 毫秒
  215. this.timer = setInterval(() => {
  216. millisecond = millisecond + 50
  217. if (millisecond >= 1000) {
  218. millisecond = 0
  219. second = second + 1
  220. }
  221. if (second >= 60) {
  222. second = 0
  223. minute = minute + 1
  224. }
  225. if (minute >= 60) {
  226. minute = 0
  227. hour = hour + 1
  228. }
  229. // console.log("-------"+hour+'时'+minute+'分'+second+'秒');
  230. this.nums = hour + '时' + minute + '分' + second + '秒'
  231. }, 50)
  232. },
  233. // 提交
  234. submit(item) {
  235. console.log(22)
  236. uni.navigateTo({
  237. url: `/pages/maintain/finish?id=${item.id}&standardId=${item.standardId}`
  238. })
  239. // item.actualStartTime = uni.getStorageSync('check-job-start');
  240. // item.status = 3
  241. // this.$Http.finishJob(item).then((res) => {
  242. // uni.showToast({
  243. // title: '已完成'
  244. // });
  245. // this.initData();
  246. // });
  247. },
  248. // 点击搜索:重置分页后按关键词查询
  249. search() {
  250. this.page = 1
  251. this.loadMore = true
  252. this.listData = []
  253. this.initData()
  254. },
  255. // 关键词搜索默认时间起点:近三个月,避免大表多列 LIKE 全表扫描,保证查询性能(后端未执行/执行中按 start_time,已完成按 actual_start_time 过滤)
  256. getSearchStartTime() {
  257. const d = new Date()
  258. d.setMonth(d.getMonth() - 3)
  259. return this.$BaseTool.Date.formatter(d, this.$BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  260. },
  261. initData() {
  262. const that = this
  263. that.status = 'loading'
  264. const kw = (this.keyword || '').trim()
  265. this.$Http
  266. .getCheckJobPage({
  267. pageNum: this.page,
  268. pageSize: this.limit,
  269. keyword: kw,
  270. // 仅在关键词搜索时默认限定近三个月,普通列表加载行为保持不变
  271. searchStartTime: kw ? this.getSearchStartTime() : null,
  272. type: 2,
  273. filter: this.filter,
  274. searchType: this.searchType,
  275. sbId: this.sbId,
  276. status: this.type,
  277. receiveOvertime: this.receiveOvertime,
  278. // 与 PC 端 CheckJob 一致:默认只查未执行/执行中/已完成,不含已过期(4)
  279. statusList: this.statusList === null ? [1, 2, 3] : this.statusList,
  280. timeFlag: this.timeFlag,
  281. // 与 PC 端 CheckJob loadData 参数保持一致
  282. mineFlag: false,
  283. record: this.type === 3 ? 1 : null
  284. })
  285. .then(res => {
  286. const data = res.data.rows
  287. if (data && data.length > 0 && data.length < that.limit) {
  288. that.status = 'nomore'
  289. that.loadMore = false
  290. } else if (data.length == that.limit) {
  291. that.status = 'loadmore'
  292. } else {
  293. that.status = 'nomore'
  294. }
  295. that.listData = [...that.listData, ...data]
  296. })
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="scss">
  302. page {
  303. background-color: #f4f4f4;
  304. }
  305. .box {
  306. padding-right: 0;
  307. border-radius: 20rpx;
  308. }
  309. .edit-box {
  310. padding: 0 30rpx;
  311. margin-top: 40rpx;
  312. .edit {
  313. padding: 8rpx 40rpx;
  314. border: 1px solid #ddd;
  315. border-radius: 20rpx;
  316. font-size: 26rpx;
  317. color: #666;
  318. margin-left: 30rpx;
  319. }
  320. }
  321. .text-overflow {
  322. width: 60%;
  323. overflow: hidden;
  324. text-overflow: ellipsis;
  325. display: -webkit-box;
  326. -webkit-line-clamp: 2;
  327. -webkit-box-orient: vertical;
  328. }
  329. .container {
  330. padding-bottom: 100rpx;
  331. .footer {
  332. bottom: 0;
  333. left: 0;
  334. right: 0;
  335. background-color: #fff;
  336. z-index: 10000;
  337. }
  338. .title {
  339. border-bottom: 1rpx solid #f4f4f4;
  340. }
  341. .img {
  342. width: 100rpx;
  343. height: 100rpx;
  344. }
  345. .p-fixed {
  346. border-top: 1rpx solid #f4f4f4;
  347. height: 100rpx;
  348. .common {
  349. padding: 15rpx 200rpx;
  350. border-radius: 30rpx;
  351. background-color: #0082ff;
  352. color: #fff;
  353. }
  354. }
  355. }
  356. </style>