<!--人员事件-->
<template>
  <div id="content-container" :class="{'expand-right': expandRight}">
    <page-loading :show="pageLoading"></page-loading>
    <div id="page-title">
      <h1 class="page-header text-overflow">人员事件管理</h1>
    </div>
    <!--Page content-->
    <el-dialog :title="formTitle" :visible.sync="dialogFormVisible">
      <data-form
        :title="formTitle"
        :btnTitle="formBtnTitle"
        :schema="formSchema"
        :model="formModel"
        :showTitle="false"
        :btnData="formBtnData"
        ref="childrenForm"
        v-loading="dialogLoading"
        element-loading-text="拼命加载中"
        @addOption="setCascaderMultipleValue"
        @handleClose="handleClose"
        @selectorValueChanged="selectorValueChanged"
        @radioValueChanged="radioValueChanged"
      >
      </data-form>
    </el-dialog>

    <el-dialog :title="delayTitle" :visible.sync="dialogdelayVisible">
      <data-form
        :title="delayTitle"
        :btnTitle="delayBtnTitle"
        :schema="delaySchema"
        :model="delayModel"
        :showTitle="false"
        :btnData="delayBtnData"
        ref="childrenForm"
        v-loading="dialogLoading"
        element-loading-text="拼命加载中"
      >
      </data-form>
    </el-dialog>

    <el-dialog :title="destoryTitle" :visible.sync="dialogdestoryVisible">
      <data-form
        :title="destoryTitle"
        :btnTitle="destoryBtnTitle"
        :schema="destorySchema"
        :model="destoryModel"
        :showTitle="false"
        :btnData="destoryBtnData"
        ref="childrenForm"
        v-loading="dialogLoading"
        element-loading-text="拼命加载中"
      >
      </data-form>
    </el-dialog>


    <div class="page-content">
      <div style="margin-bottom: 10px">
        <el-button type="primary" @click="addPersonalEvents" v-if="!isSuper">新增</el-button>
      </div>
      <data-table
        :totalColumnsData="tableColumnsData"
        :rowsData="tableRowsData"
        :showSingleOperation="tableShowSingleOperation"
        :showMultipleOperation="false"
        :canFolded="true"
        :showPageCtr="true"
        :totalPage="tableTotalPage"
        :currentPage="pageNo"
        @selectPage="tableSelectPage"
        @singleCheck="tableSingleCheck"
        @singleSalesLeave="tableSingleSalesLeave"
        @singleDelayLeave="tableSingleDelayLeave"
        @singleReimburse="tableSingleReimburse"
        @singleReimbursePrint="tableSingleReimbursePrint"
      >
      </data-table>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import PageLoading from '../../../components/PageLoading.vue'
  import Api from '../../../server/index.js'
  import DataTable from '../../../components/DataTable.vue'
  import DataForm from '../../../components/form/DataForm.vue'
  import app from '../../../assets/js/common/app'
  import {getItem} from '../../../config/mUtils'
  import {baseUrl} from '../../../config/env.js'

  export default {
    beforeRouteEnter(to, from, next) {
      next(function (vm) {
        global.getMenuIndex(vm);
      })
    },
    data() {
      return {
        expandRight: false,
        tableColumnsData: [],
        tableRowsData: [],
        pageLoading: false,
        dialogLoading: false,
        //分页
        pageNo: 1,
        pageSize: 10,
        tableTotalPage: 1,
        tableShowSingleOperation: {
          show: true,
          showEdit: false,
          showCheck: true,
          last: true
        },
        //表单弹出对话框
        dialogFormVisible: false,
        //form表单数据源
        formType: "add", //标识当前form是新增还是编辑：add：新增；edit：编辑
        formTitle: "新增人员事件",
        formBtnTitle: "确定",
        formSchema: {},
        formModel: {
          eventsType: '',
          theme: '',
          leaveType: '',
          userinfoId: '',
          executiveList: [],
          beginDate: '',
          endDate: '',
          destination: '',
          description: '',
          eventsBudget: '',
          transferWork: '',      // 移交工作事项
          emergencyNumber: '',    // 紧急情况联系电话
          fileData: [],
          conferenceNumber: '',
          travelRole: '2',
        },
        dialogdelayVisible: false,
        delayType: "edit", //标识当前form是新增还是编辑：add：新增；edit：编辑
        delayTitle: "延假",
        delayBtnTitle: "确定",
        delaySchema: {},
        delayModel: {
          oldDate: '',
          oldEndM: '',
          newDate: '',
          newEndM: ''
        },
        oldDate: '',
        oldEndM: '',
        delayBtnData: [],

        dialogdestoryVisible: false,
        destoryType: "edit", //标识当前form是新增还是编辑：add：新增；edit：编辑
        destoryTitle: "销假",
        destoryBtnTitle: "销假",
        destorySchema: {},
        destoryModel: {
          fileData: '',
        },
        fileData: '',
        destoryBtnData: [],

        recivedFormFileData: [],
        formPeopleData: [],   // 当前人员
        formBtnData: [],
        eventsOptions: [
          /*{
            "label": "出国",
            "model": "abroad"
          },
          {
            "label": "外勤",
            "model": "foreignVisit"
          },*/
          {
            "label": "请假",
            "model": "leave"
          },
          //{
          //   "label": "出差",
          //   "model": "traveling"
          // }
        ],
        app: app,
        personalEventsId: '',   //  编辑事件的id
        isSuper: false,
        formPermissionsData: [],  //自定义人员列表
        formCustomizePeopleData: [],  //自定义人员选中数据
        tagNameByRecivedOut: [],
        isPersonnel: false, //是否是人事专员
      }
    },
    created() {
      let userId = getItem('userId');
      let roles = getItem('roles');
      if (userId === '0') {
        this.isSuper = true;
      }
      if (roles.indexOf('人事专员') !== -1) {
        this.isPersonnel = true
      }
      let data = {}
      this.init();
      this.initTableColumns();
      this.getPersonalList(data);
      this.initFormData();
      this.initFormSchema();
      this.initDelayData();
      this.initDelaySchema();
      this.initDestoryData();
      this.initDestorySchema();
//      this.getAllPeople();
    },
    computed: {
      travelRole() {
        return this.formModel.travelRole
      }
    },
    watch: {
      travelRole() {
        console.log("travelRole", this.formModel.travelRole);
        this.setformPermissionsData();
      }
    },
    methods: {
      init() {
        this.setformPermissionsData();
      },
      setformPermissionsData() {
        if (this.formModel.travelRole == '1') {
          this.formModel.userinfoId = '';
          console.log("进入watch1");
          this.getPeople();
        } else {
          console.log("进入watch2");
          this.getPeers();
        }
      },
      //递归组装级联选择器数据源
      assembleOrgData(source) {
        let dest = [];
        for (let i = 0; i < source.length; i++) {
          let org = {
            value: source[i].id,
            label: source[i].name
          };
          if (source[i].childList && source[i].childList.length > 0) {
            org['children'] = this.assembleOrgData(source[i].childList);
          }
          dest.push(org);
        }
        return dest;
      },
      //初始化tableColumns
      initTableColumns() {
        this.tableColumnsData = [
          {
            label: '事件类型',
            prop: 'eventsTypeName',
            show: true
          },
          {
            label: '人员',
            prop: 'userinfoName',
            show: true
          },
          {
            label: '开始时间',
            prop: 'beginDate',
            show: true
          },
          {
            label: '结束时间',
            prop: 'endDate',
            show: true
          },
          {
            label: '备注',
            prop: 'description',
            show: false
          },
          {
            label: '审批状态',
            prop: 'activitiStatsName',
            show: true
          }
        ];
      },
      // 流程
      addPersonalEvents() {
        this.formType = 'add';
        this.dialogFormVisible = true;
        this.formTitle = '新增人员事件';
        this.formPeopleData = [
          {
            label: getItem('userName'),
            model: getItem('userInfoId')
          }
        ]
        this.initFormData();
        this.initFormSchema();

      },
      //初始化form schema
      initFormSchema() {
        let self = this;
        switch (this.formModel.eventsType) {
          case 'abroad':
            this.formSchema = [
              {
                type: "custom-selector",
                title: '事件类型',
                model: 'eventsType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.isPersonnel ? this.eventsOptions :
                    [
                     /* {
                        "label": "外勤",
                        "model": "foreignVisit"
                      },*/
                      {
                        "label": "请假",
                        "model": "leave"
                      },
                     /* {
                        "label": "出国",
                        "model": "abroad"
                      },*/
                      //{
                      //  "label": "出差",
                      //  "model": "traveling"
                      // }
                    ]
                },
                rules: [
                  {required: true, message: '事件类型不能为空'}
                ],
              },
              {
                type: "custom-input",
                title: '主题栏',
                model: 'theme',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-cascader-multiple",
                title: '人员',
                model: 'executiveList',
                closable: true,
                rules: [
                  {required: true, message: '人员不能为空'}
                ],
                externalValue: {
                  value: this.formCustomizePeopleData,
                  tagNameByC: this.formModel.executiveList,
                  changeOnSelect: true,
                  options: this.formPermissionsData
                }
              },
              {
                type: "custom-date-picker",
                title: '开始时间',
                model: 'beginDate',
                dataType: 'String',
                externalValue: {
                  type: 'date',
                  pickerOptions: {
                    disabledDate(time) {
                      let beginDateVal = self.formModel.endDate;
                      if (beginDateVal) {
                        return (time.getTime() > beginDateVal || (time.getTime() < Date.now() - 8.64e7));
                      }
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-date-picker",
                title: '结束时间',
                model: 'endDate',
                dataType: 'String',
                externalValue: {
                  type: 'date',
                  pickerOptions: {
                    disabledDate(time) {
                      let beginDateVal = self.formModel.beginDate;
                      if (beginDateVal) {
                        return time.getTime() < beginDateVal;
                      }
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-input",
                title: '目的地',
                model: 'destination',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-input",
                title: '预算',
                model: 'eventsBudget',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-input",
                title: '会议纪要文号',
                model: 'conferenceNumber',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-textarea",
                title: '内容简介',
                model: 'description',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-upload-file",
                title: '附件',
                model: 'fileData',
                externalValue: {
                  name: 'file',
                  actionUrl: `${baseUrl}/api/common/file-upload`,
                  requestHeader: {},
                  requestData: {},
                  uploadFileSuccess: (response, file, fileList) => {
                    if (response.status === 0) {
                      this.recivedFormFileData.push({
                        id: file.uid,
                        name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                        url: baseUrl + response.data.url
                      });
                      this.formModel.fileData = this.recivedFormFileData;
                      // for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      //   this.formModel.fileData = this.recivedFormFileData[i].url;
                      // }
//                  this.personBaseFormModel.fileUrl = (this.recivedFormFileData);
                    } else {
                      this.$message.error(response.msg);
                    }
                  },
                  uploadFilePreview: (file) => {
                    window.open(file.url, '_blank');
                  },
                  uploadFileRemove: (file, fileList) => {
                    for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      if (file.uid === this.recivedFormFileData[i].uid) {
                        this.recivedFormFileData.splice(i, 1);
                        this.formModel.fileData.splice(i, 1);
                        break;
                      }
                    }
                    this.initFormSchema();
                  },
                  fileList: this.recivedFormFileData
                }
              },
              {
                type: 'submit'
              }
            ];
            break;
          case 'training':
            break;
          case 'foreignVisit':
            this.formSchema = [
              {
                type: "custom-selector",
                title: '事件类型',
                model: 'eventsType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.isPersonnel ? this.eventsOptions :
                    [
                      /*{
                        "label": "外勤",
                        "model": "foreignVisit"
                      },*/
                      {
                        "label": "请假",
                        "model": "leave"
                      },
                     /* {
                        "label": "出国",
                        "model": "abroad"
                      },*/
                      //{
                      //  "label": "出差",
                      //  "model": "traveling"
                      // }
                    ]
                },
                rules: [
                  {required: true, message: '事件类型不能为空'}
                ],
              },
              {
                type: "custom-selector",
                title: '人员',
                model: 'userinfoId',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  disabled: true,
                  options: this.formPeopleData
                }
              },
              {
                type: "custom-date-time-select-picker",
                title: '外勤时间',
                model: 'foreignVisitTime',
                date: 'foreignVisitDate',
                beginTime: 'foreignVisitBeginTime',
                endTime: 'foreignVisitEndTime',
                rules: [
                  {required: true, message: '外勤时间不能为空'}
                ],
                externalValue: {
                  dateFormat: 'yyyy-MM-dd',
                  datePickerOptions: {
                    disabledDate(time) {
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  },
                  beginTimePickerOptions: {
                    start: '08:00',
                    step: '01:00',
                    end: '23:59',
                    maxTime: self.formModel.foreignVisitTime.foreignVisitEndTime
                  },
                  endTimePickerOptions: {
                    start: '08:00',
                    step: '01:00',
                    end: '23:59',
                    minTime: self.formModel.foreignVisitTime.foreignVisitBeginTime
                  }
                }
              },
              // {
              //   type: "custom-date-picker",
              //   title: '开始时间',
              //   model: 'beginDate',
              //   dataType: 'String',
              //   externalValue: {
              //     type: 'datetime',
              //     pickerOptions: {
              //       disabledDate(time) {
              //         let beginDateVal = self.formModel.endDate;
              //         if (beginDateVal) {
              //           return (time.getTime() > beginDateVal || (time.getTime() < Date.now() - 8.64e7));
              //         }
              //         return time.getTime() < Date.now() - 8.64e7;
              //       }
              //     }
              //   }
              // },
              // {
              //   type: "custom-date-picker",
              //   title: '结束时间',
              //   model: 'endDate',
              //   dataType: 'String',
              //   externalValue: {
              //     type: 'datetime',
              //     pickerOptions: {
              //       disabledDate(time) {
              //         let beginDateVal = self.formModel.beginDate;
              //         if (beginDateVal) {
              //           return time.getTime() < beginDateVal;
              //         }
              //         return time.getTime() < Date.now() - 8.64e7;
              //       }
              //     }
              //   }
              // },
              {
                type: "custom-input",
                title: '目的地',
                model: 'destination',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-input",
                title: '预算',
                model: 'eventsBudget',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-textarea",
                title: '备注',
                model: 'description',
                dataType: 'String',
                externalValue: {},
                rules: [
                  {required: true, message: '备注不能为空'}
                ],
              },
              {
                type: "custom-upload-file",
                title: '附件',
                model: 'fileData',
                externalValue: {
                  name: 'file',
                  actionUrl: `${baseUrl}/api/common/file-upload`,
                  requestHeader: {},
                  requestData: {},
                  uploadFileSuccess: (response, file, fileList) => {
                    if (response.status === 0) {
                      this.recivedFormFileData.push({
                        id: file.uid,
                        name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                        url: baseUrl + response.data.url
                      });
                      this.formModel.fileData = this.recivedFormFileData;
                      // for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      //   this.formModel.fileData = this.recivedFormFileData[i].url;
                      // }
//                  this.personBaseFormModel.fileUrl = (this.recivedFormFileData);
                    } else {
                      this.$message.error(response.msg);
                    }
                  },
                  uploadFilePreview: (file) => {
                    window.open(file.url, '_blank');
                  },
                  uploadFileRemove: (file, fileList) => {
                    for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      if (file.uid === this.recivedFormFileData[i].uid) {
                        this.recivedFormFileData.splice(i, 1);
                        this.formModel.fileData.splice(i, 1);
                        break;
                      }
                    }
                    this.initFormSchema();
                  },
                  fileList: this.recivedFormFileData
                }
              },
              {
                type: 'submit'
              }
            ];
            break;
          case  'leave':
            this.formSchema = [
              {
                type: "custom-selector",
                title: '事件类型',
                model: 'eventsType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.isPersonnel ? this.eventsOptions :
                    [
                      /*{
                        "label": "外勤",
                        "model": "foreignVisit"
                      },*/
                      {
                        "label": "请假",
                        "model": "leave"
                      },
                      /*{
                        "label": "出国",
                        "model": "abroad"
                      },*/
                      //{
                      //  "label": "出差",
                      //  "model": "traveling"
                      //}
                    ]
                },
                rules: [
                  {required: true, message: '事件类型不能为空'}
                ],
              },
              {
                type: "custom-selector",
                title: '请假类型',
                model: 'leaveType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.app.leaveType
                },
                rules: [
                  {required: true, message: '请假类型不能为空'}
                ],
              },
              {
                type: "custom-selector",
                title: '人员',
                model: 'userinfoId',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  disabled: true,
                  options: this.formPeopleData
                }
              },
              {
                type: "custom-date-mm-picker",
                title: '开始时间',
                model: 'beginDate',
                selector: 'beginM',
                dataType: 'String',
                externalValue: {
                  dateFormat: 'yyyy-MM-dd HH:mm:ss',
                  datePickerOptions: {
//                    disabledDate(time) {
//                      let beginDateVal = self.formModel.endDate;
//                      if (beginDateVal) {
//                        return (time.getTime() > beginDateVal || (time.getTime() < Date.now() - 8.64e7));
//                      }
//                      return time.getTime() < Date.now() - 8.64e7;
//                    }
                    disabledDate(time) {
                      if (self.formModel.endDate.length !== 0) {
                        return time.getTime() < Date.now() - 8.64e7 || time.getTime() > moment(self.formModel.endDate, "YYYY-MM-DD HH:mm:ss").format('x');
                      } else {
                        return time.getTime() < Date.now() - 8.64e7;
                      }
                    }
                  },
                  selector: {
                    options: [
                      {label:"08:30", model:"08:30"},
                      {label:"09:00", model:"09:00"},
                      {label:"10:00", model:"10:00"},
                      {label:"11:00", model:"11:00"},
                      {label:"12:00", model:"12:00"},
                      {label:"13:00", model:"13:00"},
                      {label:"14:00", model:"14:00"},
                      {label:"15:00", model:"15:00"},
                      {label:"16:00", model:"16:00"},
                      {label:"17:00", model:"17:00"},
                      {label:"18:00", model:"18:00"},
                      {label:"19:00", model:"19:00"},
                      {label:"20:00", model:"20:00"},
                      {label:"21:00", model:"21:00"},
                      {label:"22:00", model:"22:00"},
                      {label:"23:00", model:"23:00"},
                    ]
                  }
                }
              },
              {
                type: "custom-date-mm-picker",
                title: '结束时间',
                model: 'endDate',
                selector: 'endM',
                dataType: 'String',
                externalValue: {
                  dateFormat: 'yyyy-MM-dd HH:mm:ss',
                  datePickerOptions: {
//                    disabledDate(time) {
//                      let beginDateVal = self.formModel.beginDate;
//                      if (beginDateVal) {
//                        return time.getTime() < beginDateVal;
//                      }
//                      return time.getTime() < Date.now() - 8.64e7;
//                    }
                    disabledDate(time) {
                      if (self.formModel.beginDate.length !== 0) {
                        return time.getTime() < Date.now() - 8.64e7 || time.getTime() < moment(self.formModel.beginDate, "YYYY-MM-DD HH:mm:ss").format('x');
                      } else {
                        return time.getTime() < Date.now() - 8.64e7;
                      }
                    }
                  }
                  ,
                  selector: {
                    options: [
                      {label:"08:30", model:"08:30"},
                      {label:"09:00", model:"09:00"},
                      {label:"10:00", model:"10:00"},
                      {label:"11:00", model:"11:00"},
                      {label:"12:00", model:"12:00"},
                      {label:"13:00", model:"13:00"},
                      {label:"14:00", model:"14:00"},
                      {label:"15:00", model:"15:00"},
                      {label:"16:00", model:"16:00"},
                      {label:"17:00", model:"17:00"},
                      {label:"18:00", model:"18:00"},
                      {label:"19:00", model:"19:00"},
                      {label:"20:00", model:"20:00"},
                      {label:"21:00", model:"21:00"},
                      {label:"22:00", model:"22:00"},
                      {label:"23:00", model:"23:00"},
                    ]
                  }
                }
              }
              ,
              {
                type: "custom-input",
                title:
                  '紧急情况联系电话',
                model:
                  'emergencyNumber',
                dataType:
                  'String',
                externalValue:
                  {}
              }
              ,
              {
                type: "custom-textarea",
                title:
                  '假期移交工作事项',
                model:
                  'transferWork',
                dataType:
                  'String',
                externalValue:
                  {},
                rules: [
                  {required: true, message: '假期移交工作事项不能为空'}
                ],
              }
              ,
              {
                type: "custom-textarea",
                title:
                  '备注',
                model:
                  'description',
                dataType:
                  'String',
                externalValue:
                  {},
                rules: [
                  {required: true, message: '备注不能为空'}
                ],
              }
              ,
              {
                type: "custom-upload-file",
                title: '附件',
                model: 'fileData',
                externalValue: {
                  name: 'file',
                  actionUrl: `${baseUrl}/api/common/file-upload`,
                  requestHeader: {},
                  requestData: {},
                  uploadFileSuccess: (response, file, fileList) => {
                    if (response.status === 0) {
                      this.recivedFormFileData.push({
                        id: file.uid,
                        name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                        url: baseUrl + response.data.url
                      });
                      this.formModel.fileData = this.recivedFormFileData;
                      // for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      //   this.formModel.fileData = this.recivedFormFileData[i].url;
                      // }
//                  this.personBaseFormModel.fileUrl = (this.recivedFormFileData);
                    } else {
                      this.$message.error(response.msg);
                    }
                  },
                  uploadFilePreview: (file) => {
                    window.open(file.url, '_blank');
                  },
                  uploadFileRemove: (file, fileList) => {
                    for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      if (file.uid === this.recivedFormFileData[i].uid) {
                        this.recivedFormFileData.splice(i, 1);
                        this.formModel.fileData.splice(i, 1);
                        break;
                      }
                    }
                    this.initFormSchema();
                  },
                  fileList: this.recivedFormFileData
                }
              },
              {
                type: 'submit'
              }
            ];
            break;
          case 'traveling':
            this.formSchema = [
              {
                type: "custom-selector",
                title: '事件类型',
                model: 'eventsType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.isPersonnel ? this.eventsOptions :
                    [
                      /*{
                        "label": "外勤",
                        "model": "foreignVisit"
                      },*/
                      {
                        "label": "请假",
                        "model": "leave"
                      },
                      //{
                      //  "label": "出差",
                      //  "model": "traveling"
                      //}
                    ]
                },
                rules: [
                  {required: true, message: '事件类型不能为空'}
                ],
              },
              {
                type: "custom-radio",
                title: '出差人员',
                model: 'travelRole',
                externalValue: {
                  options: [
                    {
                      label: "所领导",
                      value: "1"
                    },
                    {
                      label: "一般人员",
                      value: "2"
                    }
                  ]
                }
              },
              {
                type: "custom-cascader-multiple",
                title: '人员',
                model: 'executiveList',
                closable: true,
                rules: [
                  {required: true, message: '人员不能为空'}
                ],
                hide: this.formModel.travelRole != '2',
                externalValue: {
                  value: this.formCustomizePeopleData,
                  tagNameByC: this.formModel.executiveList,
                  changeOnSelect: true,
                  options: this.formPermissionsData
                }
              },
              {
                type: "custom-selector",
                title: '人员',
                model: 'userinfoId',
                dataType: 'String',
                rules: [
                  {required: true, message: '人员不能为空'}
                ],
                hide: this.formModel.travelRole != '1',
                externalValue: {
                  multiple: false,
                  options: this.formPermissionsData
                }
              },
              {
                type: "custom-date-picker",
                title: '开始时间',
                model: 'beginDate',
                dataType: 'String',
                externalValue: {
                  type: 'date',
                  pickerOptions: {
                    disabledDate(time) {
                      let beginDateVal = self.formModel.endDate;
                      if (beginDateVal) {
                        return (time.getTime() > beginDateVal || (time.getTime() < Date.now() - 8.64e7));
                      }
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-date-picker",
                title: '结束时间',
                model: 'endDate',
                dataType: 'String',
                externalValue: {
                  type: 'date',
                  pickerOptions: {
                    disabledDate(time) {
                      let beginDateVal = self.formModel.beginDate;
                      if (beginDateVal) {
                        return time.getTime() < beginDateVal;
                      }
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-input",
                title: '目的地',
                model: 'destination',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-input",
                title: '预算',
                model: 'eventsBudget',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-textarea",
                title: '备注',
                model: 'description',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-upload-file",
                title: '附件',
                model: 'fileData',
                externalValue: {
                  name: 'file',
                  actionUrl: `${baseUrl}/api/common/file-upload`,
                  requestHeader: {},
                  requestData: {},
                  uploadFileSuccess: (response, file, fileList) => {
                    if (response.status === 0) {
                      this.recivedFormFileData.push({
                        id: file.uid,
                        name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                        url: baseUrl + response.data.url
                      });
                      this.formModel.fileData = this.recivedFormFileData;
                      // for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      //   this.formModel.fileData = this.recivedFormFileData[i].url;
                      // }
//                  this.personBaseFormModel.fileUrl = (this.recivedFormFileData);
                    } else {
                      this.$message.error(response.msg);
                    }
                  },
                  uploadFilePreview: (file) => {
                    window.open(file.url, '_blank');
                  },
                  uploadFileRemove: (file, fileList) => {
                    for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      if (file.uid === this.recivedFormFileData[i].uid) {
                        this.recivedFormFileData.splice(i, 1);
                        this.formModel.fileData.splice(i, 1);
                        break;
                      }
                    }
                    this.initFormSchema();
                  },
                  fileList: this.recivedFormFileData
                }
              },
              {
                type: 'submit'
              }
            ];
            break;
          default:
            this.formSchema = [
              {
                type: "custom-selector",
                title: '事件类型',
                model: 'eventsType',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  options: this.isPersonnel ? this.eventsOptions :
                    [
                     /* {
                        "label": "外勤",
                        "model": "foreignVisit"
                      },*/
                      {
                        "label": "请假",
                        "model": "leave"
                      },
                      // {
                      //  "label": "出差",
                      //   "model": "traveling"
                      // }
                    ]
                },
                rules: [
                  {required: true, message: '事件类型不能为空'}
                ],
              },
              {
                type: "custom-selector",
                title: '人员',
                model: 'userinfoId',
                dataType: 'String',
                externalValue: {
                  multiple: false,
                  disabled: true,
                  options: this.formPeopleData
                }
              },
              {
                type: "custom-date-picker",
                title: '开始时间',
                model: 'beginDate',
                dataType: 'String',
                externalValue: {
                  pickerOptions: {
                    disabledDate(time) {
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-date-picker",
                title: '结束时间',
                model: 'endDate',
                dataType: 'String',
                externalValue: {
                  pickerOptions: {
                    disabledDate(time) {
                      return time.getTime() < Date.now() - 8.64e7;
                    }
                  }
                }
              },
              {
                type: "custom-input",
                title: '目的地',
                model: 'destination',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-input",
                title: '预算',
                model: 'eventsBudget',
                dataType: 'String',
                externalValue: {}
              },
              {
                type: "custom-textarea",
                title: '备注',
                model: 'description',
                dataType: 'String',
                externalValue: {}
              },{
                type: "custom-upload-file",
                title: '附件',
                model: 'fileData',
                externalValue: {
                  name: 'file',
                  actionUrl: `${baseUrl}/api/common/file-upload`,
                  requestHeader: {},
                  requestData: {},
                  uploadFileSuccess: (response, file, fileList) => {
                    if (response.status === 0) {
                      this.recivedFormFileData.push({
                        id: file.uid,
                        name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                        url: baseUrl + response.data.url
                      });
                      this.formModel.fileData = this.recivedFormFileData;
                      // for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      //   this.formModel.fileData = this.recivedFormFileData[i].url;
                      // }
//                  this.personBaseFormModel.fileUrl = (this.recivedFormFileData);
                    } else {
                      this.$message.error(response.msg);
                    }
                  },
                  uploadFilePreview: (file) => {
                    window.open(file.url, '_blank');
                  },
                  uploadFileRemove: (file, fileList) => {
                    for (let i = 0; i < this.recivedFormFileData.length; i++) {
                      if (file.uid === this.recivedFormFileData[i].uid) {
                        this.recivedFormFileData.splice(i, 1);
                        this.formModel.fileData.splice(i, 1);
                        break;
                      }
                    }
                    this.initFormSchema();
                  },
                  fileList: this.recivedFormFileData
                }
              },
              {
                type: 'submit'
              }
            ];
            break;
        }
      },

      initDelayData() {
        this.delayModel = {
          oldDate: this.oldDate,
          oldEndM: this.oldEndM,
          newDate: '',
          newEndM: ''
        };
        this.delayBtnData = [
          {
            title: this.delayBtnTitle,
            type: 'primary',
            callback: () => {
              this.delaySubmit();
            }
          },
          {
            title: '取消',
            type: 'default',
            callback: () => {
              this.formCancel();
            }
          },
        ];
      },
      initDestoryData() {
        this.destoryBtnData = [
          {
            title: this.destoryBtnTitle,
            type: 'primary',
            callback: () => {
              this.destorySubmit();
            }
          },
          {
            title: '取消',
            type: 'default',
            callback: () => {
              this.formCancel();
            }
          },
        ];
      },
      initDelaySchema() {
        let self = this;
        this.delaySchema = [
          {
            type: "custom-date-mm-picker",
            title: '原结束时间',
            model: 'oldDate',
            selector: 'oldEndM',
            dataType: 'String',
            externalValue: {
              dateDisabled: true,
              selector: {
                disabled: true,
                options: [
                  {label:"08:30", model:"08:30"},
                  {label:"09:00", model:"09:00"},
                  {label:"10:00", model:"10:00"},
                  {label:"11:00", model:"11:00"},
                  {label:"12:00", model:"12:00"},
                  {label:"13:00", model:"13:00"},
                  {label:"14:00", model:"14:00"},
                  {label:"15:00", model:"15:00"},
                  {label:"16:00", model:"16:00"},
                  {label:"17:00", model:"17:00"},
                  {label:"18:00", model:"18:00"},
                  {label:"19:00", model:"19:00"},
                  {label:"20:00", model:"20:00"},
                  {label:"21:00", model:"21:00"},
                  {label:"22:00", model:"22:00"},
                  {label:"23:00", model:"23:00"},
                ]
              }
            }
          },
          {
            type: "custom-date-mm-picker",
            title: '延长结束时间至',
            model: 'newDate',
            selector: 'newEndM',
            dataType: 'String',
            externalValue: {
              datePickerOptions: {
                disabledDate(time) {
                  // console.log("self.oldDate", self.oldDate);
                  if (self.oldDate.length !== 0) {
                    if (self.oldEndM == 'pm') {
                      return time.getTime() <= Date.now() - 8.64e7 || time.getTime() <= moment(self.oldDate, "YYYY-MM-DD").format('x');
                    }
                    else {
                      return time.getTime() < Date.now() - 8.64e7 || time.getTime() < moment(self.oldDate, "YYYY-MM-DD").format('x');
                    }
                  } else {
                    return time.getTime() < Date.now() - 8.64e7;
                  }
                }
              }
              ,
              selector: {
                options: [
                  {label:"08:30", model:"08:30"},
                  {label:"09:00", model:"09:00"},
                  {label:"10:00", model:"10:00"},
                  {label:"11:00", model:"11:00"},
                  {label:"12:00", model:"12:00"},
                  {label:"13:00", model:"13:00"},
                  {label:"14:00", model:"14:00"},
                  {label:"15:00", model:"15:00"},
                  {label:"16:00", model:"16:00"},
                  {label:"17:00", model:"17:00"},
                  {label:"18:00", model:"18:00"},
                  {label:"19:00", model:"19:00"},
                  {label:"20:00", model:"20:00"},
                  {label:"21:00", model:"21:00"},
                  {label:"22:00", model:"22:00"},
                  {label:"23:00", model:"23:00"},
                ]
              }
            }
          },
          {
            type: "submit"
          }
        ]
      },

      initDestorySchema() {
        this.destorySchema = [
          {
            type: "custom-upload-file",
            title: '附件',
            model: 'fileData',
            externalValue: {
              name: 'file',
              actionUrl: `${baseUrl}/api/common/file-upload`,
              requestHeader: {},
              requestData: {},
              uploadFileSuccess: (response, file, fileList) => {
                if (response.status === 0) {
                  this.recivedFormFileData.push({
                    id: file.uid,
                    name: file.name + "-" + getItem("userName") + "-" + getItem("orgNameStr"),
                    url: baseUrl + response.data.url
                  });
                  this.formModel.fileData = this.recivedFormFileData;

                } else {
                  this.$message.error(response.msg);
                }
              },
              uploadFilePreview: (file) => {
                window.open(file.url, '_blank');
              },

              fileList: this.recivedFormFileData
            }
          },
          {
            type: "submit"
          }
        ]
      },

      getPeers() {
        let params = {
          path: {
            id: 0
          }
        };
        Api.Administration.getPeers(params).then((result) => {
          this.formPermissionsData = [];
          if (result.status === 0) {
            this.formPermissionsData = this.assembleOrgData(result.data);
            this.stamp++;
//            this.initRecivedSchema();
            this.initFormSchema();
          } else {
            this.$message.error(result.msg);
          }
        });
      },

      getPeople() {
        Api.PersonnelManagement.personMemberLikeRoleTag("director").then((result) => {
          console.log("userinfoId", this.formModel.userinfoId);
          this.formPermissionsData = [];
          for (let i = 0; i < result.data.length; i++) {
            let people = result.data[i];
            this.formPermissionsData.push({
              model: people.id,
              label: people.personName
            })
          }
          console.log("rolePeople", this.formPermissionsData);
          this.initFormSchema();
        })
      },
      //请求所有人员
      getAllPeople() {
        let param = {
          query: {
            pageSize: 1000,
            pageNo: 1,
          },
          data: {}
        };
        Api.PersonnelManagement.getAllPeople(param).then((result) => {
          for (let i = 0; i < result.data.ls.length; i++) {
            let people = result.data.ls[i];
            this.formPeopleData.push({
              model: people.id,
              label: people.personName
            })
          }
        });
      },
      /*
       * form相关
       */
      //初始化表单数据源
      initFormData() {
        this.formModel = {
          eventsType: '',
          theme: '',
          leaveType: '',
          userinfoId: getItem('userInfoId'),
          executiveList: [],
          beginDate: '',
          beginM: '',
          endDate: '',
          endM: '',
          destination: '',
          description: '',
          eventsBudget: '',
          transferWork: '',
          emergencyNumber: '',
          fileData: [],
          conferenceNumber: '',
          travelRole: '2',
          foreignVisitTime: {
            foreignVisitDate: moment().format('YYYY-MM-DD'),
            foreignVisitEndTime: '',
            foreignVisitBeginTime: '',
          },
        };
        this.formBtnData = [
          {
            title: this.formBtnTitle,
            type: 'primary',
            callback: () => {
              this.formSubmit();
            }
          },
          {
            title: '取消',
            type: 'default',
            callback: () => {
              this.formCancel();
            }
          },
        ];
      },

      destorySubmit(){
        this.dialogLoading = true;
        Api.PersonnelManagement.salesLeave(this.personalEventsId).then((result) => {
          this.dialogLoading = false;
          if (result.status === 0) {
            this.getPersonalList();
            this.dialogdestoryVisible = false;
            this.$message({
              type: 'success',
              message: '销假成功!'
            });
          } else {
            this.$message.error(result.msg);
          }
        });
      },

      delaySubmit() {
        let data = {
          endDate: this.delayModel.newDate ? moment(this.delayModel.newDate).format('YYYY-MM-DD HH:mm:ss') : '',
          ext: {
            endM: this.delayModel.newEndM,
          }
        }
        this.dialogLoading = true;
        Api.PersonnelManagement.delayLeave(this.personalEventsId, data).then(result => {
          this.dialogLoading = false;
          if (result.status === 0) {
            this.pageNo = 1;
            this.getPersonalList();
            this.dialogdelayVisible = false;
            this.$message.info('延假成功');
          } else {
            this.$message.error(`${result.msg}`)
          }
        })
      },
      formSubmit() {
        let regExp = new RegExp("^[0-9]*$");
        if (!regExp.test(this.formModel.eventsBudget)) {
          this.$message.info("预算必须为数字！");
          return false;
        }
        let userinfos = [];
        var beginDate = '';
        var endDate = '';
        switch (this.formModel.eventsType) {
          case "foreignVisit":
            userinfos.push(this.formModel.userinfoId);
            beginDate = moment(this.formModel.foreignVisitTime.foreignVisitDate).format('YYYY-MM-DD ' + this.formModel.foreignVisitTime.foreignVisitBeginTime + ':ss');
            endDate = moment(this.formModel.foreignVisitTime.foreignVisitDate).format('YYYY-MM-DD ' + this.formModel.foreignVisitTime.foreignVisitEndTime + ':ss');
            break;
          case "leave":
            userinfos.push(this.formModel.userinfoId);
            beginDate = this.formModel.beginDate ? moment(this.formModel.beginDate).format('YYYY-MM-DD HH:mm:ss') : '';
            endDate = this.formModel.endDate ? moment(this.formModel.endDate).format('YYYY-MM-DD HH:mm:ss') : '';
            break;
          default:
            if (this.formModel.travelRole == '1') {
              userinfos.push(this.formModel.userinfoId);
            } else {
              userinfos = this.formCustomizePeopleData
            }
            beginDate = this.formModel.beginDate ? moment(this.formModel.beginDate).format('YYYY-MM-DD HH:mm:ss') : '';
            endDate = this.formModel.endDate ? moment(this.formModel.endDate).format('YYYY-MM-DD HH:mm:ss') : '';
            break;
        }
        let data = {
          eventsType: this.formModel.eventsType,
          userinfoId: userinfos,
          beginDate: beginDate,
          endDate: endDate,
          destination: this.formModel.destination,
          description: this.formModel.description,
          eventsBudget: this.formModel.eventsBudget,
          transferWork: this.formModel.transferWork,
          emergencyNumber: this.formModel.emergencyNumber,
          ext: {
            leaveType: this.formModel.leaveType,
            fileData: this.formModel.fileData,
            conferenceNumber: this.formModel.conferenceNumber,
            travelRole: this.formModel.travelRole,
            theme: this.formModel.theme,
            beginM: this.formModel.beginM,
            endM: this.formModel.endM,
          }
        };
        console.log(data);
        this.dialogLoading = true;
        Api.PersonnelManagement.addPersonalEvents(data).then(result => {
          this.dialogLoading = false;
          if (result.status === 0) {
            this.pageNo = 1;
            this.getPersonalList();
            this.dialogFormVisible = false;
            this.$message.info('添加成功');
          } else {
            this.$message.error(`${result.msg}`)
          }
        });
      },
      //清空表单
      formResetFields() {
        this.dialogFormVisible = false;
        this.dialogdelayVisible = false;
        this.dialogdestoryVisible = false;
        // this.formLoading = false;
        this.recivedFormFileData = [];
        this.$refs.childrenForm.resetFields();
        this.$refs.childrenForm.resetFields();
        this.initFormSchema();
      },
      //取消提交
      formCancel() {
        this.formResetFields();
      },
      // 获取事件列表
      getPersonalList(data) {
        this.pageLoading = true;
        Api.PersonnelManagement.PersonalEventsList(this.pageNo, this.pageSize, data).then(result => {
          this.pageLoading = false;
          if (result.status === 0) {
            console.log(result);
            for (let i = 0; i < result.data.ls.length; i++) {
              if (result.data.ls[i].eventsType == 'foreignVisit') {
                result.data.ls[i].beginDate = moment(result.data.ls[i].beginDate).format('YYYY-MM-DD HH:mm:ss');
                result.data.ls[i].endDate = moment(result.data.ls[i].endDate).format('YYYY-MM-DD HH:mm:ss');
              }
              else {
                result.data.ls[i].beginDate = moment(result.data.ls[i].beginDate).format('YYYY-MM-DD');
                result.data.ls[i].endDate = moment(result.data.ls[i].endDate).format('YYYY-MM-DD');
              }
            }
            this.tableTotalPage = result.data.total
            this.tableRowsData = result.data.ls;
          } else {
            this.$message.error(result.msg);
          }
        })
      },
      tableSingleCheck(param) {
        this.personalEventsId = this.tableRowsData[param].id;
        this.$router.push({name: "PersonalEventsCheck", params: {id: this.personalEventsId}})
      },
      tableSingleDelayLeave(param) {
        this.personalEventsId = this.tableRowsData[param].id;
        let personalEvent = this.tableRowsData[param];
        this.oldDate = personalEvent.endDate;
        this.oldEndM = personalEvent.ext.endM;
        this.dialogdelayVisible = true;
        this.initDelaySchema();
        this.initDelayData();

      },
      /*销假*/
      tableSingleSalesLeave(param) {
        this.personalEventsId = this.tableRowsData[param].id;
        let personalEvent = this.tableRowsData[param];

        Api.PersonnelManagement.PersonEventsDetail(this.personalEventsId).then(result => {
          this.recivedFormFileData = result.data.ext.fileData;
          this.dialogdestoryVisible = true;
          this.initDestorySchema();
          this.initDestoryData();

        })

        /*this.personalEventsId = this.tableRowsData[param].id;
        this.$confirm('是否要销假', '提示', {

          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.pageLoading = true;
          Api.PersonnelManagement.salesLeave(this.personalEventsId).then((result) => {
            this.pageLoading = false;
            if (result.status === 0) {
              this.$message({
                type: 'success',
                message: '销假成功!'
              });
              let data = {};
              this.getPersonalList(data);
            } else {
              this.$message.error(result.msg);
            }
          });
        }).catch(() => {

        });*/
      },
      tableSingleReimbursePrint(param) {
        this.reimburseId = this.tableRowsData[param].reimburseId;
        this.$router.push({name: "PersonalEventsFinancial", params: {id: this.reimburseId}})
      },
      tableSingleReimburse(param) {
        this.$router.push({name: 'PersonalEventsTravelPrint', params: {id: this.tableRowsData[param].reimburseId}});
      },
      // 选择页数
      tableSelectPage(param) {
        this.pageNo = param;
        this.getPersonalList();
      },
      setCascaderMultipleValue(value) {
//        this.formCustomizePeopleData = [];  //清空级联选择器选中值
        let extOptionChildrens = this.formPermissionsData.find(item => item.value == value[0]).children;
        let checkV = extOptionChildrens.find(item => item.value == value[1]);
        let checkInclude = this.formModel.executiveList.find(item => item.value == value[1]);
        if (!checkInclude) {
          this.formModel.executiveList.push(checkV);
          this.formCustomizePeopleData.push(value[value.length - 1]);
        }
      },
      handleClose(model) {
//        this.formCustomizePeopleData = [];
        this.formModel.executiveList.find((item, index) => {
          if (item.value === model.value) {
            this.formModel.executiveList.splice(index, 1);
            this.formCustomizePeopleData.splice(index, 1);
            this.initFormSchema();
            return true;
          }
        });
      },
      selectorValueChanged(model) {
        this.initFormSchema();
      },
      radioValueChanged(model) {
        this.initFormSchema();
      }
    },
    components: {
      PageLoading, DataTable, DataForm
    }
  }

</script>

<style scoped lang="less" rel="stylesheet/less">
  .expand-right {
    @media (min-width: 768px) {
      padding-left: 0 !important;
    }
  }

  .page-content {
    padding: 15px;
  }
</style>
