<template>
  <div>
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="建设单位" prop="projectJsdwId">
        <el-select
          v-model="dataForm.projectJsdwId"
          placeholder="选择建设单位"
          style="width: 100%;"
        >
          <el-option
            v-for="item in dicJsdwList"
            :key="item.dictId"
            :label="item.name"
            :value="item.dictId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="施工地点" prop="projectSgddId">
        <el-select
          v-model="dataForm.projectSgddId"
          placeholder="选择施工地点"
          style="width: 100%;"
        >
          <el-option
            v-for="item in dicSgddList"
            :key="item.dictId"
            :label="item.name"
            :value="item.dictId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="施工年份" prop="projectYear">
        <el-date-picker
          v-model="dataForm.projectYear"
          type="year"
          placeholder="选择年份"
          style="width: 100%;">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="负责工长" prop="projectFzgzId">
        <el-select
          v-model="dataForm.projectFzgzId"
          placeholder="选择负责工长"
          style="width: 100%;"
        >
          <el-option
            v-for="item in serchList"
            :key="item.userId"
            :label="item.name"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工程类别" prop="projectGclbId">
        <el-select
          v-model="dataForm.projectGclbId"
          placeholder="选择工程类别"
          style="width: 100%;"
        >
          <el-option
            v-for="item in dicGclbList"
            :key="item.userId"
            :label="item.name"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="导入合同" prop="isContant">
        <el-select
          v-model="dataForm.isContant"
          placeholder="选择导入合同"
          style="width: 100%;"
        >
          <el-option
            v-for="item in isOneDayList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="施工进度" prop="projectSgjdId">
        <el-select
          v-model="dataForm.projectSgjdId"
          placeholder="选择施工进度"
          style="width: 100%;"
        >
          <el-option
            v-for="item in dicSgjdList"
            :key="item.userId"
            :label="item.name"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="关键字" prop="gjz">
        <el-input v-model="dataForm.gjz" placeholder="关键字"></el-input>
      </el-form-item>
    </el-form>


    <el-table
      :data="dataList"
      border>
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="projectYear"
        header-align="center"
        align="center"
        label="施工年份">
      </el-table-column>
      <el-table-column
        prop="projectJsdwId"
        header-align="center"
        align="center"
        label="建设单位">
        <template slot-scope="scope">
          <template v-for="item in dicJsdwList" v-if="scope.row.projectJsdwId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="project"
        header-align="center"
        align="center"
        label="立项名称">
      </el-table-column>
      <el-table-column
        prop="projectSgddId"
        header-align="center"
        align="center"
        label="施工地点">
        <template slot-scope="scope">
          <template v-for="item in dicSgddList" v-if="scope.row.projectSgddId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="projectSgjdId"
        header-align="center"
        align="center"
        label="施工进度">
        <template slot-scope="scope">
          <template v-for="item in dicSgjdList" v-if="scope.row.projectSgjdId === item.dictId">
            {{item.name}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="projectPhotoConut"
        header-align="center"
        align="center"
        label="现场张片">
      </el-table-column>
      <el-table-column
        prop="isContant"
        header-align="center"
        align="center"
        label="导入合同">
        <template slot-scope="scope">
          <span v-if="scope.row.isContant === 0">否</span>
          <span v-if="scope.row.isContant === 1">是</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="70"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="chooseProject(scope.row.projectId)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <el-dialog
      :title="'留言板'"
      :visible.sync="lyb"
      width="70%"
      append-to-body>
      <totalMesProject ref="totalMesProject"></totalMesProject>
    </el-dialog>
  </div>
</template>

<script>
import totalMesProject from './totalmesproject'
export default {
  components: {
    totalMesProject
  },
  data () {
    return {
      lyb: false,
      isOneDayList: [{
        value: 0,
        label: '否'
      }, {
        value: 1,
        label: '是'
      }],
      dicSgddList: [],
      dicGclbList: [],
      dicSgjdList: [],
      dicJsdwList: [],
      dicZFYList: [],
      dicSGDWList: [],
      dicJLDWList: [],
      dicSJDWList: [],
      serchList: [],
      ryList: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataForm: {
        projectJsdwId: '',
        projectYear: '',
        projectSgddId: '',
        projectGclbId: '',
        projectSgjdId: '',
        projectFzgzId: '',
        isContant: '',
        contant: '',
        gjz: ''
      }
    }
  },
  methods: {
    getDataList () {
      this.$http({
        url: this.$http.adornUrl('/business/businessplan/dictList'),
        method: 'get'
      }).then(({data}) => {
        if (data && data.code === 0) {
          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
            }
          })
        }
      })
      this.$http.request({
        url: this.$http.adornUrl('/business/businessplan/fpWlzList'),
        method: 'get'
      }).then(({data}) => {
        if (data && data.code === 0) {
          data.page.forEach((item) => {
            if (item.positionId === 151 || item.positionId === 152) {
              if (item.workId === 167) {
                this.ryList.push(item)
                this.serchList.push(item)
              }
            }
          })
        }
      })
      // 获取所有的立项信息 将立项中的负责人id拿出 方便负责工长搜索用
      this.$http.request({
        url: this.$http.adornUrl('/business/businesstotal/ddIdList'),
        method: 'get'
      }).then(({data}) => {
        // console.log(data);
        if (data && data.code === 0) {
          // console.log(this.ryList.length);
          this.serchList.forEach((item, i) => {
            let flag = 0
            data.page.forEach((itemCH) => {
              if (item.userId === itemCH) {
                flag = 1 // 说明立项信息里面包含此人，List中不去除
              }
            })
            // console.log(flag);
            if (flag === 0) {
              this.serchList.splice(i, 1)
            }
          })
          // console.log(this.ryList);
        }
      })
      this.getselectProject()
    },
    // 选择的立项
    chooseProject (id) {
      this.lyb = true
      this.$nextTick(() => {
        this.$refs.totalMesProject.init(id)
      })
    },
    // 获取立项列表
    getselectProject () {
      this.dataList = []
      this.$http.request({
        url: this.$http.adornUrl('/business/businessplan/projectList'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'projectJsdwId': this.dataForm.projectJsdwId,
          'projectYear': this.dataForm.projectYear,
          'projectSgddId': this.dataForm.projectSgddId,
          'projectGclbId': this.dataForm.projectGclbId,
          'projectSgjdId': this.dataForm.projectSgjdId,
          'isContant': this.dataForm.isContant,
          'gjz': this.dataForm.gjz,
          'limit': this.pageSize
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          data.page.list.forEach((item) => {
            if (item.projectNewName !== null) {
              item.project = item.projectNewName
            }
            this.dataList.push(item)
          })
          this.totalPage = data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getselectProject()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getselectProject()
    }
  }
}
</script>

<style scoped>

</style>
