<template>
  <div class="contradiction-div">
    <Tabs value="name1" v-model="tabValue">
      <TabPane label="基本信息" name="1">
        <div class="title-style">身份信息</div>
        <Form :model="formInline" ref="form1" :disabled="params.what === 'edit'" label-position="left" :label-width="110">
          <div v-for="(item, index) in formInline.userList" v-bind:key="index">
            <Row :gutter="16">
              <Col span="6">
                <FormItem label="当事人类型：" :prop="'userList.' + index + '.event_user_type'" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                  <Select v-model="item.event_user_type" style="width:90%;" @on-change="checkUserType(item.event_user_type)">
                    <Option value="1">自然人</Option>
                    <Option value="2">社会组织</Option>
                    <Option value="3">企业</Option>
                    <Option value="4">政府机关</Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="6" v-if="flag === 'add'">
                <Button type="primary" v-if="index == 0" @click="addPerson">添加当事人</Button>
                <Button type="error" v-else-if="index > 0" @click="deletePerson(index)">删除当事人</Button>
              </Col>
            </Row>
            <Row v-if="item.event_user_type == '1'">
              <Col span="6">
                <FormItem label="当事人：" :prop="'userList.' + index + '.event_user_name'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_user_name" style="width:90%;" placeholder="请输入当事人姓名"></Input>
                </FormItem>
              </Col>
              <Col span="6">
