maintain.vue 11 KB

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