    <template>
      <div class="app-container calendar-list-container">
        <el-form label-position="right" label-width="100px"  style='width:100%;'>
          <el-row :gutter="24">
            <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('equipment.id')" >
                  <div class="block">
                    <el-input style="width: 100%;" class="filter-item" v-model="seachQuery.ei_code" :maxlength = 20>
                    </el-input>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="6" :xl="6">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('equipment.type')" >
                <div class="block">
                  <el-select class="filter-item" v-model="seachQuery.et_code" filterable  style="width: 100%;">
                    <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-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('equipment.status')" >
                <div class="block">
                  <el-select class="filter-item" v-model="seachQuery.ei_status" filterable  style="width: 100%;">
                    <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 :xs="23" :sm="23" :md="11" :lg="5" :xl="5">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('equipment.date')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.ei_date"  value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions1" style="width: 100%;">
                  </el-date-picker>
                </div>
              </el-form-item>
            </div>
          </el-col>
          </el-row>
          <el-row :gutter="24" >
            <div  align="center" > <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" :loading ="buttonloading" @click="handleFilterfirst">
            {{$t('table.search')}}
          </el-button>
          <el-button class="filter-item" type="primary" v-waves icon="el-icon-delete" @click="handleref">
            {{$t('table.cancel')}}
          </el-button></div>
          </el-row>
          <el-row :gutter="24">
            <div align="right">
              <el-button class="filter-item" style="margin-left: 10px;" @click="femadd" type="primary"
                    icon="el-icon-edit">{{$t('equipment.emadd')}}
            </el-button>&nbsp;&nbsp;&nbsp;
            </div>
          </el-row>
        </el-form>
        <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="加载中......" border fit
                  highlight-current-row
                  style="width: 100%">
          <el-table-column align="center" :label="$t('equipment.id')">
            <template slot-scope="scope">
                <a href="#" @click="infoshow(scope.row.ei_code)"><span style="color:#409EFF">{{scope.row.ei_code}}</span></a>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('equipment.type')">
            <template slot-scope="scope">
              <span>{{scope.row.et_code}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('equipment.status')">
            <template slot-scope="scope">
              <span v-if="scope.row.ei_status == '1'">{{'可租赁'}}</span>
              <span v-if="scope.row.ei_status == '2'">{{'租赁中'}}</span>
              <span v-if="scope.row.ei_status == '3'">{{'不可租赁'}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('equipment.rent')">
            <template slot-scope="scope">
              <span>{{scope.row.et_rent}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('equipment.ei_mortagage')">
            <template slot-scope="scope">
              <span>{{scope.row.et_mortagage}}</span>
            </template>
          </el-table-column>
            <el-table-column align="center" :label="$t('equipment.date')">
            <template slot-scope="scope">
              <span>{{scope.row.ei_date}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('table.actions')" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <a href="#" @click="hrefequipmentedit(scope.row.id)"><el-tag>{{$t('table.edit')}}</el-tag></a> 
            <a href="#" @click="equipmentdelete(scope.row.id)"><el-tag>{{$t('table.delete')}}</el-tag></a> 
          </template>
        </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="page" :page-sizes="[10,20,30,50]" :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
        <!--添加设备-->
        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :before-close="handleClose">
          <el-form :rules="rules" ref="emaddForm" :model="addeminfo" label-position="left" label-width="120px"
                  style='width: 500px;margin-left:20px'>
          <el-row :gutter="20" style="margin-bottom: 15px;">
            <el-col :span="20">
              <div class="grid-content bg-purple">
                <el-form-item  :label="$t('equipment.type')" prop="et_code">
                  <el-select class="filter-item" v-model="addeminfo.et_code" filterable  style="width: 220px;" @change="selectAmount()" >
                  <el-option v-for="item in equipmentTypesOptions" :key="item.et_code" :label="item.et_name" :value="item.et_code">
                  </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
            <el-row :gutter="20" style="margin-bottom: 15px;">
            <el-col :span="20">
              <div class="grid-content bg-purple" style="width: 300px;">
                <el-form-item  :label="$t('equipment.id')" prop="ei_code" style="width: 310px;">
                  <div class="block">
                <el-input v-model="addeminfo.ei_code" style="width: 220px;" ></el-input>
                  </div>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
            <el-row :gutter="20" style="margin-bottom: 15px;">
            <el-col :span="20">
              <div class="grid-content bg-purple">
                <el-form-item  :label="$t('equipment.rent')">
                <el-input :disabled="true" v-model="addeminfo.ei_rent" style="width: 220px;" ></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <el-row :gutter="20" style="margin-bottom: 15px;">
            <el-col :span="20">
              <div class="grid-content bg-purple">
                <el-form-item  :label="$t('equipment.ei_mortagage')" >                          
                <el-input :disabled="true" v-model="addeminfo.ei_mortagage" style="width: 220px;" ></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button  type="primary" @click="addEquipment">{{$t('table.confirm')}}</el-button>
            <el-button @click="resetForm('emmoreaddForm')">{{$t('navbar.reset')}}</el-button>
          </div>
        </el-dialog>
      </div>
    </template>
    <script>
      import { fetchPv, updateArticle, createArticle } from '@/api/article'
      import { getEquipmentTypes, getEquipmentAmount, getEquipmentInfos, queryEquipmentInfo, checkEquipmentInfo, addEquipmentInfo, deleteEquipmentInfo } from '@/api/equipmentapi'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'equipmentstock',
        directives: {
          waves
        },
        data() {
          return {
            tableKey: 0,
            list: null,
            total: null,
            page: 1,
            limit: 10,
            queryType: 'list',
            listLoading: true,
            buttonloading: false,
            listQuery: {
              importance: undefined,
              title: undefined,
              type: undefined,
              sort: '+id'
            },
            checkdate: {
              ei_code: undefined
            },
            seachQuery: {
              ei_code: null,
              et_code: null,
              ei_rent: null,
              ei_status: null,
              ei_date: null,
              page: null,
              limit: null
            },
            queryAmount: {
              et_type: null
            },
            idcardquery: {
              idcard: null
            },
            equipmentdel: {
              id: undefined
            },
            checksalt: {
              salt: undefined
            },
            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: [],
            packageoptions: [],
            mmsoptions: [],
            showReviewer: false,
            addeminfo: {
              et_code: null,
              ei_code: null,
              ei_rent: null,
              ei_mortagage: null,
              ei_date: null,
              ei_status: null,
              user: null
            },
            ethnicgroupptions: '',
            provinceoptions: '',
            dialogFormVisible: false,
            dialogFormVisiblemore: false,
            checkidcard: {
              idcard: undefined
            },
            dialogStatus: '',
            textMap: {
              update: 'Edit',
              create: '添加月嫂'
            },
            dialogPvVisible: false,
            pvData: [],
            updateStatus: {
              id: undefined,
              status: undefined
            },
            rules: {
              et_code: [{ required: true, message: '请选择设备类型！', trigger: 'blur' }],
              ei_code: [{ required: true, message: '请输入设备编号！', trigger: 'blur' }]
            },
            downloadLoading: false
          }
        },
        created() {
          this.getList()
          getEquipmentTypes().then(response8 => {
            this.equipmentTypesOptions = response8.data
          })
        },
        methods: {
          getList() {
            this.listQuery.page = this.page
            this.listQuery.limit = this.limit
            this.queryType = 'list'
            this.listLoading = true
            getEquipmentInfos(this.listQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          handleFilter() {
            this.seachQuery.page = this.page
            this.seachQuery.limit = this.limit
            this.queryType = 'query'
            this.listLoading = true
            queryEquipmentInfo(this.seachQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          handleFilterfirst() {
            this.seachQuery.page = 1
            this.seachQuery.limit = 10
            this.queryType = 'query'
            this.listLoading = true
            this.buttonloading = true
            queryEquipmentInfo(this.seachQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
              this.buttonloading = false
            })
          },
          handleSizeChange(val) {
            this.limit = val
            if (this.queryType === 'list') {
              this.listQuery.limit = val
              this.listQuery.page = this.page
              this.getList()
            } else {
              this.seachQuery.limit = val
              this.seachQuery.page = this.page
              this.handleFilter()
            }
          },
          infoshow(id) {
            this.$router.push({ name: 'equipmentshow', params: { ei_code: id }})
          },
          handleCurrentChange(val) {
            this.page = val
            if (this.queryType === 'list') {
              this.listQuery.limit = this.limit
              this.listQuery.page = val
              this.getList()
            } else {
              this.seachQuery.limit = this.limit
              this.seachQuery.page = val
              this.handleFilter()
            }
          },
          handleModifyStatus(row, status) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            row.status = status
          },
          femadd() {
            this.addeminfo.dialogStatus = 'create'
            this.addeminfo.et_code = null
            this.addeminfo.ei_code = null
            this.addeminfo.ei_rent = null
            this.addeminfo.ei_date = null
            this.addeminfo.ei_status = null
            this.addeminfo.user = this.$store.state.user.introduction
            this.dialogFormVisible = true
            this.$nextTick(() => {
              this.$refs['emaddForm'].clearValidate()
            })
          },
          handleClose(done) {
            this.$confirm('确认关闭？').then(_ => {
              done()
            }).catch(_ => {})
          },
          addEquipment() {
            this.$refs['emaddForm'].validate((valid) => {
              if (valid) {
                this.checkdate.ei_code = this.addeminfo.ei_code
                this.listLoading = true
                checkEquipmentInfo(this.checkdate).then(response3 => {
                  if (response3.data !== 0) {
                    this.listLoading = false
                    createArticle(this.temp).then(() => {
                      this.dialogFormVisible = false
                      this.$notify({
                        title: '失败',
                        message: '设备编号重复！',
                        type: 'warning',
                        duration: 2000
                      })
                    })
                  } else {
                    this.addeminfo.ei_status = 1
                    var date1 = new Date()
                    this.addeminfo.ei_date = date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' + date1.getDate()
                    addEquipmentInfo(this.addeminfo).then(response => {
                      if (response.data === 1) {
                        this.list = response.data.items
                        this.total = response.data.total
                        this.listLoading = false
                        this.$refs['emaddForm'].validate((valid) => {
                          if (valid) {
                            createArticle(this.temp).then(() => {
                              this.dialogFormVisible = false
                              this.$notify({
                                title: '成功',
                                message: '创建成功',
                                type: 'success',
                                duration: 2000
                              })
                            })
                          }
                        })
                      } else {
                        this.listLoading = false
                        createArticle(this.temp).then(() => {
                          this.dialogFormVisible = false
                          this.$notify({
                            title: '失败',
                            message: '录入失败！',
                            type: 'error',
                            duration: 2000
                          })
                        })
                      }
                      this.getList()
                    })
                  }
                })
              }
            })
          },
          handleUpdate(row) {
            this.temp = Object.assign({}, row) // copy obj
            this.temp.timestamp = new Date(this.temp.timestamp)
            this.dialogStatus = 'update'
            this.dialogFormVisible = true
            this.$nextTick(() => {
              this.$refs['dataForm'].clearValidate()
            })
          },
          hrefequipmentedit(id) {
            this.$router.push({ name: 'equipmentedit', params: { orderid: id }})
          },
          selectAmount() {
            this.queryAmount.et_type = this.addeminfo.et_code
            getEquipmentAmount(this.queryAmount).then(response => {
              this.addeminfo.ei_mortagage = response.data.et_mortagage
              this.addeminfo.ei_rent = response.data.et_rent
            })
          },
          equipmentdelete(id) {
            createArticle(this.temp).then(() => {
              this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                this.equipmentdel.id = id
                this.listLoading = true
                deleteEquipmentInfo(this.equipmentdel).then(response => {
                  this.list = response.data.items
                  this.total = response.data.total
                  this.listLoading = false
                  if (response.data === 1) {
                    createArticle(this.temp).then(() => {
                      this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                      })
                    })
                  } else {
                    createArticle(this.temp).then(() => {
                      this.$notify({
                        title: '错误',
                        message: '错误',
                        type: 'error',
                        duration: 2000
                      })
                    })
                  }
                  this.getList()
                })
              }).catch(() => {})
            })
          },
          updateData() {
            this.$refs['dataForm'].validate((valid) => {
              if (valid) {
                const tempData = Object.assign({}, this.temp)
                tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
                updateArticle(tempData).then(() => {
                  for (const v of this.list) {
                    if (v.id === this.temp.id) {
                      const index = this.list.indexOf(v)
                      this.list.splice(index, 1, this.temp)
                      break
                    }
                  }
                  this.dialogFormVisible = false
                  this.$notify({
                    title: '成功',
                    message: '更新成功',
                    type: 'success',
                    duration: 2000
                  })
                })
              }
            })
          },
          handleDelete(row) {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          },
          handleFetchPv(pv) {
            fetchPv(pv).then(response => {
              this.pvData = response.data.pvData
              this.dialogPvVisible = true
            })
          },
          handleDownload() {
            this.downloadLoading = true
            import('@/vendor/Export2Excel').then(excel => {
              const tHeader = ['timestamp', 'title', 'type', 'importance', 'status']
              const filterVal = ['timestamp', 'title', 'type', 'importance', 'status']
              const data = this.formatJson(filterVal, this.list)
              excel.export_json_to_excel(tHeader, data, 'table-list')
              this.downloadLoading = false
            })
          },
          handleref() {
            this.seachQuery.ei_code = null
            this.seachQuery.et_code = null
            this.seachQuery.ei_status = null
            this.seachQuery.ei_date = null
            this.seachQuery.page = null
            this.seachQuery.limit = null
          },
          resetForm(formName) {
            this.addeminfo.et_code = null
            this.addeminfo.ei_code = null
            this.addeminfo.ei_rent = null
            this.addeminfo.ei_mortagage = null
          },
          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>
    