<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>
          <input v-model="form.NUMBERING" disabled placeholder="请输入编号"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">吊装地点：</view>
          <input :disabled="forbidEdit" v-model="form.HOISTING_LOCATION" placeholder="请输入吊装地点"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">吊装机具：</view>
          <input :disabled="forbidEdit" v-model="form.HOISTING_EQUIPMENT" placeholder="请输入吊装机具"></input>
        </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.LIFTING_OPERATION_MANAGER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'liftingOperationManagerList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.LIFTING_OPERATION_MANAGER_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.LIFTING_OPERATION_MANAGER_DEPARTMENT_NAME">
          <view class="title">吊装作业负责人：</view>
          <picker @change="liftingOperationManagerChange" :disabled="forbidEdit" :value="form.LIFTING_OPERATION_MANAGER_INDEX"
                  :range="liftingOperationManagerList" range-key="NAME">
            <view class="picker">
              {{ form.LIFTING_OPERATION_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('tkiTree1')">
                {{ form.SAFETY_GUARDIAN_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree1" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'safetyGuardianList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.SAFETY_GUARDIAN_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.SAFETY_GUARDIAN_DEPARTMENT_NAME">
          <view class="title">安全监护人：</view>
          <picker @change="safetyGuardianChange" :disabled="forbidEdit" :value="form.SAFETY_GUARDIAN_INDEX"
                  :range="safetyGuardianList" range-key="NAME">
            <view class="picker">
              {{ form.SAFETY_GUARDIAN_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title">起重司机：</view>
          <button class="cu-btn round bg-blue" v-if="!forbidEdit" @click="openMoreSelect('cityMore')">添加</button>
        </view>
        <view class="cu-form-group" v-if="form.CRANE_DRIVER_NAME.length !== 0">
          <uni-table border stripe emptyText="暂无更多数据" style="flex:1;margin: 20upx 0">
            <uni-tr>
              <uni-td>姓名</uni-td>
              <uni-td>作业证号</uni-td>
            </uni-tr>
            <uni-tr v-for="(item,index) in form.CRANE_DRIVER_NAME" :key="item">
              <uni-td>{{ form.CRANE_DRIVER_NAME[index] }}</uni-td>
              <uni-td>{{ form.CRANE_DRIVER_NUMBER[index] }}</uni-td>
            </uni-tr>
          </uni-table>
        </view>
        <uni-popup ref="cityMore" type="bottom" :maskClick="false">
          <more-select
              title="选择起重司机"
              :cityData="craneDriverList"
              @closeCity="handleCraneDriver('close')"
              @queryCity="handleCraneDriver('query')"
              @switchCity="switchCraneDriver"
              @chooseCity="chooseCraneDriver"
              :cityIndex="cityIndex"
              :cityIdArr="form.CRANE_DRIVER_ID"
              :maxCount="99"
          ></more-select>
        </uni-popup>
        <view class="cu-form-group">
          <view class="title">作业开始时间：</view>
          <ruiDatePicker v-if="!forbidEdit" :start="todayDate" fields="minute" :value="form.JOB_START_TIME || '请选择'"
                         @change="changeJobStartTime"></ruiDatePicker>
          <text v-else>{{ form.JOB_START_TIME }}</text>
        </view>
        <view class="cu-form-group">
          <view class="title">作业结束时间：</view>
          <ruiDatePicker v-if="!forbidEdit" :start="todayDate" fields="minute" :value="form.JOB_END_TIME || '请选择'"
                         @change="changeJobEndTime"></ruiDatePicker>
          <text v-else>{{ form.JOB_END_TIME }}</text>
        </view>
        <view class="cu-form-group">
          <view class="title">指挥工：</view>
          <view  v-if="!forbidEdit" @click="openMoreSelect('commanderMore')">
              <text class="right_icon" v-show="form.COMMANDER_NAME.length !== 0">
                <text v-for="item in form.COMMANDER_NAME">{{item}}</text>
              </text>
              <text class="right_icon" v-show="form.COMMANDER_NAME.length === 0">请选择</text>
          </view>
          <view v-else>{{ form.COMMANDER_NAME }}</view>
<!--          <picker @change="commanderChange" :disabled="forbidEdit" :value="form.COMMANDER_INDEX"-->
<!--                  :range="commanderList" range-key="NAME">-->
<!--            <view class="picker">-->
<!--              {{ form.COMMANDER_NAME || '请选择' }}-->
<!--            </view>-->
<!--          </picker>-->
        </view>
        <view class="cu-form-group" v-if="form.COMMANDER_NAME.length !== 0">
          <uni-table border stripe emptyText="暂无更多数据" style="flex:1;margin: 20upx 0">
            <uni-tr>
              <uni-td>姓名</uni-td>
              <uni-td>作业证号</uni-td>
            </uni-tr>
            <uni-tr v-for="(item,index) in form.COMMANDER_NAME" :key="item">
              <uni-td>{{ form.COMMANDER_NAME[index] }}</uni-td>
              <uni-td>{{ form.COMMANDER_NAME_NUMBER[index]?form.COMMANDER_NAME_NUMBER[index]:form.COMMANDER_NUMBER }}</uni-td>
            </uni-tr>
          </uni-table>
        </view>
        <uni-popup ref="commanderMore" type="bottom" :maskClick="false">
          <more-select
                  title="选择指挥工"
                  :cityData="craneDriverList"
                  @closeCity="handleCommander('close')"
                  @queryCity="handleCommander('query')"
                  @switchCity="switchCommander"
                  @chooseCity="chooseCommander"
                  :cityIndex="commanderIndex"
                  :cityIdArr="form.COMMANDER_ID"
                  :maxCount="1"
          ></more-select>
        </uni-popup>
        <view class="cu-form-group">
          <view class="title">吊装作业内容：</view>
          <input :disabled="forbidEdit" v-model="form.HOISTING_WORK_CONTENT" placeholder="请输入吊装作业内容"></input>
        </view>
        <view class="cu-form-group">
          <view class="title">起吊重物质量（吨）：</view>
          <input :disabled="forbidEdit" v-model="form.LIFTING_WEIGHT" placeholder="请输入起吊重物质量（吨）" type="number"></input>
        </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.CONSTRUCTION_JOB_MANAGER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree2" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'constructionJobManagerList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.CONSTRUCTION_JOB_MANAGER_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group">
          <view class="title">作业负责人：</view>
          <picker @change="constructionJobManagerChange" :disabled="forbidEdit" :value="form.CONSTRUCTION_JOB_MANAGER_INDEX"
                  :range="constructionJobManagerList" range-key="NAME">
            <view class="picker">
              {{ form.CONSTRUCTION_JOB_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.WORK_UNIT_MANAGER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree3" :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" style="height: auto;">
            <view>分公司（中心）审批人</view>
            <view>部门：</view>
          </view>
          <block v-if="!forbidEdit">
            <view class="picker-tree-box">
              <view class="picker-tree" @tap="showZgTree('tkiTree4')">
                {{ form.BRANCH_APPROVER_DEPARTMENT_NAME || '请选择' }}
              </view>
            </view>
            <tki-tree ref="tkiTree4" :selectParent=true :range="treeNode" rangeKey="name" @confirm="zgtreeConfirm($event,'branchApproverList')"
                      @cancel="zgtreeCancel"></tki-tree>
          </block>
          <block v-else>{{ form.BRANCH_APPROVER_DEPARTMENT_NAME }}</block>
        </view>
        <view class="cu-form-group" v-if="form.BRANCH_APPROVER_DEPARTMENT_NAME">
          <view class="title">分公司（中心）审批人：</view>
          <picker @change="branchApproverChange" :disabled="forbidEdit" :value="form.BRANCH_APPROVER_INDEX"
                  :range="branchApproverList" range-key="NAME">
            <view class="picker">
              {{ form.BRANCH_APPROVER_NAME || '请选择' }}
            </view>
          </picker>
        </view>
        <view class="cu-form-group">
          <view class="title">作业地点：</view>
          <button class="cu-btn round bg-blue" v-if="!forbidEdit" @click="chooseLocation">地图选择</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="title">纬度：</view>
          <view>{{form.WORK_LATITUDE}}</view>
        </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('1'))">提交
      </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';
import moreSelect from '@/components/more-select/more-select.vue';
import uniPopup from '@/components/more-select/uni-popup/uni-popup.vue';

export default {
  components: {
    tkiTree,
    ruiDatePicker,
    moreSelect,
    uniPopup
  },
  data() {
    return {
      noClick: true,
      form: {
        HOISTING_ID: '',
        APPLY_DEPARTMENT_ID: '',
        APPLY_DEPARTMENT_NAME: '',
        APPLY_USER_ID: '',
        APPLY_USER_NAME: '',
        NUMBERING: '',
        HOISTING_LOCATION: '',
        HOISTING_EQUIPMENT: '',
        LIFTING_OPERATION_MANAGER_DEPARTMENT_NAME: '',
        LIFTING_OPERATION_MANAGER_DEPARTMENT_ID: '',
        LIFTING_OPERATION_MANAGER_NAME: '',
        LIFTING_OPERATION_MANAGER_INDEX: '',
        LIFTING_OPERATION_MANAGER_ID: '',
        SAFETY_GUARDIAN_DEPARTMENT_NAME: '',
        SAFETY_GUARDIAN_DEPARTMENT_ID: '',
        SAFETY_GUARDIAN_NAME: '',
        SAFETY_GUARDIAN_INDEX: '',
        SAFETY_GUARDIAN_ID: '',
        CRANE_DRIVER_NAME: [],
        CRANE_DRIVER_ID: [],
        CRANE_DRIVER_NUMBER: [],
        JOB_START_TIME: '',
        JOB_END_TIME: '',
        COMMANDER_NAME: [],
        COMMANDER_NAME_NUMBER: [],
        COMMANDER_ID: [],
        HOISTING_WORK_CONTENT: '',
        LIFTING_WEIGHT: '',
        CONSTRUCTION_JOB_MANAGER_DEPARTMENT_NAME: '',
        CONSTRUCTION_JOB_MANAGER_DEPARTMENT_ID: '',
        CONSTRUCTION_JOB_MANAGER_INDEX: '',
        CONSTRUCTION_JOB_MANAGER_NAME: '',
        CONSTRUCTION_JOB_MANAGER_ID: '',
        WORK_UNIT_MANAGER_DEPARTMENT_NAME: '',
        WORK_UNIT_MANAGER_DEPARTMENT_ID: '',
        WORK_UNIT_MANAGER_NAME: '',
        WORK_UNIT_MANAGER_INDEX: '',
        WORK_UNIT_MANAGER_ID: '',
        BRANCH_APPROVER_DEPARTMENT_NAME: '',
        BRANCH_APPROVER_DEPARTMENT_ID: '',
        BRANCH_APPROVER_NAME: '',
        BRANCH_APPROVER_INDEX: '',
        BRANCH_APPROVER_ID: '',
        WORK_LONGITUDE: '',
        WORK_LATITUDE: '',
        OTHER_PROTECTIVE_MEASURES: ''
      },
      rules: [
        {name: 'NUMBERING', message: '请输入编号'},
        {name: 'HOISTING_LOCATION', message: '请输入吊装地点'},
        {name: 'HOISTING_EQUIPMENT', message: '请输入吊装机具'},
        {name: 'LIFTING_OPERATION_MANAGER_NAME', message: '请选择吊装作业负责人'},
        {name: 'SAFETY_GUARDIAN_NAME', message: '请选择安全监护人'},
        {name: 'JOB_START_TIME', message: '请选择作业开始时间'},
        {name: 'JOB_END_TIME', message: '请选择作业结束时间'},
        {name: 'COMMANDER_NAME', message: '请选择指挥工'},
        {name: 'HOISTING_WORK_CONTENT', message: '请输入吊装作业内容'},
        {name: 'LIFTING_WEIGHT', message: '请输入起吊重物质量'},
        {name: 'CONSTRUCTION_JOB_MANAGER_NAME', message: '请选择施工作业负责人'},
        {name: 'WORK_UNIT_MANAGER_NAME', message: '请选择作业单位负责人'},
        {name: 'BRANCH_APPROVER_NAME', message: '请选择分公司（中心）审批人'},
        {name: 'WORK_LONGITUDE', message: '请选择作业地点'},
      ],
      treeNode: [],
      forbidEdit: false,
      methodName: 'add',
      todayDate: formatDate(new Date(), 'yyyy-MM-dd hh:mm'),
      liftingOperationManagerList: [],
      safetyGuardianList: [],
      commanderList: [],
      constructionJobManagerList: [],
      workUnitManagerList: [],
      branchApproverList: [],
      craneDriverList: [],
      cityIndex: 0,
      commanderIndex: 0,
    }
  },
  onLoad(event) {
    if (event.id) {
      this.form.HOISTING_ID = event.id
      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
      this.form.WORK_LONGITUDE = ''
      this.form.WORK_LATITUDE = ''
      // this.form.WORK_LONGITUDE = '119.65772151947023'
      // this.form.WORK_LATITUDE = '39.93767832107088'
    }
    loginSession();
    this.getDept()
    this.getUserList('constructionJobManagerList',loginUser.DEPARTMENT_ID)
  },
  methods: {
    createWorkNumber() {
      var _this = this;
      uni.request({
        url: basePath + '/app/serialnumber/add',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          TYPE: 'DZ',
          CORPINFO_ID: corpinfoId
        },
        success: (res) => {
          if ("success" === res.data.result) {
            this.$set(_this.form, 'NUMBERING', res.data.pd.NUMBER) //参数map
          }
        }
      });
    },
    getData() {
      var _this = this;
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + '/app/hoisting/goEdit',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          HOISTING_ID: _this.form.HOISTING_ID,
        },
        success: (res) => {
          if ("success" == res.data.result) {
            _this.form = Object.assign(_this.form, res.data.pd);
            _this.measuresList = res.data.measuresList
            if (!_this.form.CRANE_DRIVER_ID) {
              _this.$set( _this.form, 'CRANE_DRIVER_ID', [] )
            } else {
              _this.form.CRANE_DRIVER_ID = _this.form.CRANE_DRIVER_ID.split(',')
            }
            if (!_this.form.CRANE_DRIVER_NAME) {
              _this.$set( _this.form, 'CRANE_DRIVER_NAME', [] )
            } else {
              _this.form.CRANE_DRIVER_NAME = _this.form.CRANE_DRIVER_NAME.split(',')
            }
            if (!_this.form.CRANE_DRIVER_NUMBER) {
              _this.$set( _this.form, 'CRANE_DRIVER_NUMBER', [] )
            } else {
              _this.form.CRANE_DRIVER_NUMBER = _this.form.CRANE_DRIVER_NUMBER.split(',')
            }
            if (!_this.form.COMMANDER_ID) {
              _this.$set( _this.form, 'COMMANDER_ID', [] )
            } else {
              if(_this.form.COMMANDER_ID.length>0){
                _this.form.COMMANDER_ID = _this.form.COMMANDER_ID.split(',')
              }
            }
            if (!_this.form.COMMANDER_NAME) {
              _this.$set( _this.form, 'COMMANDER_NAME', [] )
            } else {
              if(_this.form.COMMANDER_NAME.length>0){
                _this.form.COMMANDER_NAME = _this.form.COMMANDER_NAME.split(',')
              }
            }
            if (!_this.form.COMMANDER_NAME_NUMBER) {
              _this.$set( _this.form, 'COMMANDER_NAME_NUMBER', [] )
            } else {
                _this.form.COMMANDER_NAME_NUMBER = _this.form.COMMANDER_NAME_NUMBER
            }
            if (_this.form.OTHER_PROTECTIVE_MEASURES) {
              this.oldSupplementaryMeasures = _this.form.OTHER_PROTECTIVE_MEASURES.split(';_;')
            }
            if (Number(_this.form.APPLY_STATUS) < 1 && _this.form.APPLY_STATUS != '-5') {
              this.forbidEdit = false;
            } else {
              this.forbidEdit = true;
            }
            this.methodName = 'edit'
            uni.hideLoading();
          } else if ("exception" == res.data.result) {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }
        }
      });
    },
    goSubmit(STATUS) {
      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
      }
      if(this.form.CRANE_DRIVER_ID.length === 0){
        uni.showToast({
          icon: 'none',
          title: '请选择起重司机',
          duration: 1500
        })
        return
      }
      this.$set(this.form, 'CORPINFO_ID', corpinfoId)
      this.$set(this.form, 'CREATOR', loginUser.USER_ID)
      this.$set(this.form, 'OPERATOR', loginUser.USER_ID)
      this.$set(this.form, 'ACTION_USER', loginUser.NAME)
      this.$set(this.form, 'APPLY_STATUS', STATUS)
      this.form.COMMANDER_ID = this.form.COMMANDER_ID[0]
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + "/app/hoisting/" + this.methodName,
        method: 'POST',
        dataType: 'json',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          ...this.form,
          CRANE_DRIVER_ID: this.form.CRANE_DRIVER_ID
        },
        success: (res) => {
          uni.showToast({
            icon: 'none',
            title: '保存成功',
            duration: 2000
          });
          _this.goback()
        },
        fail: (err) => {
          uni.hideLoading();
          uni.showModal({
            content: err.errMsg,
            showCancel: false
          });
        }
      })
    },
    changeJobStartTime(e) {
      this.form.JOB_START_TIME = e
    },
    changeJobEndTime(e) {
      this.form.JOB_END_TIME = e
    },
    openMoreSelect(ref) {
      console.info(ref)
      this.$refs[ref].open();
    },
    handleCraneDriver(type) {
      if(type === 'close') {
        this.form.CRANE_DRIVER_ID = []
        this.form.CRANE_DRIVER_NAME = []
        this.form.CRANE_DRIVER_NUMBER = []
      }
      this.$refs.cityMore.close();
    },
    switchCraneDriver(index){
      this.cityIndex = index
    },
    chooseCraneDriver(item){
      console.info(item)
      if (this.form.CRANE_DRIVER_ID.indexOf(item.id) == -1) {
        this.form.CRANE_DRIVER_ID.push(item.id)
        this.form.CRANE_DRIVER_NAME.push(item.name)
        this.form.CRANE_DRIVER_NUMBER.push(item.number)
      } else {
        this.form.CRANE_DRIVER_ID.splice(this.form.CRANE_DRIVER_ID.indexOf(item.id), 1)
        this.form.CRANE_DRIVER_NAME.splice(this.form.CRANE_DRIVER_NAME.indexOf(item.name), 1)
        this.form.CRANE_DRIVER_NUMBER.splice(this.form.CRANE_DRIVER_NUMBER.indexOf(item.number), 1)
      }
    },
    handleCommander(type) {
      if(type === 'close') {
        this.form.COMMANDER_ID = []
        this.form.COMMANDER_NAME = []
      }
      this.$refs.commanderMore.close();
    },
    switchCommander(index){
      this.commanderIndex = index
    },
    chooseCommander(item){
      this.form.COMMANDER_ID = []
      this.form.COMMANDER_NAME = []
      this.form.COMMANDER_ID.push(item.id)
      this.form.COMMANDER_NAME.push(item.name)
      this.form.COMMANDER_NAME_NUMBER.push(item.number)
    },
    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.craneDriverList = JSON.parse(res.data.varList);
          } else {
            uni.showToast({
              title: res.data.message,
              duration: 2000
            });
          }
        }
      });
    },
    showZgTree(ref) {
      this.$refs[ref]._show();
    },
    zgtreeConfirm(e, list) {
      if (list === "liftingOperationManagerList") {
        this.form.LIFTING_OPERATION_MANAGER_DEPARTMENT_ID = e[0].id;
        this.form.LIFTING_OPERATION_MANAGER_DEPARTMENT_NAME = e[0].name;
        this.form.LIFTING_OPERATION_MANAGER_INDEX = '';
        this.form.LIFTING_OPERATION_MANAGER_ID = '';
        this.form.LIFTING_OPERATION_MANAGER_NAME = '';
      }
      if (list === "safetyGuardianList") {
        this.form.SAFETY_GUARDIAN_DEPARTMENT_ID = e[0].id;
        this.form.SAFETY_GUARDIAN_DEPARTMENT_NAME = e[0].name;
        this.form.SAFETY_GUARDIAN_INDEX = '';
        this.form.SAFETY_GUARDIAN_ID = '';
        this.form.SAFETY_GUARDIAN_NAME = '';
      }
      if (list === "constructionJobManagerList") {
        this.form.CONSTRUCTION_JOB_MANAGER_DEPARTMENT_ID = e[0].id;
        this.form.CONSTRUCTION_JOB_MANAGER_DEPARTMENT_NAME = e[0].name;
        this.form.CONSTRUCTION_JOB_MANAGER_INDEX = '';
        this.form.CONSTRUCTION_JOB_MANAGER_NAME = '';
        this.form.CONSTRUCTION_JOB_MANAGER_ID = '';
      }
      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 === "branchApproverList") {
        this.form.BRANCH_APPROVER_DEPARTMENT_ID = e[0].id;
        this.form.BRANCH_APPROVER_DEPARTMENT_NAME = e[0].name;
        this.form.BRANCH_APPROVER_INDEX = '';
        this.form.BRANCH_APPROVER_ID = '';
        this.form.BRANCH_APPROVER_NAME = '';
      }
      this.getUserList(list, e[0].id);
    },
    liftingOperationManagerChange(e) {
      this.form.LIFTING_OPERATION_MANAGER_INDEX = e.detail.value;
      this.form.LIFTING_OPERATION_MANAGER_ID = this.liftingOperationManagerList[e.detail.value].USER_ID;
      this.form.LIFTING_OPERATION_MANAGER_NAME = this.liftingOperationManagerList[e.detail.value].NAME;
    },
    safetyGuardianChange(e) {
      this.form.SAFETY_GUARDIAN_INDEX = e.detail.value;
      this.form.SAFETY_GUARDIAN_ID = this.safetyGuardianList[e.detail.value].USER_ID;
      this.form.SAFETY_GUARDIAN_NAME = this.safetyGuardianList[e.detail.value].NAME;
    },
    commanderChange(e) {
      this.form.COMMANDER_INDEX = e.detail.value;
      this.form.COMMANDER_ID = this.commanderList[e.detail.value].USER_ID;
      this.form.COMMANDER_NAME = this.commanderList[e.detail.value].NAME;
    },
    constructionJobManagerChange(e) {
      this.form.CONSTRUCTION_JOB_MANAGER_INDEX = e.detail.value;
      this.form.CONSTRUCTION_JOB_MANAGER_ID = this.constructionJobManagerList[e.detail.value].USER_ID;
      this.form.CONSTRUCTION_JOB_MANAGER_NAME = this.constructionJobManagerList[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;
    },
    branchApproverChange(e) {
      this.form.BRANCH_APPROVER_INDEX = e.detail.value;
      this.form.BRANCH_APPROVER_ID = this.branchApproverList[e.detail.value].USER_ID;
      this.form.BRANCH_APPROVER_NAME = this.branchApproverList[e.detail.value].NAME;
    },
    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
            });
          }
        }
      })
    },
    chooseLocation() {
      var _this = this
      uni.navigateTo({
        url: '/pages/map/map',
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          acceptDataFromOpenedPage: function (e) {
            _this.form.WORK_LONGITUDE = e.data.longitue;
            _this.form.WORK_LATITUDE = e.data.latitude;
          }
        },
      })
    },
    goback() {
      uni.navigateBack({
        delta: 1
      });
      uni.hideLoading();
    },
  }
}
</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>
