<template>
  <div>
    <Breadcrumb :list="breadcrumbList"/>
    <div class="table">
      <el-table v-loading="loading"
                :data="list"
                element-loading-background="rgba(0,0,0,0.5)"
                element-loading-spinner="el-icon-loading"
                element-loading-text="加载中..."
      >
        <el-table-column label="序号" type="index" width="80"/>

        <el-table-column label="月度" prop="periodStart" :formatter="formatMonth"/>
        <el-table-column label="所属社区" prop="communityName"/>
        <el-table-column label="事项来源" prop="satisfactionSource">
          <template slot-scope="{ row }">
            <span
                :style="{
                color: satisfactionSourceFormat(row.satisfactionSource).color,
              }">
              满意度调查
            </span>
          </template>
        </el-table-column>
        <el-table-column label="问题" prop="problemDesc"/>
        <el-table-column label="提交时间" prop="periodStart"/>
        <el-table-column label="姓名" prop="name"/>
        <el-table-column label="电话" prop="mobile">
          <template slot-scope="scope">
            {{ $sensitive(scope.row.mobile, 3, 7) }}
          </template>
        </el-table-column>
        <el-table-column label="是否完成" prop="completeFlag"/>
        <el-table-column label="消除风险" prop="dangerFlag"/>
        <el-table-column label="操作" sortable>
          <template slot-scope="{ row }">
            <span class="view" @click="handleView(row)">查看</span>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <Pagination v-show="total > 0" :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNo" :total="total"
                @pagination="getList"/>
    <DissatisfiedDetail ref="detail" :id="id" />
  </div>
</template>

<script>
import { requestPost } from "@/js/dai/request";
import Breadcrumb from "@/views/dataBoard/satisfactionEval/components/Breadcrumb";
import Pagination from "@/views/dataBoard/satisfactionEval/components/Pagination";
import Title from "@/views/dataBoard/satisfactionEval/components/Title";
import CallPhone from '@/views/dataBoard/cpts/CallPhone.vue'
import DissatisfiedDetail from "@/views/dataBoard/satisfactionEval/dissatisfied/detail.vue";

export default {
  name: "provinceSatisfaction",
  components: {Breadcrumb, Pagination, Title, CallPhone, DissatisfiedDetail},
  data() {
    return {
      queryParams: {
        agencyId: this.$route.query.id,
        pageNo: 1,
        pageSize: 10,
        satisfactionSource: "satisfaction_province"
      },
      total: 0,
      breadcrumbList: [
        {
          path: "/dataBoard/overview/index",
          name: "书记看板",
        },
        {
          path: "",
          name: "满意度调查不满意列表",
        },
      ],
      list: [],
      showDialog: false,
      rowId: "",
      id: "",
      loading: true,
      satisfactionSourceOptions: [
        {
          value: "satisfaction_12345",
          label: "12345投诉",
          color: "#FFB73C",
        },
        {
          value: "satisfaction_province",
          label: "满意度调查",
          color: "#64C1FF",
        },
        {
          value: "satisfaction_community",
          label: "社区满意度自查",
          color: "#08EBAE",
        },
      ],
    };
  },
  activated() {
    this.queryParams.reportUserId = this.$route.query.reportUserId;
    this.queryParams.pageNo = 1;
    this.getList();
  },
  methods: {
    handleView({id}) {
      this.id = id;
      this.$refs.detail.open(id);
    },
    search() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    formatMonth(row, column) {
      // 自定义格式化函数，提取年份和月份
      const date = new Date(row.periodStart);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 补零
      return `${year}-${month}`;
    },
    async getList() {
      this.loading = true

      const url = "/governance/provinceEvaluationRecord/pageInfo";

      const formData={
        agencyId:this.queryParams.agencyId,
        // orgCategoryCode:"province"
      };
      const pageSize = this.queryParams.pageSize;
      const pageNo = this.queryParams.pageNo;
      const { data, code, msg } = await requestPost(url, {
          pageSize,
          pageNo,
          ...formData,
      });
      if (code === 0) {
          this.list = data.list;
          this.total = data.total;
          this.loading = false
      }

    },
    satisfactionSourceFormat(val) {
      let satisfactionSource = this.satisfactionSourceOptions.filter((item) => item.value === val)[0];
      return satisfactionSource ? satisfactionSource : "";
    },
    close() {
      this.showDialog = false;
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/dataBoard/table.scss";

.table {
  margin-top: 40px;
}

.handle {
  font-size: 14px;
  margin-left: 10px;
  color: #9A69EC;
  cursor: pointer;
}

.view {
  font-size: 14px;
  margin-left: 10px;
  color: #007FF1;
  cursor: pointer;
}
</style>
