import * as service from '@/services/tos';
import { message } from 'antd';
import { Link, useIntl, connect, Dispatch, history } from 'umi';

import { routerRedux } from 'dva/router'

import { timestampToTime, timestampToTime4 } from '@/utils/time';
import { picFromate, Fromate } from '@/utils/method';

export default {
  namespace: 'CommunityService',
  state: {
    Data: null,
    DataSave:null,
    CurData: null,
    CurDataDetail: null,
    Data7: null,
    Data8: null,
    Result: null,
    DataSaveDetail:null,
  },

  reducers: {
    returnPage(state, { Data }) {
      return { ...state, Data };
    },
    returnDataSave(state, { DataSave }) {
      return { ...state, DataSave }
    },
    returnCurData(state, { CurData }) {
      return { ...state, CurData };
    },
    returnCurDataDetail(state, { CurDataDetail }) {
      return { ...state, CurDataDetail };
    },
    returnPage7(state, { Data7 }) {
      return { ...state, Data7 };
    },
    returnPage8(state, { Data8 }) {
      return { ...state, Data8 };
    },
    returnResult(state, { Result }) {
      return { ...state, Result };
    },
    returnDataSaveDetail(state, { DataSaveDetail }) {
      return { ...state, DataSaveDetail };
    },
    
  },

  effects: {
    

        //预订设施查询
    *RA({ playload }, { call, put }) {          
        switch (playload.index) {
          case 40: {
            var Data = null
            yield put({ type: 'returnPage', Data});
          } break;
        }
          const resp = yield call(service.RA, playload);
          console.log(resp)
          if (resp.code == 500||resp.error_code!="0000") {
            // window.location.href = '/500';
          }
          if (resp.error_code != "0000") {
            console.log("请求错误码:" + "(" + playload.index + ")" + resp.error_code)
            console.log(playload)
          } else {
   
            switch (playload.index) {
    
              case 21:
                {
                  var tmp = resp.data.rows[0].tosOwerModel;
                  var tmp2 = resp.data.rows[0];
                  
                  console.log(resp.data.rows[0].replyImgUrl)
                  console.log(Fromate(resp.data.rows[0].replyImgUrl,[["url",null]]))
                  var CurDataDetail = {
                    community: tmp.communityName,
                    address: tmp.addressAndpostalCode,
                    home: tmp.buildingNumber + "#" + tmp.floorNumber + "-" + tmp.roomNumber,
                    name: tmp.owerName,
                    phone: tmp.accountLogin!=null?tmp.accountLogin:tmp.owerPhone,
                    email: tmp.owerEmail,
                    content: resp.data.rows[0].serviceContent,
                    replyContent: resp.data.rows[0].replyContent,
                    replyImgUrl:  Fromate(resp.data.rows[0].replyImgUrl,[["url",null]]),
                    status: tmp2.handleStatus,
                    pictrues: picFromate(tmp2.imgUrl),
                    time: timestampToTime4(tmp2.createTime.time)
                  };
                  yield put({ type: 'returnCurDataDetail', CurDataDetail, });
                } break;
              case 33:
              case 22: {
                message.success("Success Operation!", 3)
                history.go(-1)
                // history.push("/CommercialService/CommunityMaintenance")
              } break;
              case 23: {
                let Data8 = resp;
                yield put({ type: 'returnPage8', Data8, });
              } break;
              case 31: {
                let Data7 = resp;
                yield put({ type: 'returnPage7', Data7 })
              } break;
              case 35: {
                let Result = resp;
                yield put({ type: 'returnResult', Result })
              } break;
              case 37:
              case 36: {
                let DataSaveDetail = resp;
                yield put({ type: 'returnDataSaveDetail', DataSaveDetail, });
              } break;
              case 40: {
                let Data = resp;
                yield put({ type: 'returnPage', Data, });
              } break;
            }
          }
    
    
    },
        
    // *TosCommunityServiceGetDetail({ playload }, { call, put }) {
    //   const resp = yield call(service.TosCommunityServiceGetDetail, playload);
    //   console.log(resp)
    //   if (resp.error_code !=0 ) {
    //     window.location.href = '/500';
    //   } else {
    //     var tmp = resp.data.rows[0].tosOwerModel; 
    //     var tmp2 = resp.data.rows[0];
    //     console.log(tmp2.imgUrl)
    //     // TODO:还差图片
        
    //     var CurDataDetail = {
    //       community: tmp.communityName,
    //       address: tmp.addressAndpostalCode,
    //       home: tmp.buildingNumber+"#"+tmp.floorNumber+"-"+tmp.roomNumber,
    //       name: tmp.owerName,
    //       phone: tmp.owerPhone,
    //       email: tmp.owerEmail,
    //       content: resp.data.rows[0].serviceContent,
    //       status: tmp2.handleStatus,
    //       time:timestampToTime(tmp2.createTime.time)
    //     };
    //     yield put({ type: 'returnCurDataDetail', CurDataDetail, });
    //   }
    // },
    *SA({ playload }, { call, put }) {
      var DataSave = playload;
        yield put({ type: 'returnDataSave', DataSave, });
    },

    *setCurData({ playload }, { call, put }) {
      var CurData = playload;
        yield put({ type: 'returnCurData', CurData, });
    },

    *setCurDataDetail({ playload }, { call, put }) {
      var CurDataDetail=null
        yield put({ type: 'returnCurDataDetail', CurDataDetail, });
    },
    
    
    *ResultClear({ }, { put }) {
      var Result = null
      console.log("清除")
      yield put({type: 'returnResult', Result} )
    },
  },

};
