booking.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <view>
  3. <u-navbar title="订气" autoBack placeholder></u-navbar>
  4. <view class="card_shipping">
  5. <view class="space_between shipping_select frame" @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" :loading="loading" :list="list" :model="model" :rules="rules" @clientele="clientele"
  23. @confirmEnsure="confirmEnsure"></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" v-if="addressList.length > 0">
  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.stop="goAmend(item)"><u-icon name="edit-pen" size="30"></u-icon>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view style="margin-top: 30%;" v-else>
  54. <u-empty mode="address"></u-empty>
  55. </view>
  56. <view class="btn_add">
  57. <u-button type="primary" size="normal" text="新增收货地址" @click="rightClick"></u-button>
  58. </view>
  59. </view>
  60. </u-popup>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. urbanArea
  66. } from '@/static/js/districtCode.js'
  67. export default {
  68. data() {
  69. return {
  70. areaData: urbanArea(), //原始数据
  71. list: [{
  72. field: 'commodity',
  73. label: '商品',
  74. placeholder: '请选择商品',
  75. type: 'select',
  76. required: true,
  77. options: [],
  78. }, {
  79. field: 'specification',
  80. label: '规格',
  81. placeholder: '请选择规格',
  82. type: 'select',
  83. required: true,
  84. options: [],
  85. }, {
  86. field: 'amount',
  87. label: '数量',
  88. placeholder: '请输入数量',
  89. type: 'input',
  90. required: true,
  91. genre: 'number',
  92. }, {
  93. field: 'remark',
  94. label: '备注',
  95. placeholder: '请输入备注',
  96. type: 'textarea',
  97. }],
  98. model: {
  99. commodity: '',
  100. specification: '',
  101. amount: '',
  102. remark: '',
  103. goodsId: null,
  104. specId: null,
  105. },
  106. rules: {
  107. 'commodity': {
  108. type: 'string',
  109. required: true,
  110. message: '请选择商品',
  111. trigger: ['blur', 'change']
  112. },
  113. 'specification': {
  114. type: 'string',
  115. required: true,
  116. message: '请选择规格',
  117. trigger: ['blur', 'change']
  118. },
  119. 'amount': {
  120. type: 'number',
  121. required: true,
  122. message: '请输入数量',
  123. trigger: ['blur', 'change']
  124. },
  125. },
  126. receivingShow: false,
  127. addressList: [],
  128. value: '',
  129. addInfo: {},
  130. companyId: null,
  131. loading: false,
  132. revamp: '',
  133. operated: '',
  134. orderData: {},
  135. }
  136. },
  137. onLoad(value) {
  138. this.companyId = value.companyId
  139. this.revamp = value.revamp
  140. this.operated = value.revamp
  141. if (value.revamp == 'true') {
  142. this.getDataEcho()
  143. }
  144. },
  145. onShow() {
  146. this.getList()
  147. },
  148. mounted() {
  149. this.getGoodsList()
  150. },
  151. methods: {
  152. selectShipping() {
  153. this.receivingShow = true
  154. },
  155. close() {
  156. this.receivingShow = false
  157. },
  158. // 获取收货地址列表
  159. getList() {
  160. this.addInfo = {}
  161. this.$api.get('/api/applet/address').then(res => {
  162. if (res.code == 200) {
  163. this.addressList = res.data.list
  164. if (this.addressList.length > 0 && !this.revamp) {
  165. this.addressList.forEach(item => {
  166. if (item.isDefault) {
  167. item.flag = true
  168. this.addInfo = item
  169. } else {
  170. item.flag = false
  171. return
  172. this.addressList[0].flag = true
  173. this.addInfo = this.addressList[0]
  174. }
  175. })
  176. } else {
  177. this.operated = false
  178. this.addressList.forEach(item => {
  179. if (this.orderData.phone == item.phone) {
  180. item.flag = true
  181. this.addInfo = item
  182. } else {
  183. item.flag = false
  184. }
  185. })
  186. }
  187. }
  188. })
  189. },
  190. // 选择商品/规格
  191. confirmEnsure(value) {
  192. // console.log(value, 24)
  193. if (value.type == 'commodity') {
  194. this.model.goodsId = value.id
  195. } else if (value.type == 'specification') {
  196. this.model.specId = value.id
  197. }
  198. },
  199. // 订单数据回显
  200. getDataEcho() {
  201. const arr = this.$cache.getCache('orderList')
  202. this.orderData = arr
  203. // console.log(arr, 22)
  204. this.model.goodsId = arr.goodsId
  205. this.model.specId = arr.specId
  206. this.model.commodity = arr.goods.name
  207. this.model.specification = arr.spec.name
  208. this.model.amount = arr.quantity
  209. this.model.remark = arr.remark
  210. },
  211. // 订气
  212. clientele() {
  213. const params = {
  214. address: '',
  215. name: this.addInfo.name,
  216. phone: this.addInfo.phone,
  217. storeId: Number(this.companyId),
  218. goodsId: this.model.goodsId,
  219. quantity: Number(this.model.amount),
  220. specId: this.model.specId,
  221. remark: this.model.remark,
  222. lng: this.addInfo.lng,
  223. lat: this.addInfo.lat,
  224. city: this.addInfo.city,
  225. area: this.addInfo.area,
  226. addressImg: this.addInfo.addressImg,
  227. }
  228. const cityty = this.cityScreening(this.addInfo.city, this.areaData)
  229. const areaty = this.cityScreening(this.addInfo.area, this.areaData)
  230. const addressty = cityty + areaty + this.addInfo.address
  231. params.address = addressty
  232. if (this.addInfo.id) {
  233. this.loading = true
  234. if (!this.revamp) {
  235. this.$api.post('/api/applet/order', params).then(res => {
  236. if (res.code == 200) {
  237. uni.navigateTo({
  238. url: '/pages/indexRouter'
  239. })
  240. uni.$emit('booking');
  241. } else {
  242. uni.showToast({
  243. title: res.msg,
  244. icon: 'none',
  245. duration: 2000
  246. });
  247. }
  248. this.loading = false
  249. })
  250. } else {
  251. params.id = this.orderData.id
  252. this.$api.put('/api/applet/order', params).then(res => {
  253. if (res.code == 200) {
  254. uni.navigateTo({
  255. url: '/pages/indexRouter'
  256. })
  257. uni.$emit('booking');
  258. } else {
  259. uni.showToast({
  260. title: res.msg,
  261. icon: 'none',
  262. duration: 2000
  263. });
  264. }
  265. this.loading = false
  266. })
  267. }
  268. } else {
  269. uni.showToast({
  270. title: '请选择收货地址',
  271. icon: 'none',
  272. duration: 2000
  273. });
  274. }
  275. },
  276. // 获取商品列表
  277. getGoodsList() {
  278. this.$api.get('/api/applet/goods', {
  279. storeId: this.companyId,
  280. }).then(res => {
  281. if (res.code == 200) {
  282. const arrList = res.data.list
  283. const dataList = [
  284. []
  285. ]
  286. arrList.forEach(item1 => {
  287. let arr = {
  288. label: item1.name,
  289. value: item1.id,
  290. }
  291. dataList[0].push(arr)
  292. })
  293. this.list.forEach(item => {
  294. if (item.field == 'commodity') {
  295. item.options = []
  296. item.options = dataList
  297. }
  298. })
  299. this.getCylinderSpec()
  300. }
  301. })
  302. },
  303. // 获取规格列表
  304. getCylinderSpec() {
  305. this.$api.get('/api/applet/gas-cylinder-spec', {
  306. storeId: this.companyId,
  307. }).then(res => {
  308. if (res.code == 200) {
  309. const arrList = res.data.list
  310. const dataList = [
  311. []
  312. ]
  313. arrList.forEach(item1 => {
  314. let arr = {
  315. label: item1.name,
  316. value: item1.id,
  317. }
  318. dataList[0].push(arr)
  319. })
  320. this.list.forEach(item => {
  321. if (item.field == 'specification') {
  322. item.options = []
  323. item.options = dataList
  324. }
  325. })
  326. }
  327. })
  328. },
  329. // 选择收货地址
  330. selectBooking(value) {
  331. this.addressList.forEach(item => {
  332. if (value.id == item.id) {
  333. this.addInfo = item
  334. this.receivingShow = false
  335. item.flag = true
  336. } else {
  337. item.flag = false
  338. }
  339. })
  340. this.$forceUpdate()
  341. },
  342. // 新增地址
  343. rightClick() {
  344. this.receivingShow = false
  345. uni.navigateTo({
  346. url: '/pages/mine/addAddress'
  347. });
  348. },
  349. // 修改地址
  350. goAmend(value) {
  351. this.receivingShow = false
  352. this.$cache.setCache('addressInfo', value)
  353. uni.navigateTo({
  354. url: '/pages/mine/addAddress?revamp=' + true + '&id=' + value.id
  355. });
  356. },
  357. // 城市筛选
  358. cityScreening(value, list) {
  359. function getChildById(parentArray, id) {
  360. for (let i = 0; i < parentArray.length; i++) {
  361. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  362. return parentArray[i];
  363. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  364. .children)) { // 判断当前元素是否有子节点且类型为数组
  365. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  366. if (result !== null) { // 若子节点存在结果,则返回该结果
  367. return result;
  368. }
  369. }
  370. }
  371. return null; // 没有找到符合条件的元素时返回null
  372. }
  373. var name = getChildById(list, value)
  374. if (name != null) {
  375. return name.label
  376. }
  377. },
  378. hidePhone(phoneNumber) {
  379. if (phoneNumber) {
  380. function hidePhoneNumber(phoneNumber) {
  381. return phoneNumber.slice(0, 3) + '****' + phoneNumber.slice(-4);
  382. }
  383. const hiddenPhoneNumber = hidePhoneNumber(phoneNumber);
  384. return hiddenPhoneNumber
  385. }
  386. },
  387. }
  388. }
  389. </script>
  390. <style lang="scss" scoped>
  391. .card_shipping {
  392. display: flex;
  393. width: 100%;
  394. }
  395. .shipping_select {
  396. display: flex;
  397. align-items: center;
  398. padding-left: 20rpx;
  399. margin: 20rpx 30rpx;
  400. width: 100%;
  401. height: 120rpx;
  402. border-radius: 6rpx;
  403. // border: 1rpx solid #e7e6e4;
  404. }
  405. // 伪元素1rpx边框
  406. .frame {
  407. position: relative; //重要
  408. }
  409. .frame::after {
  410. position: absolute;
  411. content: '';
  412. border: 2rpx solid #e7e6e4;
  413. border-radius: 16rpx;
  414. width: 200%;
  415. height: 200%;
  416. top: 0;
  417. left: 0;
  418. transform: scale(0.5);
  419. transform-origin: 0 0;
  420. }
  421. .shipping_title {
  422. font-size: 30rpx;
  423. font-weight: 600;
  424. }
  425. .card_form {
  426. margin: 10rpx 30rpx;
  427. }
  428. .card_add_booking {
  429. width: 100%;
  430. display: flex;
  431. flex-direction: column;
  432. }
  433. .card_addres {
  434. height: 50vh;
  435. }
  436. .title_address {
  437. margin-top: 20rpx;
  438. text-align: center;
  439. font-size: 32rpx;
  440. font-weight: 600;
  441. }
  442. .card_address {
  443. display: flex;
  444. margin: 30rpx 20rpx 20rpx 20rpx;
  445. padding: 10rpx;
  446. border-bottom: 1rpx solid #e7e6e4;
  447. }
  448. .center_item {
  449. display: flex;
  450. align-items: center;
  451. }
  452. .title_item {
  453. font-size: 26rpx;
  454. color: #606266;
  455. }
  456. .phone_title {
  457. position: relative;
  458. margin-left: 30rpx;
  459. }
  460. .tag_phone {
  461. position: absolute;
  462. right: -53rpx;
  463. top: -14rpx;
  464. padding: 2rpx 4rpx;
  465. border: 1rpx solid #2b85e4;
  466. font-size: 20rpx;
  467. color: #2b85e4;
  468. }
  469. .title_address1 {
  470. font-size: 30rpx;
  471. color: #303133;
  472. font-weight: 600;
  473. }
  474. .address_item {
  475. width: 100%;
  476. display: flex;
  477. justify-content: space-between;
  478. margin-top: 6rpx;
  479. }
  480. .card_group {
  481. position: relative;
  482. flex: none;
  483. margin-right: 15rpx;
  484. width: 32rpx;
  485. height: 32rpx;
  486. border-radius: 50%;
  487. }
  488. .item_radio {
  489. position: absolute;
  490. left: 50%;
  491. top: 50%;
  492. transform: translate(-50%, -50%);
  493. width: 20rpx;
  494. height: 20rpx;
  495. border-radius: 50%;
  496. background-color: #2b85e4;
  497. }
  498. .btn_add {
  499. width: calc(100% - 40rpx);
  500. position: fixed;
  501. bottom: 0;
  502. padding: 20rpx;
  503. background-color: #fff;
  504. }
  505. </style>