index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from '@/api/mall/index.js';
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({
  6. state: {
  7. isUpdate: true,
  8. hasLogin: false,
  9. userInfo: {},
  10. orderid: '',
  11. djqid: '',
  12. lasturl: '',
  13. type: '',
  14. groupid: '',
  15. zfMoney: 0,
  16. problem_co: '', //常见问题内容
  17. bindid: 0,
  18. tabbarList: [],
  19. likeList: [],
  20. page: 1, // 当前请求数据是第几页
  21. hasMoreData: true, // 上拉时是否继续请求数据,即是否还有更多数据
  22. pageSize: 10, // 获取的数据列表,以追加的形式添加进去,
  23. // 租地订单
  24. landleaseorder: {},
  25. // 租地提交订单
  26. updaordermess: {
  27. //下单的用户id
  28. // vip_id: null,
  29. //土地id
  30. soil_id: null,
  31. //地块键的id
  32. subdivision_id: null,
  33. // 土地图片
  34. soil_pic: null,
  35. // 订单金额
  36. order_money: null,
  37. // 服务id
  38. service_id: null,
  39. // 服务名称
  40. // service_name: null,
  41. // 租赁周期
  42. period_days: null,
  43. // 选购种子
  44. seeds: [],
  45. // 地址id
  46. address_id: null,
  47. // 订单信息姓名
  48. order_name: null,
  49. // 订单手机号
  50. order_mobile: null,
  51. // 备注
  52. remark: null,
  53. // 支付方式
  54. type_pay: null
  55. },
  56. addressmess: '',
  57. islogin: () => {
  58. if (!store.state.hasLogin) {
  59. let token = uni.getStorageSync('token')
  60. if (token) {
  61. store.state.hasLogin = true
  62. }
  63. }
  64. return store.state.hasLogin
  65. }
  66. },
  67. mutations: {
  68. //更改更新弹窗状态
  69. changeUpdate(state, value) {
  70. state.isUpdate = value
  71. },
  72. //更改租地提交订单
  73. setaddressmess(state, content) {
  74. state.addressmess = content
  75. },
  76. //更改租地提交订单
  77. setupdaordermess(state, content) {
  78. state.updaordermess = content
  79. },
  80. //保存租地订单
  81. setlandleaseorder(state, content) {
  82. state.landleaseorder = content
  83. },
  84. setTabbar(state, list) {
  85. state.tabbarList = list
  86. console.log("已经赋值" + state.tabbarList)
  87. },
  88. setProblem_co(state, content) {
  89. state.problem_co = content
  90. },
  91. getLike(state) {
  92. // 获取我的收藏
  93. api.goodslikelist({
  94. p: state.page
  95. }).then(res => {
  96. if (res.data.length > 0) {
  97. if (state.page == 1) {
  98. state.likeList = []
  99. }
  100. var contentlist = res.data;
  101. if (contentlist.length < state.pageSize) {
  102. state.likeList = state.likeList.concat(contentlist)
  103. state.hasMoreData = false
  104. } else {
  105. state.likeList = state.likeList.concat(contentlist)
  106. state.page = state.page + 1
  107. state.hasMoreData = true
  108. }
  109. } else {
  110. if (state.likeList.length == 1) {
  111. state.likeList = []
  112. } else {
  113. state.likeList = state.likeList.concat(res.data)
  114. }
  115. }
  116. })
  117. },
  118. login(state, provider) {
  119. state.userInfo = provider;
  120. state.hasLogin = true
  121. uni.setStorageSync( //缓存用户登陆状态
  122. 'token',
  123. provider.token
  124. )
  125. uni.setStorageSync( //缓存用户登陆状态
  126. 'userInfo',
  127. provider,
  128. )
  129. console.log("登陆状态:" + state.hasLogin)
  130. console.log("userInfo:" + JSON.stringify(provider))
  131. },
  132. /* 綁定上下级关系 */
  133. bind(state, pid) {
  134. state.bindid = pid;
  135. console.log('调用成功,已经储存上级 pid' + state.bindid)
  136. },
  137. logout(state) {
  138. state.hasLogin = false;
  139. console.log("登陆状态" + state.hasLogin)
  140. state.userInfo = {};
  141. uni.clearStorage()
  142. },
  143. islogin() {
  144. if (!state.hasLogin) {
  145. let token = uni.getStorageSync('token')
  146. if (token) {
  147. state.hasLogin = true
  148. }
  149. }
  150. return state.hasLogin
  151. }
  152. },
  153. actions: {
  154. }
  155. })
  156. export default store