booking.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view>
  3. <u-navbar title="订气" autoBack placeholder></u-navbar>
  4. <view class="card_shipping">
  5. <view class="space_between shipping_select" @click="selectShipping">
  6. <view class="shipping_title" v-if="!addInfo.id">选择收货地址</view>
  7. <view v-else>
  8. <view class="center_item">
  9. <view class="title_item">{{addInfo.name}}</view>
  10. <view class="title_item">{{hidePhone(addInfo.phone)}}</view>
  11. </view>
  12. <view class="title_address1">
  13. {{cityScreening(addInfo.city, areaData)}}{{cityScreening(addInfo.area, areaData)}}{{addInfo.address}}
  14. </view>
  15. </view>
  16. <view style="margin-right: 10rpx;">
  17. <u-icon name="arrow-right"></u-icon>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="card_form">
  22. <x-form ref="personage" :list="list" :model="model" :rules="rules" @confirm="confirm"
  23. @clientele="clientele"></x-form>
  24. </view>
  25. <u-popup :show="receivingShow" closeable :round="10" mode="bottom" @close="close">
  26. <view class="card_addres">
  27. <view class="title_address">选择收货地址</view>
  28. <view class="card_add_booking">
  29. <view class="card_address" v-for="(item,index) in addressList" :key="index"
  30. @click="selectBooking(item)">
  31. <view class="card_group"
  32. :style="{border:item.flag ? '2rpx solid #2b85e4' : '2rpx solid #e7e6e4'}">
  33. <view class="item_radio" v-if="item.flag"></view>
  34. </view>
  35. <view style="width: 100%;">
  36. <view class="center_item">
  37. <view class="title_item">{{item.name}}</view>
  38. <view class="phone_title">
  39. <view class="title_item">{{hidePhone(item.phone)}}</view>
  40. <view class="tag_phone" v-if="item.isDefault">默认</view>
  41. </view>
  42. </view>
  43. <view class="center_item address_item">
  44. <view class="title_address1">
  45. {{cityScreening(item.city, areaData)}}{{cityScreening(item.area, areaData)}}{{item.address}}
  46. </view>
  47. <view @click.native.stop="goAmend(item)"><u-icon name="edit-pen" size="30"></u-icon>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="btn_add">
  54. <u-button type="primary" size="normal" text="新增收货地址" @click="rightClick"></u-button>
  55. </view>
  56. </view>
  57. </u-popup>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. urbanArea
  63. } from '@/static/js/districtCode.js'
  64. export default {
  65. data() {
  66. return {
  67. areaData: urbanArea(), //原始数据
  68. list: [{
  69. field: 'commodity',
  70. label: '商品',
  71. placeholder: '请选择商品',
  72. type: 'select',
  73. required: true,
  74. options: [
  75. [{
  76. label: '液化石油气',
  77. value: 0,
  78. },
  79. {
  80. label: '二甲醚',
  81. value: 1,
  82. },
  83. ]
  84. ],
  85. }, {
  86. field: 'specification',
  87. label: '规格',
  88. placeholder: '请选择规格',
  89. type: 'select',
  90. required: true,
  91. }, {
  92. field: 'amount',
  93. label: '数量',
  94. placeholder: '请输入数量',
  95. type: 'input',
  96. required: true,
  97. }, {
  98. field: 'remark',
  99. label: '备注',
  100. placeholder: '请输入备注',
  101. type: 'textarea',
  102. }],
  103. model: {
  104. commodity: '',
  105. specification: '',
  106. amount: '',
  107. remark: '',
  108. },
  109. rules: {
  110. 'commodity': {
  111. type: 'string',
  112. required: true,
  113. message: '请选择商品',
  114. trigger: ['blur', 'change']
  115. },
  116. 'specification': {
  117. type: 'string',
  118. required: true,
  119. message: '请选择规格',
  120. trigger: ['blur', 'change']
  121. },
  122. 'amount': {
  123. type: 'number',
  124. required: true,
  125. message: '请输入数量',
  126. trigger: ['blur', 'change']
  127. },
  128. },
  129. receivingShow: false,
  130. addressList: [],
  131. value: '',
  132. addInfo: {},
  133. }
  134. },
  135. mounted() {
  136. this.getList()
  137. },
  138. methods: {
  139. selectShipping() {
  140. this.receivingShow = true
  141. },
  142. close() {
  143. this.receivingShow = false
  144. },
  145. getList() {
  146. this.$api.get('/api/applet/address').then(res => {
  147. if (res.code == 200) {
  148. this.addressList = res.data.list
  149. this.addressList.forEach(item => {
  150. item.flag = false
  151. })
  152. }
  153. })
  154. },
  155. // 选择收货地址
  156. selectBooking(value) {
  157. this.addressList.forEach(item => {
  158. if (value.id == item.id) {
  159. this.addInfo = item
  160. this.receivingShow = false
  161. item.flag = true
  162. } else {
  163. item.flag = false
  164. }
  165. })
  166. this.$forceUpdate()
  167. },
  168. // 新增地址
  169. rightClick() {
  170. uni.navigateTo({
  171. url: '/pages/mine/addAddress'
  172. });
  173. },
  174. // 修改地址
  175. goAmend(value) {
  176. this.$cache.setCache('addressInfo', value)
  177. uni.navigateTo({
  178. url: '/pages/mine/addAddress?revamp=' + true + '&id=' + value.id
  179. });
  180. },
  181. // 城市筛选
  182. cityScreening(value, list) {
  183. function getChildById(parentArray, id) {
  184. for (let i = 0; i < parentArray.length; i++) {
  185. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  186. return parentArray[i];
  187. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  188. .children)) { // 判断当前元素是否有子节点且类型为数组
  189. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  190. if (result !== null) { // 若子节点存在结果,则返回该结果
  191. return result;
  192. }
  193. }
  194. }
  195. return null; // 没有找到符合条件的元素时返回null
  196. }
  197. var name = getChildById(list, value)
  198. if (name != null) {
  199. return name.label
  200. }
  201. },
  202. hidePhone(phoneNumber) {
  203. if (phoneNumber) {
  204. function hidePhoneNumber(phoneNumber) {
  205. return phoneNumber.slice(0, 3) + '****' + phoneNumber.slice(-4);
  206. }
  207. const hiddenPhoneNumber = hidePhoneNumber(phoneNumber);
  208. return hiddenPhoneNumber
  209. }
  210. },
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .card_shipping {
  216. display: flex;
  217. width: 100%;
  218. }
  219. .shipping_select {
  220. display: flex;
  221. align-items: center;
  222. padding-left: 20rpx;
  223. margin: 20rpx 30rpx;
  224. width: 100%;
  225. height: 120rpx;
  226. border-radius: 6rpx;
  227. border: 1rpx solid #e7e6e4;
  228. }
  229. .shipping_title {
  230. font-size: 30rpx;
  231. font-weight: 600;
  232. }
  233. .card_form {
  234. margin: 10rpx 30rpx;
  235. }
  236. .card_add_booking {
  237. width: 100%;
  238. display: flex;
  239. flex-direction: column;
  240. }
  241. .card_addres {
  242. height: 50vh;
  243. }
  244. .title_address {
  245. margin-top: 20rpx;
  246. text-align: center;
  247. font-size: 32rpx;
  248. font-weight: 600;
  249. }
  250. .card_address {
  251. display: flex;
  252. margin: 30rpx 20rpx 20rpx 20rpx;
  253. padding: 10rpx;
  254. border-bottom: 1rpx solid #e7e6e4;
  255. }
  256. .center_item {
  257. display: flex;
  258. align-items: center;
  259. }
  260. .title_item {
  261. font-size: 26rpx;
  262. color: #606266;
  263. }
  264. .phone_title {
  265. position: relative;
  266. margin-left: 30rpx;
  267. }
  268. .tag_phone {
  269. position: absolute;
  270. right: -53rpx;
  271. top: -14rpx;
  272. padding: 2rpx 4rpx;
  273. border: 1rpx solid #2b85e4;
  274. font-size: 20rpx;
  275. color: #2b85e4;
  276. }
  277. .title_address1 {
  278. font-size: 30rpx;
  279. color: #303133;
  280. font-weight: 600;
  281. }
  282. .address_item {
  283. width: 100%;
  284. display: flex;
  285. justify-content: space-between;
  286. margin-top: 6rpx;
  287. }
  288. .card_group {
  289. position: relative;
  290. flex: none;
  291. margin-right: 15rpx;
  292. width: 32rpx;
  293. height: 32rpx;
  294. border-radius: 50%;
  295. }
  296. .item_radio {
  297. position: absolute;
  298. left: 50%;
  299. top: 50%;
  300. transform: translate(-50%, -50%);
  301. width: 20rpx;
  302. height: 20rpx;
  303. border-radius: 50%;
  304. background-color: #2b85e4;
  305. }
  306. .btn_add {
  307. width: calc(100% - 40rpx);
  308. position: fixed;
  309. bottom: 0;
  310. padding: 20rpx;
  311. background-color: #fff;
  312. }
  313. </style>