<template>
  <!-- 随访调查 -->
  <div class="screeningSearch">
    <div class="top">
      <form-components :forms="formList" :formEdit="formEdit" @handleSearch="onSearch"></form-components>
    </div>
    <div class="bot">
      <customs-table
        ref="table"
        :table-data="tableData"
        :columns="columns"
        :header-class="'newHeader'"
        :list-loading="listLoading"
        :current-page="pageIndex"
        :total-count="total"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        @pageSizeChange="handleSizeChange"
        @currentPageChange="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import FormComponents from "@/components/FormComponents"
import CustomsTable from "@/components/CustomsTable"
import paginationMixin from "@/components/TabComponents/mixin"
import { getFollowSurvey } from "@/api/followup"
import { getDictDetail } from "@/api/dict.js"
export default {
  components: {
    CustomsTable,
    FormComponents,
  },
  mixins: [paginationMixin],
  data() {
    return {
      listLoading: false,
      keyword: "",
      modifiedFlag: false,
      columns: [
        {
          label: "医联体",
          value: "unionName",
          minWidth: 120,
        },
        {
          label: "姓名",
          value: "name",
          minWidth: 120,
        },
        {
          label: "性别",
          value: "sex",
          minWidth: 120,
          // trans:'d-sex',
          transList:{
            1:'男',
            2:'女'
          }
        },
        {
          label: "身份证",
          value: "idCard",
          minWidth: 120,
        },
        {
          label: "年龄",
          value:"age",
          minWidth: 120,
        },
        {
          label: "筛查时间",
          value: "screeningTime",
          minWidth: 120,
        },
        {
          label: "风险评估结果",
          value: "riskRank",
          trans:'risk_level',
          transList:{
          },
          minWidth: 120,
        },
        {
          label: "上次随访时间",
          value: "followTime",
          minWidth: 120,
        },
        {
          label: "随访进度",
          value: "followBatch",
          trans:'follow_type',
          transList:{
          },
          minWidth: 120,
        },
        {
          label: "计划随访时间",
          value: "nextFollowTime",
          trans:'next_follow_time',
          minWidth: 120,
        },
        {
          label: "操作",
          width: 220,
          fixed: "right",
          operType: "button",
          operations: [
            {
              func: this.rowOpration,
              formatter(row) {
                return {
                  label: " 录入",
                  type: "text",
                }
              },
            },
          ],
        },
      ],
      tableData: [
        {
          "patientId": "1598222607734341634",
          "name": "小飞", //姓名
          "idCard": "340822199510260215", //身份证
          "phone": "18311112222", //手机号
          "sex": 1, //性别
          "birthday": "2022-12-31 00:00:00", //生日
          "age": 18, //年龄
          "id": "", //id
          "unionName": "合肥高新附院", //医联体名称
          "screeningTime": "2022-12-01 00:00:00", //筛查时间
          "riskRank": "", //风险等级
          "followTime": "", //随访时间
          "followContents": "", //随访内容
          "nextFollowTime": "", //计划随访时间
          "followBatch": 0, //随访进度
          "unionId": "2", //联盟id
          "riskScore": "", //风险分数
          "screeningAdvise": "", //筛查建议
          "formRecordId": "", //表单记录id
          "linkPhone": "0556-5556666", //联系方式
          "isContinueFollow": 1, //是否继续随访
          "checkStatus": "" //审核状态
          },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
        {
          name:'11',
        },
      ],//调试
      formList: [
        {
          xs: 24,
          sm: 12,
          md: 12,
          lg: 7,
          xl: 7,
          type: "select",
          label: "计划随访时间",
          prop: "nextFollowTime",
          trans:'next_follow_time',
          placeholder: "请选择计划随访时间",
          rules: [],
          opts: [{ label: "123", value: "1" }],
        },
        {
          xs: 24,
          sm: 12,
          md: 12,
          lg: 7,
          xl: 7,
          type: "input",
          label: "姓名",
          prop: "name",
          placeholder: "请输入姓名",
          rules: [],
        },
        {
          xs: 24,
          sm: 12,
          md: 12,
          lg: 7,
          xl: 7,
          type: "input",
          label: "身份证",
          prop: "idCard",
          placeholder: "请输入身份证",
          rules: [],
        },
        {
          xs: 24,
          sm: 12,
          md: 12,
          lg: 7,
          xl: 7,
          type: "input",
          label: "医联体",
          prop: "unionName",
          placeholder: "请输入医联体",
          rules: [],
        },
        {
          xs: 24,
          sm: 12,
          md: 12,
          lg: 7,
          xl: 7,
          type: "select",
          label: "随访进度",
          prop: "followBatch",
          trans:'follow_type',
          placeholder: "请选择随访进度",
          rules: [],
          opts: [{ label: "123", value: "1" }],
        },
        {
          xs: 1,
          sm: 2,
          md: 2,
          lg: 2,
          xl: 2,
          type: "btn",
          list: [
            {
              btnType: "button",
              type: "",
              style: {
                width: "80px",
                height: "32px",
                borderRadius: "4px",
                fontSize: "14px",
                marginLeft: "40px",
              },
              btnText: "查询",
              func: this.onSearch
            },
            // {
            //   btnType: "tobeModified",
            //   tobeModified: 20,
            // },
          ],
        },
      ],
      formEdit:{}
    }
  },
  watch: {
    pageSize(val){
      sessionStorage.setItem('followResearch-pageSize',val)
    },
    pageIndex(val){
      sessionStorage.setItem('followResearch-pageIndex',val)
    }
  },
  created(){
    this.initColumn()
  },
  mounted() {
    this.formEdit = JSON.parse(sessionStorage.getItem('followResearch-form')) ||{}
    this.pageSize = Number(sessionStorage.getItem('followResearch-pageSize')) || 1
    this.pageIndex = Number(sessionStorage.getItem('followResearch-pageIndex')) || 10
    // this.handleSearch() //调试注释
  },
  methods: {
    changeModified() {
      this.modifiedFlag = !this.modifiedFlag
    },
    setSelectedIndex(i) {
      console.log(this.selectedIndex)
      this.selectedIndex = i
      sessionStorage.setItem("homeSelectedIndex", this.selectedIndex)
    },
    changePage(v) {
      this.page[v.type] = v.value
      console.log(this.page)
      this.$refs.customTable.loading = false
    },
    onSearch(form) {
      sessionStorage.setItem('followResearch-form',JSON.stringify(form))
      this.formEdit = form
      this.handleSearch()
    },
    rowOpration(data, i) {
      console.log('跳转',data, i)
      this.$router.push({path:"/followupentry",query:{formEdit:JSON.stringify(data)}})
    },
    async handleSearch(){
      this.listLoading = true
      let params={
        pageSize:this.pageSize,
        pageNum:this.pageIndex
      }
      if(this.formEdit){
        params=Object.assign(this.formEdit,params)
      }
      let res = await getFollowSurvey(params)
      if(res.code==1){
        //分页内容
        const d = res.data
        this.total= d.total
        this.tableData=d['records']
      }
      this.listLoading = false
    },
    initColumn(){
      this.columns.forEach((item,index) => {
        if(item.trans){
          this.initDict(item.trans,index)
        }
      })
    },
    async initDict(type,index){
      let params={
        type:type
      }
      const res = await getDictDetail(params)
      let item = this.formList.find(_ => _.trans == type)
      res.data.forEach((itemD,inx) => {
        if(!this.columns[index]['transList']){
           this.columns[index]['transList']={}
        }
        else{
          this.columns[index]['transList'][itemD.code]=itemD.name
        }
        if(item){
          if(!item['opts']){
           item['opts']=[]
        }
        else {
            item['opts']=res.data.map((_) => {
              return {
                label: _.name,
                value: _.code,
              }
            })
          }
        }
      })
    }
  },
}
</script>
<style lang="scss" scoped>
.screeningSearch {
  .top {
    width: 100%;
    // height: 72px;
    padding: 0 116px 0 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .bot {
    padding: 0 24px;
  }
}
</style>
