import Vue from "vue";
import api from "@/api/index.js";

export default {
  namespaced: true,
  state: {
    subscribeList: [],
    subscribeDetail: {
      TPhmRegion: {
				
      }
    },
    subscribeForm: {
      age: null,
      channel: null,
      customerType: 0,
      housekeeper: 0,
      regionList: [],
      layoutList: [],
      intentionalProject: [
        {
          createTime: null,
          createrId: 0,
          createrName: null,
          id: 0,
          propCode: null,
          propName: null,
          propValue: null,
          propValueDesc: null,
          propValueInt: 0,
          wellId: 0
        }
      ],
      layoutId: null,
      name: null,
      needStatus: null,
      occupation: null,
      orderNo: null,
      phone: null,
      planLiveTime: 0,
      platform: 2,
      price: null,
      registTime: null,
      remark: null,
      seeTime: null,
      seeTimeInterval: 0,
      sex: null,
      wellCoustProps: [
        {
          // createTime: null,
          // createrId: 0,
          // createrName: null,
          // id: 0,
          propCode: null,
          propName: null,
          propValue: null,
          propValueDesc: null,
          propValueInt: 0
          //wellId: 0
        }
      ]
    },
    subscribeRegionColums: []
  },
  actions: {
    cselectDetail( { commit, state }, id) {
      return api.request("get", api.getURL("wellCustomer/cselectDetail"), {
				 id,
      }).then(res => {
        commit("SET_SUBSCRIBE_DETAIL", res.data.data);
        return res;
      });
    },
    fetchData({ commit, state }, ids) {
      return api.request("get", api.getURL("houseLayout/delete"), {
        ids: ids.join(",")
      });
    },
    subscribeList({ commit, state }) {
      return api
        .request("get", api.getURL("wellCustomer/cmyReservationPage"), {
          pn: 1,
          pageSize: 19000
        })
        .then(res => {
          commit("SET_SUBSCRIBE_LIST", res.data.data.list);
          return res;
        });
    },
    sendSubscribe({ commit, state }, ids) {
      commit("SET_SUBSCRIBE_WELL_REGION");
      return api
        .request(
          "post",
          api.getURL("wellCustomer/insert"),
          state.subscribeForm
        )
        .then(res => {
          //
          return res;
        });
    }
  },
  mutations: {
    INIT_DATA_STATUS(state, data) {},
    SET_REGION_COLUMS(state, data) {
      Vue.set(state, "subscribeRegionColums", data);
    },
    SET_SUBSCRIBE_SEX(state, data) {
      state.subscribeForm.sex = data;
    },
    SET_SUBSCRIBE_AGE(state, data) {
      state.subscribeForm.age = data.value;
    },
    SET_SUBSCRIBE_OCCUPATION(state, data) {
      state.subscribeForm.occupation = data;
    },
    SET_SUBSCRIBE_TIME(state, data) {
      state.subscribeForm.seeTime = data.seeTime;
      state.subscribeForm.seeTimeInterval = data.seeTimeInterval;
    },
    SET_SUBSCRIBE_REGION(state, data) {
      state.subscribeForm.wellCoustProps = [data];
    },
    SET_SUBSCRIBE_WELL_REGION(state, data) {
      //
      state.subscribeForm.intentionalProject = [
        ...state.subscribeForm.regionList,
        ...state.subscribeForm.layoutList
      ];
    },
    CLEAR_REGION_LIST(state, data) {
      state.subscribeForm.regionList = [];
    },
    CLEAR_LAYOUT_LIST(state, data) {
      state.subscribeForm.layoutList = [];
    },
    SET_SUBSCRIBE_REGION_LIST(state, data) {
      state.subscribeForm.regionList.push(data);
    },
    SET_SUBSCRIBE_LAYOUT_LIST(state, data) {
      state.subscribeForm.layoutList.push(data);
    },
    SET_SUBSCRIBE_PRICE(state, data) {
      state.subscribeForm.price = data;
    },
    SET_SUBSCRIBE_NEED(state, data) {
      state.subscribeForm.needStatus = data;
    },
    SET_SUBSCRIBE_CYCLE(state, data) {
      state.subscribeForm.planLiveTime = data;
    },
    SET_SUBSCRIBE_LIST(state, data) {
      Vue.set(state, "subscribeList", data);
    },
    SET_SUBSCRIBE_DETAIL(state, data) {
      //
      Vue.set(state, "subscribeDetail", data);
    },
  },
  getters: {}
};
