export default {
    /**
     * 保存地址信息
     */
    setList: (state, arr) => {
        state.list = arr
    },

    /**
     * 存储选择的送货信息
     */
    storeWaybillAd: (state, address) => {
        state.pickWaybillAd = address
        uni.setStorageSync('waybillAddress', address)
    },

    /**
     * 更新地址
     */
    updateListItem: (state, addressID) => {
        let arr = state.list.filter(item => item.detailAddress !== '自提订单：详细地址')
        let findItem = arr.find(item => item.id === addressID)
        let storeAddresss = uni.getStorageSync('waybillAddress')
        // console.log(storeAddresss)
        if (storeAddresss) {
            let storeAddress = storeAddresss[0]
            if (findItem.id === storeAddress.id) uni.setStorageSync('waybillAddress', [findItem])
        }
    },

    /**
     * 删除地址
     */
    delListItem: (state, id) => {
        console.log(state, id)
        let list = state.list
        let storeAddress = uni.getStorageSync('waybillAddress')
        // console.log(storeAddress, 'waybillAddress')
        if (storeAddress) {
            if (storeAddress[0].id === id) uni.removeStorageSync('waybillAddress')
        }
        for (let i = 0; i < list.length; i++) {
            if (list[i].id === id) {
                state.list.splice(i, 1)
                break
            }
        }
    },

    /**
     * 保存选择的地址
     */
    setCurPickAddress: (state, address) => {
        state.curPickAddress = address
    }
}