<template>
  <div>
    <el-form :model="dataFormProject">
      <div style="text-align: left;padding-bottom: 1%;font: bold 16px 新宋体">一、立项属性</div>
      <el-form-item label="1、建设单位：" prop="jsdw" label-width="8%">
        <span>{{ dataFormProject.jsdw }}</span>
      </el-form-item>
      <el-form-item label="2、施工地点：" prop="sgdd" label-width="8%">
        <span>{{ dataFormProject.sgdd }}</span>
      </el-form-item>
      <el-form-item label="3、施工年份：" prop="projectYear" label-width="8%">
        <span>{{ dataFormProject.projectYear }}</span>
      </el-form-item>
      <el-form-item label="4、开工时间：" prop="projectStart" label-width="8%">
        <span>{{ dataFormProject.projectStart }}</span>
      </el-form-item>
      <el-form-item label="5、竣工时间：" prop="projectEnd" label-width="8%">
        <span>{{ dataFormProject.projectEnd }}</span>
      </el-form-item>
      <el-form-item label="6、施工进度：" prop="sgjd" label-width="8%">
        <span>{{ dataFormProject.sgjd }}</span>
      </el-form-item>
      <el-form-item label="7、负责工长：" prop="fzgz" label-width="8%">
        <span>{{ dataFormProject.fzgz }}</span>
      </el-form-item>
      <el-form-item label="8、工程类别：" prop="projectGclb" label-width="8%">
        <span>{{ dataFormProject.projectGclb }}</span>
      </el-form-item>
    </el-form>
    <el-form :model="dataFormContract">
      <div style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">二、合同属性</div>
      <el-form-item label="1、合同年份：" prop="contractYear" label-width="8%">
        <span>{{ dataFormContract.contractYear }}</span>
      </el-form-item>
      <el-form-item label="2、合同名称：" prop="contractName" label-width="8%">
        <span>{{ dataFormContract.contractName }}</span>
      </el-form-item>
      <el-form-item label="3、直非友：" prop="contractZfyId" label-width="8%">
        <template v-for="item in dicZFYList" v-if=" dataFormContract.contractZfyId === item.dictId">
          {{item.name}}
        </template>
      </el-form-item>
      <el-form-item label="4、施工单位：" prop="contractSgdwId" label-width="8%">
        <template slot-scope="scope">
          <template v-for="item in dicSgddList" v-if=" dataFormContract.contractSgdwId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-form-item>
      <el-form-item label="5、监理单位：" prop="contractJldwId" label-width="8%">
        <template slot-scope="scope">
          <template v-for="item in dicJLDWList" v-if=" dataFormContract.contractJldwId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-form-item>
      <el-form-item label="6、一审单位：" prop="contractYsdwId" label-width="8%">
        <template slot-scope="scope">
          <template v-for="item in dicSJDWList" v-if=" dataFormContract.contractYsdwId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-form-item>
      <el-form-item label="7、二审单位：" prop="gjz" label-width="8%">
        <template slot-scope="scope">
          <template v-for="item in dicSJDWList" v-if=" dataFormContract.contractEsdwId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-form-item>
    </el-form>
    <el-form>
      <div style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">三、内容综述</div>
      <el-form-item label="内容综述" prop="gjz" label-width="8%">
        <span>{{ dataFormProject.projectNrjy }}</span>
      </el-form-item>
    </el-form>
    <div style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">四、历史留言</div>
    <el-table
      :data="dataListCommons"
      border>
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="commentsTime"
        header-align="center"
        align="center"
        label="日期">
      </el-table-column>
      <el-table-column
        prop="authenticName"
        header-align="center"
        align="center"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="commentsRemarks"
        header-align="center"
        align="center"
        label="内容">
      </el-table-column>
    </el-table>
    <div style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">五、施工日记</div>
    <el-table
      :data="historyList"
      border>
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="totalDate"
        header-align="center"
        align="center"
        label="日期">
      </el-table-column>
      <el-table-column
        prop="selectPer"
        header-align="center"
        align="center"
        label="人工">
      </el-table-column>
      <el-table-column
        prop="totalJx"
        header-align="center"
        align="center"
        label="机械">
      </el-table-column>
      <el-table-column
        prop="totalCl"
        header-align="center"
        align="center"
        label="材料">
      </el-table-column>
      <el-table-column
        prop="totalSgSummary"
        header-align="center"
        align="center"
        label="内容描述">
      </el-table-column>
    </el-table>
    <div style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">六、本次留言</div>
    <el-form>
      <el-form-item label="内容综述" prop="gjz" label-width="8%">
        <el-input v-model="dataForm.commentsRemarks" style="width: 90%" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <div style="text-align: center">
      <el-button @click="dataFormSubmit()">提交留言</el-button>
    </div>
  </div>
</template>

