<template>
  <div class="content-main fumigationRecordPage">
    <el-form
      ref="formInline"
      :model="formInline"
      class="search-bm-boder"
      inline
    >
      <el-row>
        <el-form-item label="药剂种类:" label-width="80px">
          <el-select
            v-model="formInline.drugKind"
            clearable
            placeholder="请选择"
            style="width: 180px"
          >
            <el-option
              v-for="item in yjOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="销毁类型:" label-width="80px">
          <el-select
            v-model="formInline.destroyType"
            clearable
            placeholder="请选择"
            style="width: 180px"
          >
            <el-option
              v-for="item in xhOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="库点名称:" label-width="80px">
          <el-input
            v-model="formInline.kdName"
            clearable
            style="width: 180px"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <div class="search-button">
            <span class="search-line"></span>
            <div
              class="search-select"
              @click="searchShowMoreBool = !searchShowMoreBool"
            >
              更多条件
              <i class="el-icon-arrow-up" v-show="searchShowMoreBool"></i>
              <i class="el-icon-arrow-down" v-show="!searchShowMoreBool"></i>
            </div>
            <el-button
              type="primary"
              @click="queryFun"
              size="small"
              class="iconfont iconchaxun"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="resetFun"
              size="small"
              class="iconfont iconzhongzhi"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="searchShowMoreBool">
        <el-form-item label="药剂名称:" label-width="80px">
          <el-input
            v-model="formInline.drugName"
            clearable
            style="width: 180px"
          ></el-input>
        </el-form-item>
        <el-form-item label="销毁日期:" label-width="80px">
          <el-date-picker
            v-model="formInline.time"
            class="dateInputCompatible"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table
          :data="tableList"
          v-loading="loading"
          border
          stripe
          highlight-current-row
        >
          <el-table-column align="center" label="序号" width="60">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="kdname"
            label="库点名称"
            align="center"
            min-width="260px"
          ></el-table-column>
          <el-table-column
            prop="destroyDate"
            label="销毁日期"
            align="center"
            width="95"
          ></el-table-column>
          <el-table-column
            prop="drugKind"
            label="药剂种类"
            align="center"
          ></el-table-column>
          <el-table-column prop="drugName" label="药剂名称" align="center">
          </el-table-column>
          <el-table-column
            prop="drugUnit"
            label="药剂单位"
            align="center"
          ></el-table-column>
          <!-- <el-table-column prop="drugPacking" label="药剂包装" align="center" min-width="80">
                    </el-table-column>
                    <el-table-column prop="drugSpecification" label="规格型号" align="center" width="80">
                    </el-table-column> -->
          <el-table-column prop="drugType" label="药剂形态" align="center">
          </el-table-column>
          <el-table-column prop="destroyType" label="销毁类型" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.destroyType == '1'">药剂销毁</span>
              <span v-if="scope.row.destroyType == '2'">空瓶/袋销毁</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="destroyAmount"
            label="销毁数量(袋或瓶)"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="destroyTotalNumber"
            label="销毁总量(L或kg)"
            align="center"
          ></el-table-column>

          <el-table-column
            prop="destroyReason"
            label="销毁原因"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="destroyPerson"
            label="销毁人"
            align="center"
          ></el-table-column>
          <!-- <el-table-column prop="dataStatus" label="状态" align="center">
                        <template slot-scope="scope">
                            <span v-if="scope.row.dataStatus == 0">待提交</span>
                            <span v-if="scope.row.dataStatus == 1">企业待审核</span>
                            <span v-if="scope.row.dataStatus == 2">企业待盖章</span>
                            <span v-if="scope.row.dataStatus == 3">购销公司待审核</span>
                            <span v-if="scope.row.dataStatus == 4">购销公司待盖章</span>
                            <span v-if="scope.row.dataStatus == 5">区粮办待审核</span>
                            <span v-if="scope.row.dataStatus == 6">区粮办待盖章</span>
                            <span v-if="scope.row.dataStatus == 7">已备案</span>
                            <span v-if="scope.row.dataStatus == 9">资料上传</span>
                        </template>
                    </el-table-column> -->
          <el-table-column label="操作" align="center" width="50">
            <template slot-scope="scope">
              <el-tooltip
                class="item"
                effect="light"
                content="查看"
                placement="top"
              >
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont operate_show_btn iconchakan2"
                  @click.stop="lookFun(scope.row)"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div class="pag-right clearFix">
          <el-pagination
            class="right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageInfo.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageInfo.total"
          ></el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { destroyList } from "@/api/grainReserves/zygl/index";
import * as validate from "@/directives/validate";
import { getParameter } from "@/utils/index";
import { authorityControl } from "@/api/menuList";

