index.vue 8.4 KB

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