done.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <view class="content">
  3. <template v-if="loading">
  4. <view class="skeleton">
  5. <view class="skeleton-line max animate" style="height: 200upx;"></view>
  6. <view class="skeleton-line animate"></view>
  7. <view class="skeleton-line min animate"></view>
  8. <view class="skeleton-line min animate"></view>
  9. <view class="skeleton-line max animate" style="height: 200upx;"></view>
  10. <view class="skeleton-line max animate" style="height: 200upx;"></view>
  11. </view>
  12. </template>
  13. <template v-else>
  14. <scroll-view class="goods-body" scroll-y scroll-with-animation>
  15. <view class="order-body" v-if="orderData">
  16. <view class="item-goods">
  17. <view class="item-goods-body">
  18. <view class="image">
  19. <image :src="orderData.img"></image>
  20. </view>
  21. <view class="info">
  22. <view class="title">
  23. <view class="name" v-if="orderData.product.is_new==1">
  24. {{orderData.product.price}}元代{{orderData.product.line_price}}元商场权益券{{orderData.product.product_name}}
  25. </view>
  26. <view class="name" v-else>{{ orderData.product.product_name }}</view>
  27. <view class="num">x{{ orderData.number }}</view>
  28. </view>
  29. <view class="tags">
  30. {{orderData.sku_name?orderData.sku_name:'默认'}}
  31. <view class="price">{{ $dialog.formatMoney(orderData.price,true) }}</view>
  32. </view>
  33. <view class="price-right">实付 <text>{{ $dialog.formatMoney(orderData.pay_money,true) }}</text></view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="order-info">
  38. <view class="title-h">意向商品<text>(可选{{orderData.number}}份)</text></view>
  39. <view class="goods-item" v-for="(item,indx) in doneGoods" :key="indx">
  40. <view class="item-goods" style="padding: 10rpx;background-color: #f8f8f8;">
  41. <view class="item-goods-body">
  42. <view class="image">
  43. <image :src="item.image"></image>
  44. </view>
  45. <view class="info">
  46. <view class="title">
  47. <view class="name">{{ item.title }}</view>
  48. </view>
  49. <view class="tags">
  50. <view></view>
  51. <view class="price">x{{ item.number }}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="goods-item-check" @click="chooseGoods">{{doneGoods.length == 0 ? '请选择': '更换其他'}}</view>
  58. </view>
  59. <view class="order-info">
  60. <view class="title-h">会员信息</view>
  61. <view class="form-feedbak">
  62. <view class="title"><text>*</text>姓名</view>
  63. <view class="form-textarea">
  64. <input v-model="addressForm.nickname" data-field="nickname" placeholder="请输入" class="u-input" />
  65. </view>
  66. </view>
  67. <view class="form-feedbak">
  68. <view class="title"><text>*</text>手机号码</view>
  69. <view class="form-textarea">
  70. <input v-model="addressForm.mobile" data-field="mobile" placeholder="请输入" class="u-input" />
  71. </view>
  72. </view>
  73. <view class="form-feedbak">
  74. <view class="title"><text>*</text>所属地区</view>
  75. <view class="form-textarea" @click="showAddress">
  76. {{addressData.name}}
  77. </view>
  78. </view>
  79. <view class="form-feedbak">
  80. <view class="title"><text>*</text>详细地址</view>
  81. <view class="form-textarea">
  82. <input v-model="addressForm.address" data-field="address" placeholder="请输入" class="u-textarea" />
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <view class="line-height"></view>
  88. </scroll-view>
  89. <view class="footer">
  90. <view class="footer-op">
  91. <view class="footer-right">
  92. <button :loading="isSubmit" :disabled="isSubmit" class="btn full" @click="submitOrder">提交</button>
  93. </view>
  94. </view>
  95. <view class="footer-safe"></view>
  96. </view>
  97. </template>
  98. <uni-popup ref="addressPop" type="bottom" border-radius="10px 10px 0 0" background-color="#ffffff" :mask-click="false">
  99. <view class="address-pop">
  100. <view class="address-title">请选择地区</view>
  101. <view class="address-scroll">
  102. <picker-view :indicator-style="indicatorStyle" :value="pickerValue" @change="bindChange" :range="columns" class="picker-view">
  103. <picker-view-column v-for="(col, colIndex) in columns" :key="colIndex">
  104. <view class="item" v-for="(item, itemIndex) in col" :key="itemIndex">
  105. {{ item.text }}
  106. </view>
  107. </picker-view-column>
  108. </picker-view>
  109. </view>
  110. <view class="address-footer">
  111. <view class="footer-btn" @click="closeOrder">取消</view>
  112. <view class="footer-btn full" @click="checkAddress">确定</view>
  113. </view>
  114. </view>
  115. </uni-popup>
  116. <goodsDialog ref="goodsDialog" @send="sendGoods"></goodsDialog>
  117. </view>
  118. </template>
  119. <script>
  120. var app;
  121. import goodsDialog from '@/components/chat/goods';
  122. import form from "@/static/js/form.js";
  123. export default {
  124. components: {
  125. goodsDialog
  126. },
  127. data() {
  128. return {
  129. indicatorStyle: `height: 50px;backgroud-color:#f1f1f1`,
  130. columns: [
  131. [], // 省列表
  132. [], // 市列表
  133. [] // 区列表
  134. ],
  135. pickerValue: [0, 0, 0],
  136. optionData:null,
  137. orderData:null,
  138. loading:false,
  139. cityData:[],
  140. secondData:[],
  141. dayData:[],
  142. addressForm:{},
  143. isSubmit:false,
  144. addressData:{
  145. name:"请选择",
  146. hide:null,
  147. list:[]
  148. },
  149. doneGoods:[],
  150. selectedProvince: null,
  151. selectedCity: null,
  152. selectedArea: null
  153. }
  154. },
  155. onLoad(options) {
  156. app = this;
  157. app.optionData = options;
  158. const eventChannel = this.getOpenerEventChannel();
  159. this.getOrder();
  160. },
  161. methods: {
  162. checkAddress(){
  163. app.addressData.hide = app.selectedProvince.text+app.selectedCity.text+app.selectedArea.text;
  164. app.addressData.name = app.selectedProvince.text+"/"+app.selectedCity.text+"/"+app.selectedArea.text;
  165. app.addressData.list = [app.selectedProvince.value,app.selectedCity.value,app.selectedArea.value];
  166. this.$refs.addressPop.close();
  167. },
  168. bindChange(e){
  169. const val = e.detail.value; // 例如 [2, 1, 0]
  170. let [provinceIdx, cityIdx, areaIdx] = val;
  171. // ---------- 第一步:根据省索引,更新市列表 ----------
  172. const province = this.cityData[provinceIdx];
  173. const newCityCol = province?.children || [];
  174. // 【关键】如果当前城市索引超出新列表范围,强制置为 0
  175. if (cityIdx >= newCityCol.length) {
  176. cityIdx = 0;
  177. }
  178. // 如果新列表为空(没有市),cityIdx 只能为 0,且后续区列表为空
  179. const city = newCityCol[cityIdx] || null;
  180. // ---------- 第二步:根据市索引,更新区列表 ----------
  181. const newAreaCol = city?.children || [];
  182. // 【关键】如果当前区索引超出新区列表范围,强制置为 0
  183. if (areaIdx >= newAreaCol.length) {
  184. areaIdx = 0;
  185. }
  186. const area = newAreaCol[areaIdx] || null;
  187. // ---------- 第三步:同时更新 columns 和 pickerValue ----------
  188. // 注意:必须将修正后的 [provinceIdx, cityIdx, areaIdx] 重新赋值给 pickerValue
  189. app.columns = [
  190. app.cityData, // 省列不变
  191. newCityCol, // 更新后的市列
  192. newAreaCol // 更新后的区列
  193. ];
  194. app.pickerValue = [provinceIdx, cityIdx, areaIdx];
  195. // ---------- 第四步:保存选中的完整数据(用于提交) ----------
  196. app.selectedProvince = province;
  197. app.selectedCity = city;
  198. app.selectedArea = area;
  199. },
  200. async submitOrder(){
  201. // if (app.doneGoods.length == 0) return app.$dialog.showSuccess("请选择意向商品");
  202. var formData = app.addressForm;
  203. var validation = form.validation(formData,[
  204. {name:"nickname",rule:["required"],msg:["请输入姓名"]},
  205. {name:"mobile",rule:["required","isMobile"],msg:["请填写手机号码","手机号码格式错误"]},
  206. {name:"address",rule:["required"],msg:["请输入详细地址"]},
  207. ]);
  208. if(validation){
  209. this.$dialog.showSuccess(validation);
  210. return false;
  211. }
  212. if (!app.addressData.hide) return app.$dialog.showSuccess("请选择地区");
  213. formData.goods = JSON.stringify(app.doneGoods);
  214. formData.city = JSON.stringify(app.addressData)
  215. formData.order = app.optionData.order
  216. app.isSubmit = true;
  217. var resp = await app.$api.order.address.post(formData);
  218. app.isSubmit = false;
  219. if (resp.code !== 1) return app.$dialog.showSuccess(resp.msg);
  220. app.$dialog.showSuccess(resp.msg);
  221. setTimeout(function(){
  222. const eventChannel = app.getOpenerEventChannel();
  223. eventChannel.emit('acceptKeepData', { msg: '会员信息已完善' });
  224. uni.navigateBack();
  225. },900)
  226. },
  227. chooseGoods(){
  228. this.$nextTick(()=>{
  229. this.$refs.goodsDialog.open().setData({"order":app.optionData.order,"num":app.orderData.number});
  230. })
  231. },
  232. sendGoods(data){
  233. app.doneGoods = data;
  234. },
  235. showAddress(){
  236. this.$refs.addressPop.open();
  237. },
  238. closeOrder(){
  239. this.$refs.addressPop.close();
  240. },
  241. addressChange(data){
  242. if (data.detail) {
  243. this.addressForm.city = JSON.stringify(data.detail.value);
  244. }
  245. },
  246. async getOrder(){
  247. app.loading = true;
  248. var res = await app.$api.order.detail.get({"order":app.optionData.order});
  249. app.loading = false;
  250. if (res.code && res.code == 0) {
  251. app.$dialog.showSuccess(res.msg);
  252. uni.navigateBack()
  253. return ;
  254. }
  255. app.orderData = res.data;
  256. app.getCity()
  257. },
  258. async getCity(){
  259. var resp = await app.$api.home.city.get();
  260. if (resp.code !== 1) return ;
  261. app.cityData = resp.data;
  262. const provinceCol = app.cityData;
  263. // 2. 第二列:第一个省的 children(市)
  264. const firstProvince = provinceCol[0];
  265. const cityCol = firstProvince?.children || [];
  266. // 3. 第三列:第一个市的 children(区)
  267. const firstCity = cityCol[0];
  268. const areaCol = firstCity?.children || [];
  269. app.columns = [provinceCol, cityCol, areaCol];
  270. app.pickerValue = [0, 0, 0];
  271. app.selectedProvince = firstProvince;
  272. app.selectedCity = firstCity;
  273. app.selectedArea = areaCol[0] || null;
  274. }
  275. }
  276. }
  277. </script>
  278. <style lang="scss" scoped>
  279. .goods-item-check{
  280. margin: 20rpx;
  281. border: 2rpx solid $main-text-color;
  282. height: 80rpx;
  283. line-height: 80rpx;
  284. text-align: center;
  285. font-size: 28rpx;
  286. color: $main-text-color;
  287. border-radius: 10rpx;
  288. }
  289. .address-pop{
  290. .address-title{
  291. font-size: 32rpx;
  292. font-weight: bold;
  293. padding: 20rpx;
  294. }
  295. .address-check{
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-around;
  299. color: $main-text-color;
  300. background-color: #f1f1f1;
  301. .check-name{
  302. flex: 1;
  303. text-align: center;
  304. padding: 30rpx 0;
  305. }
  306. }
  307. .address-scroll{
  308. height: 50vh;
  309. overflow: hidden;
  310. padding: 20rpx;
  311. .picker-view{
  312. height: 50vh;
  313. .item{
  314. line-height: 100rpx;
  315. text-align: center;
  316. }
  317. }
  318. .item-name{
  319. padding: 20rpx;
  320. border-bottom: 2rpx solid #f1f1f1;
  321. display: flex;
  322. align-items: center;
  323. justify-content: space-between;
  324. .icon{
  325. display: none;
  326. image {
  327. width: 40rpx;
  328. height: 40rpx;
  329. }
  330. }
  331. &.active{
  332. color: $main-color;
  333. .icon{
  334. display: block;
  335. }
  336. }
  337. }
  338. }
  339. .address-footer{
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-around;
  343. gap: 20rpx;
  344. padding: 20rpx;
  345. .footer-btn{
  346. background-color: #fff;
  347. border: 2rpx solid $main-text-color;
  348. border-radius: 10rpx;
  349. color: $main-text-color;
  350. height: 80rpx;
  351. line-height: 80rpx;
  352. text-align: center;
  353. flex: 1;
  354. &.full{
  355. border: 2rpx solid $main-color;
  356. background-color: $main-color;
  357. color: #fff;
  358. }
  359. }
  360. }
  361. }
  362. .content{
  363. position: fixed;
  364. z-index: 1;
  365. top: 0;
  366. left: 0;
  367. bottom: 0;
  368. right: 0;
  369. background-color: #f1f1f1;
  370. display: flex;
  371. flex-direction: column;
  372. .line-height{
  373. height: 40rpx;
  374. width: 100%;
  375. }
  376. }
  377. .form-feedbak{
  378. background-color: #fff;
  379. border-radius: 20upx;
  380. }
  381. .form-feedbak .title{
  382. line-height: 80upx;
  383. font-size: 28upx;
  384. }
  385. .form-feedbak .title text{
  386. color: #f00;
  387. margin-right: 10upx;
  388. }
  389. .form-feedbak .form-textarea{
  390. background-color: #f8f8f8;
  391. padding: 20upx;
  392. }
  393. .order-body {
  394. width: 95%;
  395. margin: 20rpx auto;
  396. .order-info{
  397. border-radius: 20rpx;
  398. background-color: #fff;padding: 20upx;margin-top: 20upx;
  399. .title-h{
  400. font-size: 32upx;color: #333;font-weight: bold;margin-bottom: 20rpx;
  401. text {
  402. font-size: 28rpx;
  403. color: #666;
  404. font-weight: normal;
  405. margin-left: 20rpx;
  406. }
  407. }
  408. }
  409. .item-goods{
  410. background-color: #fff;
  411. margin-top: 20rpx;
  412. border-radius: 20rpx;
  413. padding: 20rpx;
  414. .item-goods-body{
  415. display: flex;
  416. align-items: center;
  417. gap: 20rpx;
  418. }
  419. .stock{
  420. text-align: right;
  421. }
  422. .image {
  423. height: 140rpx;
  424. overflow: hidden;display: flex;align-items: center;min-width: 140rpx;
  425. position: relative;
  426. image {
  427. width: 140rpx;
  428. border-radius: 10upx;
  429. height: 100%;
  430. }
  431. }
  432. .info{
  433. flex: 1 1 0%;
  434. overflow: hidden;
  435. .title{
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. .name {
  440. overflow: hidden;
  441. text-overflow: ellipsis;
  442. font-size: 32rpx;
  443. display: -webkit-box;
  444. -webkit-line-clamp: 2;
  445. -webkit-box-orient: vertical;
  446. color: #333;
  447. font-weight: 900;
  448. }
  449. }
  450. .price-right{
  451. text-align: right;
  452. color: $main-color;
  453. margin-top: 20rpx;
  454. font-size: 28rpx;
  455. text {
  456. font-size: 30rpx;
  457. font-weight: 800;
  458. }
  459. }
  460. .tags {
  461. color: #94a3b8;
  462. font-size: 24rpx;
  463. margin: 10rpx 0;
  464. display: flex;
  465. align-items: center;
  466. justify-content: space-between;
  467. .price {
  468. font-size: 28rpx;
  469. color: $main-text-color;
  470. font-weight: 600;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. .goods-body{
  477. height: 0;
  478. flex: 1;
  479. }
  480. .footer{
  481. background-color: #fff;
  482. padding: 20upx 20upx 0 20upx;border-top: 2upx solid #f8f8f8;
  483. .footer-safe {
  484. height: env(safe-area-inset-bottom);width: 100%;
  485. }
  486. .footer-op{
  487. display: flex;
  488. align-items: center;
  489. justify-content: space-between;
  490. .footer-right{
  491. display: flex;
  492. align-items: center;
  493. gap: 20rpx;
  494. flex: 1;
  495. .btn{
  496. width: 100%;
  497. font-size: 28rpx;
  498. height: 80upx;
  499. border-radius: 10upx;
  500. line-height: 80upx;
  501. text-align: center;
  502. min-width: 200rpx;
  503. color: #333;
  504. border: 2rpx solid #ccc;
  505. &.full{
  506. background-color: $main-color;
  507. color: #fff;
  508. border: 2rpx solid $main-color;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. </style>