<template>
  <view>
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true">
      <block slot="backText">返回</block>
      <block slot="content">有限空间作业管理申请</block>
    </cu-custom>
    <view class="form">
      <view class="wui-form-list">
        <view class="cu-form-group">
          <view class="title">管理单位：</view>
          {{ form.APPLY_DEPARTMENT_NAME }}
        </view>
        <view class="cu-form-group">
          <view class="title">作业单位：</view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree')">
                {{ form.WORK_UNIT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree" :selectParent=true :range="treeNode" rangeKey="name"
                      @confirm="zgtreeConfirm($event,'workUnitList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.WORK_UNIT_NAME }}</block>
        </view>
        <view class="cu-form-group">
          <view class="title">作业证编号：</view>
          <input v-model="form.WORK_PERMIT_NUMBER" disabled placeholder="请输入作业证编号"/>
        </view>
        <view class="cu-form-group">
          <view class="title">作业地点：</view>
          <input :disabled="forbidEdit" v-model="form.WORK_LOCATION" placeholder="请输入作业地点"></input>
        </view>

        <view class="cu-form-group">
          <view class="title">地点坐标：</view>
          <button class="cu-btn bg-green shadow" @tap="showMapModal" v-if="!forbidEdit">定位</button>
        </view>
        <view class="cu-form-group" v-if="form.WORK_LONGITUDE">
          <view class="title">经度：</view>
          <view>{{form.WORK_LONGITUDE}}</view>
        </view>
        <view class="cu-form-group" v-if="form.WORK_LATITUDE">
          <view class="titletitle">纬度：</view>
          <view >{{form.WORK_LATITUDE}}</view>
        </view>

        <view class="cu-form-group">
          <view class="title">受限空间名称及编号</view>
          <picker v-if="!forbidEdit" @change="limitspaceChange" :disabled="forbidEdit" :value="form.RESTRICTED_SPACE_INDEX"
                  :range="limitSpaceList" range-key="NAME">
            <view class="picker">
              {{ form.RESTRICTED_SPACE_NAME || '请选择' }}
            </view>
          </picker>
          <view v-else>{{ form.RESTRICTED_SPACE_NAME }}</view>
        </view>
        <view class="cu-form-group">
          <view class="title">作业内容：</view>
          <input :disabled="forbidEdit" v-model="form.CONTENTS_OF_HOMEWORK" placeholder="请输入作业内容"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">主要介质：</view>
          <input :disabled="forbidEdit" v-model="form.MAIN_MEDIUM" placeholder="请输入主要介质"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">主要危害因素：</view>
          <input :disabled="forbidEdit" v-model="form.MAJOR_RISK_FACTORS" placeholder="请输入主要危害因素"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">作业人：</view>
          <input :disabled="forbidEdit" v-model="form.WORKER" placeholder="请输入作业人"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">监护人：</view>
          <input :disabled="forbidEdit" v-model="form.GUARDIAN" placeholder="请输入监护人"></input>
        </view>
<!--        <view class="cu-form-group">-->
<!--          <view class="title">作业时间：</view>-->
<!--          <ruiDatePicker v-if="!forbidEdit" :start="todayDate" fields="minute" :value="form.WORKING_TIME || '请选择'"-->
<!--                         @change="changeWorkingTimeDate"></ruiDatePicker>-->
<!--          <text v-else>{{ form.WORKING_TIME }}</text>-->
<!--        </view>-->

        <view class="cu-form-group ">
          <view class="title">作业开始时间</view>
          <ruiDatePicker v-if="!forbidEdit"
                         :start="dateBegin !== '' ? dateBegin : todayDate"
                         :end="form.WORK_END_DATE !== '' ? form.WORK_END_DATE : '2100-12-31'"
                         fields="minute"
                         :value="form.WORK_START_DATE?form.WORK_START_DATE:''"
                         @change="changeStartDate"
          ></ruiDatePicker>
          <view v-else>{{form.WORK_START_DATE}}</view>
        </view>

        <view class="cu-form-group">
          <view class="title">作业结束时间</view>
          <ruiDatePicker v-if="!forbidEdit"
                         :start="form.WORK_START_DATE !== '' ? form.WORK_START_DATE : todayDate"
                         :end="dateEnd !== '' ? dateEnd : '2100-12-31'"
                         fields="minute"
                         :value="form.WORK_END_DATE?form.WORK_END_DATE:''"
                         @change="changeEndDate"
          ></ruiDatePicker>
          <view v-else>{{form.WORK_END_DATE}}</view>
        </view>

        <block v-if="forbidEdit">
          <view style="padding: 20upx">
            <uni-table border stripe emptyText="暂无更多数据">
              <uni-tr>
                <uni-th align="center" style="font-weight: bold;width: 100upx">序号</uni-th>
                <uni-th align="center" style="font-weight: bold">安全措施</uni-th>
                <uni-th align="center" style="font-weight: bold;width: 180upx">操作</uni-th>
              </uni-tr>
              <uni-tr v-for="(item,index) in measureList" :key="item.PROTECTIVE_MEASURES">
                <uni-td>{{ index + 1 }}</uni-td>
                <uni-td>{{ item.PROTECTIVE_MEASURES }}</uni-td>
                <uni-td>{{ item.STATUS == 1 ? '符合' : '不符合' }}</uni-td>
              </uni-tr>
            </uni-table>
          </view>
          <view class="cu-form-group">
            <view class="title">危害因素辨识：</view>
          </view>
          <view class="ace-content" v-show="oldHazardIdentification && oldHazardIdentification.length > 0">
            <view class="add_pard_item" v-for="(item,index) of oldHazardIdentification" :key="index">
              <view class="cu-form-textarea">
                <textarea disabled v-model="oldHazardIdentification[index]"></textarea>
              </view>
            </view>
          </view>
          <view class="cu-form-group">
            <view class="title">作业安全措施：</view>
          </view>
          <view class="ace-content" v-show="oldWorkSafetyMeasures && oldWorkSafetyMeasures.length > 0">
            <view class="add_pard_item" v-for="(item,index) of oldWorkSafetyMeasures" :key="index">
              <view class="cu-form-textarea">
                <textarea disabled v-model="oldWorkSafetyMeasures[index]"></textarea>
              </view>
            </view>
          </view>
        </block>
        <view class="cu-form-group">
          <view class="title">采样分析人部门：</view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree1')">
                {{ form.SAMPLING_ANALYST_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree1" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'samplingAnalystList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.SAMPLING_ANALYST_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.SAMPLING_ANALYST_DEPARTMENT_NAME">
          <view class="title">采样分析人：</view>
          <picker @change="samplingAnalystChange" :disabled="forbidEdit" :value="form.SAMPLING_ANALYST_INDEX"
                  :range="samplingAnalystList" range-key="NAME">
            <view class="picker">
              {{ form.SAMPLING_ANALYST_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title">作业单位负责人部门：</view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree2')">
                {{ form.WORK_UNIT_MANAGER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree2" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'workUnitManagerList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.WORK_UNIT_MANAGER_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.WORK_UNIT_MANAGER_DEPARTMENT_NAME">
          <view class="title">作业单位负责人：</view>
          <picker @change="workUnitManagerChange" :disabled="forbidEdit" :value="form.WORK_UNIT_MANAGER_INDEX"
                  :range="workUnitManagerList" range-key="NAME">
            <view class="picker">
              {{ form.WORK_UNIT_MANAGER_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title">作业现场负责人部门：</view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree3')">
                {{ form.JOB_SITE_MANAGER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree3" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'jobSiteManagerList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.JOB_SITE_MANAGER_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.JOB_SITE_MANAGER_DEPARTMENT_NAME">
          <view class="title">作业现场负责人：</view>
          <picker @change="jobSiteManagerChange" :disabled="forbidEdit" :value="form.JOB_SITE_MANAGER_INDEX"
                  :range="jobSiteManagerList" range-key="NAME">
            <view class="picker">
              {{ form.JOB_SITE_MANAGER_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title">管理单位负责人部门：</view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree4')">
                {{ form.MANAGEMENT_UNIT_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree4" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'managementUnitList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.MANAGEMENT_UNIT_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.MANAGEMENT_UNIT_DEPARTMENT_NAME">
          <view class="title">管理单位负责人：</view>
          <picker @change="managementUnitChange" :disabled="forbidEdit" :value="form.MANAGEMENT_UNIT_INDEX"
                  :range="managementUnitList" range-key="NAME">
            <view class="picker">
              {{ form.MANAGEMENT_UNIT_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title" style="height: auto">
            <view>完工验收作业单位负责人</view>
            <view>部门：</view>
          </view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree5')">
                {{ form.COMPLETION_ACCEPTANCE_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree5" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'completionAcceptanceList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.COMPLETION_ACCEPTANCE_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.COMPLETION_ACCEPTANCE_DEPARTMENT_NAME">
          <view class="title">完工验收作业单位负责人：</view>
          <picker @change="completionAcceptanceChange" :disabled="forbidEdit" :value="form.COMPLETION_ACCEPTANCE_INDEX"
                  :range="completionAcceptanceList" range-key="NAME">
            <view class="picker">
              {{ form.COMPLETION_ACCEPTANCE_NAME || '请选择' }}
            </view>
          </picker>
        </view>
      </view>
    </view>
    <view class="cu-bar btn-group" style="margin-top: 30upx;">
      <button v-if="!forbidEdit" class="cu-btn bg-blue margin-tb-sm lg" @click="$noMultipleClicks(goSubmit)">提交
      </button>
      <button v-if="forbidEdit" class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goback)">返回</button>
    </view>
    <view class="padding flex flex-direction"></view>
  </view>
</template>

<script>
import {
  basePath,
  corpinfoId,
  loginUser,
  loginSession,
  formatDate
} from '@/common/tool.js';
import tkiTree from "@/components/select-tree/select-tree.vue"
import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue';

export default {
  components: {
    tkiTree,
    ruiDatePicker,
  },
  data() {
    return {
      noClick: true,
      CONFINEDSPACE_ID: '',
      form: {
        APPLY_DEPARTMENT_ID: '',
        APPLY_DEPARTMENT_NAME: '',
        APPLY_USER_ID: '',
        APPLY_USER_NAME: '',
        WORK_UNIT_ID: '',
        WORK_UNIT_NAME: '',
        WORK_PERMIT_NUMBER: '',
        WORK_LOCATION: '',
        WORK_LONGITUDE: '',
        WORK_LATITUDE: '',
        RESTRICTED_SPACE_INDEX: '',
        RESTRICTED_SPACE_NAME: '',
        RESTRICTED_SPACE_ID: '',
        CONTENTS_OF_HOMEWORK: '',
        MAIN_MEDIUM: '',
        MAJOR_RISK_FACTORS: '',
        WORKER: '',
        GUARDIAN: '',
        WORK_START_DATE: '',
        WORK_END_DATE: '',
        SAMPLING_ANALYST_DEPARTMENT_NAME: '',
        SAMPLING_ANALYST_DEPARTMENT_ID: '',
        SAMPLING_ANALYST_INDEX: '',
        SAMPLING_ANALYST_ID: '',
        SAMPLING_ANALYST_NAME: '',
        WORK_UNIT_MANAGER_DEPARTMENT_NAME: '',
        WORK_UNIT_MANAGER_DEPARTMENT_ID: '',
        WORK_UNIT_MANAGER_INDEX: '',
        WORK_UNIT_MANAGER_ID: '',
        WORK_UNIT_MANAGER_NAME: '',
        JOB_SITE_MANAGER_DEPARTMENT_NAME: '',
        JOB_SITE_MANAGER_DEPARTMENT_ID: '',
        JOB_SITE_MANAGER_INDEX: '',
        JOB_SITE_MANAGER_ID: '',
        JOB_SITE_MANAGER_NAME: '',
        MANAGEMENT_UNIT_DEPARTMENT_NAME: '',
        MANAGEMENT_UNIT_DEPARTMENT_ID: '',
        MANAGEMENT_UNIT_INDEX: '',
        MANAGEMENT_UNIT_ID: '',
        MANAGEMENT_UNIT_NAME: '',
        COMPLETION_ACCEPTANCE_DEPARTMENT_NAME: '',
        COMPLETION_ACCEPTANCE_DEPARTMENT_ID: '',
        COMPLETION_ACCEPTANCE_INDEX: '',
        COMPLETION_ACCEPTANCE_ID: '',
        COMPLETION_ACCEPTANCE_NAME: '',
      },
      rules: [
        {name: 'APPLY_DEPARTMENT_NAME', message: '请输入管理单位'},
        {name: 'WORK_UNIT_NAME', message: '请选择作业单位'},
        {name: 'WORK_PERMIT_NUMBER', message: '请输入作业证编号'},
        {name: 'WORK_LOCATION', message: '请输入作业地点'},
        {name: 'WORK_LONGITUDE', message: '请选择作业地点坐标'},
        {name: 'RESTRICTED_SPACE_NAME', message: '请选择受限空间名称及编号'},
        {name: 'CONTENTS_OF_HOMEWORK', message: '请输入作业内容'},
        {name: 'MAIN_MEDIUM', message: '请输入主要介质'},
        {name: 'MAJOR_RISK_FACTORS', message: '请输入主要危害因素'},
        {name: 'WORKER', message: '请输入作业人'},
        {name: 'GUARDIAN', message: '请输入监护人'},
        {name: 'WORK_START_DATE',message:'请选择作业开始时间'},
        {name: 'WORK_END_DATE',message:'请选择作业结束时间'},
        {name: 'SAMPLING_ANALYST_DEPARTMENT_NAME', message: '请选择采样分析人部门'},
        {name: 'SAMPLING_ANALYST_NAME', message: '请选择采样分析人'},
        {name: 'WORK_UNIT_MANAGER_DEPARTMENT_NAME', message: '请选择作业单位负责人部门'},
        {name: 'WORK_UNIT_MANAGER_NAME', message: '请选择作业单位负责人'},
        {name: 'JOB_SITE_MANAGER_DEPARTMENT_NAME', message: '请选择作业现场负责人部门'},
        {name: 'JOB_SITE_MANAGER_NAME', message: '请选择作业现场负责人'},
        {name: 'MANAGEMENT_UNIT_DEPARTMENT_NAME', message: '请选择管理单位负责人部门'},
        {name: 'MANAGEMENT_UNIT_NAME', message: '请选择管理单位负责人'},
        {name: 'COMPLETION_ACCEPTANCE_DEPARTMENT_NAME', message: '请选择完工验收作业单位负责人部门'},
        {name: 'COMPLETION_ACCEPTANCE_NAME', message: '请选择完工验收作业单位负责人'},
      ],
      treeNode: [],
      forbidEdit: false,
      todayDate: formatDate(new Date(), 'yyyy-MM-dd hh:mm'),
      dateBegin: '',
      dateEnd: '',
      limitSpaceList: [],
      samplingAnalystList: [],
      workUnitManagerList: [],
      jobSiteManagerList: [],
      managementUnitList: [],
      completionAcceptanceList: [],
      measureList: [],
      oldHazardIdentification: [],
      oldWorkSafetyMeasures: []
    }
  },
  watch: {
    'form.WORK_START_DATE': {
      handler(val) {
        this.dateEnd = this.addDays(val, 1)
      }
    },
    'form.WORK_END_DATE': {
      handler(val) {
        this.dateBegin = this.addDays(val, -1)
      }
    }
  },
  onLoad(event) {
    if (event.id) {
      this.CONFINEDSPACE_ID = event.id
      this.forbidEdit = true
      this.getData();
    } else {
      this.createWorkNumber()
      // 初始化作业负责人
      this.form.APPLY_DEPARTMENT_ID = loginUser.DEPARTMENT_ID;
      this.form.APPLY_DEPARTMENT_NAME = loginUser.DEPARTMENT_NAME;
      this.form.APPLY_USER_ID = loginUser.USER_ID;
      this.form.APPLY_USER_NAME = loginUser.NAME;
    }
    loginSession();
    this.getDept()
    this.getLimitSpace()
  },
  methods: {
    createWorkNumber() {
      var _this = this;
      uni.request({
        url: basePath + '/app/serialnumber/add',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          TYPE: 'KJ',
          CORPINFO_ID: corpinfoId
        },
        success: (res) => {
          if ("success" === res.data.result) {
            this.$set(_this.form, 'WORK_PERMIT_NUMBER', res.data.pd.NUMBER) //参数map
          }
        }
      });
    },
    getData() {
      var _this = this;
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/confinedspace/goEdit',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          CONFINEDSPACE_ID: _this.CONFINEDSPACE_ID,
        },
        success: (res) => {
          if ("success" === res.data.result) {
            this.form = res.data.pd;
            this.measureList = res.data.measureList;
            this.oldHazardIdentification = res.data.pd.HARM && res.data.pd.HARM.split('$$$')
            this.oldWorkSafetyMeasures = res.data.pd.SAFTETY && res.data.pd.SAFTETY.split('$$$')
            if (Number(res.data.pd.APPLY_STATUS)<0 && res.data.pd.APPLY_STATUS != '-6') this.forbidEdit = false;
            else this.forbidEdit = true;
            uni.hideLoading();
          } else if ("exception" === res.data.result) {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }
        }
      });
    },
    goSubmit() {
      var _this = this;
      let required = true
      this.rules.map(({name, message}) => {
        if (!this.form[name]) {
          uni.showToast({
            icon: 'none',
            title: message,
            duration: 1500
          });
          required = false
        }
      })
      if (!required) {
        return
      }
      var startTime = Date.parse(this.form.WORK_START_DATE + ':00')
      var endTime = Date.parse(this.form.WORK_END_DATE + ':00')
      if ((endTime - startTime) > (24 * 60 * 60 * 1000)) {
        uni.showToast({
          icon: 'none',
          title: '作业申请用时不能超过1天',
          duration: 1500
        });
        return false
      }
      uni.showLoading({
        title: '请稍候'
      })
      let url = ''
      let data = {
        ...this.form,
        APPLY_STATUS: '0',
        CREATOR: loginUser.USER_ID
      }
      if(this.CONFINEDSPACE_ID) {
        url = "/app/confinedspace/edit"
        data.ISDELETE = '0'
        data.APPLY_STATUS = '1'
      } else {
        url = "/app/confinedspace/add"
      }
      uni.request({
        url: basePath + url,
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data,
        success: (res) => {
          uni.showToast({
            icon: 'none',
            title: '保存成功',
            duration: 2000
          });
          _this.goback()
        },
        fail: (err) => {
          uni.hideLoading();
          uni.showModal({
            content: err.errMsg,
            showCancel: false
          });
        }
      })
    },
    // 获取有限空间列表
    getLimitSpace() {
      var _this = this;
      uni.request({
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        url: basePath + '/app/limitspace/listAllSpace?tm=' + new Date().getTime(),
        data: {CORPINFO_ID: corpinfoId},
        success: function (res) {
          _this.limitSpaceList = res.data.varList;
        }
      });
    },
    limitspaceChange(e) {
      console.log(this.limitSpaceList[e.detail.value])
      this.form.RESTRICTED_SPACE_INDEX = e.detail.value
      this.form.RESTRICTED_SPACE_NAME = this.limitSpaceList[e.detail.value].NAME + this.limitSpaceList[e.detail.value].NUMBER
      this.form.RESTRICTED_SPACE_ID = this.limitSpaceList[e.detail.value].LIMITSPACE_ID
    },
    samplingAnalystChange(e) {
      this.form.SAMPLING_ANALYST_INDEX = e.detail.value;
      this.form.SAMPLING_ANALYST_ID = this.samplingAnalystList[e.detail.value].USER_ID;
      this.form.SAMPLING_ANALYST_NAME = this.samplingAnalystList[e.detail.value].NAME;
    },
    workUnitManagerChange(e) {
      this.form.WORK_UNIT_MANAGER_INDEX = e.detail.value;
      this.form.WORK_UNIT_MANAGER_ID = this.workUnitManagerList[e.detail.value].USER_ID;
      this.form.WORK_UNIT_MANAGER_NAME = this.workUnitManagerList[e.detail.value].NAME;
    },
    jobSiteManagerChange(e) {
      this.form.JOB_SITE_MANAGER_INDEX = e.detail.value;
      this.form.JOB_SITE_MANAGER_ID = this.jobSiteManagerList[e.detail.value].USER_ID;
      this.form.JOB_SITE_MANAGER_NAME = this.jobSiteManagerList[e.detail.value].NAME;
    },
    managementUnitChange(e) {
      this.form.MANAGEMENT_UNIT_INDEX = e.detail.value;
      this.form.MANAGEMENT_UNIT_ID = this.managementUnitList[e.detail.value].USER_ID;
      this.form.MANAGEMENT_UNIT_NAME = this.managementUnitList[e.detail.value].NAME;
    },
    completionAcceptanceChange(e) {
      this.form.COMPLETION_ACCEPTANCE_INDEX = e.detail.value;
      this.form.COMPLETION_ACCEPTANCE_ID = this.completionAcceptanceList[e.detail.value].USER_ID;
      this.form.COMPLETION_ACCEPTANCE_NAME = this.completionAcceptanceList[e.detail.value].NAME;
    },
    changeWorkingTimeDate(e) {
      this.form.WORKING_TIME = e
    },
    getDept() {
      var _this = this;
      uni.request({
        url: basePath + '/app/sys/listTree', //部门下拉接口
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          CORPINFO_ID: corpinfoId,
        },
        success: (res) => {
          if ("success" == res.data.result) {
            _this.treeNode = eval(res.data.zTreeNodes);
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      });
      uni.request({
        url: basePath + '/app/relevantunit/listAllTree',
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          CORPINFO_ID: corpinfoId,
        },
        success: (res) => {
          if ("success" === res.data.result) {
            _this.hotWorkOperatorDepartmentList = JSON.parse(res.data.varList);
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      });
      uni.request({
        url: basePath + '/dictionaries/getLevels',
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          DICTIONARIES_ID: "63cf39931a89467594efc441bf67f6dd",
        },
        success: (res) => {
          if ("success" === res.data.result) {
            _this.hotWorkMethodList = res.data.list
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      });
    },
    showZgTree(ref) {
      this.$refs[ref]._show();
    },
    zgtreeConfirm(e, list) {
      if (list === "workUnitList") {
        this.form.WORK_UNIT_ID = e[0].id;
        this.form.WORK_UNIT_NAME = e[0].name;
      }
      if (list === "samplingAnalystList") {
        this.form.SAMPLING_ANALYST_DEPARTMENT_ID = e[0].id;
        this.form.SAMPLING_ANALYST_DEPARTMENT_NAME = e[0].name;
        this.form.SAMPLING_ANALYST_INDEX = '';
        this.form.SAMPLING_ANALYST_ID = '';
        this.form.SAMPLING_ANALYST_NAME = '';
      }
      if (list === "workUnitManagerList") {
        this.form.WORK_UNIT_MANAGER_DEPARTMENT_ID = e[0].id;
        this.form.WORK_UNIT_MANAGER_DEPARTMENT_NAME = e[0].name;
        this.form.WORK_UNIT_MANAGER_INDEX = '';
        this.form.WORK_UNIT_MANAGER_ID = '';
        this.form.WORK_UNIT_MANAGER_NAME = '';
      }
      if (list === "jobSiteManagerList") {
        this.form.JOB_SITE_MANAGER_DEPARTMENT_ID = e[0].id;
        this.form.JOB_SITE_MANAGER_DEPARTMENT_NAME = e[0].name;
        this.form.JOB_SITE_MANAGER_INDEX = '';
        this.form.JOB_SITE_MANAGER_ID = '';
        this.form.JOB_SITE_MANAGER_NAME = '';
      }
      if (list === "managementUnitList") {
        this.form.MANAGEMENT_UNIT_DEPARTMENT_ID = e[0].id;
        this.form.MANAGEMENT_UNIT_DEPARTMENT_NAME = e[0].name;
        this.form.MANAGEMENT_UNIT_INDEX = '';
        this.form.MANAGEMENT_UNIT_ID = '';
        this.form.MANAGEMENT_UNIT_NAME = '';
      }
      if (list === "completionAcceptanceList") {
        this.form.COMPLETION_ACCEPTANCE_DEPARTMENT_ID = e[0].id;
        this.form.COMPLETION_ACCEPTANCE_DEPARTMENT_NAME = e[0].name;
        this.form.COMPLETION_ACCEPTANCE_INDEX = '';
        this.form.COMPLETION_ACCEPTANCE_ID = '';
        this.form.COMPLETION_ACCEPTANCE_NAME = '';
      }
      this.getUserList(list, e[0].id);
    },
    zgtreeCancel(e) {
      this.isUps = false;
    },
    getUserList(list, DEPARTMENT_ID) {
      //发送 post 请求
      var _this = this;
      uni.request({
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        url: basePath + '/app/sys/listUser',
        data: {
          DEPARTMENT_ID, NOMAIN:'1',
          tm: new Date().getTime()
        },
        success: function (res) {
          if ("success" == res.data.result) {
            _this[list] = res.data.userList;
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      })
    },
    goback() {
      uni.navigateBack({
        delta: 1
      });
      uni.hideLoading();
    },

    changeStartDate(e) {
      this.form.WORK_START_DATE = e
      this.$forceUpdate();//强制刷新
    },
    changeEndDate(e) {
      this.form.WORK_END_DATE = e
      this.$forceUpdate();//强制刷新
    },

    //日期加上天数后的新日期.
    addDays(date,days){
      var nd = new Date(date);
      nd = nd.valueOf();
      nd = nd + days * 24 * 60 * 60 * 1000;
      nd = new Date(nd);
      return formatDate(nd, 'yyyy-MM-dd hh:mm');
    },

    /** 坐标定位 */
    showMapModal() {
      var _this = this
      uni.navigateTo({
        url: '/pages/map/map',
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          acceptDataFromOpenedPage: function (e) {
            // console.log(e.data)
            // console.info(e.data.longitue)
            _this.form.WORK_LONGITUDE = e.data.longitue;
            _this.form.WORK_LATITUDE = e.data.latitude;
            // console.info(_this.pd)
          }
        },
      })
    }
  }
}
</script>

<style>
.right_icon {
  position: relative;
  padding-right: 36upx;
  width: 200upx;
  text-align: right;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.right_icon ::after {
  font-family: cuIcon;
  display: block;
  content: "\e6a3";
  position: absolute;
  font-size: 17px;
  color: #8799a3;
  line-height: 50px;
  width: 30px;
  text-align: center;
  top: -28upx;
  bottom: 0;
  right: -22upx;
  margin: auto;
}

.modal_content {
  display: flex;
  text-align: left;
}

.modal_left {
  flex-basis: 50%;
  padding: 50upx 20upx;
  border-right: 1px solid #000000;
}

.modal_right {
  flex-basis: 50%;
  padding: 50upx;
}

.modal_left_title, .modal_right_title {
  font-size: 16px;
  color: #000000;
  font-weight: 700;
}

.checkbox-item {
  display: flex;
  align-items: center;
  padding: 0 30upx;
  min-height: 100upx;
  background-color: #ffffff;
  border-bottom: 1upx solid #ddd;
}

.checkbox-item:last-child {
  border-bottom: none;
}
</style>
