<!-- 从 学校 跳入 -->
<template>
  <DetailContainer v-if="detailMsg.jdd_id"
    :d="{ jdd_id: detailMsg.jdd_id, ptype: '3', jddt_uo_id: detailMsg.jddx_uo_id, page_type: 'myupload' }"
    @finish="getRwDetail" :key="timestamp">
    <!-- 无指标 -->
    <el-table v-if="['1', '3'].includes(detailMsg.jdd_ddlx)" :data="tableData" tooltip-effect="dark" v-loading="loading"
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="佐证材料:">
              <el-link class="ml-2" v-for="({ name, url }) in getFullUrlArray(scope.row.jddr_zzcl_json)" :href="url"
                type="primary">
                {{
                  name
                }}</el-link>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column label="提交部门" prop="jddt_uo_name" show-overflow-tooltip></el-table-column>
      <el-table-column label="自评分" prop="jddr_zp_score" show-overflow-tooltip></el-table-column>
      <el-table-column label="自评" prop="jddr_zp_content" show-overflow-tooltip></el-table-column>

      <!-- <el-table-column label="附件完成情况" prop="ddqk_name"></el-table-column> -->
      <el-table-column label="状态" prop="jddr_sh_status" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jddr_sh_status">{{
            sh_option[scope.row.jddr_sh_status]
          }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>

      <el-table-column label="审核分数" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jddr_sh_score">{{ scope.row.jddr_sh_score }}</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="审核意见">
        <template slot-scope="scope">
          <div v-if="scope.row.jddr_sh_content">{{ scope.row.jddr_sh_content }}</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="审核人" prop="jddr_shr" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jddr_shr">{{ scope.row.jddr_shr }}</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip v-if="isDdkUser">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.jddr_sh_status !== '3'" type="text" @click="handleAudit(scope.row)">审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 有指标 -->
    <el-table v-if="['2', '4'].includes(detailMsg.jdd_ddlx)" :data="tableData" tooltip-effect="dark" v-loading="loading"
      style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="scope">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="佐证材料:">
              <el-link class="ml-2"
                v-for="({ name, url }) in getFullUrlArray(scope.row.jdbg_dddx_ddrw_tjjl.jddr_zzcl_json)" :href="url"
                type="primary">
                {{
                  name
                }}</el-link>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column label="提交部门" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ scope.row.jdbg_dddx_ddrw_tjjl.jddt_uo_name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="指标名称" show-overflow-tooltip prop="jddr_name"></el-table-column>
      <el-table-column label="指标内容" show-overflow-tooltip prop="jddr_content"></el-table-column>
      <el-table-column label="指标分值" prop="jddr_score" show-overflow-tooltip></el-table-column>
      <el-table-column label="责任部门" show-overflow-tooltip prop="jddr_uo_name"></el-table-column>
      <el-table-column label="自评分" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_zp_score">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_zp_score }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="自评" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_zp_content">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_zp_content }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="附件完成情况" prop="jddr_fjwcqk" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_fjwcqk">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_fjwcqk }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="jddr_sh_status" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_status">{{
            sh_option[scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_status]
          }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="审核分数" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_score">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_score }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="审核意见">
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_content">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_content }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>

      <el-table-column label="审核人" prop="jddr_shr" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.jdbg_dddx_ddrw_tjjl.jddr_shr">{{ scope.row.jdbg_dddx_ddrw_tjjl.jddr_shr }}
          </div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip v-if="isDdkUser">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.jdbg_dddx_ddrw_tjjl.jddr_sh_status !== '3'" type="text"
            @click="handleAudit(scope.row.jdbg_dddx_ddrw_tjjl)">审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="审核" :visible.sync="dialogFormVisible" width="700px">
      <el-form :model="dialogForm" :rules="rules" ref="dialogFormRef" label-width="80px" :key="dialogFormVisible">
        <el-form-item label="审核分数" prop="jddr_sh_score">
          <el-input v-model="dialogForm.jddr_sh_score" />
        </el-form-item>
        <el-form-item label="审核意见" prop="jddr_sh_content">
          <el-input type="textarea" v-model="dialogForm.jddr_sh_content" :rows="6"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleAuditSubmit()">确 定</el-button>
      </div>
    </el-dialog>
  </DetailContainer>
</template>
<script>
import { rwfk_detail } from './api.js';
import { userInfo as user } from '~/stores/user';
import DetailContainer from './container.vue';
import request from '~/utils/request';
export default {
  components: { DetailContainer },
  data() {
    return {
      loading: false,
      detailMsg: {},
      tableData: [],
      rwDetail: {},
      dialogFormVisible: false,
      dialogFormRef: undefined,
      dialogForm: {},
      rules: {
        jddr_sh_score: [
          { required: true, message: "请填写审核分数", trigger: "submit" },
        ],
        jddr_sh_content: [
          { required: true, message: "请填写审核意见", trigger: "submit" },
        ],
      },
      timestamp: Date.now(),
      sh_option: { 1: "已审核", 2: "未提交", 3: "待审核" }
    };
  },
  computed: {
    isDdkUser() {
      return user.uo_id === '386' || user.user_group_id === '100'
    }
  },
  methods: {
    getFullUrlArray(arr) {
      console.log('arr :>> ', arr);
      if (arr)
        return arr.split(';').map(u => {
          const [part, name] = u.split('|')
          return {
            name,
            url: window.globalVariables.api + '/' + part
          }
        })
      else return []
    },
    getRwDetail(info) {
      this.rwDetail = info
      if (['1', '3'].includes(this.detailMsg.jdd_ddlx)) {
        if (info.is_upload !== 2) {
          this.tableData = [...info.jdbg_dddx_ddrw_tjjl]
        }
      } else if (['2', '4'].includes(this.detailMsg.jdd_ddlx)) {
        console.log('info :>> ', info);
        request({
          url: '/jdbg/dddx_ddrw_rwzb/index',
          data: {
            jdd_id: this.detailMsg.jdd_id,
            ptype: 3,
            jddx_uo_id: this.detailMsg.jddx_uo_id
          }
        }).then(res => {
          this.tableData = res.data.page_data
        })
      }
    },
    handleAudit(row) {
      this.dialogForm = {
        jddt_id: row.jddt_id,
        jddr_sh_status: '1',
        jddr_shr: user.user_realname,
        jddr_shr_user_id: user.user_id,
        jddr_sh_content: '',
        jddr_sh_score: ''
      }
      console.log('this.dialogForm :>> ', this.dialogForm);
      this.dialogFormVisible = true
    },
    handleAuditSubmit() {
      this.$refs['dialogFormRef'].validate((valid) => {
        // console.log('valid :>> ', valid);
        if (valid) {
          request({
            url: '/jdbg/dddx_ddrw_tjjl/edit',
            data: {
              jddt_id: this.dialogForm.jddt_id,
              jdbg_dddx_ddrw_tjjl: this.dialogForm
            }
          }).then(res => {
            if (res.code === '1') {
              this.dialogFormVisible = false
              this.timestamp = Date.now()
            }
          })
        }
      })
    }
  },
  created() {
    // request({ url: '/jdbg/dddx_ddrw_tjjl/index' })

    rwfk_detail({
      jddx_id: this.$route.params.id,
    }).then(res => {
      this.detailMsg = res.data.one_info
    })
  },
};
</script>
<style lang="scss" scoped>
.wight {
  font-weight: 500;
}
</style>
