<template>
  <div class="wrapper">
    <NavHeader color="#0687D2" title="人才事项详情" @back="$router.go(-1)" />

    <img :src="imgUrl" style="width: 100%" />

    <div class="title">
      {{ detail.name }}
    </div>
    <div class="content-box">
      <list-no-active class="ml-" label="content" :list="list">
      </list-no-active>
    </div>
    <!-- <div class="bottom-clear"> -->
    <van-button class="bottom-fixed" block color="#0687D2" @click="report" v-if="detail.handlingMethod == 1">政策申报/去办理
    </van-button>
    <!-- </div> -->
  </div>
</template>

<script>
import NavHeader from "@/components/NavHeader";
import ListNoActive from "@/components/ListNoActive";
import Vue from "vue";
import { Button,Dialog } from "vant";
import {
  /*mattersById,*/ mattersByUserId,
  mattersGuideGet
} from "@/api/policy";
import {queryUserApplyForRecord,queryApplyingDeedTaxInfo,idCardVerification} from '@/api/deedtax'
// import { decryptByDES } from "@/utils/utils";

import imgUrl from "@/assets/policy/banner.png";
Vue.use(Button).use(Dialog);

export default {
  components: { NavHeader, ListNoActive },
  data() {
    return {
      id: "",
      imgUrl,
      detail: {
        nameL: "",
        contentList: [],
        handlingMethod: null
      },
      userInfo: {},
      talentCode: ''
    };
  },
  computed: {
    list() {
      return this.detail.contentList.map(el => {
        return el;
      });
    }
  },
  methods: {
    init() {
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "加载中..."
      });
      mattersGuideGet({ appId: 1234, id: this.id }).then(res => {
        if (res.code == 200) {

          console.log("详情的res---", res);
          this.$toast.clear();
          this.detail = res.data;  
        }
        
      });
    },
    report() {
      console.log(this.detail.matterType);
      // return
      // console.log(1111111);
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "加载中..."
      });
      mattersByUserId({
        appId: 1234,
        guideId: this.detail.id,
        // userId: this.userInfo.userId
      }).then(res => {
        console.log("人才吗的code----", res);
        sessionStorage.setItem("talentCode", res.data.talentCode);
        this.talentCode = res.data.talentCode
        this.$toast.clear();
        // console.log(res)
        if (this.detail.matterType === 7) {
          // 购房补贴申领服务指南
          this.$router.push({
            name: "PolicyPurchaseIndex",
            query: {
              departmentCode: this.detail.departmentCode,
              guideId: this.detail.id,
              talentCode: res.data.talentCode,
              matterType: this.detail.matterType,
              type: "add"
            }
          });
        } else {
          if (!res.data.mark) {
            this.$dialog
              .confirm({
                message: "您现在还不具备申报该政策的资格，请先申请人才码！",
                showCancelButton: false
              })
              .then(() => {
                console.log("无法申报");
              });
          } else {
            // 已申请人才码
            // 已申请该事项类型
            if (!res.data.recordMark) {
              if (this.detail.matterType === 5 || this.detail.matterType === 6) {
                this.$router.push({ name: "PolicyReportTwo" });
              }
              else {
                this.$router.push({
                  name: "PolicyReportOne",
                  query: {
                    departmentCode: this.detail.departmentCode,
                    guideId: this.detail.id,
                    talentCode: res.data.talentCode,
                    type: "add"
                  }
                });
              }
              return false;
            }

            // 可以申请该事项政策
            if (this.detail.matterType === 1) {
              // 健康管理服务
              this.$router.push({
                name: "HealthManage",
                query: {
                  departmentCode: this.detail.departmentCode,
                  guideId: this.detail.id,
                  talentCode: res.data.talentCode,
                  type: "add"
                }
              });
            } else if (this.detail.matterType === 2) {
              // 健康体检
              this.$router.push({
                name: "HealthCheck",
                query: {
                  departmentCode: this.detail.departmentCode,
                  guideId: this.detail.id,
                  talentCode: res.data.talentCode,
                  type: "add"
                }
              });
            } else if (this.detail.matterType === 3) {
              // 绿色就医通道
              this.$router.push({
                name: "HealthPath",
                query: {
                  departmentCode: this.detail.departmentCode,
                  guideId: this.detail.id,
                  talentCode: res.data.talentCode,
                  type: "add"
                }
              });
            } else if (this.detail.matterType === 4) {
              // 惠老关怀
              this.$router.push({
                name: "PolicyCare",
                query: {
                  departmentCode: this.detail.departmentCode,
                  guideId: this.detail.id,
                  talentCode: res.data.talentCode,
                  type: "add"
                }
              });
            } else if (
              this.detail.matterType === 5 ||
              this.detail.matterType === 6
            ) {
              idCardVerification({idCard: this.userInfo.idCardNo}).then((res) => {
                if (res.data) {
                  // let params = {
                  //   // userId: this.userInfo.userId,
                  //   // idCard: this.userInfo.idCardNo
                  //   idCard: decryptByDES(this.userInfo.idCardNo, "MnuYbhGv")
                  // }
                  queryUserApplyForRecord({idCard: this.userInfo.idCardNo}).then((res) => {
                    console.log(res)
                    if (res.code == 200) {
                      if (res.data.state == 0) {
                        // 人才“镇兴”行动购住房契税补贴(住宅)||人才“镇兴”行动购住房契税补贴(商办)
                        this.$router.push({
                          name: "HousePurchase",
                          query: {
                            departmentCode: this.detail.departmentCode,
                            guideId: this.detail.id,
                            talentCode: this.talentCode,
                            matterType: this.detail.matterType,
                            type: "add"
                          }
                        });
                      } else if (res.data.state == 1) {
                        Dialog.confirm({
                          confirmButtonText: '查看',
                          message: res.data.msg || '您的申请已提交',
                        }).then(() => {
                          queryApplyingDeedTaxInfo({
                            code: "",
                            idCard: this.userInfo.idCardNo,
                            name: "",
                            pageNum: 1,
                            pageSize: 10,
                            state: 0,
                            userId: ""
                          }).then((res) => {
                            console.log(res)
                            this.$router.push({ name: 'DeedtaxHandling', query: { code: res.data.code } })
                          })
                        })
                      } else if (res.data.state == 11) {
                        console.log(111)
                        Dialog.confirm({
                          confirmButtonText: '查看',
                          message: res.data.msg || '您的申请已提交',
                        }).then(() => {
                          this.$router.push({ name: 'PolicyReportTwo', query: { code: res.data.code } })
                        })
                      }
                    }
                  })
                } else {
                  Dialog.confirm({
                    title: '提示',
                    messageAlign: 'left',
                    message: "经系统查询，您已享受过相关政策补贴 ，不能再次申报契税补贴政策。如有异议请联系市财政窗口，地址：镇江市政务服务中心（冠城路8号工人大厦）二楼市财政局窗口，联系电话：0511-89881850",
                  })
                }
              })
            }
          }
        }
      });
    }
  },
  created() {
    let res = sessionStorage.getItem("ZJCD-UserInfo");
    this.userInfo = JSON.parse(res);
    this.id = this.$route.query.id;
    this.init();
  }
};
</script>

<style lang="stylus" scoped>
.wrapper:after {
  content: '';
  display: table;
  clear: both;
}

.wrapper {
  background: #fff;
  height: 100vh;
  overflow: hidden;

  .title {
    width: 100%;
    height: 100px;
    font-size: 54px;
    font-weight: 400;
    color: #333333;
    text-align: center;
    line-height: 100px;
  }

  .content-box {
    padding: 10px 30px;
    height: 100%;
    box-sizing: border-box;
    padding-bottom: 500px;
  }

  .bottom-fixed {
    position: fixed;
    left: 0;
    bottom: 0;
    height: 100px;
  }
}
</style>