<!--                <FormItem label="身份证号码：" :prop="'userList.' + index + '.event_cardno'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">-->
                  <FormItem label="身份证号码：" :prop="'userList.' + index + '.event_cardno'" >

                  <Input v-model="item.event_cardno" style="width:90%;" placeholder="请输入身份证号码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="联系电话：" :prop="'userList.' + index + '.event_tel'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_tel" style="width:90%;" placeholder="请输入联系电话"></Input>
                </FormItem>
              </Col>
            </Row>
            <Row v-if="item.event_user_type == '2'" :gutter="16">
              <Col span="6">
                <FormItem label="机构代表：" :prop="'userList.' + index + '.event_represent'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_represent" style="width:90%;" placeholder="请输入机构代表"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="身份证号码：" :prop="'userList.' + index + '.event_cardno'" >
                  <Input v-model="item.event_cardno" style="width:90%;" placeholder="请输入身份证号码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="机构代码：" :prop="'userList.' + index + '.tyshxydm'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.tyshxydm" style="width:90%;" placeholder="请输入机构代码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="机构名称：" :prop="'userList.' + index + '.event_user_name'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_user_name" style="width:90%;" placeholder="请输入机构名称"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="联系电话：" :prop="'userList.' + index + '.event_tel'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_tel" style="width:90%;" placeholder="请输入联系电话"></Input>
                </FormItem>
              </Col>
            </Row>
            <Row v-if="item.event_user_type == '3'">
              <Col span="6">
                <FormItem label="法定代表：" :prop="'userList.' + index + '.event_represent'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_represent" style="width:90%;" placeholder="请输入法定代表"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="身份证号码：" :prop="'userList.' + index + '.event_cardno'" >
                  <Input v-model="item.event_cardno" style="width:90%;" placeholder="请输入身份证号码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="社会信用代码：" :prop="'userList.' + index + '.tyshxydm'" >
                  <Input v-model="item.tyshxydm" style="width:90%;" placeholder="请输入社会信用代码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="单位名称：" :prop="'userList.' + index + '.event_user_name'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_user_name" style="width:90%;" placeholder="请输入单位名称"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="联系电话：" :prop="'userList.' + index + '.event_tel'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_tel" style="width:90%;" placeholder="请输入联系电话"></Input>
                </FormItem>
              </Col>
            </Row>
            <Row v-if="item.event_user_type == '4'">
              <Col span="6">
                <FormItem label="社会信用代码：" :prop="'userList.' + index + '.tyshxydm'" >
                  <Input v-model="item.tyshxydm" style="width:90%;" placeholder="请输入社会信用代码"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="单位名称：" :prop="'userList.' + index + '.event_user_name'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_user_name" style="width:90%;" placeholder="请输入单位名称"></Input>
                </FormItem>
              </Col>
              <Col span="6">
                <FormItem label="联系电话：" :prop="'userList.' + index + '.event_tel'" :rules="[{required: true, message: '必填', trigger: 'blur'}]">
                  <Input v-model="item.event_tel" style="width:90%;" placeholder="请输入联系电话"></Input>
                </FormItem>
              </Col>
            </Row>
          </div>
        </Form>
        <div class="title-style">事件信息</div>
        <Form :model="formInline" ref="form2" label-position="left" :label-width="110">
          <Row>
            <Col span="6">
              <FormItem label="事件大类：" prop="info" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                <Select v-model="formInline.info" :disabled="params.what === 'edit'" @on-change="changeDispute(formInline.info)" style="width:90%">
                  <Option v-for="item in dictData.list1" :value="JSON.stringify(item)" :key="item.value">{{ item.label }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem label="事件小类：" prop="event_type_id" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                <Select v-model="formInline.event_type_id" :disabled="params.what === 'edit'" style="width:90%">
                  <Option v-for="item in dictData.list2" :value="item.value" :key="item.value">{{ item.label }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem label="重点事件：" prop="is_point_event" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                <Select v-model="formInline.is_point_event" :disabled="params.what === 'edit'" style="width:90%">
                  <Option value="1">是</Option>
                  <Option value="2">否</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem label="发生时间：" prop="occurrence_time" :rules="[{required: true, type: 'date', message: '必填', trigger: 'change' }]">
                <DatePicker type="datetime" v-model="formInline.occurrence_time" :disabled="params.what === 'edit'" placeholder="请选择发生时间"></DatePicker>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span="6">
              <FormItem label="是否化解：" prop="is_resolve" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                <Select v-model="formInline.is_resolve" :disabled="params.what === 'edit' && !params.dispose" style="width:90%">
                  <Option value="1">是</Option>
                  <Option value="2">否</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="5">
<!--              <FormItem label="事件发生地：" prop="city_id" :rules="[{required: true, message: '必填', trigger: 'change' }]">-->
                <FormItem label="事件发生地：" prop="city_id" >
                <Select v-model="formInline.city_id" :disabled="params.what === 'edit'" @on-change="changeArea('2',formInline.city_id)" placeholder="请选择市" style="width:90%">
                  <Option v-for="item in areaData.list1" :value="item.parent_id" :key="item.parent_id">{{ item.name }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="area_id" :rules="[{required: true, message: '必填', trigger: 'change' }]" style="margin-left:-100px;">
                <Select v-model="formInline.area_id" :disabled="params.what === 'edit'" @on-change="changeArea('3',formInline.area_id)" placeholder="请选择区" style="width:90%">
                  <Option v-for="item in areaData.list2" :value="item.parent_id" :key="item.parent_id">{{ item.name }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="street_id" :rules="[{required: true, message: '必填', trigger: 'change' }]" style="margin-left:-100px;">
                <Select v-model="formInline.street_id" :disabled="params.what === 'edit'" @on-change="changeArea('4',formInline.street_id)" placeholder="请选择街道" style="width:90%;color: #0C0C0C">
                  <Option v-for="item in areaData.list3" :value="item.parent_id" :key="item.parent_id">{{ item.name }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="community_id" :rules="[{required: true, message: '必填', trigger: 'change' }]" style="margin-left:-100px;">
                <Select v-model="formInline.community_id" :disabled="params.what === 'edit'" placeholder="请选择社区" style="width:90%">
                  <Option v-for="item in areaData.list4" :value="item.parent_id" :key="item.parent_id">{{ item.name }}</Option>
                </Select>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="garden_id" style="margin-left:-100px;">
                <Input v-model="formInline.garden_id" :disabled="params.what === 'edit'" style="width:90%;margin-left:0px;" placeholder="请输入网格" ></Input>
              </FormItem>
            </Col>
            <!-- <Col span="3">
              <FormItem prop="building_id" style="margin-left:-100px;">
                <Input v-model="formInline.building_id" :disabled="params.what === 'edit'" style="width:90%;margin-left:0px;" placeholder="请输入楼" ></Input>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="unit_id" style="margin-left:-100px;">
                <Input v-model="formInline.unit_id" :disabled="params.what === 'edit'" style="width:90%;margin-left:0px;" placeholder="请输入单元"></Input>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="floor_id" style="margin-left:-100px;">
                <Input v-model="formInline.floor_id" :disabled="params.what === 'edit'" style="width:90%;margin-left:0px;" placeholder="请输入层"></Input>
              </FormItem>
            </Col>
            <Col span="3">
              <FormItem prop="doorplate_id" style="margin-left:-100px;">
                <Input v-model="formInline.doorplate_id" :disabled="params.what === 'edit'" style="width:90%;margin-left:0px;" placeholder="请输入户"></Input>
              </FormItem>
            </Col> -->
          </Row>
          <Row>
            <Col span="24">
              <FormItem label="详细地址：" prop="address" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.address" :disabled="params.what === 'edit'" type="textarea" :rows="2"  placeholder="请输入详细地址"></Input>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span="24">
              <FormItem label="事件简述：" prop="dispute_description" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.dispute_description" :disabled="params.what === 'edit'" type="textarea" :rows="4"  placeholder="请输入详细地址"></Input>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span="6">
              <FormItem label="上报人：">
                <Input disabled v-model="serverUserInfo.name" style="width:90%"></Input>
              </FormItem>
            </Col>
            <Col span="6">
              <FormItem label="上报人单位：">
                <Input disabled v-model="serverUserInfo.company_name" style="width:90%"></Input>
              </FormItem>
            </Col>
          </Row>
        </Form>
        <div class="title-style" v-if="formInline.is_resolve == '1'">化解过程</div>
        <Form :model="formInline" ref="form3" :disabled="params.what === 'edit' && !params.dispose" label-position="left" :label-width=150 v-if="formInline.is_resolve == '1'">
          <Row>
            <Col span="8">
              <FormItem label="化解人：" prop="resolve_name" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.resolve_name" style="width:80%"  placeholder="请输入化解人"></Input>
              </FormItem>
            </Col>
            <Col span="8">
              <FormItem label="化解人所属单位：" prop="resolve_unit" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.resolve_unit" style="width:80%"  placeholder="请输入化解人所属单位"></Input>
              </FormItem>
            </Col>
            <Col span="8">
              <FormItem label="化解层级：" prop="resolve_hierarchy" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Select v-model="formInline.resolve_hierarchy" style="width:80%">
                  <Option value="1">省级</Option>
                  <Option value="2">市级</Option>
                  <Option value="3">县级</Option>
                  <Option value="4">乡镇街道</Option>
                  <Option value="5">村/社区</Option>
                </Select>
              </FormItem>
            </Col>
            </Row>
          <Row>
            <Col span="8">
            <FormItem label="化解方式：" prop="resolve_hierarchy" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
              <Select v-model="formInline.resolve_way " style="width:80%">
                <Option value="1">人民调解</Option>
                <Option value="2">行政调解</Option>
                <Option value="3">司法调解</Option>
                <Option value="4">行业调解</Option>
                <Option value="5">仲裁</Option>
                <Option value="6">诉讼</Option>
                <Option value="7">其他</Option>
              </Select>
            </FormItem>
          </Col>
            <Col span="8">
              <FormItem label="化解时间：" prop="resolve_time" :rules="[{required: true, type: 'date', message: '必填', trigger: 'change' }]">
                <DatePicker type="datetime" v-model="formInline.resolve_time" placeholder="请选择发生时间" style="width:80%"></DatePicker>
              </FormItem>
            </Col>
            <Col span="8">
              <FormItem label="化解是否满意：" prop="is_satisfaction" :rules="[{required: true, message: '必填', trigger: 'change' }]">
                <Select v-model="formInline.is_satisfaction" placeholder="请选择是否满意" style="width:80%">
                  <Option value="1">是</Option>
                  <Option value="2">否</Option>
                </Select>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span="24">
              <FormItem label="化解过程描述：" prop="resolve_process" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.resolve_process" type="textarea" :rows="4" placeholder="请选择化解过程描述"></Input>
            </FormItem>
            </Col>
          </Row>
          <Row>
            <Col span="24">
              <FormItem label="附件上传：" prop="resolve_process">
                <Upload action="http://jilinmdjf.lngov.top/api/ac/jilinsscgsdp/uploadService/uploadFile"
                        :show-upload-list="false" :before-upload="beforeUpload">
                  <Button icon="ios-cloud-upload-outline">上传图片</Button>
                </Upload>
              </FormItem>
            </Col>
          </Row>
          <img :src="imageUrl" alt="">
          <Row>
            <Col span="24">
              <div class="demo-upload-list" v-for="(item, index) in imgArr" v-bind:key="index">
                <template>
                  <img :src="item.url">
                  <div class="demo-upload-list-cover">
                      <Icon type="ios-eye-outline" @click.native="handleView(item, index)"></Icon>
                      <Icon type="ios-trash-outline" v-if="params.what !== 'edit'" @click.native="handleRemove(index)"></Icon>
                  </div>
                </template>
              </div>
              <!-- <img v-if="imgUrl" :src="imgUrl" alt="" style="width:100px;height:100px;"> -->
            </Col>
          </Row>
        </Form>
        <div class="title-style" v-if="params.level == 'street'">处置情况</div>
        <Form :model="formInline" ref="form4" :disabled="params.what === 'edit' &&  params.level !== 'community' && !params.dispose" label-position="left" :label-width="120" v-if="params.level == 'street'">
          <Row>
            <Col span="24">
              <FormItem label="处置过程描述：" prop="resolve_process" :rules="[{required: true, message: '必填', trigger: 'blur' }]">
                <Input v-model="formInline.log_result" type="textarea" :rows="4" placeholder="请输入处置过程描述"></Input>
            </FormItem>
            </Col>
          </Row>
        </Form>
        <div class="flex-div">
          <Button type="primary" class="mr10" v-if="serverUserInfo.company_grade === '6' && flag === 'add' && formInline.is_resolve !== '1'" @click="report('form1')">上报</Button>
          <Button type="primary" class="mr10" v-if="params.level === 'street' && formInline.status !== '3' && params.dispose === 'dispose'" @click="dispose('form4')">处置</Button>
          <Button type="primary" class="mr10" v-if="serverUserInfo.company_grade === '6' && this.formInline.status !== '3' && formInline.is_resolve === '1'" @click="complete()">办结</Button>
          <!-- <Button type="primary" class="mr5" @click="returnBack(row)" v-if="formInline.status === '1'  && type === '2'">退回</Button> -->
          <!-- <Button type="success" class="mr10">办结</Button> -->
        </div>
      </TabPane>
      <TabPane label="进度信息" name="2" v-if="params.id">
        <Card style="width:500px;">
          <Steps :current="processList.length" direction="vertical">
            <Step v-for="(item, index) in processList" v-bind:key="index">
              <template slot="title">已完成：{{item.hierarchy_name}}</template>
              <template slot="content">
                <div v-if="item.receive_time">受理时间：{{item.receive_time}}</div>
                <div v-if="item.assign_time">分派时间：{{item.assign_time}}</div>
                <div v-if="item.back_time">退回时间：{{item.back_time}}</div>
                <div v-if="item.complete_time">完成时间：{{item.complete_time}}</div>
                <div v-if="item.resolve_time">化解时间：{{item.resolve_time}}</div>
              </template>
            </Step>
          </Steps>
        </Card>
      </TabPane>
    </Tabs>
    <Modal v-model="modal1" title="提示">
      <p>{{confirmTtile}}</p>
      <div slot="footer">
        <Button type="default" @click="modal1 = false">取消</Button>
        <Button type="primary" @click="save">确定</Button>
      </div>
    </Modal>
    <Modal title="查看图片" v-model="visible">
      <img :src="imgName" v-if="visible" style="width: 100%">
    </Modal>
  </div>
</template>
<script>
import {
  insertEvent,
  selectDictList,
  selectCityList,
  getEventLogByCreateId,
  getEventLogById,
  // updateEventAcceptance,
  insertEventEnd, insertEventFlowLog, findFlowLogProcessList, getEventAllAsc, uploadFile, selectEventIdByAttachList
} from '@/api/contradiction.js'
import { datetime2str } from '@/api/eventlist.js'
import validateData from '@/view/contradiction/validate.js'
import axios from 'axios'
export default {
  inject: ['reload'],
  name: 'registerAdd',
  data () {
    return {
      imgName: '',
      visible: false,
      tabValue: '1',
      confirmTtile: '',
      modal1: false,
      isEmpty: validateData.isEmpty,
      formInline: {
        userList: [
          { event_user_type: '' }
          // ... more items
        ],
        info: '',
        garden_id: '',
        building_id: ''
      },
      rules: {},
      formData: {
        personList: [{
          event_user_type: ''
        }]
      },
      dictData: {
        list1: [],
        list2: []
      },
      dictNextData: [],
      disputeInfo: {
        event_type: '1' // 事件
      },
      areaData: {
        list1: [],
        list2: [],
        list3: [],
        list4: []
      },
      param: {
        pageNo: 1,
        pageSize: 10
      },
      params: this.$route.params,
      url: '',
      dataParam: {},
      successFlag: [],
      type: this.$route.params.type,
      flag: this.$route.query.type,
      processList: [],
      imgUrl: '',
      imgArr: [],
      uniUuid: '',
      imageUrl: null,
      urlList: [],
      url111: ''
    }
  },
  computed: {
    serverUserInfo () {
      return this.$store.state.user.severUserInfo
    }
  },
  watch: {
    '$route' (to, from) {
      // 路由发生变化时的处理逻辑
      console.log('Route changed from', from, 'to', to)
      if (to.query.type) {
        this.getReload()
        // this.params.what = 'add'
        // this.formInline = {
        //   userList: [
        //     { event_user_type: '' }
        //     // ... more items
        //   ],
        //   info: '',
        //   garden_id: '',
        //   building_id: ''
        // }
      }
      // 你可以在这里根据路由变化执行相应的操作
    }
  },
  mounted () {
    this.imgArr = []
    this.getDictList('1')
    this.getCityData('1')
    this.url = this.type === '1' ? getEventLogByCreateId : this.type === '2' ? getEventLogById : this.type === '3' ? getEventLogById : getEventAllAsc // type=1是网格事件列表，2是社区事件列表，3是街道区市省事件列表，不传是事件查询列表，是单独的列表页面
    if (this.params.id) {
      this.getInfo()
      this.getImg()
    }
    this.getProcessList()
  },
  methods: {
    getReload () {
      this.reload()
    },
    getDictList (level, id, event_type_id, event_category_id) {
      selectDictList({ type: 'event_category', parent_id: id }).then(res => {
        if (res.data.errcode === 0) {
          this.dictData['list' + level] = res.data.data
          if (event_category_id) {
            let list1 = this.dictData['list' + level]
            list1.forEach(element => {
              if (element.label === event_category_id) {
                this.formInline.info = JSON.stringify(element)
                if (this.formInline.event_type_id) {
                  this.getDictList('2', element.id, this.formInline.event_type_id, '')
                }
              }
            })
          }
          if (event_type_id) {
            this.dictData.list2.forEach(element => {
              if (event_type_id === element.label) {
                this.formInline.event_type_id = element.value
              }
            })
          }
          return
        }
        this.$Message.error(res.errmsg)
      })
    },
    getCityData (level, id) {
      selectCityList({ parent_id: id }).then(res => {
        if (res.data.errcode === 0) {
          this.areaData['list' + level] = res.data.data
          return
        }
        this.$Message.error(res.errmsg)
      })
    },
    changeDispute (item) {
      this.formInline.event_category_id = JSON.parse(item).value
      this.getDictList('2', JSON.parse(item).id)
    },
    changeArea (level, parent_id) {
      this.getCityData(level, parent_id)
    },
    addPerson () { // 添加当事人
      this.$refs['form1'].validate((valid) => {
        if (valid) {
          console.log('success')
          this.formInline.userList.push({ event_user_type: '' })
          // this.insertEventData()
        } else {
          console.log('fail')
          return false
        }
      })
    },
    checkUserType (type) {
      console.log(type, '类型')
    },
    deletePerson (index) {
      if (confirm('确定删除该当事人吗？')) {
        this.formInline.userList.splice(index, 1)
      }
    },
    report () {
      this.successFlag = []
      if (this.formInline.is_resolve === '1') { // 如果已经化解
        this.$refs['form1'].validate((valid) => {
          if (valid) {
            console.log('success1')
            this.successFlag.push(true)
          } else {
            console.log('fail')
            this.successFlag.push(false)
            return false
          }
        })
        this.$refs['form2'].validate((valid) => {
          if (valid) {
            console.log('success2')
            this.successFlag.push(true)
            // this.insertEventData()
          } else {
            console.log('fail')
            this.successFlag.push(false)
            return false
          }
        })
        this.$refs['form3'].validate((valid) => {
          if (valid) {
            console.log('success3')
            this.successFlag.push(true)
            // this.insertEventData()
          } else {
            console.log('fail')
            this.successFlag.push(false)
            return false
          }
        })
      } else { // 未化解
        this.$refs['form1'].validate((valid) => {
          if (valid) {
            console.log('success1')
            this.successFlag.push(true)
          } else {
            console.log('fail')
            this.successFlag.push(false)
            return false
          }
        })
        this.$refs['form2'].validate((valid) => {
          if (valid) {
            console.log('success2')
            this.successFlag.push(true)
          } else {
            console.log('fail')
            this.successFlag.push(false)
            return false
          }
        })
      }
      let flag = this.successFlag.every(item => {
        return item === true
      })
      console.log(flag, 'flagflag')
      if (flag) {
        this.insertEventData()
      }
    },
    dispose () { // 处置
      this.$refs['form4'].validate((valid) => {
        if (valid) {
          console.log('success')
          if (this.formInline.is_resolve === '1') { // 已化解
            this.$refs['form3'].validate((valid) => {
              if (valid) {
                let data = {
                  id: this.formInline.event_id,
                  log_result: this.formInline.resolve_process,
                  is_special_tasks: this.formInline.is_special_tasks,
                  status: this.formInline.status,
                  flow_version: this.formInline.flow_version,
                  flow_id: this.formInline.flow_id,
                  log_type: '2',
                  is_resolve: this.formInline.is_resolve,
                  resolve_name: this.formInline.resolve_name,
                  resolve_unit: this.formInline.resolve_unit,
                  resolve_hierarchy: this.formInline.resolve_hierarchy,
                  resolve_time: datetime2str(this.formInline.resolve_time),
                  is_satisfaction: this.formInline.is_satisfaction,
                  resolve_process: this.formInline.resolve_process
                }
                insertEventFlowLog(data).then(ret => {
                  if (ret.data.errcode === 0) {
                    this.$Message.success('操作成功')
                    this.$router.push({
                      name: 'contradictionRegister',
                      query: {
                        type: this.params.type
                      }
                    })
                  }
                })
              }
            })
          } else { // 未化解
            this.$Message.error('事件未化解不可进行处置')
          }
          // 处置
        } else {
          console.log('fail')
          return false
        }
      })
    },
    complete () { // 确认办结
      this.url = insertEventEnd
      // this.dataParam = {
      //   is_special_tasks: '2',
      //   id: this.formInline.id,
      //   event_id: this.formInline.event_id,
      //   flow_version: this.formInline.flow_version,
      //   status: this.formInline.status,
      //   flow_id: this.formInline.flow_id,
      //   log_type: '2'
      // }
      let param = {}
      if (this.formInline.occurrence_time) {
        this.formInline.occurrence_time = datetime2str(this.formInline.occurrence_time)
      }
      if (this.formInline.resolve_time) {
        this.formInline.resolve_time = datetime2str(this.formInline.resolve_time)
      }
      param = Object.assign(this.formInline)
      param['userList'] = this.formInline.userList
      param['event_source'] = '1'
      param['reporting_name'] = this.serverUserInfo.name
      param['reporting_unit'] = this.serverUserInfo.company_name
      param['event_type'] = '1'
      param['urlList'] = this.urlList
      console.log(param, '办结入参')
      this.dataParam = param
      this.modal1 = true
      this.confirmTtile = '此事件已处置完成，是否办结？'
    },
    insertEventData () { // 调用上报接口
      console.log('调用上报接口')
      let param = {}
      if (this.formInline.occurrence_time) {
        this.formInline.occurrence_time = datetime2str(this.formInline.occurrence_time)
      }
      if (this.formInline.resolve_time) {
        this.formInline.resolve_time = datetime2str(this.formInline.resolve_time)
      }
      param = Object.assign(this.formInline)
      param['userList'] = this.formInline.userList
      param['event_source'] = '1'
      param['reporting_name'] = this.serverUserInfo.name
      param['reporting_unit'] = this.serverUserInfo.company_name
      param['event_type'] = '1'
      param['urlList'] = this.urlList
      console.log(param, '入参1')
      insertEvent(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success('上报成功')
          this.$router.push({
            name: 'incidentIncidentEventList',
            query: {
              type: '1'
            }
          })
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    save () {
      this.url(this.dataParam).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success('成功')
          this.modal1 = false
          this.$router.push({
            name: 'incidentIncidentEventList'
          })
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    getInfo () {
      this.url({ id: this.params.id }).then(res => {
        if (res.data.errcode === 0) {
          this.formInline = res.data.data
          if (this.formInline.city_id) {
            this.getCityData('2', this.formInline.city_id)
          }
          if (this.formInline.area_id) {
            this.getCityData('3', this.formInline.area_id)
          }
          if (this.formInline.street_id) {
            this.getCityData('4', this.formInline.street_id)
          }
          console.log(this.dictData, 'dddd')
          if (this.formInline.event_category_id) {
            this.getDictList('1', '', '', this.formInline.event_category_id) // level,一级id，二级id，用于回显的一级id
            // this.dictData.list1.forEach(element => {
            //   console.log(element, '循环')
            //   if (this.formInline.event_category_id === element.label) {
            //     console.log('匹配上了')
            //     this.formInline.info = JSON.stringify(element)
            //     this.getDictList('2', element.id, this.formInline.event_type_id)
            //     // this.formInline.event_type_id = element.value
            //   }
            // })
          }
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    getImg () {
      selectEventIdByAttachList({ id: this.params.id }).then(res => {
        if (res.data.errcode === 0) {
          let imgList = res.data.data
          imgList.forEach(element => {
            // 把后台返回的uuid传给接口
            let url = this.getImgUrl(element.uuid, element.suffix)
            console.log(url, 'memeiemieiei')
          })
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    getImgUrl (uuid, suffix) {
      let that = this
      axios({
        method: 'get',
        responseType: 'arraybuffer',
        url: '/api/ac/jilinsscgsdp/uploadService/getObsObject?uuid=' + uuid + '&&suffix=' + suffix
      }).then(function (res) {
        const base64String = btoa(
          new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
        )
        let url = 'data:image/png;base64,' + base64String
        that.imgArr.push({ url: url })
        // 调用下载方法，把后端传过来的流传给fileDownload方法
        // this.fileDownload(res.data, fileName)
      })
    },
    arrayBufferToBase64 (buffer) {
      var binary = ''
      var bytes = new Uint8Array(buffer)
      var len = bytes.byteLength
      for (var i = 0; i < len; i++) {
        binary += String.fromCharCode(bytes[i])
      }
      return window.btoa(binary)
    },
    getProcessList () {
      findFlowLogProcessList({ event_id: this.params.id }).then(res => {
        if (res.data.errcode === 0) {
          this.processList = res.data.data
          return
        }
        this.$Message.success(res.data.errmsg)
      })
    },
    // 上传图片前转base64
    beforeUpload (file) {
      let imgObj = {}
      const reader = new FileReader()
      reader.onload = (e) => {
        imgObj.url = e.target.result
        this.imgArr.push(imgObj)
      }
      reader.readAsDataURL(file)
      let formdata = new FormData()
      formdata.append('file', file)
      formdata.append('fileName', file.name)
      let form = {
        business_type: 'jlEvent'
      }
      formdata.append('json', JSON.stringify(form))
      uploadFile(formdata, form).then(res => {
        let len = this.imgArr.length
        this.imgArr[len - 1]['uuid'] = res.data.data.uuid
        this.urlList.push(res.data.data)
      })
      // return isLt2M
      // this.upPicData.fileName = this.upPicData.fileName + '.' + file.type.substring(6)
      // let that = this
      // const reader = new FileReader()
      // reader.readAsDataURL(file)
      // reader.onload = () => {
      //   let index = reader.result.indexOf('base64,') + 7
      //   that.upPicData.file = reader.result.substring(index)
      //   that.upPic(that.upPicData)
      // }
      // return false
    },
    handleView (item, index) {
      this.imgName = item.url
      this.visible = true
    },
    handleRemove (index) {
      this.imgArr.splice(index, 1)
      this.urlList.splice(index, 1)
      console.log(this.imgArr, this.urlList)
    }
  }
}
</script>
<style scoped lang="less">
 /deep/ input:disabled,textarea:disabled {
    opacity: 1;
    -webkit-text-fill-color: #515a6e;
    font-size: 14px;
  }

  /* 修改被禁用的Select组件的文本颜色 */
 /deep/ .ivu-select-disabled .ivu-select-selected-value{
    color: #515a6e; /* 修改为你想要的颜色 */
     font-size: 14px;
}
 /deep/ .ivu-select-disabled .ivu-select-placeholder{
    color: #515a6e; /* 修改为你想要的颜色 */
     font-size: 14px;
}
/deep/ .ivu-input-disabled{
 color: #515a6e !important; /* 修改为你想要的颜色 */
  font-size: 14px;
}
/deep/ .ivu-form .ivu-form-item-label{
  font-size: 14px;
}
.contradiction-div {
    // padding: 10px;
    background: #fff;
    padding:10px;
     font-size: 14px;
    .title-style {
      padding: 8px 12px;
      background-color: #ecf8ff;
      border-radius: 4px;
      border-left: 5px solid #50bfff;
      margin: 15px 0;
      font-size: 16px;
      width: 100%;
    }
  }
  .red-star {
    color: red;
  }
  .flex-div {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  //.Input{
  //  color: black;
  //}
  .mr10 {
    margin-right: 10px;
  }
</style>
