<template>
  <div class="content-main">
    <el-form :inline="true" :model="searchForm" class="search-bm-boder">
      <el-row>
        <el-form-item label="委托编号:">
          <el-input
            v-model="searchForm.wtbh"
            clearable
            placeholder="请输入"
            style="width: 170px"
          ></el-input>
        </el-form-item>
        <el-form-item label="委托单位:">
          <el-input
            v-model="searchForm.wtfmc"
            clearable
            placeholder="请输入"
            style="width: 170px"
          ></el-input>
        </el-form-item>
        <el-form-item label="交易方向:">
          <el-select clearable v-model="searchForm.jyfx" style="width: 170px">
            <el-option
              v-for="item in jyfxOption"
              :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="searchInfo"
              size="small"
              class="iconfont iconchaxun"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="doReset"
              size="small"
              class="iconfont iconzhongzhi"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="searchShowMoreBool">
        <el-form-item>
          <label slot="label">交易方式:</label>
          <el-select v-model="searchForm.jyfs" style="width: 170px" clearable>
            <el-option
              v-for="item in jyfsOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <label slot="label">状&emsp;&emsp;态:</label>
          <el-select v-model="searchForm.fbzt" style="width: 170px" clearable>
            <el-option
              v-for="item in ztOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-row>
    </el-form>

    <el-table :data="tableData" border stripe tooltip-effect="dark">
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="50"
      ></el-table-column>
      <el-table-column
        prop="apcc"
        label="场次"
        align="center"
        show-overflow-tooltip
        width="120"
      ></el-table-column>
      <el-table-column
        prop="wtbh"
        label="委托编号"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="wtfmc"
        label="委托单位"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="jyfxmc"
        label="交易方向"
        align="center"
        show-overflow-tooltip
        width="80"
      ></el-table-column>
      <el-table-column
        prop="jyfsmc"
        label="交易方式"
        align="center"
        show-overflow-tooltip
        width="80"
      ></el-table-column>
      <el-table-column
        prop="pz"
        label="品种"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="jyrq"
        label="交易日期"
        align="center"
        show-overflow-tooltip
        width="100"
      ></el-table-column>
      <el-table-column
        prop="fbztmc"
        label="状态"
        align="center"
        show-overflow-tooltip
        width="100"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.fbzt == 0">未发布</span>
          <span v-if="scope.row.fbzt == 1">已发布</span>
          <span v-if="scope.row.fbzt == 2">发布后撤回</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="80px">
        <template slot-scope="scope">
          <el-tooltip
            class="item"
            effect="light"
            content="查看"
            placement="top"
            v-if="scope.row.fbzt !== 0"
          >
            <el-button
              type="primary"
              size="small"
              @click="showInfo(scope.row)"
              class="operate_show_btn iconfont iconchakan2"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="发布"
            placement="top"
            v-if="scope.row.fbzt !== 1"
          >
            <el-button
              type="primary"
              size="small"
              @click="updateInfo(scope.row)"
              class="operate_show_btn iconfont iconfabu"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="撤回发布"
            placement="top"
            v-else
          >
            <el-button
              type="primary"
              size="small"
              @click="undoInfo(scope.row)"
              class="operate_show_btn iconfont iconchehui"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <el-row class="pagination-wrap">
      <el-pagination
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        :current-page="pageForm.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageForm.total"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import { selectList, updateNotice } from "@/api/transaction/announcement/index";
import { authorityControl } from "@/api/menuList";
export default {
  data() {
    return {
      searchForm: {},
      jyfxOption: [
        {
          value: "0",
          label: "采购",
        },
        {
          value: "1",
          label: "销售",
        },
      ],
      jyfsOption: [
        {
          value: "0",
          label: "竞价",
        },
        {
          value: "1",
          label: "挂牌",
        },
        {
          value: "2",
          label: "购销双向",
        },
      ],
      ztOption: [
        {
          value: "0",
          label: "未发布",
        },
        {
          value: "1",
          label: "已发布",
        },
        {
          value: "2",
          label: "发布后撤回",
        },
      ],
      variety: [],
      excalFalse: false,
      tableMrtabl: [],
      searchShowMoreBool: false,
      statusList: [
        { dictCode: null, dictName: "不限" },
        {
          dictCode: "0",
          dictName: "采购",
        },
        {
          dictCode: "1",
          dictName: "销售",
        },
      ], //引用json状态
      ztOptions: [],
      tableData: [],
      listLoading: true,
      showType: false,

      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 1,
      },
      buttonNameList: [],
    };
  },
  created() {
    this.getresourceCode();
  },
  methods: {
    getresourceCode() {
      let codeData = {
        resourceCode: sessionStorage.getItem("resourceCode"),
        userId: sessionStorage.getItem("userCode"),
      };
      authorityControl(codeData).then((res) => {
        this.buttonNameList = [];
        res.data.forEach((item) => {
          this.buttonNameList.push(item.resourceName);
        });
        this.getList("start");
      });
    },
    getList(type) {
      // 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();
      }
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
        sessionStorage.setItem("pageForm", JSON.stringify(this.pageForm));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          this.searchForm = JSON.parse(sessionStorage.getItem("searchData"));
          this.pageForm = JSON.parse(sessionStorage.getItem("pageForm"));
        } else {
          //第一次进去此菜单时，保存上方默认的data
		  console.log('7777777777')
          sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
          sessionStorage.setItem("pageForm", JSON.stringify(this.pageForm));
        }
      }
      let data = {
        ...JSON.parse(sessionStorage.getItem("searchData")),
        ...JSON.parse(sessionStorage.getItem("pageForm")),
      };
      selectList(data)
        .then((res) => {
          if (res && res.infoCode === 200) {
            var d = res.data;
            var list = d.items;
            this.tableData = list;
            this.pageForm.total = d.total;
            this.pageForm.page = d.currentPage;
          } else {
            this.tableData = [];
            this.pageForm.total = 0;
          }
        })
        .catch((err) => {
          this.pageForm.total = 0;
          this.tableData = [];
        });
    },

    //点击搜索时
    searchInfo() {
      this.pageForm.pageNum = 1;
      this.getList();
    },
    //点击查看 跳到detail页面
    showInfo(row) {
      this.$router.push({
        path: "/transaction/announcement/detail",
        query: {
          wtbm: row.wtbm,
          type: "show",
        },
      });
    },

    //去detail页面 进行数据添加
    updateInfo(row) {
      this.$router.push({
        path: "/transaction/announcement/detail",
        query: {
          wtbm: row.wtbm,
          fbztmc: row.fbztmc,
          apcc: row.apcc,
          pz: row.pz,
          type: "update",
        },
      });
    },
    //点击撤销按钮
    undoInfo(row) {
      this.$confirm("此操作将撤销该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = {
            wtbm: row.wtbm,
            fbzt: 2,
            fbztmc: "发布后撤回",
          };
          updateNotice(data).then((res) => {
            if (res && res.infoCode === 200) {
              this.$message({
                type: "success",
                // message: res.data.msg1 + res.data.msg2,
                message: "撤销成功",
              });
              this.getList();
            } else {
              this.$message({
                type: "error",
                message: "撤销失败!",
              });
            }
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //分页
    handleSizeChange(val) {
      this.pageForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageForm.pageNum = val;
      this.getList();
    },
    doReset() {
      this.searchForm = {};
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
