index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view>
  3. <view class="My_search-box">
  4. <My_search :value="content.where.condition" @onSearch="onSearch" />
  5. </view>
  6. <My_listbox ref="List" @getlist="getList" bottomHeight="70">
  7. <view class="item" v-for="(item, index) in list" :key="item.contactsid">
  8. <view class="head" hover-class="navigator-hover">
  9. <view class="label u-line-1">
  10. <text class="iconfont icon-dizhi-hui" />
  11. <text style="margin-right: 10px;">
  12. {{ item.name }}
  13. </text>
  14. <text>
  15. {{ item.phonenumber }}
  16. </text>
  17. </view>
  18. <view class="address">
  19. {{ getCity(item) }}
  20. </view>
  21. </view>
  22. <view class="bottom">
  23. <view class="switch-box" @click="setDefault(index)">
  24. <u-switch :value="item.isdefault == 1" activeColor="#70D95D" size="18" :loading="item.loading" />
  25. <text class="text">
  26. 设为默认
  27. </text>
  28. </view>
  29. <view class="funs">
  30. <view class="fun" @click="edit(item)">
  31. <text class="iconfont icon-bianji" />
  32. 编辑
  33. </view>
  34. <view class="fun" @click="deleteItem(item.contactsid)">
  35. <text class="iconfont icon-shanchu" />
  36. 删除
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </My_listbox>
  42. <view class="footer">
  43. <navigator class="add" url="/store/deliveryAddress/insert" @click="toAdd" hover-class="navigator-hover">
  44. 添加地址
  45. </navigator>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. "content": {
  54. "where": {
  55. "condition": ""
  56. }
  57. },
  58. list: [],
  59. }
  60. },
  61. onLoad() {
  62. uni.setNavigationBarTitle({
  63. title: '收货地址',
  64. });
  65. this.getList(true)
  66. },
  67. onShow() {
  68. delete this.$Http.updateList
  69. },
  70. methods: {
  71. getList(init = false) {
  72. if (this.paging(this.content, init)) return;
  73. this.$Http.basic({
  74. "id": "20240506103702",
  75. content: this.content
  76. }).then(res => {
  77. console.log("收货地址列表", res)
  78. this.$refs.List.RefreshToComplete()
  79. if (this.cutoff(res.msg)) return;
  80. this.list = res.pageNumber == 1 ? res.data : this.list.concat(res.data);
  81. this.content = this.$refs.List.paging(this.content, res)
  82. })
  83. },
  84. updateList() {
  85. let content = this.paging(this.content, true, true)
  86. this.$Http.basic({
  87. "id": "20240506103702",
  88. content
  89. }).then(res => {
  90. console.log("更新收货地址列表", res)
  91. if (this.cutoff(res.msg)) return;
  92. this.list = res.data;
  93. })
  94. },
  95. toAdd() {
  96. this.$Http.updateList = this.updateList.bind(this);
  97. },
  98. onSearch(condition) {
  99. if (condition == this.content.where.condition) return;
  100. this.content.where.condition = condition;
  101. this.getList(true);
  102. },
  103. setDefault(index) {
  104. this.$set(this.list[index], 'loading', true);
  105. let item = this.list[index],
  106. isdefault = item.isdefault == 1 ? 0 : 1
  107. this.$Http.basic({
  108. "id": 20240506103602,
  109. "content": {
  110. "contactsid": item.contactsid,
  111. isdefault
  112. }
  113. }).then(res => {
  114. console.log("设置默认", res)
  115. if (this.cutoff(res.msg)) return;
  116. item.loading = false;
  117. if (isdefault == 0) {
  118. item.isdefault = 0;
  119. this.$set(this.list, index, item);
  120. } else {
  121. this.list = this.list.map(v => {
  122. v.isdefault = v.contactsid == item.contactsid ? 1 : 0
  123. return v
  124. })
  125. }
  126. })
  127. },
  128. deleteItem(id) {
  129. let that = this;
  130. uni.showModal({
  131. title: '提示',
  132. content: '是否确定删除该地址?',
  133. confirmText: "删除",
  134. success: function ({ confirm }) {
  135. if (confirm) that.$Http.basic({
  136. "id": 20240506103502,
  137. "content": {
  138. "contactsids": [
  139. id
  140. ]
  141. },
  142. }).then(res => {
  143. console.log("删除", res)
  144. if (that.cutoff(res.msg)) return;
  145. that.updateList()
  146. })
  147. }
  148. });
  149. },
  150. edit(item) {
  151. this.toAdd()
  152. uni.navigateTo({
  153. url: '/store/deliveryAddress/insert?data=' + JSON.stringify(item),
  154. });
  155. }
  156. },
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. .My_search-box {
  161. background: #fff;
  162. width: 100vw;
  163. padding: 10px;
  164. box-sizing: border-box;
  165. }
  166. .item {
  167. margin-top: 10px;
  168. width: 100vw;
  169. background: #fff;
  170. .head {
  171. padding: 10px;
  172. .label {
  173. line-height: 20px;
  174. font-family: Source Han Sans SC, Source Han Sans SC;
  175. font-weight: bold;
  176. font-size: 14px;
  177. color: #000000;
  178. .iconfont {
  179. font-size: 12px;
  180. margin-right: 5px;
  181. }
  182. }
  183. .address {
  184. line-height: 17px;
  185. font-family: Source Han Sans SC, Source Han Sans SC;
  186. font-size: 12px;
  187. color: #666666;
  188. margin-top: 7px;
  189. }
  190. }
  191. .bottom {
  192. display: flex;
  193. align-items: center;
  194. justify-content: space-between;
  195. border-top: 1px solid #ddd;
  196. box-sizing: border-box;
  197. width: 100vw;
  198. height: 45px;
  199. background: #fff;
  200. .switch-box {
  201. display: flex;
  202. margin-left: 10px;
  203. align-items: center;
  204. .text {
  205. margin-left: 5px;
  206. font-family: Source Han Sans SC, Source Han Sans SC;
  207. font-size: 12px;
  208. color: #333333;
  209. }
  210. }
  211. .funs {
  212. display: flex;
  213. align-items: center;
  214. margin-right: 14px;
  215. .fun {
  216. font-family: Source Han Sans SC,
  217. Source Han Sans SC;
  218. font-size: 12px;
  219. color: #333333;
  220. margin-left: 20px;
  221. .iconfont {
  222. font-size: 12px;
  223. margin-right: 5px;
  224. }
  225. }
  226. }
  227. }
  228. }
  229. .footer {
  230. position: fixed;
  231. width: 100vw;
  232. height: 65px;
  233. background: #FFFFFF;
  234. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  235. box-sizing: border-box;
  236. padding: 10px;
  237. padding-top: 5px;
  238. bottom: 0;
  239. .add {
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. width: 100%;
  244. height: 45px;
  245. background: #C30D23;
  246. border-radius: 5px;
  247. font-family: PingFang SC, PingFang SC;
  248. font-size: 14px;
  249. color: #FFFFFF;
  250. }
  251. }
  252. </style>