<template>
  <div class="content-main">
    <el-form :inline="true" :model="searchForm" class="demo-form-inline">
      <el-row class="search-bm-boder">
        <el-form-item label="细则标题:">
          <el-input
            v-model="searchForm.xzbt"
            placeholder="细则标题"
            clearable
            class="input-w-220"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态:">
          <!-- <el-input v-model="" placeholder="状态" clearable class="input-w-220"></el-input> -->
          <el-select
            clearable
            v-model="searchForm.fbzt"
            style="width: 170px"
            placeholder="状态"
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictCode"
              :label="item.dictName"
              :value="item.dictCode"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="编制时间:">
          <el-date-picker
            style="width: 250px"
            v-model="searchForm.bzsj"
            type="daterange"
            unlink-pannels
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            clearable
          ></el-date-picker>
          <!-- <el-input v-model="searchForm.bzsj" placeholder="编制时间" clearable class="input-w-220"></el-input> -->
        </el-form-item>
        <el-form-item>
          <div class="search-button">
            <span class="search-line"></span>
            <el-button
              type="primary"
              @click="searchInfo"
              size="small"
              class="iconfont iconchaxun"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="chongzhi"
              size="small"
              class="iconfont iconzhongzhi"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
    </el-form>

    <el-row class="addBtnBg">
      <el-button
        type="primary"
        @click="newlyIncreased"
        size="small"
        class="iconfont iconxinzeng"
        >新增</el-button
      >
    </el-row>

    <el-table :data="tableData" border stripe tooltip-effect="dark">
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="60"
      ></el-table-column>
      <el-table-column
        prop="xzbt"
        label="细则标题"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="bzr"
        label="编制人员"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="bzsj"
        label="编制时间"
        align="center"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        prop="fbztmc"
        label="状态"
        align="center"
        show-overflow-tooltip
        width="80"
      ></el-table-column>
      <el-table-column align="center" label="操作" width="180px">
        <template slot-scope="scope">
          <el-tooltip
            class="item"
            effect="light"
            content="查看"
            placement="top"
          >
            <el-button
              type="primary"
              size="small"
              @click="showInfo(scope.row)"
              class="operate_show_btn iconfont iconxiangqing iconchakan2"
            ></el-button>
          </el-tooltip>
          <!-- 修改上报 -->
          <!-- <el-tooltip
            class="item"
            effect="light"
            content="发布"
            placement="top"
            v-if="buttonNameList.indexOf('发布') > -1"
          >
            <el-button
              type="primary"
              size="small"
              v-if="scope.row.fbzt != '1'"
              class="operate_show_btn iconfont iconshangbao"
              @click="updateInfo(scope.row)"
            ></el-button>
          </el-tooltip>-->
          <!-- 修改保存 -->
          <el-tooltip
            class="item"
            effect="light"
            content="编辑"
            placement="top"
            v-if="buttonNameList.indexOf('编辑') > -1"
          >
            <el-button
              type="primary"
              size="small"
              v-if="scope.row.fbzt != '1'"
              class="operate_edit_btn iconfont iconxiugai"
              @click="updateInfoSave(scope.row)"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="删除"
            placement="top"
            v-if="buttonNameList.indexOf('删除') > -1"
          >
            <el-button
              type="primary"
              size="small"
              v-if="scope.row.fbzt != '1'"
              @click="deleteInfo(scope.row)"
              class="operate_delete_btn iconfont iconshanchu"
            ></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 {
  getScalePlanUpdate,
  deleteListItem,
  selectOwnList,
  getScalePlanDetails,
  selectParentList,
} from "@/api/transaction/trading/tradingRules/index";
import { statusList, playtime } from "./zoots4.js";
import { authorityControl } from "@/api/menuList";
import { getParameter } from "@/utils/index";
export default {
  // components: {
  //   scalePlan
  // },
  // name:"scalePlan",
  data() {
    return {
      statusList: statusList, //引用json状态
      ztOptions: [],
      tableData: [],
      listLoading: true,
      showType: false,
      searchForm: {
        xzbt: "",
        fbzt: "",
        bzsj: "",
        fbztmc: "",
      },
      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 1,
      },
      buttonNameList: [],
    };
  },
  mounted() {},
  destroyed() {},
  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.getInfo("start");
      });
    },
    chongzhi() {
      this.searchForm = {
        xzbt: "",
        fbzt: "",
        bzsj: "",
        fbztmc: "",
      };
      this.getInfo();
    },
    submitUpload() {
      let list = document.getElementsByClassName(
        "el-upload-list__item is-ready"
      );
      if (list.length == 0) {
        this.$message({
          type: "warning",
          message: "请选择需要导入的模板！",
        });
        return;
      }
      this.$refs.upload.submit();
    },
    uploadSectionFile(param) {
      var fileObj = param.file;
      // FormData 对象
      var form = new FormData();
      // 文件对象
      form.append("file", fileObj);
      form.append("userId", this.userId);
      form.append("userName", this.userName);
      this.GLOBAL.POST("/hqx/knowledge/importKnowledge", form).then((res) => {
        if (res.data.success == true) {
          this.$message({
            type: "success",
            message: res.data.msg,
          });
          this.fileList = [];
        } else {
          this.$message({
            type: "success",
            message: res.data.msg,
          });
          this.fileList = [];
        }
      });
    },
    getInfo(type) {
      let data = {
        fbzt: this.searchForm.fbzt,
        startDate: this.searchForm.bzsj[0],
        endDate: this.searchForm.bzsj[1],
        xzbt: this.searchForm.xzbt,
        pageNum: this.pageForm.pageNum,
        pageSize: this.pageForm.pageSize,
      };
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(data));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          let searchData = JSON.parse(sessionStorage.getItem("searchData"));
          this.searchForm = getParameter(searchData, ["fbzt", "xzbt"]);
          this.searchForm.bzsj =
            searchData.startDate && searchData.endDate
              ? [searchData.startDate, searchData.endDate]
              : "";
          this.pageForm = getParameter(searchData, ["pageNum", "pageSize"]);
        } else {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(data));
        }
      }
      selectParentList(JSON.parse(sessionStorage.getItem("searchData"))).then(
        (res) => {
          console.log(res, "列表页");
          if (res.infoCode == 200) {
            this.tableData = res.data.items;
            this.pageForm.total = Number(res.data.total);
          } else {
            this.$message({
              type: "error",
              message: "获取失败!",
            });
          }
        }
      );
    },
    searchInfo() {
      this.getInfo();
    },
    showInfo(row) {
      this.$router.push({
        name: "tradingRulesDetails",
        query: {
          xzbm: row.xzbm,
          type: "show",
        },
      });
    },
    //发布
    updateInfo(row) {
      this.$confirm("此操作将发布该条记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = {
            xzbm: row.xzbm,
          };
          getScalePlanDetails(data)
            .then((res) => {
              this.formQuery = res.data;
              if (res.infoCode == "200") {
                this.formQuery = res.data;
                this.wjids = res.data.fjid || "";
                // if (this.wjids) {
                //     this.getFileDetail();
                // }
              }
            })
            .then(() => {
              let datas = {
                ...this.formQuery,
                fbztmc: "已发布",
                fbzt: 1,
                remark: "ssss",
                bzsj: this.dtime,
              };
              getScalePlanUpdate(datas).then((res) => {
                this.getInfo();
                if (res.infoCode == "200") {
                  this.$message({
                    message: "发布成功",
                    type: "success",
                  });
                } else {
                  this.$message({
                    message: "发布失败",
                    type: "error",
                  });
                }
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消发布",
          });
        });
    },
    updateInfoSave(row) {
      this.$router.push({
        name: "tradingRulesDetails",
        query: {
          xzbm: row.xzbm,
          type: "updateSave",
        },
      });
    },
    deleteInfo(row) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = {
            xzbm: row.xzbm,
          };
          deleteListItem(data).then((res) => {
            if (res.infoCode == 200) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getInfo();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    handleSizeChange(val) {
      this.pageForm.pageSize = val;
      this.getInfo();
    },
    handleCurrentChange(val) {
      this.pageForm.pageNum = val;
      this.getInfo();
    },

    //新增
    newlyIncreased() {
      this.$router.push({
        name: "tradingRulesDetails",
        query: {
          type: "newSa",
        },
      });
    },
    //保存
    save() {
      // let data = {
      //   pzbm: this.formQuery.pzbm,
      //   nxqz: this.formQuery.nxqz,
      //   qualityArrStr: JSON.stringify(this.qualityRule),
      //   yearsArrStr: JSON.stringify(this.yearRule)
      // }
      // save(data).then(res=>{
      //   if (res.infoCode == "200") {
      //     this.$message({
      //       message: '保存成功',
      //       type: 'success'
      //     });
      //     this.dialogTableVisible = false;
      //     this.getList()
      //   }
      // })
    },
    submit() {
      //  let data = {
      //   pzbm: this.formQuery.pzbm,
      //   nxqz: this.formQuery.nxqz,
      //   fbzt: 1,
      //   qualityArrStr: JSON.stringify(this.qualityRule),
      //   yearsArrStr: JSON.stringify(this.yearRule)
      // }
      // submit(data).then(res=>{
      //   if (res.infoCode == "200") {
      //     this.$message({
      //       message: '发布成功',
      //       type: 'success'
      //     });
      //     this.dialogTableVisible = false;
      //     this.getList()
      //   }
      // })
    },
  },
};
</script>

<style lang="scss" scoped>
.pagination-wrap {
  text-align: right;
  margin-top: 10px;
}

.input-w-220 {
  width: 220px;
}

.iconfont {
  color: white;
}
</style>
