Mr.Zhang
2023-10-12 7f05ab4e75036b2697c9208e581f609b27f0af82
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
<template>
  <GlobalAlertWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    width="600px"
    @confirm="confirm"
  >
    <el-descriptions title="" :column="1" >
      <el-descriptions-item label="车编号">{{ form.bikeCode }}</el-descriptions-item>
      <el-descriptions-item label="车类型">{{ form.bikeType }}</el-descriptions-item>
      <el-descriptions-item label="借出时长">{{ form.rideTime }}</el-descriptions-item>
      <el-descriptions-item label="借出站点">{{ form.rentSiteId }}</el-descriptions-item>
      <el-descriptions-item label="锁止器号">{{ form.rentLockId }}</el-descriptions-item>
    </el-descriptions>
    <el-form :model="form" ref="form" :rules="backInfoRequired ? rules2 : rules " label-suffix=":">
      <el-form-item label="计费时长" prop="duration">
        <div style="display: flex;">
          <el-input style="flex: 1;" v-model="form.duration" placeholder="请输入排序码" v-trim/>
          分钟
        </div>
      </el-form-item>
      <el-form-item label="调整原因" prop="backReason">
        <el-select v-model="form.backReason" placeholder="请选择调整原因" @change="selectReason">
          <el-option
            v-for="item in reason"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="调整备注" prop="backInfo">
        <el-input
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 4}"
          v-model="form.backInfo"
          placeholder="请输入调整备注"
          v-trim
        />
      </el-form-item>
      
    </el-form>
  </GlobalAlertWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
import { baseParamList } from '@/api/business/baseParam'
import { updateDuration } from '@/api/business/memberRides'
// import { findList } from '@/api/business/roomTime'
import { numRule } from '@/utils/form'
export default {
  name: 'OperaSuggestWindow',
  extends: BaseOpera,
  components: { GlobalAlertWindow },
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        bikeCode: '',
        rentSiteId: '',
        rentLockId: '',
        bikeType: '',
        rentDate: '',
        rideTime: '',
        duration: '',
        backReason: '',
        backInfo: '',
      },
      reason: [],
      backInfoRequired: false,
      // 验证规则
      rules: {
        duration: [
         { required: true, validator: numRule, message: '请输入计费时长', tigger: 'blur' }
        ],
        backReason: [
          { required: true, message: '请选择调整原因', tigger: 'change'},
        ]
      },
      rules2: {
        duration: [
         { required: true, validator: numRule, message: '请输入计费时长', tigger: 'blur' }
        ],
        backReason: [
          { required: true, message: '请选择调整原因', tigger: 'change'},
        ],
        backInfo: [
          { required: true, message: '请输入调整备注', tigger: 'blur'},
        ],
      }
    }
  },
  created () {
    baseParamList({type: 2})
      .then(res => {
        this.reason = res
      })
  },
  methods: {
    /**
     * 打开窗口
     * @title 窗口标题
     * @target 编辑的对象
     */
     open (title, target) {
      this.title = title
      this.visible = true
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.backReason = ''
        this.form.backInfo = ''
        this.$refs.form.clearValidate()
      })
    },
    selectReason(v) {
      // console.log(item);
      let item = this.reason.find(item => item.name == v)
      this.backInfoRequired = item.required == 1
    },
    confirm() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        this.isWorking = true
        updateDuration(this.form)
          .then(res => {
            this.visible = false
            this.$tip.apiSuccess('修改成功')
            this.$emit('success')
 
          })
          .catch(err => {
            this.$tip.apiFailed(err)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    }
  },
}
</script>
 
<style lang="scss" scoped>
@import "@/assets/style/alertstyle.scss";
@import "@/assets/style/variables.scss";
 
::v-deep .el-input.is-disabled .el-input__inner {
  background-color: #fff !important;
  cursor: pointer;
}
 
.time-style {
  display: flex;
  flex-wrap: wrap;
  cursor: pointer;
  .time-item {
    margin-right: 8px;
    margin-bottom: 8px;
    border: #111 solid 1px;
    font-size: 14px;
    line-height: 14px;
    padding: 5px;
    border-radius: 5px;
    color: #111;
  }
  .time-item-sel {
    border-color: $primary-color;
    background-color: $primary-color;
    color: #fff;
  }
  .time-item-disable {
    border-color: #999;
    background-color: #999;
    color: #111;
  }
}
 
</style>