<!--货品信息-->
<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="货物类型"  label-width="80px">
          <el-select v-model="queryParams.typeId" filterable  placeholder="请选择">
            <el-option
              v-for="item in materialTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue">
            </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-hasPermiRouter="['airbottle:googs: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="goodsName"/>
        <el-table-column label="货物类型" align="left" prop="typeId">
          <template slot-scope="scope">
            <span v-if="scope.row.typeId==1">气瓶</span>
          </template>
        </el-table-column>
        <el-table-column label="Sku数" align="left" prop="skuCount"></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="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="handleClick('',scope.row,'edit')"
                 v-hasPermiRouter="['airbottle:googs:edit']"
              >编辑</p>
              <p class="table-button-p"
                 @click="handleClick('',scope.row,'delete')"
                 v-hasPermiRouter="['airbottle:googs:del']"
              >删除</p>
              <p class="table-button-null"></p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        layout="total, prev, pager, next, sizes, jumper"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!--新增页面-->
    <add-page v-if="pageType==2" :pageData="pageData"></add-page>
  </div>
</template>

<script>
import {
  airbottleGoogsDelete,
  airbottleGoogsList,
  gasCategoryList
} from '@/api/gasManage3_0/index'
import { getToken } from "@/utils/auth";
import addPage from "./goodsInfoAdd.vue"

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


  },
  methods: {
      handleClick(index,row,doType){
        let _this=this;
        if(doType=='add'){//添加
          _this.pageData.status=0;
          _this.pageType=2;
        }else if(doType=='edit'){//编辑
          _this.pageData.status=1
          _this.pageData.id=row.id
          _this.pageType=2;
        }else if(doType=='delete'){//删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            airbottleGoogsDelete(row.id).then( response => {
              let res=response.rows;
              _this.getList();
              _this.msgSuccess("删除成功");
            });
          }).then(() => {

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

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