| | |
| | | :pagination="tableData.pagination" |
| | | /> |
| | | </template> |
| | | <el-dialog |
| | | title="立即抄表" |
| | | :visible.sync="syncDialogVisible" |
| | | width="520px" |
| | | append-to-body |
| | | @closed="resetSyncForm" |
| | | > |
| | | <el-form ref="syncFormRef" :model="syncForm" :rules="syncRules" label-width="110px"> |
| | | <el-form-item label="抄表时间段" prop="readTimeRange"> |
| | | <el-date-picker |
| | | v-model="syncForm.readTimeRange" |
| | | type="datetimerange" |
| | | value-format="yyyy-MM-dd HH:mm:ss" |
| | | range-separator="-" |
| | | start-placeholder="开始时间" |
| | | end-placeholder="结束时间" |
| | | :picker-options="syncPickerOptions" |
| | | style="width: 100%" |
| | | /> |
| | | </el-form-item> |
| | | <p class="sync-tip">时间段最长不超过7天</p> |
| | | </el-form> |
| | | <template v-slot:footer> |
| | | <el-button @click="syncDialogVisible = false">取消</el-button> |
| | | <el-button type="primary" :loading="isReading" @click="submitSync">确认抄表</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </TableLayout> |
| | | </template> |
| | | |
| | |
| | | readTimeRange: [] |
| | | }, |
| | | roomOptions: [], |
| | | isReading: false |
| | | isReading: false, |
| | | syncDialogVisible: false, |
| | | syncMinDate: null, |
| | | syncForm: { |
| | | readTimeRange: [] |
| | | }, |
| | | syncRules: { |
| | | readTimeRange: [{ required: true, message: '请选择抄表时间段', trigger: 'change' }] |
| | | } |
| | | } |
| | | }, |
| | | computed: { |
| | | syncPickerOptions () { |
| | | return { |
| | | onPick: ({ minDate, maxDate }) => { |
| | | this.syncMinDate = minDate && !maxDate ? minDate : null |
| | | }, |
| | | disabledDate: (time) => { |
| | | if (!this.syncMinDate) return false |
| | | const anchor = dayjs(this.syncMinDate) |
| | | const min = anchor.subtract(7, 'day').startOf('day') |
| | | const max = anchor.add(7, 'day').endOf('day') |
| | | const current = dayjs(time) |
| | | return current.isBefore(min) || current.isAfter(max) |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | created () { |
| | |
| | | this.search() |
| | | }, |
| | | handleReadNow () { |
| | | this.$dialog.actionConfirm('确认立即从第三方平台同步抄表数据吗?', '操作确认提醒') |
| | | .then(() => { |
| | | this.isReading = true |
| | | dataApi.syncAll({}) |
| | | .then(res => { |
| | | this.$tip.apiSuccess(res || '抄表同步成功') |
| | | this.search() |
| | | }) |
| | | .catch(e => { |
| | | this.$tip.apiFailed(e) |
| | | }) |
| | | .finally(() => { |
| | | this.isReading = false |
| | | }) |
| | | this.syncForm.readTimeRange = this.defaultSyncRange() |
| | | this.syncDialogVisible = true |
| | | this.$nextTick(() => { |
| | | if (this.$refs.syncFormRef) { |
| | | this.$refs.syncFormRef.clearValidate() |
| | | } |
| | | }) |
| | | }, |
| | | defaultSyncRange () { |
| | | const end = dayjs() |
| | | const start = end.subtract(24, 'hour') |
| | | return [start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss')] |
| | | }, |
| | | resetSyncForm () { |
| | | this.syncMinDate = null |
| | | this.syncForm.readTimeRange = [] |
| | | if (this.$refs.syncFormRef) { |
| | | this.$refs.syncFormRef.resetFields() |
| | | } |
| | | }, |
| | | validateSyncRange (range) { |
| | | if (!range || range.length !== 2) { |
| | | this.$tip.warning('请选择抄表时间段') |
| | | return false |
| | | } |
| | | const start = dayjs(range[0]) |
| | | const end = dayjs(range[1]) |
| | | if (!start.isValid() || !end.isValid()) { |
| | | this.$tip.warning('抄表时间格式不正确') |
| | | return false |
| | | } |
| | | if (!end.isAfter(start)) { |
| | | this.$tip.warning('抄表开始时间必须早于结束时间') |
| | | return false |
| | | } |
| | | if (end.diff(start, 'day', true) > 7) { |
| | | this.$tip.warning('抄表时间段不能超过7天') |
| | | return false |
| | | } |
| | | return true |
| | | }, |
| | | submitSync () { |
| | | this.$refs.syncFormRef.validate(valid => { |
| | | if (!valid) return |
| | | const range = this.syncForm.readTimeRange |
| | | if (!this.validateSyncRange(range)) return |
| | | this.isReading = true |
| | | dataApi.syncAll({ |
| | | readTimeBegin: range[0], |
| | | readTimeEnd: range[1] |
| | | }) |
| | | .catch(() => {}) |
| | | .then(res => { |
| | | this.$tip.apiSuccess(res || '抄表同步成功') |
| | | this.syncDialogVisible = false |
| | | this.search() |
| | | }) |
| | | .catch(e => { |
| | | this.$tip.apiFailed(e) |
| | | }) |
| | | .finally(() => { |
| | | this.isReading = false |
| | | }) |
| | | }) |
| | | }, |
| | | formatJsfs (val) { |
| | | if (val == null || val === '') return '-' |
| | |
| | | |
| | | <style scoped> |
| | | .red { color: #f56c6c; } |
| | | .sync-tip { |
| | | margin: 0 0 0 110px; |
| | | color: #909399; |
| | | font-size: 12px; |
| | | line-height: 1.5; |
| | | } |
| | | </style> |