<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    :destroy-on-close="true"
    size="50%"
  >
    <div class="content_box">
      <div class="text_line">
        <div class="text_box">
          <span>窗口负责人：</span>
          <span>{{ form.ownerName }}</span>
        </div>
        <div class="text_box">
          <span style="width: 120px;">登记年月：</span>
          <span>{{
            `${form.year ? form.year : "--"}-${
              form.month
                ? [1, 2, 3, 4, 5, 6, 7, 8, 9].includes(form.month)
                  ? "0" + form.month
                  : form.month
                : "--"
            }`
          }}</span>
        </div>
        <div class="text_box">
          <span style="width: 140px;">窗口编号：</span>
          <span>{{ form.windowCode ? form.windowCode : "--" }}</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span style="width: 120px;">工作总结：</span>
          <span style="display: inline-block;">{{
            form.workSummary ? form.workSummary : "--"
          }}</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span style="width: 120px;">加分申报：</span>
          <span v-if="form.bonusarrText">
            <span
              style="width: auto;"
              v-for="val in form.bonusarrText"
              :key="val.id"
              >{{ val.content }}（{{
                dict.subAddType[val.subAddType] + val.score
              }}分）</span
            >
          </span>
          <span v-else>--</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span v-if="form.proofUrl" style="width: 110px;">加分佐证材料：</span>
          <span v-else style="width: 195px;">加分佐证材料：</span>
          <el-link
            v-if="form.proofUrl"
            :href="baseUrl + form.proofUrl"
            target="_blank"
            type="primary"
          >
            {{ form.proof || "--" }}</el-link
          >
          <span v-else> {{ form.proof || "--" }}</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span style="width: 140px;">扣分情况：</span>
          <span v-if="form.deductarrText">
            <span
              style="width: auto;"
              v-for="val in form.deductarrText"
              :key="val.id"
              >{{ val.content }}（{{
                dict.subAddType[val.subAddType] + val.score
              }}分）</span
            >
          </span>
          <span v-else>--</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span>扣分分值：</span>
          <span>{{ form.deductScore ? form.deductScore : "--" }}</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span style="width: 80px;">自评得分：</span>
          <span style="width: 700px;"
            ><el-table :data="tableData" border style="width: 100%">
              <el-table-column
                prop="discipline"
                label="工作纪律"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="specification"
                label="服务规范"
                align="center"
              >
              </el-table-column>
              <el-table-column prop="bonusScore" label="加分" align="center">
              </el-table-column>
              <el-table-column prop="sumScore" label="合计得分" align="center">
              </el-table-column>
              <el-table-column prop="selfLevel" label="自评等级" align="center">
              </el-table-column>
            </el-table>
          </span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span style="width: 90px;">备注：</span>
          <span>{{ form.remark ? form.remark : "--" }}</span>
        </div>
      </div>
      <div class="text_line">
        <div class="text_box">
          <span v-if="form.annexUrl" style="width: 70px;">附件材料：</span>
          <span v-else style="width: 180px;">附件材料：</span>
          <el-link
            v-if="form.annexUrl"
            :href="baseUrl + form.annexUrl"
            target="_blank"
            type="primary"
          >
            {{ form.annex || "--" }}</el-link
          >
          <span v-else> {{ form.annex || "--" }}</span>
        </div>
      </div>
      <div class="hecha_box">
        <div class="hecha_title">
          <span class="line"></span>
          <span>核查情况</span>
        </div>
        <div class="hecha_content">
          <el-form ref="form" :model="form" :rules="rules" label-width="180px">
            <el-row>
              <el-form-item label="政务服务管理科评荐意见：" prop="checkResult">
                <div
                  v-if="form.view == '查看'"
                  style="display: flex; justify-content: space-between;"
                >
                  <span class="left">
                    {{ dict.manageCheckResult[form.manageCheckResult] }}
                  </span>
                  <span class="right">
                    {{ form.manageCheckPerson }}
                    {{ functionTime(form.manageCheckTime) }} 核查
                  </span>
                </div>
                <el-radio-group v-model="form.manageCheckResult" v-else>
                  <el-radio
                    v-for="(val, i) in dict.manageCheckResult"
                    :key="i"
                    :label="i"
                    >{{ val }}</el-radio
                  >
                </el-radio-group>
              </el-form-item>
              <el-form-item label="管理组核查说明：" prop="manageCheckDesc">
                <el-input
                  v-model="form.manageCheckDesc"
                  type="textarea"
                  placeholder="请填写说明"
                  :disabled="form.view == '查看'"
                ></el-input>
              </el-form-item>
              <el-form-item label="领导小组审定意见：" prop="leaderCheckResult">
                <div
                  v-if="form.view == '查看'"
                  style="display: flex; justify-content: space-between;"
                >
                  <span class="left">
                    {{ dict.leaderCheckResult[form.leaderCheckResult] }}
                  </span>
                  <span class="right">
                    {{ form.leaderCheckPerson }}
                    {{ functionTime(form.leaderCheckTime) }} 核查
                  </span>
                </div>
                <el-radio-group v-model="form.leaderCheckResult" v-else>
                  <el-radio
                    v-for="(val, i) in dict.leaderCheckResult"
                    :key="i"
                    :label="i"
                    >{{ val }}</el-radio
                  >
                </el-radio-group>
              </el-form-item>
              <el-form-item label="领导小组核查说明：" prop="leaderCheckDesc">
                <el-input
                  v-model="form.leaderCheckDesc"
                  type="textarea"
                  placeholder="请填写说明"
                  :disabled="form.view == '查看'"
                ></el-input>
              </el-form-item>
            </el-row>
            <form-buttons
              @submit="submitForm"
              v-if="pageInfo.type != 'view'"
              noCancelBtn
            />
          </el-form>
        </div>
      </div>
    </div>
    <!-- <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          label="记录ID"
          prop="recordId"
          v-model="form.recordId"
          placeholder="请输入记录ID"
        />
        <Field
          label="考核年度"
          prop="year"
          v-model="form.year"
          placeholder="请输入考核年度"
        />
        <Field
          label="考核月份"
          prop="month"
          v-model="form.month"
          placeholder="请输入考核月份"
        />
        <Field
          label="窗口ID"
          prop="windowId"
          v-model="form.windowId"
          placeholder="请输入窗口ID"
        />
        <Field
          label="窗口名称"
          prop="windowName"
          v-model="form.windowName"
          placeholder="请输入窗口名称"
        />
        <Field
          label="窗口负责人id"
          prop="ownerId"
          v-model="form.ownerId"
          placeholder="请输入窗口负责人id"
        />
        <Field
          label="窗口负责人名称"
          prop="ownerName"
          v-model="form.ownerName"
          placeholder="请输入窗口负责人名称"
        />
        <Field
          label="所属部门id"
          prop="deptId"
          v-model="form.deptId"
          placeholder="请输入所属部门id"
        />
        <Field
          label="所属部门名称"
          prop="deptName"
          v-model="form.deptName"
          type="textarea"
          placeholder="请输入所属部门名称"
        />
        <Field
          label="所属大厅"
          prop="salaId"
          v-model="form.salaId"
          placeholder="请输入所属大厅"
        />
        <Field
          label="所属大厅名称"
          prop="salaName"
          v-model="form.salaName"
          placeholder="请输入所属大厅名称"
        />
        <Field
          label="考核表单名称"
          prop="fromName"
          v-model="form.fromName"
          placeholder="请输入考核表单名称"
        />
        <Field
          label="合计得分"
          prop="sumScore"
          v-model="form.sumScore"
          placeholder="请输入合计得分"
        />
        <Field
          label="提交时间"
          prop="submitDate"
          v-model="form.submitDate"
          type="date"
        />
        <Field
          label="管理组核查人员"
          prop="manageCheckPerson"
          v-model="form.manageCheckPerson"
          placeholder="请输入管理组核查人员"
        />
        <Field
          label="管理组核查时间"
          prop="manageCheckTime"
          v-model="form.manageCheckTime"
          type="date"
        />
        <Field
          label="管理组核查说明"
          prop="manageCheckDesc"
          v-model="form.manageCheckDesc"
          type="textarea"
          placeholder="请输入管理组核查说明"
        />
        <Field
          label="管理组核查结果"
          prop="manageCheckResult"
          v-model="form.manageCheckResult"
          type="radio"
          :enumData="dict.manageCheckResult"
        />
        <Field
          label="领导组核查人员"
          prop="leaderCheckPerson"
          v-model="form.leaderCheckPerson"
          placeholder="请输入领导组核查人员"
        />
        <Field
          label="领导组核查时间"
          prop="leaderCheckTime"
          v-model="form.leaderCheckTime"
          type="date"
        />
        <Field
          label="领导组核查说明"
          prop="leaderCheckDesc"
          v-model="form.leaderCheckDesc"
          type="textarea"
          placeholder="请输入领导组核查说明"
        />
        <Field
          label="领导组核查结果"
          prop="leaderCheckResult"
          v-model="form.leaderCheckResult"
          type="radio"
          :enumData="dict.leaderCheckResult"
        />
        <Field
          label="处理状态"
          prop="checkStatus"
          v-model="form.checkStatus"
          type="select"
          :enumData="dict.checkStatus"
          placeholder="请选择处理状态"
        />
        <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
      </el-row>

      <form-buttons
        @submit="submitForm"
        v-if="pageInfo.type != 'view'"
        noCancelBtn
      />
    </el-form> -->
  </el-drawer>
