<template>
  <div class="container">
    <div style="padding: 0px 20px">
      <div ref="lxHeader">
        <LxHeader icon="md-apps" text="雨管巡查管理" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content"></div>
          <slot>
            <div>
              <el-select class="vm10" filterable v-model="searchFields.area_id" placeholder="请选择所属片区">
                  <el-option
                    v-for="item in selects.areasList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              <!-- <Input style="width: 200px; margin-right: 10px" v-model="searchFields.KeyWord" placeholder="关键字搜索" /> -->
              <Button type="primary" @click="load" style="margin-left: 10px">查询</Button>
              <Button type="primary" @click="edit()" style="margin-left: 10px">新增</Button>
            </div>
          </slot>
        </LxHeader>
      </div>
      <div ref="lxTable">
        <el-table :data="tableData" class="v-table" :height="tableHeight" style="width: 100%">
          <el-table-column type="index" width="50" fixed label="序号" align="center"> </el-table-column>
          <el-table-column :prop="column.field" :align="column.align" v-for="(column,index) in columns"
            :label="column.title" :width="column.width" :fixed="column.fixed">
            <template slot-scope="scope">
              <div v-if="column.type=='opt'">
                <Button ghost size="small" @click="show(scope.row)" type="primary" style="margin-left: 10px;"
                  v-if="scope.row['status']==2||scope.row['status']==3">查看</Button>

                <Button v-if="scope.row['status']==0" ghost size="small" @click="edit(scope.row)" type="primary"
                  style="margin-left: 10px;">编辑</Button>
                <Button v-if="scope.row['status']==0" ghost size="small" @click="show(scope.row)" type="primary"
                  style="margin-left: 10px;">审核</Button>
                <Button v-if="scope.row['status']==1" ghost size="small" @click="show(scope.row)" type="primary"
                  style="margin-left: 10px;">办结</Button>
                <Button ghost size="small" @click="del(scope.row)" type="error" style="margin-left: 10px;">删除</Button>
              </div>
              <div v-else-if="column.type=='type'">
                <el-tag v-if="scope.row[column.field]==1">日常雨水设施</el-tag>
                <el-tag v-if="scope.row[column.field]==2">在建工地巡查</el-tag>
              </div>
              <div v-else-if="column.type=='status'">
                <el-tag v-if="scope.row[column.field]==0">待审核</el-tag>
                <el-tag type="success" v-if="scope.row[column.field]==1">已审核</el-tag>
                <el-tag type="warning" v-if="scope.row[column.field]==2">已办结</el-tag>
                <el-tag type="info" v-if="scope.row[column.field]==3">已退回</el-tag>

              </div>
              <div v-else-if="column.type=='format'">
                {{scope.row[column.field]?scope.row[column.field].name:""}}
              </div>
              <!-- <div v-else-if="column.type=='end_type'">
                    <el-tag v-if="scope.row[column.field]==0">无</el-tag>
                    <el-tag  type="danger" v-if="scope.row[column.field]==1" >违法转办</el-tag>
                </div> -->
              <div v-else>{{scope.row[column.field]}}</div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination">
          <el-pagination @current-change="handleCurrentChange" :current-page="paginations.page"
            :page-size="paginations.page_size" background layout="prev, pager, next" :total="paginations.total">
          </el-pagination>
        </div>
      </div>
      <el-dialog title="雨管养护类型选择" :visible.sync="rainTypeVisible" width="60%">
        <div class="dialogConcent">
          <el-radio v-model="rainType" label="1">日常雨水设施</el-radio>
          <el-radio v-model="rainType" label="2">在建工地</el-radio>
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button @click="resetrainType()">取 消</el-button>
          <el-button type="primary" v-preventReClick @click="submitRainType()">确认</el-button>
        </div>
      </el-dialog>

      <!-- 审核 -->
      <el-dialog :title="rainTitle" :visible.sync="dialogFormDetailVisible" width="60%">
        <div class="dialogConcent">
          <el-scrollbar style="flex: 1">
            <!-- 疏通疏挖 -->
            <el-form v-if="rainType==1" :model="formdetail" :rules="{}" ref="formdetail" label-position="right"
              :label-width="formLabelWidth">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="巡查内容" prop="ask_content_id">
                    <div v-for="item in equiementList">
                      <div v-if="item.id==form.ask_content_id">
                        {{item.value}}
                      </div>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="所在位置" prop="address">
                    {{form.address}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="经度" prop="longitude">
                    {{form.longitude}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="纬度" prop="latitude">
                    {{form.latitude}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="描述" prop="content">
                    {{form.content}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="现场照片" prop="files_list" class="files_check">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="filesList"
                      ref="pictureUploads">
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-form-item label="是否异常" prop="is_unusual">
                    <el-tag v-if="form.is_unusual==0">否</el-tag>
                    <el-tag type="warning" v-if="form.is_unusual==1">丢失</el-tag>
                    <el-tag type="success" v-if="form.is_unusual==2">破损</el-tag>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_unusual!=0">
                  <el-form-item label="异常处置建议" prop="tip">
                    {{form.tip}}
                  </el-form-item>
                </el-col>
                <el-col :span="10">
                  <el-form-item label="是否现场处理" prop="is_scene">
                    <el-tag v-if="form.is_scene==0">否</el-tag>
                    <el-tag type="success" v-if="form.is_scene==1">丢失</el-tag>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_scene==1">
                  <el-form-item label="现场处理结果" prop="result">
                    {{form.result}}
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_scene==1">
                  <el-form-item label="处理后照片" prop="files_end_list" class="files_check">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="dealFilesList"
                      ref="pictureUploads">
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>

                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-form-item label="备注" prop="content">
                    <el-input type="textarea" v-model="formdetail.content" placeholder="请填写备注"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==1">
                  <el-form-item label="转办类型" prop="end_type">
                    <el-radio-group v-model="formdetail.end_type">
                      <el-radio :label="0">无</el-radio>
                      <el-radio :label="1">养护转办</el-radio>
                      <el-radio :label="2">违法转办</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==2||nowstatus==3">
                  <el-form-item label="转办类型">
                    <el-tag v-if="end_types==0">无</el-tag>
                    <el-tag type="warning" v-if="end_types==1">养护转办</el-tag>
                    <el-tag type="warning" v-if="end_types==2">违法转办</el-tag>
                  </el-form-item>
                </el-col>

                <el-col :span="24" v-if="nowstatus==1 && formdetail.end_type==1">
                    <el-form-item label="要求完成时间" prop="complete_date">
                      <el-date-picker
                        style="width:100%"
                        v-model="form.complete_date"
                        type="datetime"
                        placeholder="选择时间"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        >
                      </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==1 && formdetail.end_type==1">
                 <el-form-item label="备注" prop="remarks">
                   <el-input type="textarea" v-model="form.remarks" placeholder="请填写备注" autocomplete="off"></el-input>
                 </el-form-item>
                </el-col>






                <el-col :span="24" v-if="nowstatus==2||nowstatus==3">
                  <el-form-item label="处理日志" prop="">

                  </el-form-item>
                  <el-table :data="rainMaintainLogs" style="width: 90%;margin: 0 auto;">
                    <el-table-column prop="created_at" label="日期" width="180">
                    </el-table-column>
                    <el-table-column prop="content" label="内容">
                    </el-table-column>
                    <!-- <el-table-column
                              prop="end_type"
                              label="有无违法转办"
                              >

                            </el-table-column> -->
                    <el-table-column prop="type_name" label="操作结果">
                    </el-table-column>

                    <el-table-column prop="admin_id" label="操作人" width="180">
                    </el-table-column>
                  </el-table>

                </el-col>

              </el-row>

            </el-form>


            <!-- 在建工地 -->
            <el-form v-if="rainType==2" :model="formdetail" :rules="{}" ref="formdetail" label-position="right"
              :label-width="formLabelWidth">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="工地名称" prop="name">
                    {{form.name}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="所在位置" prop="address">
                    {{form.address}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="经度" prop="longitude">
                    {{form.longitude}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="纬度" prop="address">
                    {{form.latitude}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地编号" prop="number">
                    {{form.number}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地类型" prop="type">
                    <div v-for="item in siteType">
                      <div v-if="item.id==form.type">
                        {{item.value}}
                      </div>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地状态" prop="status">
                    <div v-for="item in siteStatus">
                      <el-tag v-if="item.id==form.status">{{item.value}}</el-tag>
                    </div>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="24">
                      <el-form-item label="工地类型" prop="type">
                          <el-input v-model="form.type" placeholder="工地类型" autocomplete="off"></el-input>
                      </el-form-item>

                  </el-col> -->
                <el-col :span="24">
                  <el-form-item label="备注" prop="remark">
                    {{form.remark}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="描述" prop="content">
                    {{form.content}}
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="现场照片" prop="files_list" class="files_check">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="filesList"
                      ref="pictureUploads">
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="是否违法" prop="is_law">
                    <el-tag v-if="form.is_law==0">否</el-tag>
                    <el-tag v-if="form.is_law==1">是</el-tag>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_law==1">
                  <el-form-item label="违规内容" prop="break_id">
                    <div v-for=" item in siteLaw">
                      <div v-if="item.id==form.break_id">
                        {{item.value}}
                      </div>
                    </div>
                  </el-form-item>
                </el-col>

                <el-col :span="24">
                  <el-form-item label="备注" prop="content">
                    <el-input type="textarea" v-model="formdetail.content" placeholder="请填写备注"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==1">
                  <el-form-item label="有无违法转办" prop="end_type">
                    <el-radio-group v-model="formdetail.end_type">
                      <el-radio :label="0">无</el-radio>
                      <el-radio :label="1">养护转办</el-radio>
                      <el-radio :label="2">违法转办</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==1 && formdetail.end_type==1">
                    <el-form-item label="要求完成时间" prop="complete_date">
                      <el-date-picker
                        style="width:100%"
                        v-model="form.complete_date"
                        type="datetime"
                        placeholder="选择时间"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        >
                      </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==1 && formdetail.end_type==1">
                 <el-form-item label="备注" prop="remarks">
                   <el-input type="textarea" v-model="form.remarks" placeholder="请填写备注" autocomplete="off"></el-input>
                 </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==2||nowstatus==3">
                  <el-form-item label="有无违法转办">
                    <el-tag v-if="end_types==0">无</el-tag>
                    <el-tag type="warning" v-if="end_types==1">养护转办</el-tag>
                    <el-tag type="warning" v-if="end_types==2">违法转办</el-tag>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="nowstatus==2||nowstatus==3">
                  <el-form-item label="处理日志" prop="">

                  </el-form-item>
                  <el-table :data="rainMaintainLogs" style="width: 90%;margin: 0 auto;">
                    <el-table-column prop="created_at" label="日期" width="180">
                    </el-table-column>
                    <el-table-column prop="content" label="内容">
                    </el-table-column>
                    <el-table-column prop="type_name" label="操作结果">
                    </el-table-column>

                    <el-table-column prop="admin_id" label="操作人" width="180">
                    </el-table-column>
                  </el-table>

                </el-col>


              </el-row>

            </el-form>
          </el-scrollbar>
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button @click="resetFormDetail('formdetail')">取 消</el-button>
          <el-button v-if="nowstatus==0" type="primary" v-preventReClick @click="submitFormDetail('formdetail','1')">审核
          </el-button>
          <el-button v-if="nowstatus==1" type="primary" v-preventReClick @click="submitFormDetail('formdetail','2')">办结
          </el-button>
          <el-button v-if="nowstatus==1" type="danger" v-preventReClick @click="submitFormDetail('formdetail','3')">退回
          </el-button>

        </div>
      </el-dialog>




      <!-- 编辑 -->
      <el-dialog :title="rainTitle" :visible.sync="dialogFormVisible" width="60%">
        <div class="dialogConcent">
          <el-scrollbar style="flex: 1">
            <!-- 日常雨水设施 -->
            <el-form v-if="rainType==1" :model="form" :rules="rules" ref="form" label-position="right"
              :label-width="formLabelWidth">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="巡查内容" prop="ask_content_id">
                    <el-select class="width100" v-model="form.ask_content_id" placeholder="请选择巡查内容">
                      <el-option v-for="item in equiementList" :key="item.id" :label="item.value" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="所在位置" prop="address">
                    <avue-input-map :params="mapparams"  placeholder="请选择地图" v-model="mapform"></avue-input-map>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="经度" prop="longitude">
                    <el-input disabled="" v-model="form.longitude" placeholder="经度" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="纬度" prop="address">
                    <el-input disabled="" v-model="form.latitude" placeholder="纬度" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="描述" prop="content">
                    <el-input type="textarea" v-model="form.content" placeholder="请填写描述" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="现场照片" prop="files_list">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="filesList"
                      ref="pictureUpload" :auto-upload="true" :data="uploadOther"
                      :on-success="function(responsose,file,fileList) {return handlesuccess(responsose,file,fileList,1)}">
                      <i slot="default" class="el-icon-plus"></i>
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
                            <i class="el-icon-delete"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="是否异常" prop="is_unusual">
                    <el-radio-group v-model="form.is_unusual">
                      <el-radio :label="0">否</el-radio>
                      <el-radio :label="1">丢失</el-radio>
                      <el-radio :label="2">破损</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_unusual!=0">
                  <el-form-item label="异常处置建议" prop="tip">
                    <el-input type="textarea" v-model="form.tip" placeholder="请填写异常处置建议" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="10">
                  <el-form-item label="是否现场处理" prop="is_scene">
                    <el-radio-group v-model="form.is_scene">
                      <el-radio :label="0">否</el-radio>
                      <el-radio :label="1">是</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_scene==1">
                  <el-form-item label="现场处理结果" prop="result">
                    <el-input type="textarea" v-model="form.result" placeholder="请填写现场处理结果" autocomplete="off">
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_scene==1">
                  <el-form-item label="处理后照片" prop="files_end_list">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="dealFilesList"
                      ref="pictureUploads" :limit="3" :auto-upload="true" :data="uploadOther"
                      :on-success="function(responsose,file,fileList) {return handlesuccess(responsose,file,fileList,2)}">
                      <i slot="default" class="el-icon-plus"></i>
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
                            <i class="el-icon-delete"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-col>


              </el-row>

            </el-form>


            <!-- 在建工地 -->
            <el-form v-if="rainType==2" :model="form" :rules="rules" ref="form" label-position="right"
              :label-width="formLabelWidth">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="工地名称" prop="name">
                    <el-select v-model="form.name" allow-create filterable @change="buildchange" class="width100"
                      placeholder="请选择工地或新建工地">
                      <el-option v-for="item in buildList" :key="item.id" :label="item.name" :value="item">
                      </el-option>
                    </el-select>
                    <!-- <el-input disabled="" v-model="form.name" placeholder="工地名称" autocomplete="off"></el-input> -->
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="所在位置" prop="address">
                    <avue-input-map :params="mapparams" placeholder="请选择地图" v-model="mapform"></avue-input-map>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="经度" prop="longitude">
                    <el-input disabled="" v-model="form.longitude" placeholder="经度" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="纬度" prop="address">
                    <el-input disabled="" v-model="form.latitude" placeholder="纬度" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地编号" prop="number">
                    <el-input v-model="form.number" placeholder="工地编号" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地类型" prop="type">
                    <el-select class="width100" v-model="form.type" placeholder="请选择">
                      <el-option v-for="item in siteType" :key="item.id" :label="item.value" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="工地状态" prop="status">
                    <el-radio v-model="form.status" v-for="item in siteStatus" :label="item.id">{{item.value}}
                    </el-radio>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="24">
                      <el-form-item label="工地类型" prop="type">
                          <el-input v-model="form.type" placeholder="工地类型" autocomplete="off"></el-input>
                      </el-form-item>

                  </el-col> -->
                <el-col :span="24">
                  <el-form-item label="备注" prop="remark">
                    <el-input type="textarea" v-model="form.remark" placeholder="备注" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="描述" prop="content">
                    <el-input type="textarea" v-model="form.content" placeholder="备注" autocomplete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="现场照片" prop="files_list">
                    <el-upload action="/api/admin/upload-file" list-type="picture-card" :file-list="filesList"
                      ref="pictureUpload" :auto-upload="true" :data="uploadOther"
                      :on-success="function(responsose,file,fileList) {return handlesuccess(responsose,file,fileList,1)}">
                      <i slot="default" class="el-icon-plus"></i>
                      <div slot="file" slot-scope="{file}">
                        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
                        <span class="el-upload-list__item-actions">
                          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                            <i class="el-icon-zoom-in"></i>
                          </span>
                          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
                            <i class="el-icon-delete"></i>
                          </span>
                        </span>
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="是否违法" prop="is_law">
                    <el-radio-group v-model="form.is_law">
                      <el-radio :label="0">否</el-radio>
                      <el-radio :label="1">是</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24" v-if="form.is_law==1">
                  <el-form-item label="违规内容" prop="break_id">
                    <el-select class="width100" v-model="form.break_id" placeholder="请选择违规内容">
                      <el-option v-for="item in siteLaw" :key="item.id" :label="item.value" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>




              </el-row>

            </el-form>

          </el-scrollbar>
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button @click="resetForm('form')">取 消</el-button>
          <el-button type="primary" v-preventReClick @click="submitForm('form')">保存</el-button>
        </div>
      </el-dialog>

      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt="">
      </el-dialog>





    </div>
  </div>
</template>

<script>
  import {
    listall,
    get,
    del,
    update,
    getbuilding,
    storeequipment,
    saveequipment,
    storebuilding,
    savebuilding,
  } from '../../../api/rain/inspection.js'
  import {
    getToken
  } from '@/utils/auth'
  import {
    getparameteritem
  } from '../../../api/system/dictionary.js'
  import { listarea } from '../../../api/basic/area.js'
  import LxHeader from "@/components/LxHeader/index.vue";
  import AvueMap from 'avue-plugin-map'

  export default {
    components: {
      LxHeader,
      AvueMap
    },
    data() {
      return {
        tableHeight: 0,
        rainTypeVisible: false,
        rainType: "1",
        dialogFormVisible: false,
        dialogFormDetailVisible: false,
        formLabelWidth: "120px",
        dialogImageUrl: "",
        dialogVisible: false,
        rainTitle: "日常雨水设施",
        tableData: [],
        mapparams: {
          zoom: 11,
        },
        mapform: [],
        tableHeight: 0,
        searchFields: {
          area_id: ""
        },
        selects:{
          areasList:[{
            id:"",
            name:"所有"
          }]
        },
        paginations: {
          page: 1,
          page_size: 15,
          total: 0
        },
        filesList: [],
        dealFilesList: [],
        rainMaintainLogs: [],
        end_types: 0,
        disabled: false,
        uploadOther: {
          token: ""
        },
        idname: "",
        nowstatus: 0,
        buildList: [],
        siteType: [],
        siteLaw: [],
        equiementList: [],
        siteStatus: [{
          id: 1,
          value: "在建"
        }, {
          id: 2,
          value: "完工"
        }],
        form: {
          content: "",
          ask_content_id: "",
          is_unusual: 0,
          is_scene: 0,
          result: "",
          tip: "",
          longitude: "",
          latitude: "",
          address: "",
          files_list: [],
          files_end_list: [],

          building_site_id: "",
          name: "",
          number: "",
          type: "",
          status: 0,
          remark: "",
          is_law: 0,
          break_id: ""
        },
        formdetail: {
          status: 0,
          end_type: 0,
          content: ""
        },

        rules: {
          content: [{
            required: true,
            message: '请填写描述',
            trigger: 'blur',
          }]
        },

        columns: [{
            field: "address",
            title: "地址",
            type: "string",
            align: "left",
            width: 360
          },
          {
            field: "type",
            title: "类型",
            type: "type",
            align: "center",
            width: 180
          },
          {
            field: "status",
            title: "状态",
            type: "status",
            align: "center",
            width: 180
          },
          // {
          //   field: "end_type",
          //   title: "结办类型",
          //   type: "end_type",
          //   align: "center",
          //   width:160
          // },
          {
            field: "admin",
            title: "提交人",
            type: "format",
            align: "center",
            width: 180
          },
          {
            field: "created_at",
            title: "提交日期",
            type: "string",
            align: "center",
            width: 180
          },
          {
            field: "操作",
            title: "操作",
            width: 220,
            type: "opt",
            fixed: "right"
          }
        ],
      }
    },
    created() {
      this.initLoad();
      this.load();

    },
    watch: {
      mapform(newVal, oldVal) {
        this.form.longitude = newVal[0];
        this.form.latitude = newVal[1];
        // if(this.rainType!=4){
        this.form.address = newVal[2];
        // }
      }
    },
    methods: {
      buildchange(val) {
        if (Object.prototype.toString.call(val) === '[object Object]') {
          this.mapform = [val.longitude, val.latitude, val.address]
          this.form.longitude = val.longitude
          this.form.latitude = val.latitude
          this.form.address = val.address
          this.form.number = val.number
          this.form.type = parseInt(val.type)
          this.form.status = val.status
          this.form.remark = val.remark
          this.form.building_site_id = val.id
          this.form.name = val.name

        }
        //判断对象

      },
      initLoad() {
        var that = this;
        var clientHeight = document.documentElement.clientHeight
        var lxHeader_height = 96.5; //查询 头部
        var paginationHeight = 37; //分页的高度
        var topHeight = 50; //页面 头部
        let tableHeight = clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
        that.tableHeight = tableHeight;

        this.uploadOther.token = getToken();

        getparameteritem('siteType').then(res => {
          that.siteType = res.detail
        })
        getparameteritem('siteLaw').then(res => {
          that.siteLaw = res.detail
        })
        getparameteritem('equiementList').then(res => {
          that.equiementList = res.detail
        })

        getbuilding().then(res => {
          this.buildList = res
        })

        listarea({
          page: 1,
          page_size: 99
        }).then(res => {
          for(var m of res.data){
            that.selects.areasList.push({
              id:m.id,
              name:m.name
            })
          }
        })


      },
      handleCurrentChange(page) {
        this.paginations.page = page;
        this.load();
      },
      load() {
        listall({
          page: this.paginations.page,
          page_size: this.paginations.page_size,
          area_id: this.searchFields.area_id
        }).then(response => {
          this.tableData = response.data;
          this.paginations.total = response.total;
        }).catch(error => {
          console.log(error)
          reject(error)
        });



      },
      info(obj) {
        var that = this;
        get(obj.id).then(res => {
          let result = Object.assign(that.form, res);
          // this.$set(that.form,res)
          that.rainType = result.type;
          that.nowstatus = result.status;
          that.rainMaintainLogs = result.rain_maintain_logs;
          that.end_types = result.end_type
          if (that.rainType == 1) {
            that.rainTitle = "日常雨水设施"
          } else if (that.rainType == 2) {
            that.rainTitle = "在建工地"
          }
          switch (result.type) {
            case 1:
              that.form = result.rain_equipment_info;
              that.form.rain_equipment_id = result.rain_equipment_id;
              that.idname = "rain_equipment_id"
              that.mapform = [result.rain_equipment_info.longitude, result.rain_equipment_info.latitude, result.rain_equipment_info.address]
              let _files = [];
              for (var mod of result.rain_equipment_info.rain_equipment_files) {
                let m = Object.assign({}, mod);
                m.url = mod.files.url;
                m.id = mod.files.id;
                m.photoType = "before";
                _files.push(m);
              }
              that.filesList = _files;

              let _filesafter = [];
              for (var mod of result.rain_equipment_info.rain_equipment_end_files) {
                let m = Object.assign({}, mod);
                m.url = mod.files.url;
                m.id = mod.files.id;
                m.photoType = "after";
                _filesafter.push(m);
              }
              that.dealFilesList = _filesafter;
              break;
            case 2:
              that.form = result.building_site_info;
              let building_site = result.building_site_info.building_site
              that.form.building_site_id =
              that.form.address = building_site.address
              that.form.latitude=building_site.latitude
              that.form.longitude=building_site.longitude
              that.form.name=building_site.name
              that.form.number=building_site.number
              that.form.remark=building_site.remark
              that.form.status=building_site.status
              that.form.type=parseInt(building_site.type)
              that.form.building_site_id = building_site.id
              that.form.building_site_content_id = result.building_site_content_id;
              that.idname = "building_site_content_id"
              that.mapform = [building_site.longitude, building_site.latitude, building_site.address]
              let discharge_files = [];
              for (var mod of result.building_site_info.building_site_content_files) {
                let m = Object.assign({}, mod);
                m.url = mod.files.url;
                m.id = mod.files.id;
                m.photoType = "before";
                discharge_files.push(m);
              }
              that.filesList = discharge_files;

              break;

          }
          that.formdetail.id = result.id
          console.log("detail",that.filesList)

        }).catch(error => {
          //reject(error)
        })
      },

      show(obj) {
        this.dialogFormDetailVisible = true;
        this.info(obj)
      },

      edit(obj) {
        var that = this;
        this.form = this.$options.data().form
        that.filesList = [];
        that.dealFilesList = [];
        that.mapform = ['', '', ''];
        if (obj) {
          that.info(obj);
          this.dialogFormVisible = true;
        } else {
          this.dialogFormVisible = false
          this.rainTypeVisible = true
        }

      },
      del(obj) {
        var that = this;
        if (obj) {
          this.$Modal.confirm({
            title: '确认要删除数据？',
            onOk: () => {
              del(obj.id).then(response => {
                this.$Message.success('操作成功');
                that.load();
              }).catch(error => {
                console.log(error)
                reject(error)
              })
            },
            onCancel: () => {
              //this.$Message.info('Clicked cancel');
            }
          });
        }
      },

      submitForm(formName) {
        var that = this;
        var listUrlbefore = []
        for (var m of this.filesList) {
          m.photoType = "before";
          if (m.response)
            listUrlbefore.push({
              "upload_id": m.response.id
            });
          else
            listUrlbefore.push({
              "upload_id": m.id
            });
        }
        this.form.files_list = listUrlbefore;
        let listUrlafter = [];
        for (var m of this.dealFilesList) {
          if (m.response)
            listUrlafter.push({
              "upload_id": m.response.id
            });
          else
            listUrlafter.push({
              "upload_id": m.upload_id
            });
        }
        this.form.files_end_list = listUrlafter

        this.$refs[formName].validate((valid) => {
          if (valid) {
            that.submitAll(that.rainType, that.form[this.idname])
          } else {
            this.$Message.error('数据校验失败');
            console.log('error submit!!');
            return false;
          }
        });
      },
      submitFormDetail(formName, status) {

        var that = this;
        that.formdetail.status = status
        console.log(that.formdetail);


        update(that.formdetail).then(response => {
          this.$Message.success('操作成功');
          that.load();
          that.dialogFormDetailVisible = false;
        }).catch(error => {
          //reject(error)
        })

      },
      resetForm(formName) {
        var that = this;
        that.filesList = [];
        that.dealFilesList = [];
        that.mapform = ['', '', ''];
        this.$refs[formName].resetFields();
        that.dialogFormVisible = false;
        that.dialogFormDetailVisible = false;
      },
      resetFormDetail(formName) {
        var that = this;
        that.filesList = [];
        that.dealFilesList = [];
        that.mapform = ['', '', ''];
        that.form = {};
        that.rainMaintainLogs = []
        that.end_types = 0;
        that.formdetail = {
          status: 0,
          end_type: 0,
          content: ""
        }
        that.dialogFormVisible = false;
        that.dialogFormDetailVisible = false;
      },
      handleRemove(file) {
        if (file.photoType == "before") {
          for (var i = 0; i < this.filesList.length; i++) {
            if (this.filesList[i].url == file.url) {
              this.filesList.splice(i, 1)
            }
          }
        } else if (file.photoType == "after") {
          for (var i = 0; i < this.dealFilesList.length; i++) {
            if (this.dealFilesList[i].url == file.url) {
              this.dealFilesList.splice(i, 1)
            }
          }

        }
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handlesuccess(response, file, fileList, index) {
        if (index == 1) {
          file.photoType = "before"
          this.filesList = fileList;
          // this.form.files_list = listUrl;
        } else {

          file.photoType = "after"
          this.dealFilesList = fileList
        }
      },

      resetrainType() {
        this.rainTypeVisible = false
      },
      submitRainType() {
        var that = this
        this.rainTypeVisible = false
        if (that.rainType == 1) {
          that.rainTitle = "日常雨水设施"
        } else if (that.rainType == 2) {
          that.rainTitle = "在建工地"
        }
        this.dialogFormVisible = true;
      },


      submitAll(type, id) {
        var that = this;

        // return
        // that.form.type = type;
        console.log("that.form", that.form);
        // return;
        switch (parseInt(type)) {
          case 1:
            if (id) {
              saveequipment(that.form).then(response => {
                this.$Message.success('操作成功');
                that.load();
                that.dialogFormVisible = false;
              }).catch(error => {
                //reject(error)
              })
            } else {
              storeequipment(that.form).then(response => {
                this.$Message.success('操作成功');
                that.load();
                that.dialogFormVisible = false;
              }).catch(error => {
                //reject(error)
              })
            }
            break;
          case 2:
            if (id) {
              savebuilding(that.form).then(response => {
                this.$Message.success('操作成功');
                that.load();
                that.dialogFormVisible = false;
              }).catch(error => {
                //reject(error)
              })
            } else {
              storebuilding(that.form).then(response => {
                this.$Message.success('操作成功');
                that.load();
                that.dialogFormVisible = false;
              }).catch(error => {
                //reject(error)
              })
            }
            break;



        }





      }

    }
  }
</script>

<style>
  .dialogConcent {
    overflow-y: auto;
  }

  .width100 {
    width: 100%;
  }

  .files_check .el-upload.el-upload--picture-card {
    display: none;
  }
  .vm10 input{
    height:32px;vertical-align: middle;
  }
  .vm10 .el-select__caret.el-input__icon.el-icon-arrow-up{
    line-height: 30px;
  }
</style>
