//1待初审 2.待选房 3.待复审 4.初审不通过 5.待办理 6.入住成功 7.办理失效 8.撤销申请 
//9.复审不通过 10.待支付 11.待缴费 12.交易关闭 13.待退款 14.已退款 15.支付失效
import Vue from "vue";
import api from "@/api/index.js";
import store from "@/utils/store";
export default {
  namespaced: true,
  state: {
    applyInfo: {
      applicantSex: "1", //1男  2女
      liveProps: [],
      marryStatus: "2", //1已婚  2未婚
      partyMember: "1", //1是   2否
      spouseName: "",
      occupation: "",
      education: "",
      spousePhone: "",
      spouseCardCode: "",
      spouseSex: "1",
      company:"",
      regionId:""
    },
    applyList: [],
    applyDetail: {},
    modal: {
      //-1删除 1申请入住/待核验 2.通过核验/待选房 4.不通过核验 5.待办理 6.入住成功 7.办理失效 8.撤销申请 ,
      visible: false
    },
    depositForm:{
      businessId:0,
      orderAmount:0, 
      orderTitle:"选房定金", 
      orderType:4, 
      remark:"", 
      wxCode:""
    }
  },
  actions: {
    cancelApply( { commit, state }, id) {
      return api.request("get", api.getURL("cAPPHouse/applyLiveCancel"), {
				 id,
      }).then(res => {
        return res;
      });
    },
    applyLiveDetail({ commit, state }, id) {
      return api
        .request("get", api.getURL("cAPPHouse/newapplyLiveDetail"), {
          id
        })
        .then(res => {
          commit("SET_APPLY_DETAIL", res.data.data);
          return res;
        });
    },
    applyLiveList({ commit, state }, params) {
      return api
        .request("get", api.getURL("cAPPHouse/newapplyLiveList"), {
          pn: 1,
          pageSize: 30000
        })
        .then(res => {
          commit("SET_APPLY_LIST_STATUS", res.data.data.list);
          return res;
        });
    },
    applyLiveFirst({ commit, state }, userInfo) {
      return api
        .request(
          "post",
          api.getURL("cAPPHouse/applyLiveFirst"),
          userInfo
        )
        .then(res => {
          return res;
        });
    },
    applyLiveFirstInfo({ commit, state }) {
      return api
        .request("post", api.getURL("cAPPHouse/applyLiveFirstInfo"))
        .then(res => {
          if(res) {
            commit("SET_APPLY_INFO", res.data.data);
          }
          return res;
        });
    },
    commitApply({ commit, state }, params) {
      let imgs = state.applyInfo.liveProps;
      state.applyInfo = Object.assign({}, state.applyInfo, store("applyInfo"));
      state.applyInfo.applicantPhone = state.applyInfo.phone;
      delete state.applyInfo.id;
      delete state.applyInfo.flag;
      delete state.applyInfo.cardCodeFilter;
      delete state.applyInfo.userName;
      delete state.applyInfo.phone;
      state.applyInfo.applicantSex = state.applyInfo.applicantSex | 0;
      state.applyInfo.marryStatus = state.applyInfo.marryStatus | 0;
      state.applyInfo.liveProps = imgs;
      state.applyInfo.partyMember = state.applyInfo.partyMember | 0;  
      //state.applyInfo.marryStatus = state.applyInfo.marryStatus | 0;
      // 
      // return
      return api
        .request(
          "post",
          api.getURL("cAPPHouse/applyLiveCommit"),
          state.applyInfo
        )
        .then(res => {
          return res;
        });
    },
    payDepositMoney({ commit, state },depositForm) {
      return api
        .request("post", api.getURL("scanningPay/selHouseOrder"),depositForm)
        .then(res => {
          
          return res;
        });
    },
    depositGetPayUrl({ commit, state },applyId) {
      return api
        .request("get", api.getURL("cAPPHouse/getPayUrl"),applyId)
        .then(res => {
          //
          return res;
        });
    },
  },
  mutations: {
    INIT_DATA_STATUS(state, data) {},
    SET_APPLY_OCCUPATION(state, data) {
      state.applyInfo.occupation = data;
    },
    SET_APPLY_EDUCATION(state, data) {
      state.applyInfo.education = data;
    },
    SET_APPLY_REGIONID(state, data) {
      state.applyInfo.regionId = data;
    },
    SET_APPLY_INFO(state, data) {
      let loginInfo = store("login");
      state.applyInfo = Object.assign({}, state.applyInfo, data);
      if(!state.applyInfo.userName) {
        state.applyInfo.userName = loginInfo.zhName;
      }
      
    },
    INIT_APPLY_INFO(state, data) {
      //
      state.applyInfo = {
        applicantSex: "1", //1男  2女
        liveProps: [],
        marryStatus: "2", //1已婚  2未婚
        partyMember: "2", 
        spouseName: "",
        spousePhone: "",
        spouseCardCode: "",
        spouseSex: "1",
        regionId:""
      };
    },
    ADD_IMG_INFO(state, data) {
      state.applyInfo.liveProps.push(data);
      
    },
    REMOVE_IMG_INFO(state, url) {
      let targetIndex = 0;
      state.applyInfo.liveProps.map((item, index) => {
        if (item.propValue === url) {
          targetIndex = index;
        }
      });
      state.applyInfo.liveProps.splice(targetIndex, 1);
    },
    SET_APPLY_LIST_STATUS(state, data) {
      Vue.set(state, "applyList", data);
    },
    CHANGE_APPLY_DETAIL_STATUS(state, status) {
      state.applyDetail.status = 8;
      state.applyDetail.cancelTime = Date.now();
    },
    SET_APPLY_DETAIL(state, data) {
      Vue.set(state, "applyDetail", data);
    },
    SET_APPLY_MARRYSTATUS(state, data) {
      state.applyInfo.marryStatus = data;
    }
  },
  getters: {}
};
