<template>
  <div>
    <div style="display: flex">
      <div style="width: 50%">
        <el-form :model="dataOldForm" ref="dataOldForm" label-width="80px">
          <div >
            <div style="text-align: left;padding-bottom: 1%;font: bold 16px 新宋体">一、内容选取</div>
            <el-form-item label="施工时间" prop="planTime">
              <el-date-picker
                disabled
                v-model="dataOldForm.planTime"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <div>
              <el-form-item label="立项名称" prop="planProjectId">
                <el-input disabled v-model="dataOldForm.project" placeholder="立项名称"></el-input>
              </el-form-item>
            </div>
            <el-form-item label="负责工长" prop="planDdId">
              <el-input disabled v-model="dataOldForm.fzgz" placeholder=" "></el-input>
            </el-form-item>
            <el-form-item label="带队人" prop="totalDdId">
              <el-select
                disabled
                v-model="dataOldForm.totalDdId"
                placeholder="选择带队人"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in ryList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="施工人员" prop="oldSg">
              <el-select
                disabled
                v-model="oldSg"
                placeholder="选择施工人员"
                style="width: 100%;"
                multiple
              >
                <el-option
                  v-for="item in ryList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否一天" prop="isOneDay">
              <el-select
                disabled
                v-model="dataOldForm.isOneDay"
                placeholder="请选择"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in isOneDayList"
                  :key="item.dictId"
                  :label="item.name"
                  :value="item.dictId"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div  style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">二、施工内容</div>
          <el-form-item label="施工内容" prop="totalSgSummary">
            <el-input disabled v-model="dataOldForm.totalSgSummary" placeholder="施工内容输入"></el-input>
          </el-form-item>
          <el-form-item label="工具/材料" prop="totalCl">
            <el-input disabled v-model="dataOldForm.totalCl" placeholder="工具/材料"></el-input>
          </el-form-item>
          <el-form-item label="机械" prop="totalJx">
            <el-input disabled v-model="dataOldForm.totalJx" placeholder="机械"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="width: 50%">
        <el-form :model="dataForm"  ref="dataForm"  label-width="80px">
          <div >
            <div style="text-align: left;padding-bottom: 1%;font: bold 16px 新宋体">一、内容选取</div>
            <el-form-item label="施工时间" prop="planTime">
              <el-date-picker
                disabled
                v-model="dataForm.planTime"
                type="date"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
            <div>
              <el-form-item label="立项名称" prop="planProjectId">
                <el-input disabled v-model="dataForm.project" placeholder="立项名称"></el-input>
              </el-form-item>
            </div>
            <el-form-item label="负责工长" prop="planDdId">
              <el-input disabled v-model="dataForm.fzgz" placeholder=" "></el-input>
            </el-form-item>
            <el-form-item label="带队人" prop="totalDdId">
              <el-select
                disabled
                v-model="dataForm.totalDdId"
                placeholder="选择带队人"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in ryList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="施工人员" prop="newSg">
              <el-select
                disabled
                v-model="newSg"
                placeholder="选择施工人员"
                style="width: 100%;"
                multiple
              >
                <el-option
                  v-for="item in ryList"
                  :key="item.userId"
                  :label="item.name"
                  :value="item.userId"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否一天" prop="isOneDay">
              <el-select
                disabled
                v-model="dataForm.isOneDay"
                placeholder="请选择"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in isOneDayList"
                  :key="item.dictId"
                  :label="item.name"
                  :value="item.dictId"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div  style="text-align: left;padding: 5% 0 1% 0;font: bold 16px 新宋体">二、施工内容</div>
          <el-form-item label="施工内容" prop="totalSgSummary">
            <el-input disabled v-model="dataForm.totalSgSummary" placeholder="施工内容输入"></el-input>
          </el-form-item>
          <el-form-item label="工具/材料" prop="totalCl">
            <el-input disabled v-model="dataForm.totalCl" placeholder="工具/材料"></el-input>
          </el-form-item>
          <el-form-item label="机械" prop="totalJx">
            <el-input disabled v-model="dataForm.totalJx" placeholder="机械"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div style="text-align: center">
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="pass()">通过</el-button>
        <el-button type="danger" @click="noPassed()">不通过</el-button>
      </span>
  </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      num: 0, // 跳转标记
      isOneDayList: [],
      dicSgddList: [],
      dicGclbList: [],
      dicSgjdList: [],
      dicJsdwList: [],
      dicZFYList: [],
      dicSGDWList: [],
      dicJLDWList: [],
      dicSJDWList: [],
      ryList: [],
      dataProjectList: [],
      dataContractList: [],
      id: '',
      chooseId: '', // project 选择的id
      oldSg: [],
      newSg: [],
      dataForm: {
        id: '',
        totalDdId: '',
        totalProjectId: '',
        selectPersionId: '',
        totalPersonNum: '',
        isOneDay: '',
        totalSgSummary: '',
        totalCl: '',
        totalJx: '',
        planTime: '',
        totalDate: '',
        status: '',
        approval: ''
      },
      dataOldForm: {
        id: '',
        totalProjectId: '',
        selectPersionId: '',
        totalPersonNum: '',
        isOneDay: '',
        totalSgSummary: '',
        totalCl: '',
        totalJx: '',
        planTime: '',
        totalDdId: '',
        totalDate: '',
        status: '',
        approval: ''
      }
    }
  },
  methods: {
    getDataList (id) {
      this.id = id
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        this.$http.request({
          url: this.$http.adornUrl('/business/businessapproval/info/' + id),
          method: 'get'
        }).then(({data}) => {
          const res = data.businessApproval
          if (data && data.code === 0) {
            this.dataForm = {
              ...JSON.parse(res.approvalData)
            }
            this.dataOldForm = {
              ...JSON.parse(res.approvalOldData)
            }
            this.dataOldForm.selectPersionId.split(',').forEach((item) => {
              this.oldSg.push(parseInt(item))
            })
            this.dataForm.selectPersionId.split(',').forEach((item) => {
              this.newSg.push(parseInt(item))
            })
          }
        })
      })
      this.$http.request({
        url: this.$http.adornUrl('/business/businessworker/allWorkerList'),
        method: 'get'
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.ryList = data.page
          console.log(this.ryList)
        }
      })
    },
    pass () {
      this.$http.request({
        url: this.$http.adornUrl('/business/businessapproval/pass'),
        method: 'post',
        params: this.$http.adornParams({
          'id': this.id,
          'approvalData': JSON.stringify(this.dataForm),
          'approvalType': 5
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    noPassed () {
      this.$http.request({
        url: this.$http.adornUrl('/business/businessapproval/noPass'),
        method: 'post',
        params: this.$http.adornParams({
          'id': this.id,
          'approvalId': this.dataForm.id,
          'approvalType': 5
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      })
    }
  },
  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>
