maintain.vue 11 KB

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