<script>
export default {
  components: {
  },
  data () {
    return {
      id: '',
      dicSgjdList: [],
      dicSgddList: [],
      dicGclbList: [],
      dicJsdwList: [],
      dicZFYList: [],
      dicSGDWList: [],
      dicJLDWList: [],
      dicSJDWList: [],
      dataListCommons: [], // 评论信息
      historyList: [], // 历史信息
      dataFormProject: {
        jsdw: '',
        projectYear: '',
        projectStart: '',
        projectEnd: '',
        sgdd: '',
        projectGclbId: '',
        projectGclb: '',
        sgjd: '',
        fzgz: '',
        projectNrjy: ''
      },
      dataFormContract: {
        contractYear: '',
        contractZfyId: '',
        contractSgdwId: '',
        contractJldwId: '',
        contractYsdwId: '',
        contractEsdwId: ''
      },
      dataForm: {
        commentsRemarks: '',
        commentsTime: '',
        commentsFj: ''
      }
    }
  },
  methods: {
    init (id) {
      this.id = id
      // 获取字典信息
      this.$http.request({
        url: this.$http.adornUrl('/business/businesstotal/dictList'),
        method: 'get'
      }).then((data) => {
        if (data && data.data.code === 0) {
          data.data.data.forEach((item) => {
            if (item.dictCode === 'work_place') { // 施工地点
              this.dicSgddList = item.children
            } else if (item.dictCode === 'work_type') { // 工程类别
              this.dicGclbList = item.children
            } else if (item.dictCode === 'work_tatus') { // 施工进度
              this.dicSgjdList = item.children
            } else if (item.dictCode === 'construction_unit') { // 建设单位
              this.dicJsdwList = item.children
            } else if (item.dictCode === 'is_friend') { // 直非友
              this.dicZFYList = item.children
            } else if (item.dictCode === 'building_section') { // 施工单位
              this.dicSGDWList = item.children
            } else if (item.dictCode === 'surveillance_unit') { // 监理单位
              this.dicJLDWList = item.children
            } else if (item.dictCode === 'approval_unit') { // 审批单位(一审单位、二审单位)
              this.dicSJDWList = item.children
            }
          })
          // 根据立项id获取  立项信息 合同信息 总结信息
          this.$http.request({
            url: this.$http.adornUrl('/business/businesstotal/projectInfo/' + id),
            method: 'get'
          }).then((data) => {
            if (data && data.data.code === 0) {
              this.dataFormProject = {
                ...data.data.businessProject[0]
              }
              if (this.dataFormProject.projectGclbId !== null && this.dataFormProject.projectGclbId !== undefined && this.dataFormProject.projectGclbId !== '') { // 工程类别
                this.dicGclbList.forEach((item) => {
                  if (!this.dataFormProject.projectGclbId.toString().includes(',')) {
                    if (item.dictId.toString() === this.dataFormProject.projectGclbId) {
                      this.dataFormProject.projectGclb = item.name
                    }
                  } else {
                    this.dataFormProject.projectGclbId.split(',').forEach((itemProject) => {
                      if (itemProject.toString() === item.dictId.toString()) {
                        // 排除undefined
                        if (this.dataFormProject.projectGclb === undefined) {
                          this.dataFormProject.projectGclb = item.name
                        } else {
                          this.dataFormProject.projectGclb += ',' + item.name
                        }
                      }
                    })
                  }
                })
              }
            }
          })
          // 获取合同信息
          this.$http.request({
            url: this.$http.adornUrl('/business/businesstotal/contractInfo/' + id),
            method: 'get'
          }).then((data) => {
            // console.log(data);
            if (data && data.data.code === 0) {
              this.dataFormContract = {
                ...data.data.contractList[id][0]
              }
              // console.log(this.dataFormContract);
            }
          })
        }
      })
      // 根据立项id获取所有的评论信息
      this.$http.request({
        url: this.$http.adornUrl('/business/businesscomments/getListByProjectId/' + id),
        method: 'get'
      }).then((data) => {
        // console.log(data);
        if (data.data && data.data.code === 0) {
          this.dataListCommons = data.data.page
        }
      })
      // 根据立项id获取施工日记
      this.$http.request({
        url: this.$http.adornUrl('/business/businesstotal/getListByProjectId/' + id),
        method: 'get'
      }).then((data) => {
        console.log(data.data.page)
        if (data.data && data.data.code === 0) {
          this.historyList = data.data.page
          this.historyList.forEach((item) => {
            if (item.selectPer !== null && item.ddName !== null) {
              item.selectPer += ',' + item.ddName
            } else if (item.ddName !== null) {
              item.selectPer = item.ddName
            }
          })
        }
      })
      // 获取当前时间
      let nowDate = new Date()
      let date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate()
      }
      this.dataForm.commentsTime = date.year + '-' + date.month + '-' + date.date
    },
    dataFormSubmit () {
      // console.log(this.dataForm);
      this.$http.request({
        url: this.$http.adornUrl('/business/businesscomments/save'),
        method: 'post',
        body: this.$http.adornData({
          'commentsProjectId': this.id,
          'commentsRemarks': this.dataForm.commentsRemarks,
          'commentsTime': this.dataForm.commentsTime,
          'commentsFj': this.dataForm.commentsFj
        })
      }).then((data) => {
        if (data && data.code === 0) {
          this.init(this.id)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
