车间能级提升-智能设备管理系统
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<route lang="json5">
{
  layout: 'default',
  needLogin: true,
  style: { navigationBarTitleText: '报修列表', navigationStyle: 'custom' },
}
</route>
<template>
  <z-paging
    ref="paging"
    v-model="dataList"
    :auto="false"
    @query="queryList"
    show-refresher-update-time
  >
    <template #top>
      <wd-navbar
        title="报修列表"
        left-arrow
        @click-left="goBack"
        right-text="新增"
        @click-right="handleClickRight"
        custom-style="background: #4D80F0;"
        safeAreaInsetTop
      ></wd-navbar>
      <!-- 增加一个搜索栏 -->
      <wd-search v-model="searchValue" @search="handleSearch"></wd-search>
<!--      <wd-drop-menu v-if="!isSelectReq">-->
<!--        <wd-drop-menu-item-->
<!--          v-model="reqTypeId"-->
<!--          label-key="dictLabel"-->
<!--          value-key="dictValue"-->
<!--          :options="reqTypeList"-->
<!--          @change="handleReqType"-->
<!--        />-->
<!--        <wd-drop-menu-item-->
<!--          v-model="filterDate"-->
<!--          :options="filterDateList"-->
<!--          @change="handleFilterDate"-->
<!--        />-->
<!--        <wd-drop-menu-item-->
<!--          v-model="status"-->
<!--          label-key="dictLabel"-->
<!--          value-key="dictValue"-->
<!--          :options="statusList"-->
<!--          @change="handleReqStatu"-->
<!--        />-->
<!--      </wd-drop-menu>-->
    </template>
 
    <view class="bg-base">
      <ReqCard
        v-for="item in dataList"
        :key="item.id"
        :item="item"
        @itemClick="itemClick"
      ></ReqCard>
<!--      <wd-card type="rectangle" v-for="(item, index) in dataList" :key="item.id">-->
<!--        <template #title>-->
<!--          <view class="flex justify-between items-center">-->
<!--            <view class="flex items-center menu-title-box">-->
<!--              <view class="menu-indicator"></view>-->
<!--              <text class="ml-1 text-sm">{{ item.code }}</text>-->
<!--            </view>-->
 
<!--            <view>-->
<!--              <wd-button size="small" v-if="item.status === '0'" type="info">待接单</wd-button>-->
<!--              <wd-button size="small" v-else-if="item.status === '1'" type="warning">-->
<!--                已接单-->
<!--              </wd-button>-->
<!--              <wd-button size="small" v-else-if="item.status === '2'" type="primary">-->
<!--                维修中-->
<!--              </wd-button>-->
<!--              <wd-button size="small" v-else-if="item.status === '3'" type="success">-->
<!--                已完成-->
<!--              </wd-button>-->
<!--            </view>-->
<!--          </view>-->
<!--        </template>-->
<!--        <wd-swipe-action>-->
<!--          <view class="flex h-[160rpx] items-center" @click.stop="itemClick(item)">-->
<!--            <image-->
<!--              v-if="item.reqType === '1'"-->
<!--              class="slot-img text-center"-->
<!--              src="/static/ico/ico-huiyi.png"-->
<!--            />-->
<!--            <image-->
<!--              v-else-if="item.reqType === '2'"-->
<!--              class="slot-img text-center"-->
<!--              src="/static/ico/ico-setting.png"-->
<!--            />-->
<!--            <image-->
<!--              v-else-if="item.reqType === '3'"-->
<!--              class="slot-img text-center"-->
<!--              src="/static/ico/ico-faxian.png"-->
<!--            />-->
<!--            <view class="flex-1 mt-1">-->
<!--              <view class="text-color-base">-->
<!--                <template v-if="item.reqType === '1'">-->
<!--                  <text>设备类型</text>-->
<!--                  <text class="mx-2">|</text>-->
<!--                  <text>{{ item.equName }}</text>-->
<!--                </template>-->
 