</template>

<script>
import form from "@/assets/mixins/formdialog";
import { timestampToTime } from "@/assets/utils/dateFormat.js";

export default {
  name: "CheckWindowPerformDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("check/window/perform");
  },
  data() {
    return {
      baseUrl: process.env.VUE_APP_API_BASE_URL + "/",
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "市政务服务大厅窗口考核登记表",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: ["checkStatus"],
      toDate: ["submitDate", "manageCheckTime", "leaderCheckTime"],
      // 表单校验
      rules: {},
      tableData: [],
    };
  },

  methods: {
    functionTime(val) {
      let time = timestampToTime(val, 6);
      return time;
    },
    /** 编辑 */
    async edit(row) {
      //   this.reset();
      //   this.query = { id: row.id };
      this.urls.saveUrl = "check/window/perform/examine";
      //   this.getData();
      //   this.pageInfo.type = "edit";
      //   this.title = "修改窗口考核核查";
      this.form = row;
      this.reset();
      this.query = { id: row.id };
      await this.$get("/window/perform/info", { id: row.id })
        .then((res) => {
          if (res.code == 1) {
            this.form = res.data;
            this.form.id = row.id;
            this.dict = res.dict;
          } else {
            this.form = row;
          }
          for (let key in this.form) {
            key == "fillDate"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "createTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "deductTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "updateTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "checkTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "reviewTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : "";
          }
          this.$get("/check/window/perform/info", { id: row.id }).then(
            (response) => {
              if (response.code == 1) {
                this.form = { ...this.form, ...response.data };
                this.dict = { ...this.dict, ...response.dict };

                this.$post("/perform/rules/list", {
                  page: 1,
                  size: -1,
                }).then((responsed) => {
                  if (responsed.code == 1) {
                    this.dict = { ...this.dict, ...responsed.dict };
                    if (
                      this.form.bonusReport &&
                      this.form.bonusReport != "[]"
                    ) {
                      let bonusArr = [];
                      bonusArr = JSON.parse(this.form.bonusReport);
                      let bonusarrText = responsed.data.data.filter((item) =>
                        bonusArr.includes(item.id)
                      );
                      this.form.bonusarrText = bonusarrText;
                    }
                    if (
                      this.form.deductStatement &&
                      this.form.deductStatement != "[]"
                    ) {
                      let deductArr = [];
                      deductArr = JSON.parse(this.form.deductStatement);
                      let deductarrText = responsed.data.data.filter((item) =>
                        deductArr.includes(item.id)
                      );
                      this.form.deductarrText = deductarrText;
                    }
                    this.form.view = "修改";
                    this.open = true;
                  }
                });
              }
            }
          );

          this.tableData = [];
          this.tableData.push({
            discipline: this.form["discipline"]
              ? this.form["discipline"]
              : "--",
            specification: this.form["specification"]
              ? this.form["specification"]
              : "--",
            bonusScore: this.form["bonusScore"]
              ? this.form["bonusScore"]
              : "--",
            sumScore: this.form["sumScore"] ? this.form["sumScore"] : "--",
            selfLevel: this.form["selfLevel"]
              ? this.form["selfLevel"] == 1
                ? "红旗窗口"
                : "黑旗窗口"
              : "--",
          });
        })
        .catch((error) => {
          this.$message.error(error.message);
        });
      this.pageInfo.type = "edit";
      this.title = "市政务服务大厅窗口考核登记表";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "check/window/perform/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增窗口考核核查";
    },
    /** 查看*/
    async view(row) {
      //   this.reset();
      //   this.query = { id: row.id };
      //   this.urls.currUrl = "check/window/perform/view";
      //   this.getData();
      //   this.pageInfo.type = "view";
      //   this.title = "窗口考核核查详细";
      this.form = row;
      this.reset();
      this.query = { id: row.id };
      await this.$get("/window/perform/info", { id: row.id })
        .then((res) => {
          if (res.code == 1) {
            this.form = res.data;
            this.dict = res.dict;
          } else {
            this.form = row;
          }
          for (let key in this.form) {
            key == "fillDate"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "createTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "deductTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "updateTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "checkTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : key == "reviewTime"
              ? (this.form[key] = timestampToTime(this.form[key], 6))
              : "";
          }
          this.$get("/check/window/perform/info", { id: row.id }).then(
            (response) => {
              if (response.code == 1) {
                this.form = { ...this.form, ...response.data };

                this.dict = { ...this.dict, ...response.dict };
                this.$post("/perform/rules/list", {
                  page: 1,
                  size: -1,
                }).then((responsed) => {
                  if (responsed.code == 1) {
                    this.dict = { ...this.dict, ...responsed.dict };
                    if (
                      this.form.bonusReport &&
                      this.form.bonusReport != "[]"
                    ) {
                      let bonusArr = [];
                      bonusArr = JSON.parse(this.form.bonusReport);
                      let bonusarrText = responsed.data.data.filter((item) =>
                        bonusArr.includes(item.id)
                      );
                      this.form.bonusarrText = bonusarrText;
                    }
                    if (
                      this.form.deductStatement &&
                      this.form.deductStatement != "[]"
                    ) {
                      let deductArr = [];
                      deductArr = JSON.parse(this.form.deductStatement);
                      let deductarrText = responsed.data.data.filter((item) =>
                        deductArr.includes(item.id)
                      );
                      this.form.deductarrText = deductarrText;
                    }
                    this.form.view = "查看";
                    this.open = true;
                  }
                });
              }
            }
          );
          this.tableData = [];
          this.tableData.push({
            discipline: this.form["discipline"]
              ? this.form["discipline"]
              : "--",
            specification: this.form["specification"]
              ? this.form["specification"]
              : "--",
            bonusScore: this.form["bonusScore"]
              ? this.form["bonusScore"]
              : "--",
            sumScore: this.form["sumScore"] ? this.form["sumScore"] : "--",
            selfLevel: this.form["selfLevel"]
              ? this.form["selfLevel"] == 1
                ? "红旗窗口"
                : "黑旗窗口"
              : "--",
          });
        })
        .catch((error) => {
          this.$message.error(error.message);
        });
      this.pageInfo.type = "view";
      this.title = "市政务服务大厅窗口考核登记表";
    },
    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    afterSubmit(data) {
      this.open = false;
      this.$emit("ok");
    },

    // 表单重置
    reset() {
      this.form = {
        recordId: null,
        year: null,
        month: null,
        windowId: null,
        windowName: "",
        ownerId: null,
        ownerName: "",
        deptId: null,
        deptName: "",
        salaId: null,
        salaName: "",
        fromName: "",
        sumScore: 0,
        submitDate: null,
        manageCheckPerson: "",
        manageCheckTime: null,
        manageCheckDesc: "",
        manageCheckResult: "",
        leaderCheckPerson: "",
        leaderCheckTime: null,
        leaderCheckDesc: "",
        leaderCheckResult: "",
        checkStatus: 1,
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
<style lang="less" scoped>
.content_box {
  padding: 0 20px;
  font-size: 14px;
  .text_line {
    width: 100%;
    display: flex;
    margin-bottom: 25px;
    .text_box:nth-child(2) {
      margin: 0 100px;
    }
    .text_box {
      display: flex;
      span {
        width: 160px;
        display: inline-block;
      }
      span:nth-child(2) {
        text-align: start;
        width: 100%;
      }
    }
  }
}
</style>
