maintain.vue 10 KB

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