<template>
  <div class="mod-config">
    <div style="text-align: center">
      <el-button @click="wzj()">未总结列表</el-button>
      <el-button @click="nrCopy()">内容复制</el-button>
      <el-button @click="lybClick()">留言板</el-button>
    </div>
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
<!--        <el-button v-if="isAuth('business:businesstotal:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
<!--        <el-button v-if="isAuth('business:businesstotal:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="planTime"
        header-align="center"
        align="center"
        label="施工日期">
      </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="totalPersonNum"
        header-align="center"
        align="center"
        label="总人数">
      </el-table-column>
      <el-table-column
        prop="projectFzgzId"
        header-align="center"
        align="center"
        label="负责工长">
        <template slot-scope="scope">
          <template v-for="item in ryList" v-if="scope.row.projectFzgzId === item.userId">
            {{item.name}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        prop="totalDdId"
        header-align="center"
        align="center"
        label="带队人">
        <template slot-scope="scope">
          <template v-for="item in ryList" v-if="scope.row.totalDdId === item.userId">
            {{item.name}}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id, 0)">详情</el-button>
          <el-button type="text" v-if="isAuth('business:businesstotal:update')" size="small" @click="addOrUpdateHandle(scope.row.id, 1)">修改</el-button>
<!--          <el-button type="text" size="small" @click="deleteHandle(scope.row.totalId)">删除</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>
    <!-- 弹窗, 新增 / 修改 -->
    <addorupdate v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></addorupdate>

    <el-dialog
    :title="'未总结列表'"
    :visible.sync="totalPlan"
    width="80%"
    >
      <businessTotalPlan ref="addOrUpdateTP" @refreshDataList="getDataList"></businessTotalPlan>
    </el-dialog>
    <el-dialog
    :title="'内容复制'"
    :visible.sync="nrfz"
    width="80%"
    >
      <totalCopy ref="addOrUpdateCP" @refreshDataList="getDataList"></totalCopy>
    </el-dialog>
    <el-dialog
    :title="'留言板'"
    :visible.sync="lyb"
    width="80%"
    >
      <totalMessage ref="addOrUpdateLyb" @refreshDataList="getDataList"></totalMessage>
    </el-dialog>
  </div>
</template>

<script>
  import businessTotalPlan from './businesstotalplan'
  import totalCopy from './totalcopy'
  import addorupdate from './businesstotal-add-or-update'
  import totalMessage from './totalmessage'

  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        totalPlan: false,
        nrfz: false,
        lyb: false,
        dataList: [],
        isOneDayList: [],
        dicSgddList: [],
        dicGclbList: [],
        dicSgjdList: [],
        dicJsdwList: [],
        dicZFYList: [],
        dicSGDWList: [],
        dicJLDWList: [],
        dicSJDWList: [],
        ryList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      businessTotalPlan,
      addorupdate,
      totalCopy,
      totalMessage
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/business/businesstotal/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
            this.dataList.forEach((item) => {
              if (item.projectNewName !== null) {
                item.project = item.projectNewName
              }
            })
            console.log(this.dataList)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id, num) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, num)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.totalId
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/business/businesstotal/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      // 未总结
      wzj () {
        this.totalPlan = true
        this.$nextTick(() => {
          this.$refs.addOrUpdateTP.getDataList()
        })
      },
      nrCopy () {
        this.nrfz = true
        this.$nextTick(() => {
          this.$refs.addOrUpdateCP.getDataList()
        })
      },
      lybClick () {
        this.lyb = true
        this.$nextTick(() => {
          this.$refs.addOrUpdateLyb.getDataList()
        })
      }
    },
    mounted () {
      this.$http.request({
        url: this.$http.adornUrl('/business/businesstotal/dictList'),
        method: 'get'
      }).then(({data}) => {
        if (data && data.code === 0) {
          // console.log(data);
          data.data.forEach((item) => {
            if (item.dictCode === 'is_one_day') {
              this.isOneDayList = item.children
            } else 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/businesstotal/fpWlzList'),
        method: 'get'
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.ryList = data.page
          // console.log(this.ryList);
        }
      })
    }
  }
</script>
