Blame view

src/store/modules/address.js 1.36 KB
7d6833f2c   范牧   地址列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  import urlAlias from '../url'
  import request from '../request'
  
  const { editAddress, addressList, getAddress } = urlAlias
  
  const state = { list: [], detail: {} }
  
  const mutations = {
    LIST: (state, list) => {
      state.list = list
    },
    DETAILS: (state, details) => {
      state.details = details
    }
  }
  
  const actions = {
    edit(mutations, param, success) {
      request({
        url: editAddress,
        data: param,
        success,
        fail: () => {
          uni.showModal({
            content: '编辑失败',
            showCancel: false
          })
        },
        complete: (res) => {
          console.log('complete status === > ', res)
        }
      })
    },
    list({ commit }) {
      request({
        url: addressList,
        success: (res) => {
          commit('LIST', res.data.data)
        },
        fail: () => {
          uni.showModal({
            content: '获取地址列表失败',
            showCancel: false
          })
        }
      })
    },
    details({ commit }, param, execute) {
      return new Promise((resolve, reject) => request({
        url: getAddress,
        data: param,
        success: (res) => {
          commit('DETAILS', res.data.data)
          resolve()
        },
        fail: () => {
          uni.showModal({
            content: '获取地址信息失败',
            showCancel: false
          })
        }
      }))
    }
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }