<!--气瓶管理-->
<template>
  <div class="app-container approval_handle">
    <div class="approval_handle-page" v-if="pageType == 1">
      <el-form :model="queryParams" ref="queryForm" style="margin-top:20px;" :inline="true">
        <el-form-item label="关键字" prop="name">
          <el-input
            v-model="queryParams.searchValue"
            placeholder="标签码/气瓶编号"
            clearable
            maxLength="30"
            size="small"
          />
        </el-form-item>
        <el-form-item label="最后使用时间" prop="dateRange">
          <el-date-picker
            :clearable="false"
            v-model="dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <p class="inquire-button-one" @click="handleQuery">查询</p>
          <p class="reset-button-one" @click="resetQuery">重置</p>
        </el-form-item>
        <el-form-item style="float: right;">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleClick('','','add')"
              v-hasPermi="['bottle:bottleStorage:add']"
            >气瓶入库</el-button>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="标签码" align="left" prop="electronicTag"/>
        <el-table-column label="气瓶编号" align="left" prop="airNumber"></el-table-column>
        <el-table-column label="气体名称" align="left" prop="airName"></el-table-column>
        <el-table-column label="气瓶规格" align="left" prop="configName"></el-table-column>
        <el-table-column label="使用人数" align="left" prop="numberPersons"></el-table-column>
        <el-table-column label="当前气压" align="left" prop="currentPressure">
          <template slot-scope="scope">
            <span >{{scope.row.currentPressure}}Mpa</span>
          </template>
        </el-table-column>
        <el-table-column label="最后使用时间" align="left" prop="lastTime"></el-table-column>
        <el-table-column label="状态" align="left" prop="storageStatus">
          <template slot-scope="scope">
            <p :class="scope.row.storageStatus == 1?'color_warn':(scope.row.storageStatus == 2?'color_14AE10':(scope.row.storageStatus == 3?'color_red':''))">{{scope.row.storageStatus == 1?'闲置':(scope.row.storageStatus == 2?'使用':(scope.row.storageStatus == 3?'出库':''))}}</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160">
          <template slot-scope="scope">
            <div class="button-box">
              <p class="table-min-button"
                 v-hasPermi="['bottle:bottleStorage:query']"
                 @click="handleClick('',scope.row,'detail')"
              >查看</p>
              <p class="table-min-button"
                 v-hasPermi="['bottle:bottleStorageOut:add']"
                 @click="handleClick('',scope.row,'out')"
              >出库</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination :page-sizes="[20, 30, 40, 50]"
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!--新增页面-->
    <add-page v-if="pageType==2" :pageData="pageData"></add-page>
     <!--详情页面-->
    <detail-page v-if="pageType==3" :pageData2="pageData2"></detail-page>
    <!--    弹窗-->
    <el-dialog :title=dialogTitle :visible.sync="dialogVisible" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <div style="margin-bottom: 20px">{{dialogContent}}</div>
        <el-input oninput="value=value.replace(/[^1-9]{0,1}(\d*(?:\.\d{0,1})?).*$/g, '$1')"  v-model="form.pressure" placeholder="请输入气表实际压力，精确到小数点后一位" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="submitForm">出库</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import addPage from "./gasManageAdd.vue"
import detailPage from "./gasManageDetail.vue"
import { gasManageList, gasManageOut, returnRecord, useRecord } from '@/api/gasManage3_0/gasManageSYD'
export default {
  name: "Approval",
  components: {
    addPage,
    detailPage
  },
  data() {
    return {
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      dialogTitle:'气瓶出库提示',
      dialogContent:'请输入当前气压值',
      dialogVisible:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        remark:'login',
        searchValue:'',
        startTime:'',
        endTime:'',
      },
      form:{
        pressure:'',
      },
      total:0,
      tableData:[{}],
      dateRange:[],
      pageData:{},
      pageData2:{},
    };


  },
  methods: {
      handleClick(index,row,doType){
        let _this=this;
        if(doType=='add'){//新增
          _this.pageType=2;
        }else if(doType=='detail'){//查看
          _this.pageData2.id=row.id;
          _this.pageType=3;
        }else if(doType=='out'){//出库
          _this.dialogVisible=true;
          _this.form.storageId=row.id
          // this.$confirm('是否确认出库?', '提示', {
          //   confirmButtonText: '确定',
          //   cancelButtonText: '取消',
          //   type: 'warning'
          // }).then(() => {
          //
          // }).catch(() => {});
        }else if(doType=='back'){//返回
          _this.pageType=1;
          _this.getList()
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.searchValue = "";
        this.dateRange=[];
        this.queryParams.startTime=null;
        this.queryParams.endTime=null
        this.handleQuery();
      },
      // 取消按钮
      cancel() {
        this.form = {};
        this.dialogVisible = false;
      },
      //出库
        submitForm(){
        let _this=this;

        this.$refs["form"].validate(valid => {
          if (valid) {
            gasManageOut(this.form).then( response => {
              let res=response.data;
              if(response.code==200){
                _this.dialogVisible=false;
                _this.getList()
              }
            });

          }
        });
      },
      getList(){
        let _this=this;
        if(this.dateRange&&this.dateRange.length>0) {
          this.queryParams.startTime=this.dateRange[0]
          this.queryParams.endTime=this.dateRange[1]
        } else {
          this.queryParams.startTime=null;
          this.queryParams.endTime=null
        }
        gasManageList(_this.queryParams).then( response => {
          let res=response.rows;
          _this.tableData=res;
          _this.total=response.total;
        });
      },
  },
  mounted() {
    this.getList()
  }
};
</script>

<style scoped lang="scss">
  .approval_handle {
    display: flex!important;
    flex-direction: column;
    .approval_handle-page{
      flex:1;
      display: flex!important;
      flex-direction: column;
      box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
      padding:20px 20px 20px!important;
      border-radius:10px;

      .button-box{
        width:200px;
        display: flex;
      }
    }

  }
</style>
