<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-11-15 15:26:39
-->
<template>
  <div class="page">
    <div class="main">
      <el-form
        ref="select"
        :model="select"
        style="padding: 10px 10px 10px 0; background-color: #fff"
        label-width="100px"
      >
        <el-row :gutter="10">
          <!-- 一层 -->

          <el-col :span="4">
            <el-form-item :label="'产品名称'">
              <el-input
                clearable
                v-model="select.productName"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'产品编号'">
              <el-input
                clearable
                v-model="select.productCode"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'追溯编号'">
              <el-input
                clearable
                v-model="select.barCode"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'追溯状态'">
              <el-select clearable v-model="select.codeStatus">
                <el-option
                  v-for="item in codeStatusList"
                  :key="item.val"
                  :label="item.text"
                  :value="item.val"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 二层 -->
          <el-col :span="8">
            <el-form-item :label="'打印日期'">
              <el-date-picker
                v-model="creationTime2"
                @change="changeTime2"
                value-format="yyyy-MM-dd"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'生成时间'">
              <el-date-picker
                v-model="creationTime1"
                @change="changeTime1"
                type="daterange"
                value-format="yyyy-MM-dd"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'追溯批次'">
              <el-input
                clearable
                v-model="select.batch"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="margin-left: 30px">
            <el-button class="my_search" @click="getDataList">
              {{ '搜索' }}</el-button
            >
            <el-button class="my_reset" @click="reset">
              {{ '重置' }}</el-button
            >
          </el-col>
        </el-row>
      </el-form>
      <!-- <div class="openClose"
           @click="changeActive">
        <i :class="isActive?'el-icon-arrow-up':'el-icon-arrow-down'"></i>
        <div>{{isActive?'':'点击展开'}}</div>
      </div> -->
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" @click="handleExport" class="exportBtn">
            {{ '导出' }}</el-button
          >
          <el-button size="small" @click="handleExportDetail" class="exportBtn"
            >导出明细</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          style="width: 100%"
          height="570px"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column
            align="center"
            prop="productCode"
            :label="'产品编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="productName"
            :label="'产品名称'"
          >
          </el-table-column>
          <el-table-column align="center" prop="barCode" :label="'追溯编号'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="codeStatus"
            :label="'追溯状态'"
          >
            <template slot-scope="scope">
              <div
                v-if="scope.row.codeStatus == item.val"
                v-for="item in codeStatusList"
                :key="item.val"
              >
                {{ item.text }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="batch"
            :label="'追溯批次'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="printTime"
            :label="'打印日期'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'生成时间'"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/configManage.js";
import { accountSave, accountUpdate } from "@/api/configManage";
import { getToken } from "@/utils/auth";
import { specialArea } from "@/api/configManage";

export default {
  name: "ProductList",
  components: {
    topBar,
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    },
  },
  data() {
    return {
      // 折叠搜索框
      isActive: false,
      select: { pkBarCode: "" },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      addOrEdit: "",
      total: 0,

      tableData: [],
      // 1=已生成 2=已打印 3=已绑定
      codeStatusList: [
        {
          text: '已生成',
          val: 1,
        },
        {
          text: '会员级',
          val: 2,
        },
        {
          text: '会员级',
          val: 3,
        },
      ],
      form: {},
      creationTime1: [],
      creationTime2: [],
      isCopy: false,
      selPkId: "",
      // 预售状态
      presaleList: [],
      //供应方式
      gyList: [],
      //商品分类
      hierarchyList: [],
      // 所属专区
      areaList: [],
    };
  },
  mounted() {
    this.select.pkBarCode = this.$route.query.id;
    this.select.pkBarCodeId = this.$route.query.id;
    // 获取列表
    this.getDataList();
  },
  methods: {
    reset() {
      this.select = {
        pkBarCode: this.$route.query.id,
        pkBarCodeId: this.$route.query.id,
      };
      this.creationTime1 = [];
      this.creationTime2 = [];
      this.getDataList();
    },
    changeTime1(val) {
      this.select.startDate = val[0];
      this.select.endDate = val[1];
    },
    changeTime2(val) {
      this.select.startDatePrint = val[0];
      this.select.endDatePrint = val[1];
    },

    // 展开折叠
    changeActive() {
      this.isActive = !this.isActive;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/bar-code-items/printTxm",
          Object.assign({}, this.queryParams, this.select),
          `${'条形码明细'}${new Date().getTime()}.pdf`
        );
        // api.printTxm(Object.assign({}, this.queryParams, this.select)).then(res=>{
        //   console.log('%c [ res ]-267', 'font-size:13px; background:#9fe869; color:#e3ffad;', res)

        // })
      });
    },
    handleExportDetail() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/bar-code-items/export",
          Object.assign({}, this.queryParams, this.select),
          `${'条形码明细'}${new Date().getTime()}.xlsx`
        );
        // api.printTxm(Object.assign({}, this.queryParams, this.select)).then(res=>{
        //   console.log('%c [ res ]-267', 'font-size:13px; background:#9fe869; color:#e3ffad;', res)

        // })
      });
    },
    // 删除
    handleDelete(id) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        api.waresDel(id).then((res) => {
          // 获取列表
          this.getDataList();
        });
      });
    },
    openDig() {
      this.$router.push({
        path: "/goodsManage/goodsRelease/jcsz",
      });
    },
    // 查看 0，编辑1,复制2
    toChecked(id, index) {
      this.$router.push({
        path: "/goodsManage/goodsList/goodsEdit/jcsz",
        query: {
          id: id,
          methods: index,
        },
      });
    },
    upEdit(id, index) {
      api
        .waresMove({
          waresId: id,
          waresMoveType: index,
        })
        .then((res) => {
          this.getDataList();
        });
    },
    topEdit(id) {
      api
        .waresTop({
          waresId: id,
        })
        .then((res) => {
          this.getDataList();
        });
    },
    // 获取列表
    getDataList() {
      api
        .bd_bar_codeItem(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
        });
    },
    toCopy() {
      this.toChecked(this.selPkId, 2);
    },
    handleSelectionChange(val) {
      this.selPkId = val[0].pkWares;
      if (val.length > 1) {
        this.isCopy = true;
      } else {
        this.isCopy = false;
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .maintop {
      display: flex;
      padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
          width: 68px;
          height: 32px;
        }
        .thebtn3 {
          background: #6962f6;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  margin-right: 10px;
  color: #666666;
  text-align: center;
}
.btnHeng {
  display: flex;
}
</style>
