<template>
  <div class="subPage">
    <form class="mainForm">
      <ul>
        <li class="flex-h">
          <span>案场：</span>
          <div class="flex-item">
            <div style="width:50%">
              <el-select v-model="CaseId" placeholder="请选择">
                <el-option
                  v-for="item in cases"
                  :key="item.CaseId"
                  :label="item.CaseName"
                  :value="item.CaseId">
                </el-option>
              </el-select>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>起始柜号：</span>
          <div class="flex-item">
            <div style="width:50%">
              <el-input
                placeholder="请输入数字"
                v-model="postData.beginnum"
                clearable
                onkeyup="value=value.replace(/[^\d]/g,'')"
                @blur="postData.beginnum=postData.beginnum.replace(/[^\d]/g,'')">
              </el-input>
            </div>
          </div>
        </li>
        <li class="flex-h">
          <span>截止柜号：</span>
          <div class="flex-item">
            <div style="width:50%">
              <el-input
                placeholder="请输入数字"
                v-model="postData.endnum"
                clearable
                onkeyup="value=value.replace(/[^\d]/g,'')"
                @blur="postData.beginnum=postData.beginnum.replace(/[^\d]/g,'')">
              </el-input>
            </div>
          </div>
        </li>
        <li style="text-align:center">
          <el-button type="primary" size="mini" @click="submit">保存</el-button>
          <el-button type="danger" size="mini" @click="cancel">取消</el-button>
        </li>
      </ul>
    </form>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: '',
  data () {
    return {
      postData: {
        caseid: '', // 案场id
        orgid: '', // 机构id
        beginnum: '', // 起始柜号
        endnum: '', // 截止柜号
      },
      caseList: [{
        value: '0',
        label: '案场1'
      }, {
        value: '1',
        label: '案场3'
      }, {
        value: '2',
        label: '案场3'
      }],
    }
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default,
      OrgId: x => x.app.user.OrgId,
    }),
    CaseId: {
      get () {
        return this.postData.caseid || this.defaultCaseId
      },
      set (val) {
        this.postData.caseid = val
      }
    }
  },
  components: {},
  methods: {
    handleAvatarSuccesser (res, file) {
      this.postData.AreaIconWhite = res.result.url
    },
    handleAvatarSuccess (res, file) {
      this.postData.AreaIcon = res.result.url
    },
    submit () { // 提交数据
      if (this.postData.beginnum === '') {
        this.$message({
          type: 'error',
          message: '起始柜号不能为空'
        })
        return false
      }
      if (this.postData.endnum === '') {
        this.$message({
          type: 'error',
          message: '截止柜号不能为空'
        })
        return false
      }
      this.postData.orgid = this.OrgId
      this.$ajax(this.$api.caseManager.addKey.url, {
        method: this.$api.caseManager.addKey.method,
        data: { ...this.postData, caseid: this.CaseId }
      }).then(res => {
        this.$message({
          type: 'success',
          message: '操作成功!'
        })
        this.$router.push({name: 'keyManager'})
      })
    },
    cancel () {
      this.$router.push({name: 'keyManager'})
    }
  },
  mounted () { }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
</style>