<!--                <template v-if="item.reqType === '2'">-->
<!--                  <text>工具类型</text>-->
<!--                  <text class="mx-2">|</text>-->
<!--                  <text>{{ item.fixtureName }}</text>-->
<!--                </template>-->
 
<!--                <template v-if="item.reqType === '3'">-->
<!--                  <text>其他类型</text>-->
<!--                </template>-->
<!--                <view class="text-color-gray mt-1 text-mini">-->
<!--                  <text>发生时间: {{ item.occTime }}</text>-->
<!--                </view>-->
 
<!--                <view class="text-color-gray mt-1 text-mini">-->
<!--                  <text>报修时间: {{ item.reqTime }}</text>-->
<!--                </view>-->
<!--                <view class="text-color-gray mt-1 text-mini">-->
<!--                  <text>报修人: {{ item.reqUserName }}</text>-->
<!--                </view>-->
<!--              </view>-->
<!--              <view class="text-color-gray text-sm mt-1">-->
<!--                {{ item.location }} {{ item.madeIn }}-->
<!--              </view>-->
<!--            </view>-->
<!--            <view v-if="isSelectReq">-->
<!--              <wd-button size="small" icon="edit-outline" @click.stop="handleSelectReq(item)">-->
<!--                接单-->
<!--              </wd-button>-->
<!--            </view>-->
<!--          </view>-->
<!--          <template #right>-->
<!--            <view class="h-full px-3 flex items-center">-->
<!--              <wd-button size="small" type="error" @click.stop="handleDelete(item)">删除</wd-button>-->
<!--            </view>-->
<!--          </template>-->
<!--        </wd-swipe-action>-->
<!--      </wd-card>-->
    </view>
  </z-paging>
</template>
 
<script setup lang="ts">
import { useToast, useMessage } from 'wot-design-uni'
import { getRepairReqList, delRepairReq } from '@/service/repair'
import { DICT_REPAIR_REQ_STATUS, DICT_REPAIR_REQ_TYPE, getDictInfo } from '@/service/dict'
import dayjs from "dayjs";
import { isEquAdmin, isRepair } from "@/utils/RoleUtils";
import { useUserStore } from "@/store";
import ReqCard from "@/components/repair/req-card.vue";
 
const userStore = useUserStore()
const message = useMessage()
const toast = useToast()
// 报修单类型
const reqTypeId = ref<number>(-1)
// 报修单处理状态
const status = ref<number>(-1)
const searchValue = ref<string>('')
const isSelectReq = ref(false)
 
const filterDate = ref<string>('2')
 
const filterDateList = ref<Record<string, any>[]>([
  { label: '所有数据', value: '0' },
  { label: '当天数据', value: '1' },
  { label: '当月数据', value: '2' },
])
 
const reqTypeList = ref<any>([{ dictLabel: '所有类型', dictValue: -1 }])
const statusList = ref<any>([{ dictLabel: '所有状态', dictValue: -1 }])
function handleReqType({ value }) {
  reloadData()
}
function handleReqStatu({ value }) {
  reloadData()
}
function handleFilterDate({ value }) {
  reloadData()
}
 
 
 
const paging = ref(null)
const dataList = ref([])
 
const queryList = (pageNum?: number, pageSize?: number) => {
  const queryParams: any = {
    pageNum,
    pageSize,
    params: {
      searchValue: searchValue.value,
    },
  }
  // if (reqTypeId.value === -1) {
  //   delete queryParams.reqType
  // }
  // if (status.value === -1) {
  //   delete queryParams.status
  // }
  //
  // if (filterDate.value === '1') {
  //   // 获取当前日期
  //   const now = dayjs()
  //   queryParams.params = {
  //     beginReqTime: now.startOf('day').format('YYYY-MM-DD 00:00:00'),
  //     endReqTime: now.endOf('day').format('YYYY-MM-DD 23:59:59'),
  //   }
  // } else if (filterDate.value === '2') {
  //   const now = dayjs()
  //   queryParams.params = {
  //     beginReqTime: now.startOf('month').format('YYYY-MM-DD 00:00:00'),
  //     endReqTime: now.endOf('month').format('YYYY-MM-DD 23:59:59'),
  //   }
  // } else {
  //   delete queryParams.params
  // }
 
  // 查询未完成的报修单
  queryParams.params.status = '0,1,2'
  queryParams.reqUser = userStore?.userInfo?.userId
  if (isRepair() || isEquAdmin()) {
    queryParams.params.status = '0'
    queryParams.reqUser = undefined
  }
 
  getRepairReqList(queryParams)
    .then((res: any) => {
      paging.value.completeByTotal(res.rows, res.total)
    })
    .catch((res) => {
      paging.value.complete(false)
    })
}
function reloadData() {
  paging.value.reload()
}
 
