booking.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. phone: this.addInfo.phone,
  216. storeId: Number(this.companyId),
  217. goodsId: this.model.goodsId,
  218. quantity: Number(this.model.amount),
  219. specId: this.model.specId,
  220. remark: this.model.remark,
  221. lng: this.addInfo.lng,
  222. lat: this.addInfo.lat,
  223. city: this.addInfo.city,
  224. area: this.addInfo.area,
  225. addressImg: this.addInfo.addressImg,
  226. }
  227. const cityty = this.cityScreening(this.addInfo.city, this.areaData)
  228. const areaty = this.cityScreening(this.addInfo.area, this.areaData)
  229. const addressty = cityty + areaty + this.addInfo.address
  230. params.address = addressty
  231. this.loading = true
  232. if (!this.revamp) {
  233. this.$api.post('/api/applet/order', params).then(res => {
  234. if (res.code == 200) {
  235. uni.navigateTo({
  236. url: '/pages/indexRouter'
  237. })
  238. uni.$emit('booking');
  239. } else {
  240. uni.showToast({
  241. title: res.msg,
  242. icon: 'none',
  243. duration: 2000
  244. });
  245. }
  246. this.loading = false
  247. })
  248. } else {
  249. params.id = this.orderData.id
  250. this.$api.put('/api/applet/order', params).then(res => {
  251. if (res.code == 200) {
  252. uni.navigateTo({
  253. url: '/pages/indexRouter'
  254. })
  255. uni.$emit('booking');
  256. } else {
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'none',
  260. duration: 2000
  261. });
  262. }
  263. this.loading = false
  264. })
  265. }
  266. },
  267. // 获取商品列表
  268. getGoodsList() {
  269. this.$api.get('/api/applet/goods', {
  270. storeId: this.companyId,
  271. }).then(res => {
  272. if (res.code == 200) {
  273. const arrList = res.data.list
  274. const dataList = [
  275. []
  276. ]
  277. arrList.forEach(item1 => {
  278. let arr = {
  279. label: item1.name,
  280. value: item1.id,
  281. }
  282. dataList[0].push(arr)
  283. })
  284. this.list.forEach(item => {
  285. if (item.field == 'commodity') {
  286. item.options = []
  287. item.options = dataList
  288. }
  289. })
  290. this.getCylinderSpec()
  291. }
  292. })
  293. },
  294. // 获取规格列表
  295. getCylinderSpec() {
  296. this.$api.get('/api/applet/gas-cylinder-spec', {
  297. storeId: this.companyId,
  298. }).then(res => {
  299. if (res.code == 200) {
  300. const arrList = res.data.list
  301. const dataList = [
  302. []
  303. ]
  304. arrList.forEach(item1 => {
  305. let arr = {
  306. label: item1.name,
  307. value: item1.id,
  308. }
  309. dataList[0].push(arr)
  310. })
  311. this.list.forEach(item => {
  312. if (item.field == 'specification') {
  313. item.options = []
  314. item.options = dataList
  315. }
  316. })
  317. }
  318. })
  319. },
  320. // 选择收货地址
  321. selectBooking(value) {
  322. this.addressList.forEach(item => {
  323. if (value.id == item.id) {
  324. this.addInfo = item
  325. this.receivingShow = false
  326. item.flag = true
  327. } else {
  328. item.flag = false
  329. }
  330. })
  331. this.$forceUpdate()
  332. },
  333. // 新增地址
  334. rightClick() {
  335. this.receivingShow = false
  336. uni.navigateTo({
  337. url: '/pages/mine/addAddress'
  338. });
  339. },
  340. // 修改地址
  341. goAmend(value) {
  342. this.receivingShow = false
  343. this.$cache.setCache('addressInfo', value)
  344. uni.navigateTo({
  345. url: '/pages/mine/addAddress?revamp=' + true + '&id=' + value.id
  346. });
  347. },
  348. // 城市筛选
  349. cityScreening(value, list) {
  350. function getChildById(parentArray, id) {
  351. for (let i = 0; i < parentArray.length; i++) {
  352. if (parentArray[i].value === id) { // 如果当前元素的ID与目标ID相等,则返回该元素
  353. return parentArray[i];
  354. } else if (parentArray[i].children && Array.isArray(parentArray[i]
  355. .children)) { // 判断当前元素是否有子节点且类型为数组
  356. const result = getChildById(parentArray[i].children, id); // 对子节点进行递归调用
  357. if (result !== null) { // 若子节点存在结果,则返回该结果
  358. return result;
  359. }
  360. }
  361. }
  362. return null; // 没有找到符合条件的元素时返回null
  363. }
  364. var name = getChildById(list, value)
  365. if (name != null) {
  366. return name.label
  367. }
  368. },
  369. hidePhone(phoneNumber) {
  370. if (phoneNumber) {
  371. function hidePhoneNumber(phoneNumber) {
  372. return phoneNumber.slice(0, 3) + '****' + phoneNumber.slice(-4);
  373. }
  374. const hiddenPhoneNumber = hidePhoneNumber(phoneNumber);
  375. return hiddenPhoneNumber
  376. }
  377. },
  378. }
  379. }
  380. </script>
  381. <style lang="scss" scoped>
  382. .card_shipping {
  383. display: flex;
  384. width: 100%;
  385. }
  386. .shipping_select {
  387. display: flex;
  388. align-items: center;
  389. padding-left: 20rpx;
  390. margin: 20rpx 30rpx;
  391. width: 100%;
  392. height: 120rpx;
  393. border-radius: 6rpx;
  394. // border: 1rpx solid #e7e6e4;
  395. }
  396. // 伪元素1rpx边框
  397. .frame {
  398. position: relative; //重要
  399. }
  400. .frame::after {
  401. position: absolute;
  402. content: '';
  403. border: 2rpx solid #e7e6e4;
  404. border-radius: 16rpx;
  405. width: 200%;
  406. height: 200%;
  407. top: 0;
  408. left: 0;
  409. transform: scale(0.5);
  410. transform-origin: 0 0;
  411. }
  412. .shipping_title {
  413. font-size: 30rpx;
  414. font-weight: 600;
  415. }
  416. .card_form {
  417. margin: 10rpx 30rpx;
  418. }
  419. .card_add_booking {
  420. width: 100%;
  421. display: flex;
  422. flex-direction: column;
  423. }
  424. .card_addres {
  425. height: 50vh;
  426. }
  427. .title_address {
  428. margin-top: 20rpx;
  429. text-align: center;
  430. font-size: 32rpx;
  431. font-weight: 600;
  432. }
  433. .card_address {
  434. display: flex;
  435. margin: 30rpx 20rpx 20rpx 20rpx;
  436. padding: 10rpx;
  437. border-bottom: 1rpx solid #e7e6e4;
  438. }
  439. .center_item {
  440. display: flex;
  441. align-items: center;
  442. }
  443. .title_item {
  444. font-size: 26rpx;
  445. color: #606266;
  446. }
  447. .phone_title {
  448. position: relative;
  449. margin-left: 30rpx;
  450. }
  451. .tag_phone {
  452. position: absolute;
  453. right: -53rpx;
  454. top: -14rpx;
  455. padding: 2rpx 4rpx;
  456. border: 1rpx solid #2b85e4;
  457. font-size: 20rpx;
  458. color: #2b85e4;
  459. }
  460. .title_address1 {
  461. font-size: 30rpx;
  462. color: #303133;
  463. font-weight: 600;
  464. }
  465. .address_item {
  466. width: 100%;
  467. display: flex;
  468. justify-content: space-between;
  469. margin-top: 6rpx;
  470. }
  471. .card_group {
  472. position: relative;
  473. flex: none;
  474. margin-right: 15rpx;
  475. width: 32rpx;
  476. height: 32rpx;
  477. border-radius: 50%;
  478. }
  479. .item_radio {
  480. position: absolute;
  481. left: 50%;
  482. top: 50%;
  483. transform: translate(-50%, -50%);
  484. width: 20rpx;
  485. height: 20rpx;
  486. border-radius: 50%;
  487. background-color: #2b85e4;
  488. }
  489. .btn_add {
  490. width: calc(100% - 40rpx);
  491. position: fixed;
  492. bottom: 0;
  493. padding: 20rpx;
  494. background-color: #fff;
  495. }
  496. </style>