              <template>
                <div class="app-container calendar-list-container">
                  <el-form :rules="rules" ref="addForm" :model="updateequipmentinfo" label-position="left" label-width="120px"
                            style='width:800px;margin-left:20px'>
                        <br/>
                          <el-row :gutter="24" style="margin-bottom: 15px;">
                            <el-col :span="12">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('equipment.id')" prop="ei_code" style="width: 320px;">
                                  <div class="block">
                                <el-input v-model="updateequipmentinfo.ei_code"> </el-input>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                             <el-col :span="12">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('equipment.type')" prop="et_code" style="width: 300px;">
                                  <div class="block">
                                <el-select class="filter-item" v-model="updateequipmentinfo.et_code" filterable  style="width: 200px;">
                                <el-option v-for="item in equipmentTypesOptions" :key="item.et_code" :label="item.et_name" :value="item.et_code">
                                </el-option>
                                </el-select>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="24" style="margin-bottom: 15px;">
                            <el-col :span="12">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('equipment.status')" prop="ei_status" style="width: 300px;">
                                  <div class="block">
                                <el-select class="filter-item" v-model="updateequipmentinfo.ei_status" filterable  style="width: 200px;">
                                <el-option v-for="item in statusOptions" :key="item.key" :label="item.label" :value="item.key">
                                </el-option>
                                </el-select>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                             <el-col :span="12">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('equipment.rent')" prop="ei_rent" style="width: 300px;">
                                  <div class="block">
                                 <el-input-number v-model="updateequipmentinfo.ei_rent" controls-position="right" :max="99999" style="width: 200px;">
                                 </el-input-number>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="24" style="margin-bottom: 15px;">
                            <el-col :span="12">
                              <div class="grid-content bg-purple" style="width: 300px;">
                                <el-form-item  :label="$t('equipment.date')" prop="ei_date" style="width: 320px;">
                                  <div class="block">
                                <el-input v-model="updateequipmentinfo.ei_date" :disabled="true"> </el-input>
                                  </div>
                                </el-form-item>
                              </div>
                            </el-col>
                          </el-row>
                          <el-row :gutter="24" style="margin-bottom: 15px;">
                          <el-col :span="8"><div>&nbsp;</div></el-col>
                          <el-col :span="12">
                            <div >
                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<el-button  type="primary" @click="ordertempUpdate">{{$t('table.confirm')}}</el-button>
                              <el-button @click="handleref()">{{$t('navbar.reset')}}</el-button>
                            </div>
                          </el-col>
                          <el-col :span="6"><div>&nbsp;</div></el-col>
                        </el-row>
                      </el-form>
                  <el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
                    <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
                      <el-table-column prop="key" label="Channel"></el-table-column>
                      <el-table-column prop="pv" label="Pv"></el-table-column>
                    </el-table>
                    <span slot="footer" class="dialog-footer">
                      <el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
                    </span>
                  </el-dialog>
                </div>
              </template>
              <script>
                import { getBranches, createArticle, getjlServiceUsers } from '@/api/article'
                import { getEquipmentTypes, getEquipmentInfo, updateEquipmentInfo, checkEquipmentInfo } from '@/api/equipmentapi'
                import waves from '@/directive/waves' // 水波纹指令
                import { parseTime } from '@/utils'
                // arr to obj ,such as { CN : "China", US : "USA" }
                export default {
                  name: 'equipmentedit',
                  directives: {
                    waves
                  },
                  data() {
                    return {
                      tableKey: 0,
                      list: null,
                      total: null,
                      page: 1,
                      limit: 10,
                      queryType: 'list',
                      listLoading: true,
                      equipmentQuery: {
                        id: undefined
                      },
                      checkCouponCreate: 0,
                      checkCouponbatch: {
                        id: null
                      },
                      updateequipmentinfo: {
                        id: null,
                        et_code: null,
                        ei_code: null,
                        ei_rent: null,
                        ei_status: null,
                        ei_date: null,
                        user: null
                      },
                      updateequipmentinfoconf: {
                        id: null,
                        et_code: null,
                        ei_code: null,
                        ei_rent: null,
                        ei_status: null,
                        ei_date: null
                      },
                      pickerOptions1: {
                        shortcuts: [{
                          text: '今天',
                          onClick(picker) {
                            picker.$emit('pick', new Date())
                          }
                        }, {
                          text: '昨天',
                          onClick(picker) {
                            const date = new Date()
                            date.setTime(date.getTime() - 3600 * 1000 * 24)
                            picker.$emit('pick', date)
                          }
                        }, {
                          text: '一周前',
                          onClick(picker) {
                            const date = new Date()
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
                            picker.$emit('pick', date)
                          }
                        }]
                      },
                      sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
                      statusOptions: [{ label: '可租赁', key: 1 }, { label: '租赁中', key: 2 }, { label: '不可租赁', key: 3 }],
                      branchesOptions: [],
                      citysOptions: [],
                      equipmentTypesOptions: [],
                      mmsoptions: [],
                      showReviewer: false,
                      ethnicgroupptions: '',
                      provinceoptions: '',
                      dialogFormVisible: false,
                      checkidcard: {
                        idcard: undefined
                      },
                      checkdate: {
                        ei_code: undefined
                      },
                      dialogStatus: '',
                      dialogPvVisible: false,
                      pvData: [],
                      updateStatus: {
                        id: undefined,
                        status: undefined
                      },
                      rules: {
                        et_code: [{ required: true, message: '请选择设备类型！', trigger: 'blur' }],
                        ei_code: [{ required: true, message: '请输入设备编号！', trigger: 'blur' }],
                        ei_rent: [{ required: true, message: '请输入租金！', trigger: 'blur' },
                          { pattern: /^[1-9]\d*(\.\d+)?$/, message: '请正确输入租金!', trigger: 'blur' }]
                      },
                      downloadLoading: false
                    }
                  },
                  created() {
                    this.getList()
                    getBranches().then(response5 => {
                      this.branchesOptions = response5.data
                      this.citysOptions = response5.data
                    })
                    getjlServiceUsers().then(response7 => {
                      this.mmsoptions = response7.data
                    })
                    getEquipmentTypes().then(response8 => {
                      this.equipmentTypesOptions = response8.data
                    })
                    this.checkCouponbatch.id = this.$route.params.couponBatch
                  },
                  methods: {
                    getList() {
                      this.equipmentQuery.id = this.$route.params.orderid
                      getEquipmentInfo(this.equipmentQuery).then(response => {
                        this.updateequipmentinfo.et_code = Number(response.data.et_code)
                        this.updateequipmentinfo.ei_code = response.data.ei_code
                        this.updateequipmentinfo.ei_rent = response.data.ei_rent
                        this.updateequipmentinfo.ei_status = response.data.ei_status
                        this.updateequipmentinfo.ei_date = response.data.ei_date
                        this.updateequipmentinfoconf.et_code = Number(response.data.et_code)
                        this.updateequipmentinfoconf.ei_code = response.data.ei_code
                        this.updateequipmentinfoconf.ei_rent = response.data.ei_rent
                        this.updateequipmentinfoconf.ei_status = response.data.ei_status
                        this.updateequipmentinfoconf.ei_date = response.data.ei_date
                      })
                    },
                    ordertempUpdate() {
                      this.$refs['addForm'].validate((valid) => {
                        if (valid) {
                          this.checkdate.ei_code = this.updateequipmentinfo.ei_code
                          checkEquipmentInfo(this.checkdate).then(response3 => {
                            if (response3.data !== 0 && this.updateequipmentinfo.ei_code !== this.updateequipmentinfoconf.ei_code) {
                              this.$notify({
                                title: '失败',
                                message: '设备编号重复！',
                                type: 'warning',
                                duration: 2000
                              })
                            } else {
                              this.updateequipmentinfo.id = this.$route.params.orderid
                              this.updateequipmentinfo.user = this.$store.state.user.introduction
                              updateEquipmentInfo(this.updateequipmentinfo).then(response => {
                                if (response.data !== 1) {
                                  createArticle(this.temp).then(() => {
                                    this.$notify({
                                      title: '失败',
                                      message: '更新失败',
                                      type: 'warning',
                                      duration: 2000
                                    })
                                  })
                                } else {
                                  createArticle(this.temp).then(() => {
                                    this.$notify({
                                      title: '成功',
                                      message: '更新成功',
                                      type: 'success',
                                      duration: 2000
                                    })
                                  })
                                }
                              })
                            }
                          })
                        }
                      })
                    },
                    handleref() {
                      this.updateequipmentinfo.et_code = this.updateequipmentinfoconf.et_code
                      this.updateequipmentinfo.ei_code = this.updateequipmentinfoconf.ei_code
                      this.updateequipmentinfo.ei_rent = this.updateequipmentinfoconf.ei_rent
                      this.updateequipmentinfo.ei_status = this.updateequipmentinfoconf.ei_status
                      this.updateequipmentinfo.ei_date = this.updateequipmentinfoconf.ei_date
                    },
                    resetForm(formName) {
                      this.$refs[formName].resetFields()
                    },
                    formatJson(filterVal, jsonData) {
                      return jsonData.map(v => filterVal.map(j => {
                        if (j === 'timestamp') {
                          return parseTime(v[j])
                        } else {
                          return v[j]
                        }
                      }))
                    }
                  }
                }
              </script>
              <style>
              .el-form--label-left .el-form-item__label{
                text-align:right
              }
              .el-rate{
                line-height: 0;
                margin-top:8px;
              }
              .el-checkbox.el-checkbox {
                  margin-left: 30px;
              }
              </style>