<template>
  <div class="content-main">
    <el-form :inline="true" :model="searchForm" class="search-bm-boder">
      <el-row>
        <el-form-item label="合同号:">
          <el-input
            clearable
            v-model="searchForm.hth"
            style="width: 170px"
            placeholder="请输入合同号"
          ></el-input>
        </el-form-item>
        <el-form-item label="粮食品种:">
          <el-select
            v-model="searchForm.pzbm"
            style="width: 170px"
            clearable
            placeholder="请选择品种"
          >
            <el-option
              v-for="item in variety"
              :key="item.dictCode"
              :label="item.dictName"
              :value="item.dictCode"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="收购等级:">
          <el-select
            v-model="searchForm.jylx"
            style="width: 170px"
            clearable
            placeholder="请选择收购等级"
          >
            <el-option
              v-for="item in tradeTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </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="doSearch"
              size="small"
              class="iconfont iconchaxun"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="searchForm = {}"
              size="small"
              class="iconfont iconzhongzhi"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="searchShowMoreBool">
        <el-form-item label="成交时间:">
          <!-- <el-select v-model="searchForm.apzt" style="width:170px" clearable placeholder="请选择状态">
            <el-option v-for="item in types" :key="item.name" :label="item.name" :value="item.name"></el-option>
          </el-select>-->
          <el-date-picker
            v-model="searchForm.cjsj"
            style="width: 250px"
            clearable
            placeholder-start="开始时间"
            placeholder-end="结束时间"
            range-separator="至"
            type="daterange"
          ></el-date-picker>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row>
      <el-table
        :data="tableData"
        stripe
        v-loading="listLoading"
        border
        fit
        id="out-table"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column
          align="center"
          label="序号"
          width="70"
          type="index"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="hth"
          width="170"
          label="合同号"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="mfcckmc"
          label="卖方承储库"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="chmc"
          label="仓号"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="scnf"
          label="生产年份"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="sgdjmc"
          label="收购等级"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="cjsl"
          label="总成交数量"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="lspzmc"
          label="粮食品种"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="cjje"
          label="成交金额"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="cjrq"
          label="成交日期"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="light"
              content="查看"
              placement="top"
            >
              <el-button
                type="primary"
                class="operate_show_btn iconfont iconchakan2"
                size="small"
                @click="
                  $router.push({
                    path: 'detail',
                    query: { cjbm: scope.row.cjbm, state: 2 },
                  })
                "
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageForm.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageForm.total"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import { list } from "@/api/transaction/tradePlan/auction.js";
import { varietys } from "@/api/dict/index.js";
import { dateTimeFormat } from "@/utils/index";
const status = {
  // 91000008:'已驳回',
  // 91000048:'已发布',
  // 91000049: '待安排',
  // 91000001: '待提交',
  91000004: "已提交",
};
export default {
  data() {
    return {
      searchShowMoreBool: false,
      variety: [], // 品种列表
      tradeTypes: [
        {
          label: "采购",
          value: "0",
        },
        {
          label: "销售",
          value: "1",
        },
      ],
      types: Object.keys(status).map((item) => ({
        code: item,
        name: status[item],
      })),
      listLoading: false,
      searchForm: {
        page: 1,
        zts: Object.keys(status),
      },
      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
    };
  },
  created() {
    this.getTypes();
    this.getList();
  },
  methods: {
    handlePublish(row) {
      this.$router.push({
        path: "publish",
        query: {
          state: 0,
          wtbm: row.wtbm,
        },
      });
    },
    handlePublished(row) {
      this.$router.push({
        path: "publish",
        query: {
          state: 1,
          wtbm: row.wtbm,
        },
      });
    },
    async handleDel(row) {
      await this.$confirm("此操作删除该委托, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      });
      var res = await del(row.wtbm);
      if (res && res.infoCode === 200) {
        this.$message.success(res.msg);
        this.getList();
        return;
      }
      this.$message.error(res.msg);
    },
    handleUpdate(row) {
      this.$router.push({
        path: "plan",
        query: {
          state: 1,
          wtbm: row.wtbm,
          jylx: row.jylx,
        },
      });
    },
    handlePlan(row) {
      this.$router.push({
        path: "plan",
        query: {
          state: 0,
          wtbm: row.wtbm,
          jylx: row.jylx,
        },
      });
    },
    handleDetail(row) {
      this.$router.push({
        path: "detail",
        query: {
          state: 2,
          wtbm: row.wtbm,
        },
      });
    },
    handlePlanDetail(row) {
      this.$router.push({
        path: "planDetail",
        query: {
          state: 2,
          wtbm: row.wtbm,
          jylx: row.jylx,
        },
      });
    },
    handleAdd() {
      this.$router.push({
        path: "add",
        query: {
          state: 0,
        },
      });
    },
    handleConfirm(row) {
      this.$router.push({
        path: "confirm",
        query: {
          state: 3,
          wtbm: row.wtbm,
        },
      });
    },
    getTypes() {
      varietys(11).then((res) => {
        this.variety = res.data;
      });
    },
    doSearch() {
      this.pageForm.pageNum = 1;
      var tbrq = this.searchForm.tbrq;
      this.getList();
    },
    async getList() {
      this.listLoading = true;
      let { pageNum, pageSize } = this.pageForm;
      for (var key in this.searchForm) {
        if (this.searchForm[key] === "") this.searchForm[key] = null;
        if (typeof this.searchForm[key] === "string")
          this.searchForm[key] = this.searchForm[key].trim();
      }
      let res = await list({
        ...this.searchForm,
        pageNum,
        pageSize,
      });
      this.listLoading = false;
      if (res && res.infoCode === 200) {
        this.pageForm.total = res.data.total;
        this.tableData = res.data.items;
        return;
      }
      this.pageForm.total = 0;
      this.tableData = [];
    },
    handleSizeChange(val) {
      this.pageForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageForm.pageNum = val;
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
.iconfont {
  font-size: 13px;
}
</style>