export default {
  data() {
    return {
      searchShowMoreBool: false,
      zts: [5, 6, 7],
      formInline: {
        drugKind: null,
        drugName: null,
        kdName: null,
        time: [],
        destroyType: null,
      },
      breedNameList: [
        {
          value: "0",
          label: "玉米",
        },
        {
          value: "1",
          label: "小麦",
        },
        {
          value: "2",
          label: "大豆",
        },
        {
          value: "3",
          label: "稻谷",
        },
        {
          value: "4",
          label: "其他",
        },
      ],
      fumigationTypeList: [
        {
          value: "0",
          label: "常规熏蒸",
        },
        {
          value: "1",
          label: "整仓环流熏蒸",
        },
        {
          value: "2",
          label: "膜下环流熏蒸",
        },
        {
          value: "3",
          label: "其他熏蒸方式",
        },
      ],
      curId: "", //该条数据的id
      typeZgData: [],
      paginationShow: true,
      tableList: [],
      loading: false,
      pageInfo: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      buttonNameList: [],
      dataStatusList: [
        // {
        //     value: 0,
        //     label: '待提交',
        // },
        // {
        //     value: 1,
        //     label: '企业待审核',
        // },
        // {
        //     value: 2,
        //     label: '企业待盖章',
        // },
        // {
        //     value: 3,
        //     label: '购销公司待审核',
        // },
        // {
        //     value: 4,
        //     label: '购销公司待盖章',
        // },
        {
          value: 5,
          label: "区粮办待审核",
        },
        {
          value: 6,
          label: "区粮办待盖章",
        },
        {
          value: 7,
          label: "已备案",
        },
        // {
        //     value: 11,
        //     label: '已退回',
        // },
      ],
      xhOption: [
        {
          value: "1",
          label: "药剂销毁",
        },
        {
          value: "2",
          label: "空瓶/袋销毁",
        },
      ],
      yjOption: [
        {
          value: "3023",
          label: "防护剂",
        },
        {
          value: "3024",
          label: "熏蒸剂",
        },
        {
          value: "3025",
          label: "空仓、器材杀虫器",
        },
      ],
      xzfsOption: [],
    };
  },
  watch: {},
  created() {
    this.getButtonList();
  },
  methods: {
    //获取按钮
    getButtonList() {
      let codeData = {
        resourceCode: sessionStorage.getItem("resourceCode"),
        userId: sessionStorage.getItem("userCode"),
      };
      authorityControl(codeData).then((res) => {
        res.data.forEach((item) => {
          this.buttonNameList.push(item.resourceName);
        });
        this.getList("start");
      });
    },
    //获取列表
    getList(type) {
      let data = {
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
        drugKind: this.formInline.drugKind,
        drugName: this.formInline.drugName,
        kdName: this.formInline.kdName,
        endTime:
          this.formInline.time && this.formInline.time.length
            ? this.formInline.time[1]
            : "",
        startTime:
          this.formInline.time && this.formInline.time.length
            ? this.formInline.time[0]
            : "",
        time: this.formInline.time,
        destroyType: this.formInline.destroyType,
      };
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(data));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (
          JSON.parse(sessionStorage.getItem("searchData")) &&
          sessionStorage.getItem("searchData") != "{}"
        ) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          let searchData = JSON.parse(sessionStorage.getItem("searchData"));
          this.formInline = getParameter(searchData, [
            "drugKind",
            "drugName",
            "kdName",
            "time",
            "destroyType",
          ]);
          this.pageInfo = getParameter(searchData, ["pageNum", "pageSize"]);
        } else {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(data));
        }
      }

      console.log("this.formInline", this.formInline);
      console.log(
        "JSON.parse(sessionStorage.getItem('searchData'))",
        JSON.parse(sessionStorage.getItem("searchData"))
      );
      destroyList(JSON.parse(sessionStorage.getItem("searchData")))
        .then((res) => {
          // console.log("res",res)
          if (res.infoCode && res.infoCode == 200) {
            this.tableList = res.data.items;
            this.$set(this.pageInfo, "total", res.data.total);
          }
        })
        .catch((error) => {});
    },
    //查询
    queryFun() {
      //查询
      this.handleCurrentChange(1);
    },
    //重置
    resetFun() {
      //重置
      this.formInline = {
        drugKind: null,
        drugName: null,
        kdName: null,
        time: [],
        destroyType: null,
      };
      this.pageInfo = {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      };
      this.queryFun();
    },
    //查看
    lookFun(row) {
      this.$router.push({
        path: "destroyDetail",
        query: {
          id: row.id,
          // type: 'look'
        },
      });
    },
    handleSizeChange(val) {
      //条数改变
      this.pageInfo.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      //页数改变
      this.pageInfo.pageNum = val;
      this.getList();
    },
  },
};
</script>
<style lang="scss">
.fumigationRecordPage {
  .el-select {
    width: 100%;
  }
  .itemStyle .el-form-item__label {
    line-height: 20px;
  }
  .el-dialog__body {
    padding-bottom: 0px;
  }
  .curStyle .el-form-item__label {
    line-height: 20px;
  }
}
</style>
