booking.vue 12 KB

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