<template>
  <view class="handler">
    <view class="head">
      <view class="tab" :class="{active: tab.value === dataInfo.tabActiveValue}" v-for="tab in dataInfo.tabs" :key="tab.id" @click="clickTab(tab.value)">
        {{tab.name}}<text v-if="tab.num !== ''">({{tab.num}})</text>
      </view>
    </view>
    <scroll-view scroll-y class="body">
      <!-- 汇总单 -->
      <template v-if="dataInfo.tabActiveValue === 'doing' && isInSummaryOrder">
        <!-- 耗材 -->
        <view class="summaryItem">
          <view class="summaryItem_head">
            耗材清单
          </view>
          <view class="summaryItem_body" v-if="dataInfo.summaryObj.consumableList.length">
            <view class="summaryItem_bodyItem" v-for="item in dataInfo.summaryObj.consumableList" :key="item.id" @click="numberClick(item, 'editConsumable')">
              <view class="summaryItem_bodyItem_top">
                <text class="name ellipsis">{{ item.consumableName }}({{ item.consumableBrandModel }})</text>
                <text class="value">{{ item.consumableEndPrice }}元</text>
              </view>
              <view class="summaryItem_bodyItem_bottom">
                <text class="name">x{{ item.consumablesNum }}</text>
                <text class="value">总价{{item.consumablesNum * item.consumableEndPrice}}元</text>
              </view>
            </view>
          </view>
          <view class="summaryItem_foot">
            <view class="summaryItem_foot_total">
              耗材总价：{{dataInfo.summaryObj.consumablePrice}}元
            </view>
            <view class="summaryItem_foot_add" @click="addConsumable">
              <text class="newicon newicon-icon-test"></text>
            </view>
          </view>
        </view>
        
        <!-- 工时 -->
        <view class="summaryItem">
          <view class="summaryItem_head">
            工时清单
          </view>
          <view class="summaryItem_body" v-if="dataInfo.summaryObj.workHourManagementList.length">
            <view class="summaryItem_bodyItem" v-for="item in dataInfo.summaryObj.workHourManagementList" :key="item.id" @click="numberClick(item, 'editWorkHourManagement')">
              <view class="summaryItem_bodyItem_top">
                <text class="name ellipsis">{{ item.workName }}</text>
                <text class="value">{{ item.wage }}元</text>
              </view>
              <view class="summaryItem_bodyItem_bottom">
                <text class="name">x{{ item.workHourNum2 }}{{ item.workUnit }}</text>
                <text class="value">总价{{item.workHourNum2 * item.wage}}元</text>
              </view>
            </view>
          </view>
          <view class="summaryItem_foot">
            <view class="summaryItem_foot_total">
              工时总价：{{dataInfo.summaryObj.workHourPrice}}元
            </view>
            <view class="summaryItem_foot_add" @click="addWorkHourManagement">
              <text class="newicon newicon-icon-test"></text>
            </view>
          </view>
        </view>
        
        <!-- 汇总单总价 -->
        <view class="summaryItem">
          <view class="summaryItem_foot total">
            <view class="summary_total">
              汇总单总价：{{dataInfo.summaryObj.totalMaintenancePrice}}元
            </view>
          </view>
        </view>
      </template>
      
      <!-- 故障处理 -->
      <template v-if="dataInfo.tabActiveValue === 'doing' && !isInSummaryOrder">故障处理
        <view class="form_item">
          <view class="title select"><text class="required newicon newicon-bitian"></text>院区：</view>
          <uni-data-select class="value" v-model="dataInfo.branchId" :localdata="dataInfo.branchList" :clear="false" placeholder="请选择院区" @change="changeBranch" :class="{formRed: isSubmmit && !dataInfo.branchId}"></uni-data-select>
        </view>
        <view class="form_item">
          <view class="title select"><text class="required newicon newicon-bitian"></text>责任科室：</view>
          <uni-data-select class="value" v-model="dataInfo.dutyId" :localdata="dataInfo.dutyList" :clear="false" placeholder="请选择责任科室" @change="changeDuty" :class="{formRed: isSubmmit && !dataInfo.dutyId}"></uni-data-select>
        </view>
        <view class="form_item">
          <view class="title select"><text class="required newicon newicon-bitian"></text>工作组：</view>
          <uni-data-select class="value" v-model="dataInfo.groupId" :localdata="dataInfo.groupList" :clear="false" placeholder="请选择工作组" @change="changeGroup" :class="{formRed: isSubmmit && !dataInfo.groupId}"></uni-data-select>
        </view>
        <view class="form_item">
          <view class="title radio"><text class="required newicon newicon-bitian"></text>是否指派到人：</view>
          <uni-data-checkbox class="value" v-model="dataInfo.isAssignUser" :localdata="dataInfo.isAssignUserList" @change="changeIsAssignUser" />
        </view>
        <view class="form_item" v-if="dataInfo.isAssignUser === 1">
          <view class="title select"><text class="required newicon newicon-bitian"></text>指派对象：</view>
          <uni-data-select class="value" v-model="dataInfo.userId" :localdata="dataInfo.userList" :clear="false" placeholder="请选择指派对象" :class="{formRed: isSubmmit && dataInfo.groupId && dataInfo.isAssignUser == 1 && !dataInfo.userId}"></uni-data-select>
        </view>
      </template>
      
      <!-- 延期处理 -->
      <template v-if="dataInfo.tabActiveValue === 'overtime'">
        <view class="form_item">
          <view class="title select"><text class="required newicon newicon-bitian"></text>延期原因：</view>
          <uni-data-select class="value" v-model="dataInfo.repairTypeId" :localdata="dataInfo.repairTypeList" :clear="false" placeholder="请选择延期原因" :class="{formRed: isSubmmit && !dataInfo.repairTypeId}"></uni-data-select>
        </view>
        <view class="form_item column">
          <view class="title"><text class="required newicon newicon-bitian"></text>延期说明：</view>
          <uni-easyinput class="value" type="textarea" v-model="dataInfo.deferralRemark" placeholder="请输入延期说明" :class="{formRed: isSubmmit && !dataInfo.deferralRemark.trim()}" />
        </view>
        <view class="form_item">
          <view class="title select"><text class="required newicon newicon-bitian"></text>延期天数：</view>
          <uni-data-select class="value" v-model="dataInfo.deferralDayId" :localdata="dataInfo.deferralDayList" :clear="false" placeholder="请选择延期天数" :class="{formRed: isSubmmit && !dataInfo.deferralDayId}"></uni-data-select>
        </view>
      </template>
    </scroll-view>
    <view class="foot_common_btns">
      <button @click="goBack" type="default" class="cancelButton btn">返回</button>
      <button @click="submmit" type="default" class="primaryButton btn">{{dataInfo.tabActiveValue === 'doing' && isInSummaryOrder ? '下一步' : '提交'}}</button>
    </view>
    <NumberModal v-if="dataInfo.isNumber" @cancelEmit="cancelNumber" @confirmEmit="conformNumber" @removeEmit="removeNumber" :selectData="dataInfo.selectData" :selectType="dataInfo.selectType" :evtNumber="dataInfo.evtNumber" showRemove></NumberModal>
  </view>