/**
 * 删除
 * @param item
 */
function handleDelete(item: any) {
  message
    .confirm({
      msg: '确定删除?',
      title: '提示',
      beforeConfirm: ({ resolve }) => {
        resolve(true)
        if (item.status !== '0') {
          toast.error('该报修单已被接单,请联系管理员!')
        } else {
          delRepairReq(item.id)
            .then((res: any) => {
              if (res?.code === 200) {
                toast.success('删除成功')
                reloadData()
              }
            })
            .catch((res) => {
              toast.error('删除失败')
            })
        }
      },
    })
    .then(() => {})
    .catch((error) => {
      console.log(error)
    })
}
 
function handleSearch() {
  console.log('handleSearch')
  paging.value.reload()
}
 
/**
 * 条目点击事件
 * @param item
 */
function itemClick(item: any) {}
 
/**
 * 其它页面选择报修单
 * @param item
 */
function handleSelectReq(item: any) {
  // 弹出确认是否接单弹窗
  message.confirm({
    msg: '确定接单?',
    title: '提示',
    beforeConfirm: ({ resolve }) => {
      resolve(true)
      // 接单逻辑处理
      if (isSelectReq.value) {
        emitSelectReq(item)
        uni.navigateBack()
      }
    },
  })
}
 
/**
 * 选择回调
 * @param req
 */
function emitSelectReq(req: any) {
  eventChannel.value.emit('selectReq', {
    data: req,
  })
}
 
const goBack = () => {
  uni.navigateBack()
}
function handleClickRight() {
  // if (e.index === 0 && !isSelectReq.value) {
  //   uni.navigateTo({
  //     url: `/pages/repair/repair-add`,
  //   })
  // }
 
  uni.navigateTo({
    url: `/pages/repair/repair-add`,
  })
}
 
const eventChannel = ref<any>()
onMounted(() => {
  const instance: any = getCurrentInstance().proxy
  const event = instance.getOpenerEventChannel()
  eventChannel.value = event
  event.on('OnSelectReq', function (data) {
    isSelectReq.value = true
    // 只显示未接单数据
    status.value = 0
    console.log('OnSelectReq', data)
    // reloadData()
  })
})
 
async function initData() {
  const rList: any = await getDictInfo(DICT_REPAIR_REQ_TYPE)
  reqTypeList.value.push(...rList)
  const sList: any = await getDictInfo(DICT_REPAIR_REQ_STATUS)
  statusList.value.push(...sList)
 
  setTimeout(() => {
    reloadData()
  }, 800)
}
 
onLoad(() => {
  initData()
  uni.$on('list-refresh', reloadData)
})
onUnload(() => {
  uni.$off('list-refresh', reloadData)
})
</script>
 
<style scoped lang="scss">
.menu-title-box {
  height: 30rpx;
  line-height: 30rpx;
}
 
.slot-img {
  width: 72rpx;
  height: 72rpx;
  margin-right: 24rpx;
}
.text-mini {
  font-size: 22rpx;
}
 
.menu-indicator {
  width: 6rpx;
  height: 22rpx;
  border-radius: 10rpx;
  background-color: $uni-color-primary;
}
:deep(.wd-card__title-content) {
  padding: 16rpx !important;
}
:deep(.wd-card__content) {
  padding: 16rpx !important;
}
:deep(.wd-card__footer) {
  padding: 10rpx !important;
}
</style>