import { defineStore } from 'pinia';
import { clone, cloneDeep } from 'lodash-es';
// 默认任务信息
const defaulTaskFormInfo = {
  name: '',
  typeId: '',
  planTime: '',
  phoneList: [{ phone: null, name: null, gender: null }],
  callUserTestId:'',
  callPlatform: ''
};

const task = defineStore({
  id: 'task',
  state: () => ({
    taskFormInfo: uni.getStorageSync('taskFormInfo')||cloneDeep(defaulTaskFormInfo), // 任务信息
  }),

  actions: {

    // 更新任务信息
    async updateTaskFormInfo(taskFormData) {
      this.taskFormInfo = Object.assign(this.taskFormInfo,taskFormData)
	  uni.setStorageSync('taskFormInfo', this.taskFormInfo)
	  return this.taskFormInfo
    },
	// 重置默认数据
	resetTaskData() {
	  this.taskFormInfo = cloneDeep(defaulTaskFormInfo)
	  uni.setStorageSync('taskFormInfo', this.taskFormInfo)
	},
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'task-store',
      },
    ],
  },
});

export default task;
