index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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" @click="onClick(item)">
  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(options) {
  62. uni.setNavigationBarTitle({
  63. title: options.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. this.$refs.List.paging(this.content, res, true)
  94. })
  95. },
  96. toAdd() {
  97. this.$Http.updateList = this.updateList.bind(this);
  98. },
  99. onSearch(condition) {
  100. if (condition == this.content.where.condition) return;
  101. this.content.where.condition = condition;
  102. this.getList(true);
  103. },
  104. setDefault(index) {
  105. this.$set(this.list[index], 'loading', true);
  106. let item = this.list[index],
  107. isdefault = item.isdefault == 1 ? 0 : 1
  108. this.$Http.basic({
  109. "id": 20240506103602,
  110. "content": {
  111. "contactsid": item.contactsid,
  112. isdefault
  113. }
  114. }).then(res => {
  115. console.log("设置默认", res)
  116. if (this.cutoff(res.msg)) return;
  117. item.loading = false;
  118. if (isdefault == 0) {
  119. item.isdefault = 0;
  120. this.$set(this.list, index, item);
  121. } else {
  122. this.list = this.list.map(v => {
  123. v.isdefault = v.contactsid == item.contactsid ? 1 : 0
  124. return v
  125. })
  126. }
  127. })
  128. },
  129. deleteItem(id) {
  130. let that = this;
  131. uni.showModal({
  132. title: '提示',
  133. content: '是否确定删除该地址?',
  134. confirmText: "删除",
  135. success: function ({ confirm }) {
  136. if (confirm) that.$Http.basic({
  137. "id": 20240506103502,
  138. "content": {
  139. "contactsids": [
  140. id
  141. ]
  142. },
  143. }).then(res => {
  144. console.log("删除", res)
  145. if (that.cutoff(res.msg)) return;
  146. that.updateList()
  147. })
  148. }
  149. });
  150. },
  151. edit(item) {
  152. this.toAdd()
  153. uni.navigateTo({
  154. url: '/store/deliveryAddress/insert?data=' + JSON.stringify(item),
  155. });
  156. },
  157. onClick(item) {
  158. this.$Http.selectAddress && this.$Http.selectAddress(item)
  159. }
  160. },
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .My_search-box {
  165. background: #fff;
  166. width: 100vw;
  167. padding: 10px;
  168. box-sizing: border-box;
  169. }
  170. .item {
  171. margin-top: 10px;
  172. width: 100vw;
  173. background: #fff;
  174. .head {
  175. padding: 10px;
  176. .label {
  177. line-height: 20px;
  178. font-family: Source Han Sans SC, Source Han Sans SC;
  179. font-weight: bold;
  180. font-size: 14px;
  181. color: #000000;
  182. .iconfont {
  183. font-size: 12px;
  184. margin-right: 5px;
  185. }
  186. }
  187. .address {
  188. line-height: 17px;
  189. font-family: Source Han Sans SC, Source Han Sans SC;
  190. font-size: 12px;
  191. color: #666666;
  192. margin-top: 7px;
  193. }
  194. }
  195. .bottom {
  196. display: flex;
  197. align-items: center;
  198. justify-content: space-between;
  199. border-top: 1px solid #ddd;
  200. box-sizing: border-box;
  201. width: 100vw;
  202. height: 45px;
  203. background: #fff;
  204. .switch-box {
  205. display: flex;
  206. margin-left: 10px;
  207. align-items: center;
  208. .text {
  209. margin-left: 5px;
  210. font-family: Source Han Sans SC, Source Han Sans SC;
  211. font-size: 12px;
  212. color: #333333;
  213. }
  214. }
  215. .funs {
  216. display: flex;
  217. align-items: center;
  218. margin-right: 14px;
  219. .fun {
  220. font-family: Source Han Sans SC,
  221. Source Han Sans SC;
  222. font-size: 12px;
  223. color: #333333;
  224. margin-left: 20px;
  225. .iconfont {
  226. font-size: 12px;
  227. margin-right: 5px;
  228. }
  229. }
  230. }
  231. }
  232. }
  233. .footer {
  234. position: fixed;
  235. width: 100vw;
  236. height: 65px;
  237. background: #FFFFFF;
  238. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  239. box-sizing: border-box;
  240. padding: 10px;
  241. padding-top: 5px;
  242. bottom: 0;
  243. .add {
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. width: 100%;
  248. height: 45px;
  249. background: #C30D23;
  250. border-radius: 5px;
  251. font-family: PingFang SC, PingFang SC;
  252. font-size: 14px;
  253. color: #FFFFFF;
  254. }
  255. }
  256. </style>