<!--规格管理-->
<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="zgType" label-width="80px">
          <el-select v-model="queryParams.category" placeholder="请选择">
            <el-option :label="item.dictLabel" :value="item.dictLabel" v-for="(item,index) in materialTypeList" :key="index"></el-option>
          </el-select>
        </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 label="" prop="title" style="float: right">
          <el-col :span="1.5" style="margin-left: 10px;">
            <p class="add-button-one-90"
               @click="handleClick('','','add')"
               v-hasPermi="['airbottle:specification:add']"
            ><i class="el-icon-plus"></i>新增</p>
          </el-col>
        </el-form-item>
      </el-form>
      <el-table border v-loading="loading" :data="tableData">
        <el-table-column label="规格名称" align="left" prop="specName"/>
        <el-table-column label="所属类目" align="left" prop="category"></el-table-column>
        <el-table-column label="规格数量" align="left" prop="detailSum"></el-table-column>
        <el-table-column label="添加人" align="left" prop="createBy"></el-table-column>
        <el-table-column label="添加时间" align="left" prop="createTime"></el-table-column>
        <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="260">
          <template slot-scope="scope">
            <div class="button-box">
              <p class="table-min-button"
                 style="margin-right: 10px"
                 @click="handleClick('',scope.row,'edit')"
                 v-hasPermiAnd="['airbottle:specification:edit']"
              ><i class="el-icon-edit"></i>编辑</p>
              <p class="table-min-button"
                 @click="handleClick('',scope.row,'delete')"
                 v-hasPermi="['airbottle:specification:remove']"
              >删除</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :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" :pageData2="pageData2"></add-page>
  </div>
</template>

<script>
import { gasApplyList, gasCategoryList, specificationDelete, specificationList } from '@/api/gasManage3_0/gasManage'
import { getToken } from "@/utils/auth";
import addPage from "./specificationManageAdd.vue"

export default {
  name: "Approval",
  components: {
    addPage
  },
  data() {
    return {
      //页面状态
      pageType:1,
      loading:false,
      headers: {
        Authorization: "Bearer " + getToken()
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize:20,
        searchValue:'',
        category:'',
      },
      total:0,
      tableData:[{}],
      dateRange:[],
      pageData2:{},
      materialTypeList:[],
    };


  },
  methods: {
      handleClick(index,row,doType){
        let _this=this;
        if(doType=='add'){//添加
          _this.pageData2.status=0
          _this.pageType=2;
        }else if(doType=='edit'){//编辑
          _this.pageData2.status=1
          _this.pageData2.id=row.id
          _this.pageType=2;
        }else if(doType=='delete'){//删除

          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            specificationDelete(row.id).then( response => {
              let res=response.rows;
              _this.getList();
              _this.msgSuccess("删除成功");
            });
          }).then(() => {

          }).catch(() => {});

        }else if(doType=='back'){//重新申请
          _this.pageType=1;
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.searchValue = "";
      this.queryParams.category = "";
      this.dateRange=[];
      this.queryParams.startTime=null;
      this.queryParams.endTime=null
      this.handleQuery();
    },
    //气瓶类目
    gasCategoryList(){
      let _this=this;
      gasCategoryList().then( response => {
        let res=response.rows;
        _this.materialTypeList=res;
      });
    },
    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
      }
      specificationList(_this.queryParams).then( response => {
        let res=response.rows;
        _this.tableData=res;
        _this.total=response.total
      });
    },
  },
  mounted() {
    this.gasCategoryList()
    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>
