<template>
  <basic-container>
    <div>
      <Card class="cardTitle">
        <p>
          <el-button type="primary" @click="backPage" style="width: 80px"
            >返回</el-button
          >
          <el-button
            v-if="examineShow"
            type="primary"
            @click="examineBtnPl"
            style="width: 100px;margin-left: 20px;"
            >批量审核</el-button
          >
        </p>
      </Card>

      <avue-crud
        style="width: 100%; margin-top: 15px"
        :data="tableData"
        :option="option"
        :page.sync="page"
        :table-loading="tableLoading"
        @selection-change="selectionChange"
        @on-load="getList"
        @size-change="sizeChange"
        @current-change="currentChange"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            type="text"
            size="small"
            icon="el-icon-document-checked"
            v-show="examineShow"
            :disabled="
              scope.row.taskStatus == '3' || scope.row.taskStatus == '4'
            "
            @click="examineBtn(scope.row, scope.index)"
            >审核
          </el-button>

          <el-button
            type="text"
            size="small"
            icon="el-icon-view"
            @click="lookBtn(scope.row, scope.index)"
            >查看
          </el-button>
        </template>
      </avue-crud>

      <el-dialog
        title="审核"
        :visible.sync="showDialog"
        top="12vh"
        width="50%"
        center
        :before-close="handleClose"
        class="review-dialog"
      >
        <el-form
          :model="taskForm"
          :rules="rules"
          ref="taskForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <p v-if="atypismData.length" class="teskDetailsty">不一致信息</p>
          <el-table
            v-if="atypismData.length"
            :data="atypismData"
            border
            style="width: 100%; margin-bottom:20px;"
          >
            <el-table-column
              prop="name"
              label="信息项"
              width="180"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="oldData"
              label="系统数据"
              width="180"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="newData" label="调研数据" align="center">
            </el-table-column>
          </el-table>
          <p v-show="singleFlag" class="teskDetailsty">任务详情</p>
          <!--         <p v-show="singleFlag" class="missionContsty">-->
          <!--           <iframe-->
          <!--             class="iframe"-->
          <!--             :src="taskDetail"-->
          <!--             width="100%"-->
          <!--             height="100%"-->
          <!--             scrolling="auto"-->
          <!--             frameborder="0"-->
          <!--           />-->
          <!--         </p>-->
          <div v-if="singleFlag && showDialog">
            <task-detail
              :id="examineVal"
              @getSurveyTaskInfoById="getSurveyTaskInfoById"
            />
          </div>

          <p class="teskDetailsty">审批意见</p>

          <el-form-item label="审批意见:" prop="taskStatus">
            <el-radio-group v-model="taskForm.taskStatus">
              <el-radio label="3">通过</el-radio>
              <el-radio label="4">拒绝</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="说明:" prop="taskStatusInfo">
            <el-input
              type="textarea"
              v-model="taskForm.taskStatusInfo"
            ></el-input>
          </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="sureBtn('taskForm')"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </basic-container>
</template>

<script>
import { taskAuditData } from "@/const/crud/assignPoints/commonUse/taskAudit";
import {
  getWmTaskList,
  approvalTask
} from "@/api/assignPoints/currency/taskAudit";
import Config from "@/settings";
import taskDetail from "@/components/taskDetail";
import taskApi from "@/api/taskDetail/task";

export default {
  name: "taskAudit",
  data() {
    return {
      singleFlag: false,
      tableData: [],
      option: taskAuditData,
      page: {
        pageSize: 10,
        pagerCount: 5
      },
      isHasAudit: false,
      packageIds: null,
      showDialog: false,
      taskForm: {},
      taskDetail: "",
      examineShow: false,
      rules: {
        taskStatus: [
          { required: true, message: "请选择活动资源", trigger: "change" }
        ]
      },
      tableLoading: false,
      searchForm: {},
      examineVal: "",
      jfbID: "",
      atypismData: []
    };
  },
  mounted() {
    if (this.$route.query.type == "taskAudit") {
      this.examineShow = true;
    } else {
      this.examineShow = false;
    }
  },
  methods: {
    // 复选框选中的值
    selectionChange(selection, row) {
      this.isHasAudit = false;
      this.packageIds = "";
      if (undefined != selection) {
        for (var i = 0; i < selection.length; i++) {
          if (selection[i].taskStatus > 0) {
            this.isHasAudit = true;
          }

          this.packageIds += selection[i].id;
          if (i < selection.length - 1) {
            this.packageIds += ",";
          }
        }
      }
    },
    // 初始化页面
    getList(page, params) {
      this.tableLoading = true;
      getWmTaskList(
        Object.assign(
          {
            taskStatus: this.$route.query.taskStatus == "2" ? "2" : "",
            scorePackageId: this.$route.query.id,
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm
        )
      )
        .then(response => {
          this.tableData = [];
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
          this.taskForm = {};
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    // 返回按钮
    backPage() {
      this.$router.$avueRouter.closeTag();
      this.$router.push({ path: "/admin/assignPoints/commonUse/index" });
    },

    // 审核按钮
    examineBtn(row) {
      this.examineVal = row.id;
      this.jfbID = row.scorePackageId;
      this.showDialog = true;
      this.singleFlag = true;
      this.taskDetail =
        Config.outsideUrl + "/h5/#/pages/task/task-detail/index?id=" + row.id;
    },

    //批量审核按钮
    examineBtnPl() {
      this.examineVal = this.packageIds;
      this.singleFlag = false;
      if (this.examineVal == null) {
        this.$message.error("请选择需要审核的任务");
        return false;
      } else if (this.examineVal == "") {
        this.$message.error("请选择需要审核的任务");
        return false;
      } else {
        this.showDialog = true;
      }
    },

    // 弹窗确定按钮
    sureBtn(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.taskForm.id = this.examineVal;
          this.taskForm.scorePackageId = this.jfbID;
          let args = {
            id: this.examineVal,
            taskStatus: this.taskForm.taskStatus,
            taskStatusInfo: this.taskForm.taskStatusInfo
          };
          approvalTask(args)
            .then(response => {
              this.showDialog = false;
              this.getList(this.page);
              this.tableLoading = false;
              this.$message.success(response.data.data);
            })
            .catch(() => {
              this.tableLoading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 查看
    lookBtn(row, index) {
      window.open(
        Config.outsideUrl + "/h5/#/pages/task/task-detail/index?id=" + row.id,
        "newwindow",
        "height=500, width=400, top=200, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
      );
    },

    // 隐藏弹窗
    cancelBtn() {
      this.showDialog = false;
    },

    handleClose() {
      this.showDialog = false;
      this.atypismData = [];
    },

    // 分页查询
    sizeChange() {},
    currentChange() {},
    // 获取不一致信息
    getSurveyTaskInfoById(id) {
      taskApi.getSurveyTaskInfoById(id).then(res => {
        this.atypismData = res.data.data.compareList;
      });
    }
  },
  components: {
    taskDetail
  }
};
</script>

<style lang="scss" scoped>
.review-dialog {
  ::v-deep .el-dialog__body {
    padding: 0 25px 0;
  }
}
</style>

<style>
.teskDetailsty {
  width: 100%;
  height: 30px;
  line-height: 30px;
  font-size: 16px;
  font-weight: 600;
  color: #333333;
  border-bottom: 1px solid #d7d6d5;
  margin: 0 0 10px 0;
}
.missionContsty {
  height: 300px;
  border: 1px solid #f2f2f2;
  margin-bottom: 15px;
}
</style>