</template>

<script setup>
  import { ref, reactive, computed } from 'vue'
  import NumberModal from '@/components/NumberModal.vue';
  import { onLoad } from '@dcloudio/uni-app'
  import { generateNumberArray } from '@/utils/index.js'
  import { api_group, api_incidentDetail, api_user, api_incidentTask, api_branch, api_dutyDepartment, api_getDictionary, api_querySummaryDoc, api_addSummaryDoc } from "@/http/api.js"
  import { defaultColor } from '@/static/js/theme.js'
  import { useSetTitle } from '@/share/useSetTitle.js'
  import { useMakePhoneCall } from '@/share/useMakePhoneCall.js'
  import { useGoBack } from '@/share/useGoBack.js'
  import { useLoginUserStore } from '@/stores/loginUser'
  
  useSetTitle();
  const loginUserStore = useLoginUserStore();
  const { makePhoneCall }  = useMakePhoneCall();
  const { goBack }  = useGoBack();
  
  // 主题颜色
  const primaryColor = ref(defaultColor)
  
  // 是否进入汇总单
  const isInSummaryOrder = computed(() => () => {
    return dataInfo.tabActiveValue === 'doing' && dataInfo.incidentData.duty && dataInfo.incidentData.duty.addSummary == 1 && (dataInfo.incidentData.handlerUser.id == loginUserStore.loginUser.user.id);
  })
  
  // 数据
  const dataInfo = reactive({
    tabs: [
      // {id: 5, name: '故障处理', value: 'doing', num: ''},
      {id: 6, name: '延期处理', value: 'overtime', num: ''},
    ],
    tabActiveValue: 0,//当前选择的tab
    incidentId: undefined,//事件ID
    incidentData: {},//事件对象
    groupList: [], //工作组列表
    groupId: undefined, //工作组ID
    userList: [], //用户列表
    userId: undefined, //用户ID
    branchList: [], //院区列表
    branchId: undefined, //院区ID
    dutyList: [], //责任科室列表
    dutyId: undefined, //责任科室ID
    repairTypeList: [], //维修原因列表
    repairTypeId: undefined, //维修原因ID
    deferralDayList: [], //延期天数列表
    deferralDayId: undefined, //延期天数ID
    isAssignUser: 1, //工作组是否转派到人
    isAssignUserList: [
      { text: '是', value: 1 },
      { text: '否', value: 0 },
    ], //工作组是否转派到人选项
    reassignRemark: '',//退回原因
    deferralRemark: '',//延期说明
    summaryObj: {
      consumableList: [],//耗材列表
      workHourManagementList: [],//工时列表
    },//汇总单信息
    summaryId: undefined,//汇总单Id
    isNumber: false,//修改数量弹窗
    evtNumber: 1,//弹窗返回的数量
    selectData: {},//选择的对象
    selectType: {},//选择的对象类型
  })
  
  // 是否提交
  const isSubmmit = ref(false)
  
  // 点击修改数量
  function numberClick(data, type){
    if(type === 'editConsumable'){
      dataInfo.evtNumber = data.consumablesNum;
    }else if(type === 'editWorkHourManagement'){
      dataInfo.evtNumber = data.workHourNum2;
    }
    
    dataInfo.isNumber = true;
    dataInfo.selectData = data;
    dataInfo.selectType = type;
  }
  
  // 确认修改数量
  function conformNumber(evtNumber){
    dataInfo.evtNumber = evtNumber;
    dataInfo.isNumber = false;
    addSummaryDoc();
  }
  
  // 移除数量
  function removeNumber(evtNumber){
    dataInfo.evtNumber = evtNumber;
    dataInfo.isNumber = false;
    removeSummaryDoc();
  }
  
  // 关闭修改数量
  function cancelNumber(){
    dataInfo.isNumber = false;
  }
  
  // 修改耗材/工时
  function addSummaryDoc(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "summaryId": dataInfo.summaryId,
      "modifyNum": 'edit',
    };
    if(dataInfo.selectType === 'editConsumable'){
      postData.consumableList = [
        {
          "consumablesId": dataInfo.selectData.consumableId,
          "consumablesNum": dataInfo.evtNumber,
        }
      ];
    }else if(dataInfo.selectType === 'editWorkHourManagement'){
      postData.workHourManagementList = [
        {
          "workHourId": dataInfo.selectData.id,
          "workHourNum": dataInfo.evtNumber,
        }
      ];
    }
    api_addSummaryDoc(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        uni.showToast({
        	icon: 'none',
          title: '修改数量成功',
          mask: true,
        });
        getSummaryList();
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 移除耗材/工时
  function removeSummaryDoc(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "summaryId": dataInfo.summaryId,
      "remove": 'remove',
    };
    if(dataInfo.selectType === 'editConsumable'){
      postData.consumableList = [
        {
          "consumablesId": dataInfo.selectData.consumableId,
          "consumablesNum": dataInfo.evtNumber,
        }
      ];
    }else if(dataInfo.selectType === 'editWorkHourManagement'){
      postData.workHourManagementList = [
        {
          "workHourId": dataInfo.selectData.id,
          "workHourNum": dataInfo.evtNumber,
        }
      ];
    }
    api_addSummaryDoc(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        uni.showToast({
        	icon: 'none',
          title: '移除成功',
          mask: true,
        });
        getSummaryList();
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 重置
  function reset(){
    dataInfo.branchId = undefined;
    dataInfo.branchList = [];
    
    dataInfo.dutyId = undefined;
    dataInfo.dutyList = [];
    
    dataInfo.groupId = undefined;
    dataInfo.groupList = [];
    
    dataInfo.userId = undefined;
    dataInfo.userList = [];
    
    dataInfo.isAssignUser = 1;
    
    dataInfo.reassignRemark = '';
    dataInfo.deferralRemark = '';
  }
  
  // 初始化表单
  function initForm(){
    if(dataInfo.tabActiveValue === 'doing'){
      getSummaryList();
    }else if(dataInfo.tabActiveValue === 'overtime'){
      getRepairTypes();
      getDeferralDays();
    }
  }
  
  // 点击tab
  function clickTab(tabValue){
    if(dataInfo.tabActiveValue == tabValue){
      return;
    }
    dataInfo.tabActiveValue = tabValue;
    isSubmmit.value = false;
    reset();
    initForm()
  }
  
  // 获取事件详情
  function getIncidentDetail(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });

    api_incidentDetail(dataInfo.incidentId).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        dataInfo.incidentData = res.data || {};
        let chuli = false;//故障处理权限
        for (let i = 0; i < loginUserStore.loginUser.menu.length; i++) {
            if (loginUserStore.loginUser.menu[i].link == "shijianliebiao_chuli") {
              chuli = true
            }
        }
        
        // 故障处理
        if(dataInfo.incidentData.state.value == 'handler' && dataInfo.incidentData.handlingPersonnelUser && dataInfo.incidentData.handlingPersonnelUser.id == loginUserStore.loginUser.user.id && chuli){
          dataInfo.tabs.splice(0, 0, {id: 5, name: '故障处理', value: 'doing', num: ''});
        }
        
        dataInfo.tabActiveValue = dataInfo.tabs[0].value;
        
        initForm()
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 获取延期原因列表
  function getRepairTypes(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "key": 'repair_type',
      "type": "list",
    };
    api_getDictionary(postData).then(res => {
      uni.hideLoading();
      res = res || [];
      dataInfo.repairTypeList = res.map(v => ({
        text: v.name,
        value: v.id,
      }));
    })
  }
  
  // 获取延期天数列表
  function getDeferralDays(){
    dataInfo.deferralDayList = generateNumberArray(1, 15).map(v => ({
      text: v + '天',
      value: v,
    }));
  }
  
  // 获取汇总单信息
  function getSummaryList(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "incidentId": dataInfo.incidentId,
    };
    api_querySummaryDoc(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        dataInfo.summaryObj = {...{consumableList:[], workHourManagementList: []}, ...res };
        console.log(dataInfo.summaryObj)
        dataInfo.summaryId = res.summaryId;
      }else if(res.status == 201){
        // 事件第一次绑定汇总单
        dataInfo.summaryId = res.summaryId;
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 添加耗材
  function addConsumable(){
    uni.navigateTo({
      url: `/pages/consumableList/consumableList?incidentId=${dataInfo.incidentId}&summaryId=${dataInfo.summaryId}`
    })
  }
  
  // 添加工时
  function addWorkHourManagement(){
    uni.navigateTo({
      url: `/pages/workHourManagementOne/workHourManagementOne?incidentId=${dataInfo.incidentId}&summaryId=${dataInfo.summaryId}`
    })
  }
  
  // 获取院区列表
  function getBranchs(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "idx": 0,
      "sum": 9999,
    };
    api_branch(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        res.list = res.list || [];
        dataInfo.branchList = res.list.map(v => ({
          text: v.hosName,
          value: v.id,
        }));
        
        if(loginUserStore.loginUser.user.duty){
          // 当前的所属责任科室
          dataInfo.branchId = loginUserStore.loginUser.user.duty.branch;
          changeBranch();
          
          dataInfo.dutyId = loginUserStore.loginUser.user.duty.id;
          changeDuty();
        }else if(loginUserStore.loginUser.user.branch){
          // 当前的所属院区
          dataInfo.branchId = loginUserStore.loginUser.user.branch.id;
        }
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 获取责任科室列表
  function getDutys(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "idx": 0,
      "sum": 9999,
      "dutyDepartment": {
        "branch": dataInfo.branchId,
      }
    };
    api_dutyDepartment(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        res.list = res.list || [];
        dataInfo.dutyList = res.list.map(v => ({
          text: v.dept,
          value: v.id,
        }));
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 获取工作组列表
  function getGroups(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    
    let duty = undefined;
    if(dataInfo.tabActiveValue === 'redeploy'){
      duty = dataInfo.incidentData.duty;
    }else if(dataInfo.tabActiveValue === 'assign'){
      duty = { id: dataInfo.dutyId };
    }
    
    let postData = {
      "idx": 0,
      "sum": 9999,
      "group": {
          "duty": duty,
          "selectType": "nouser"
      }
    };
    api_group(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        res.list = res.list || [];
        dataInfo.groupList = res.list.map(v => ({
          text: v.groupName,
          value: v.id,
        }));
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 获取用户列表
  function getUsers(){
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    let postData = {
      "idx": 0,
      "sum": 9999,
      "user": {
          "groupdata":{
            "id": dataInfo.groupId,
          },
          "roledata": {
              "rolecode": "first-line support"
          },
          "roledata2": {
              "rolecode": "second-line support"
          },
          "selectType": "1",
          "selectDetails": 1,
          "simple": true,
          "engineer": 1
      }
    };
    api_user(postData).then(res => {
      uni.hideLoading();
      if(res.status == 200){
        res.list = res.list || [];
        dataInfo.userList = res.list.map(v => ({
          text: v.name,
          value: v.id,
        }));
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 选择院区
  function changeBranch(){
    dataInfo.dutyId = undefined;
    dataInfo.dutyList = [];
    
    dataInfo.groupId = undefined;
    dataInfo.groupList = [];
    
    dataInfo.userId = undefined;
    dataInfo.userList = [];
    getDutys();
  }
  
  // 选择责任科室
  function changeDuty(){
    dataInfo.groupId = undefined;
    dataInfo.groupList = [];
    
    dataInfo.userId = undefined;
    dataInfo.userList = [];
    getGroups();
  }
  
  // 选择工作组
  function changeGroup(){
    dataInfo.userId = undefined;
    dataInfo.userList = [];
    getUsers();
  }
  
  // 选择是否转派到人
  function changeIsAssignUser(){
    dataInfo.userId = undefined;
  }
  
  // 提交
  function submmit(){
    isSubmmit.value = true;
    if(dataInfo.tabActiveValue === 'doing' && isInSummaryOrder){
      
    }else if(dataInfo.tabActiveValue === 'doing' && isInSummaryOrder){
      
    }else if(dataInfo.tabActiveValue === 'overtime'){
      submmitOvertime();
    }
  }
  
  // 转派提交
  function submmitRedeploy(){
    if(!dataInfo.groupId){
      uni.showToast({
      	icon: 'none',
        title: '请选择工作组'
      });
      return;
    }
    
    if(dataInfo.isAssignUser == 1 && !dataInfo.userId){
      uni.showToast({
      	icon: 'none',
        title: '请选择指派对象'
      });
      return;
    }
    
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    
    let postData = {
      incident: dataInfo.incidentData,
    }
    
    if(dataInfo.userId){
      // 派人
      postData.incident.assignee = dataInfo.userId;
    } else {
      // 派组
      postData.incident.candidateGroups = dataInfo.groupId;
    }
    
    api_incidentTask(dataInfo.tabActiveValue, postData).then(res => {
      uni.hideLoading();
      if(res.state == 200){
        uni.showToast({
        	icon: 'none',
          title: '转派成功',
          mask: true,
        });
        setTimeout(() => {
          uni.reLaunch({
            url: '/pages/incidentList/incidentList',
          })
        }, 1500)
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 指派提交
  function submmitAssign(){
    if(!dataInfo.branchId){
      uni.showToast({
      	icon: 'none',
        title: '请选择院区'
      });
      return;
    }
    
    if(!dataInfo.dutyId){
      uni.showToast({
      	icon: 'none',
        title: '请选择责任科室'
      });
      return;
    }
    
    if(!dataInfo.groupId){
      uni.showToast({
      	icon: 'none',
        title: '请选择工作组'
      });
      return;
    }
    
    if(dataInfo.isAssignUser == 1 && !dataInfo.userId){
      uni.showToast({
      	icon: 'none',
        title: '请选择指派对象'
      });
      return;
    }
    
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    
    let postData = {
      incident: dataInfo.incidentData,
    }
    
    if(dataInfo.userId){
      // 派人
      postData.incident.assignee = dataInfo.userId;
    } else {
      // 派组
      postData.incident.candidateGroups = dataInfo.groupId;
    }
    
    api_incidentTask(dataInfo.tabActiveValue, postData).then(res => {
      uni.hideLoading();
      if(res.state == 200){
        uni.showToast({
        	icon: 'none',
          title: '指派成功',
          mask: true,
        });
        setTimeout(() => {
          uni.reLaunch({
            url: '/pages/incidentList/incidentList',
          })
        }, 1500)
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  // 退回提交
  function submmitReassign(){
    if(!dataInfo.reassignRemark.trim()){
      uni.showToast({
      	icon: 'none',
        title: '请填写退回原因'
      });
      return;
    }
    
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    
    let postData = {
      incident: dataInfo.incidentData,
    }
    
    postData.incident.reassignRemark = dataInfo.reassignRemark;
    
    api_incidentTask(dataInfo.tabActiveValue, postData).then(res => {
      uni.hideLoading();
      if(res.state == 200){
        uni.showToast({
        	icon: 'none',
          title: '退回成功',
          mask: true,
        });
        setTimeout(() => {
          uni.reLaunch({
            url: '/pages/incidentList/incidentList',
          })
        }, 1500)
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  // 延期处理提交
  function submmitOvertime(){
    if(!dataInfo.repairTypeId){
      uni.showToast({
      	icon: 'none',
        title: '请选择延期原因'
      });
      return;
    }
    
    if(!dataInfo.deferralRemark.trim()){
      uni.showToast({
      	icon: 'none',
        title: '请填写延期说明'
      });
      return;
    }
    
    if(!dataInfo.deferralDayId){
      uni.showToast({
      	icon: 'none',
        title: '请选择延期天数'
      });
      return;
    }
    
    uni.showLoading({
      title: "加载中",
      mask: true,
    });
    
    let postData = {
      incident: dataInfo.incidentData,
    }
    
    postData.incident.currentLog = {
      remark: dataInfo.deferralRemark,
      extra1: dataInfo.repairTypeId,
      extra2: dataInfo.deferralDayId,
    }
    
    api_incidentTask(dataInfo.tabActiveValue, postData).then(res => {
      uni.hideLoading();
      if(res.state == 200){
        uni.showToast({
        	icon: 'none',
          title: '延期处理成功',
          mask: true,
        });
        setTimeout(() => {
          uni.reLaunch({
            url: '/pages/incidentList/incidentList',
          })
        }, 1500)
      }else{
        uni.showToast({
          icon: 'none',
          title: res.msg || '请求数据失败！'
        });
      }
    })
  }
  
  onLoad((option) => {
    dataInfo.incidentId = option.incidentId;
    getIncidentDetail();
  })
</script>

<style lang="scss" scoped>
.handler{
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: #F7F7F7;
  .head{
    height: 88rpx;
    display: flex;
    position: fixed;
    z-index: 99;
    width: 100%;
    background-color: #fff;
    font-size: 30rpx;
    .tab{
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      border-bottom: 4rpx solid transparent;
      &.active{
        color: $uni-primary;
        border-color: $uni-primary;
      }
    }
  }
  .body{
    margin-top: 88rpx;
    box-sizing: border-box;
    flex: 1;
    min-height: 0;
    .summaryItem{
      &:first-of-type{
        .summaryItem_head{
          border-bottom: 1rpx solid #DDDDDD;
        }
      }
      .summary_total{
        padding: 20rpx 0;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .summaryItem_head{
        padding: 24rpx;
        font-size: 26rpx;
        color: #3A3A3A;
      }
      .summaryItem_body{
        font-size: 30rpx;
        background-color: #fff;
        .summaryItem_bodyItem{
          padding: 24rpx;
          border-bottom: 1rpx solid #DDDDDD;
          .summaryItem_bodyItem_top{
            display: flex;
            justify-content: space-between;
            align-items: center;
            .value{
              padding-left: 48rpx;
              flex-shrink: 0;
            }
          }
          .summaryItem_bodyItem_bottom{
            margin-top: 24rpx;
            display: flex;
            justify-content: space-between;
            align-items: center;
            .name{
              text-align: right;
              flex: 1;
            }
            .value{
              width: 240rpx;
              text-align: right;
              padding-left: 48rpx;
              flex-shrink: 0;
            }
          }
        }
      }
      .summaryItem_foot{
        font-size: 30rpx;
        background-color: #fff;
        &.total{
          margin-top: 24rpx;
        }
        .summaryItem_foot_total{
          padding: 24rpx 0;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .summaryItem_foot_add{
          border-top: 1rpx solid #DDDDDD;
          padding: 24rpx 0;
          display: flex;
          justify-content: center;
          align-items: center;
          .newicon-icon-test{
            font-size: 30rpx;
            font-weight: bold;
          }
        }
      }
    }
    .form_item{
      display: flex;
      align-items: center;
      padding-top: 24rpx;
      height: 86rpx;
      &.column{
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        .title{
          margin-right: 0;
        }
        .value{
          margin-top: 10rpx;
          padding-left: 20rpx;
          box-sizing: border-box;
        }
        .tips{
          padding: 24rpx;
          text-align: center;
          font-size: 22rpx;
          color: #909399;
          width: 100%;
          box-sizing: border-box;
        }
      }
      .title{
        font-size: 26rpx;
        display: flex;
        align-items: center;
        margin-right: 12rpx;
        &.select{
          width: calc(5em + 20rpx);
        }
      }
    }
  }
}
</style>
