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

export default {
  namespaced: true,
  state: {
    complainInfo: {
      contactId: 0,
      contactName: "",
      contactTele: "",
      feedbackContent: "",
      feedbackOrgCode: "c_wechat",
      feedbackOrgName: "微信",
      id: 0,
      remark: "",
      suggestProps: []
    },
    funInfo: {
      contactId: 0,
      contactName: "",
      contactTele: "",
      createTime: "",
      feedbackContent: "",
      feedbackOrgCode: "c_wechat",
      feedbackOrgName: "微信",
      handleMsg: "",
      id: 0,
      props: [
				
      ],
      status: 0,
      systomInfo: "",
      version: ""
    }
  },
  actions: {
    sendComplainSuggest({ commit, state, rootState }, ids) {
      //
      state.complainInfo.contactId = rootState.loginModule.loginInfo.id;
      return api
        .request(
          "post",
          api.getURL("ComplaintSuggest/addComplaint"),
          state.complainInfo
        )
        .then(res => {
					
          return res;
        });
    },
    sendFunSuggest({ commit, state, rootState }, ids) {
      //
      state.funInfo.contactId = rootState.loginModule.loginInfo.id;
      return api
        .request(
          "post",
          api.getURL("FsAbnormal/addComplaint"),
          state.funInfo
        )
        .then(res => {
					
          return res;
        });
    }
  },
  mutations: {
    CLEAR_FUN_INFO(state) {
      state.funInfo = {
        contactId: 0,
        contactName: "",
        contactTele: "",
        createTime: "",
        feedbackContent: "",
        feedbackOrgCode: "c_wechat",
        feedbackOrgName: "微信",
        handleMsg: "",
        id: 0,
        props: [
					
        ],
        status: 0,
        systomInfo: "",
        version: ""
      };
    },
    CLEAR_COMPLAIN_INFO(state) {
      state.complainInfo = {
        contactId: 0,
        contactName: "",
        contactTele: "",
        feedbackContent: "",
        feedbackOrgCode: "c_wechat",
        feedbackOrgName: "微信",
        id: 0,
        remark: "",
        suggestProps: []
      };
    },
    INIT_DATA_STATUS(state, data) {},
    ADD_IMG_INFO(state, files) {
      state.complainInfo.suggestProps.push({
        complaintSuggestId: null,
        createTime: "",
        createrId: 0,
        createrName: "",
        id: null,
        propCode: "1",
        propName: "投诉建议",
        propValue: files.response.data,
        propValueDesc: "投诉建议",
        propValueInt: 0
      });
    },
    REMOVE_IMG_INFO(state, url) {
      let targetIndex = 0;
      state.complainInfo.suggestProps.map((item, index) => {
        if (item.propValue === url) {
          targetIndex = index;
        }
      });
      state.complainInfo.suggestProps.splice(targetIndex, 1);
    },
    FUN_ADD_IMG_INFO(state, files) {
      state.funInfo.props.push({
        abnormalId: 0,
        id: 0,
        propCode: "1",
        propName: "功能异常反馈",
        propValue: files.response.data,
        propValueDesc: "功能异常反馈",
        propValueInt: 0
      });
    },
    FUN_REMOVE_IMG_INFO(state, url) {
      let targetIndex = 0;
      state.funInfo.props.map((item, index) => {
        if (item.propValue === url) {
          targetIndex = index;
        }
      });
      state.funInfo.props.splice(targetIndex, 1);
    }
  },
  getters: {}
};
