<!-- 气瓶类型 -->
<template>
  <div class="app-container cylinderSetting">
    <div class="page-container cylinderSettingPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="关键字" prop="searchValue" label-width="60px">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="气体名称"
              clearable
              style="width: 240px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             style="float: right;"
             v-hasPermi="['db:bottleType:add']"
             @click="tableButton(1)"
          >新增</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="气体名称" prop="gasName"  show-overflow-tooltip/>
          <el-table-column label="级别" prop="level" width="300" show-overflow-tooltip>
            <template slot-scope="scope">
              {{forData(1,scope.row.level)}}
            </template>
          </el-table-column>
          <el-table-column label="规格" prop="size" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              {{forData(2,scope.row.size)}}
            </template>
          </el-table-column>
          <el-table-column label="成分" prop="gasComposition" width="300" show-overflow-tooltip/>
          <el-table-column label="编辑时间" prop="updateTime" width="249" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.updateTime,'{y}-{m}-{d} {h}:{i}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="180" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                   v-hasPermiAnd="['db:bottleType:edit','db:bottleType:query']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermi="['db:bottleType:remove']"
                >删除</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <el-dialog class="cylinderSetting-dialog-box"
               :title="dialogTitle" :visible.sync="dialogType" v-if="dialogType"
               :close-on-click-modal="false" width="500px" append-to-body>
      <el-form ref="dialogForm" :model="dialogForm" :rules="rules" label-width="120px">
        <el-form-item label="名称：" prop="gasName">
          <el-input
            maxLength="10"
            v-model="dialogForm.gasName"
            placeholder="请输入名称"
            style="width: 280px"
          />
        </el-form-item>
        <el-form-item label="级别：" prop="level">
          <el-select v-model="dialogForm.level"
                     placeholder="请选择" style="width: 280px">
            <el-option
              v-for="dict in gasBottleLevel"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="规格：" prop="size">
          <el-select v-model="dialogForm.size"
                     placeholder="请选择" style="width: 280px">
            <el-option
              v-for="dict in gasBottleSpecification"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="气体成分：" prop="gasComposition">
          <el-input
            maxLength="20"
            v-model="dialogForm.gasComposition"
            placeholder="请输入名称"
            style="width: 280px"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <p class="dialog-footer-null-p"></p>
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
        <p class="dialog-footer-null-p"></p>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import vueQr from 'vue-qr'
  import { getLodop } from "@/utils/LodopFuncs";
  import { airbottleBottleTypeList,airbottleBottleTypeAdd,
    airbottleBottleTypeUpdate,airbottleBottleTypeFindById,
    airbottleBottleTypeDelete} from "@/api/gasBottleManage/index";
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  //import addPage from "./addPage.vue";
  export default {
    name: 'index',
    components: {
      vueQr
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['db:bottleType:edit','db:bottleType:query','db:bottleType:remove',]),
        //页面遮罩
        loading:false,
        //气瓶级别
        gasBottleLevel:[],
        gasBottleSpecification:[],
        //查询条件
        queryParams:{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //弹窗开关
        dialogType:false,
        dialogTitle:"",
        dialogForm:{},
        //校验
        rules:{
          gasName:[
            { required: true, message: '请输入名称', trigger: 'blur' },
            { required: true, message: "请输入名称", validator: this.spaceJudgment, trigger: "blur" }
          ],
          level:[
            { required: true, message: '请选择级别', trigger: 'blur' },
          ],
          size:[
            { required: true, message: '请选择规格', trigger: 'blur' },
          ],
          // gasComposition:[
          //   { required: true, message: '请输入气体成分', trigger: 'blur' },
          //   { required: true, message: "请输入气体成分", validator: this.spaceJudgment, trigger: "blur" }
          // ],
        },
      }
    },
    created () {

    },
    mounted () {
      this.getList();
      this.getDicts("gasBottleLevel").then((response) => {
        this.$set(this,'gasBottleLevel',response.data);
      });
      this.getDicts("gasBottleSpecification").then((response) => {
        this.$set(this,'gasBottleSpecification',response.data);
      });
    },
    methods: {
      //弹窗相关
      cancel(){
        this.$set(this,'dialogType',false);
      },
      submit(){
        this.$refs["dialogForm"].validate(valid => {
          if (valid) {
            if(this.dialogForm.id){
              //编辑
              airbottleBottleTypeUpdate(this.dialogForm).then(response => {
                this.$set(this,'dialogType',false);
                this.msgSuccess(response.msg)
                this.getList();
              });
            } else {
              //新增
              airbottleBottleTypeAdd(this.dialogForm).then(response => {
                this.$set(this,'dialogType',false);
                this.msgSuccess(response.msg)
                this.getList();
              });
            }
          }
        })
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'pageNum',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          pageNum:1,
          pageSize:20,
          searchValue:"",
          collegeId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        airbottleBottleTypeList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'dialogTitle','新增');
          this.$set(this,'dialogForm',{
            gasName:"",
            level:"",
            size:"",
            gasComposition:"",
          });
          this.$set(this,'dialogType',true);
        }else if(type == 2){
          //编辑
          this.$set(this,'dialogTitle','编辑');
          this.$set(this,'dialogForm',{
            id:row.id,
            gasName:row.gasName,
            level:row.level+'',
            size:row.size+'',
            gasComposition:row.gasComposition,
          });
          this.$set(this,'dialogType',true);
        }else if(type == 3){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            airbottleBottleTypeDelete({id:row.id}).then(response => {
              self.msgSuccess(response.msg)
              self.getList();
            });
          }).catch(() => {});
        }
      },
      forData(type,id){
        let self = this;
        let num = 0;
        if(type == 1){
          for(let i=0;i<self.gasBottleLevel.length;i++){
            if(id == self.gasBottleLevel[i].dictValue){
              num++
              return self.gasBottleLevel[i].dictLabel
            }
          }
        }else if (type){
          for(let i=0;i<self.gasBottleSpecification.length;i++){
            if(id == self.gasBottleSpecification[i].dictValue){
              num++
              return self.gasBottleSpecification[i].dictLabel
            }
          }
        }
        if(num == 0){
          return '其他'
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .cylinderSetting{
    display: flex;
    flex-direction: column;
    .cylinderSettingPage{

    }
  }
</style>
<style lang="scss">
  .cylinderSetting-dialog-box{
    .text-p{
      line-height:40px;
      font-size:16px;
      text-align: center;
    }
    .dialog-footer{
      display: flex;
      .dialog-footer-null-p{
        flex:1;
      }
    }
  }
</style>
