confirm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view>
  3. <view class="order-type">
  4. <view :class="service_type==2?'type-item active':'type-item'" @click="service_type=2">代提</view>
  5. <view :class="service_type==1?'type-item active':'type-item'" @click="service_type=1">自提</view>
  6. </view>
  7. <view class="address" v-if="storeInfo && service_type==2">
  8. <view class="addressInfo" v-if="addressInfo" @click="toAddress">
  9. <view class="empty-data">
  10. <view class="left">
  11. <view class="contact-name">{{addressInfo.username}} <view class="mobile">{{addressInfo.mobile}}</view></view>
  12. <view class="desc">{{addressInfo.region}}{{addressInfo.address}}</view>
  13. </view>
  14. <view class="right"><image src="/static/image/right.png"></image></view>
  15. </view>
  16. </view>
  17. <view class="addressInfo" @click="toAddress" v-else>
  18. <view class="empty-data">
  19. <view class="left"><image src="/static/image/location.png"></image></view>
  20. <view class="name">完善收货地址</view>
  21. <view class="right"><image src="/static/image/right.png"></image></view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="location" @click="toDetail">
  26. <view class="left">
  27. <view class="name">{{poi_name}}</view>
  28. <view class="desc"><image src="/static/image/location.png"></image>距您{{juli}}公里</view>
  29. </view>
  30. <view class="right"><image src="/static/image/right.png"></image></view>
  31. </view>
  32. <view class="goods" v-if="goodsInfo">
  33. <view class="goods-info">
  34. <view class="image"><image :src="goodsInfo.goods.product_img"></image></view>
  35. <view class="info">
  36. <view class="name">{{ goodsInfo.product_name }}</view>
  37. <view class="desc">x {{goodsInfo.count}}</view>
  38. <view class="desc">有效期至{{goodsInfo.expire_at}}</view>
  39. </view>
  40. </view>
  41. <view class="goods-item">
  42. <view class="left">商品总额</view>
  43. <view class="right">¥{{goodsInfo.order_amount}}</view>
  44. </view>
  45. <view class="goods-item">
  46. <view class="left">商品优惠</view>
  47. <view class="right red">¥{{goodsInfo.order_amount}}</view>
  48. </view>
  49. </view>
  50. <view class="empty-data" v-else>
  51. <u-skeleton
  52. rows="3"
  53. title
  54. loading
  55. ></u-skeleton>
  56. </view>
  57. <view class="goods_skus" v-if="goodsSku.length > 0">
  58. <view class="sku_box" v-for="(item,indx) in goodsSku" :key="indx">
  59. <view class="sku_name">
  60. {{item.name}}({{item.list.length}}选{{item.num}})
  61. <view class="right" @click="clearSku(indx)">清除</view>
  62. </view>
  63. <view class="sku_list">
  64. <view :class="itm.check?'sku_item':'sku_item active'" @click="skuCheck(item.name,item.num,indx,iddx)" v-for="(itm,iddx) in item.list" :key="iddx">{{itm.name}}</view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="order-time" v-if="storeInfo && service_type==1">
  69. <view class="title">预约到店时间</view>
  70. <view class="msg" @click="selectTime(1)">
  71. {{timeStr?timeStr:'请选择'}}
  72. <view class="right"><image src="/static/image/right.png"></image></view>
  73. </view>
  74. </view>
  75. <view class="order-msg">
  76. <view class="title">订单备注</view>
  77. <view class="msg"><textarea class="textarea" placeholder="请输入" v-model="msg" :rows="5"></textarea></view>
  78. </view>
  79. <view class="flx-footer">
  80. <view class="footer-btn">
  81. <view class="price"><text class="desc">已优惠:¥{{goodsInfo.order_amount}},</text>合计<text class="money">¥0</text></view>
  82. <view class="btn-group"><button :disabled="disabled" @click="submitOrder" class="btn">{{disabled?'处理中...':'确认兑换'}}</button></view>
  83. </view>
  84. <view class="footer-safe"></view>
  85. </view>
  86. <uni-popup ref="timepopup" type="bottom" borderRadius="10px 10px 0 0" backgroundColor="#F8F8F8">
  87. <view class="time-select">
  88. <view class="title">选择时间<view class="close" @click="selectTime(2)"><image src="/static/image/round_close.png"></image></view> </view>
  89. </view>
  90. <view class="time-body">
  91. <view class="time-left">
  92. <view :class="timeIndex==index?'time-left-item active':'time-left-item'" @click="timeCheck(index)" v-for="(item,index) in timeData">
  93. <view class="name">{{item.day}}</view>
  94. <view class="desc">{{item.week}}</view>
  95. </view>
  96. </view>
  97. <view class="time-right">
  98. <view :class="childIndex==index?'time-right-item active':'time-right-item'" @click="childCheck(index)" v-for="(item,index) in timeChildren">
  99. <view class="name">{{item.display}}</view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="time-btn">
  104. <button class="btn" @click="checkTimeEnd">确认选择</button>
  105. </view>
  106. </uni-popup>
  107. </view>
  108. </template>
  109. <script>
  110. var app;
  111. import * as Api from "@/static/api/order.js";
  112. export default {
  113. data() {
  114. return {
  115. disabled:false,
  116. timeIndex:0,
  117. childIndex:0,
  118. order:"",
  119. poi_name:"",
  120. poi_id:"",
  121. juli:"",
  122. goodsInfo:null,
  123. storeInfo:null,
  124. timeStr:null,
  125. timeState:false,
  126. timeData:[],
  127. timeChildren:[],
  128. addressInfo:null,
  129. msg:"",
  130. totalData:[],
  131. goodsSku:[],
  132. service_type:2
  133. }
  134. },
  135. onLoad({order,poi_id,poi_name,juli}) {
  136. app = this;
  137. app.order = order;
  138. app.poi_id = poi_id;
  139. app.poi_name = poi_name;
  140. app.juli = juli;
  141. app.getOrder();
  142. },
  143. methods: {
  144. submitOrder(){
  145. var formData = {};
  146. formData.order = app.order;
  147. formData.poi_id = app.poi_id;
  148. if (app.service_type==2 && app.addressInfo == null) {
  149. return app.$dialog.showSuccess("请选择会员地址");
  150. }
  151. if (app.service_type==1 && app.timeStr == null) {
  152. return app.$dialog.showSuccess("请选择预约时间");
  153. }
  154. formData.service_type = app.service_type;
  155. var skuInfo = "",skuState = true;
  156. if (app.goodsSku.length > 0) {
  157. app.goodsSku.forEach((item,index)=>{
  158. var skuCheck = [],skuI = 0;
  159. skuInfo += item.name+":";
  160. item.list.forEach((itm,idx)=>{
  161. if (itm.check==false){
  162. skuInfo += itm.name+',';
  163. skuCheck[skuI] = itm.name;
  164. skuI ++;
  165. }
  166. });
  167. skuInfo = skuInfo.slice(0, -1);
  168. skuInfo += ";";
  169. if (item.num > skuCheck.length) {
  170. app.$dialog.showSuccess("请完善【"+item.name+"】选项");
  171. skuState = false;
  172. return false;
  173. }
  174. });
  175. if (!skuState) return ;
  176. }
  177. formData.sku = skuInfo;
  178. formData.address = JSON.stringify(app.addressInfo);
  179. formData.time = app.timeStr;
  180. formData.remark = app.msg;
  181. app.disabled = true;
  182. Api.submit(formData).then((res)=>{
  183. app.disabled = false;
  184. if (res.code == 0) {
  185. return app.$dialog.showSuccess(res.msg);
  186. }
  187. app.$dialog.showSuccess(res.msg,"none",function(){
  188. uni.switchTab({
  189. url:"/pages/order/order"
  190. })
  191. });
  192. })
  193. },
  194. clearSku(parent){
  195. app.totalData = [];
  196. var goodsSku = app.goodsSku;
  197. goodsSku[parent].list.forEach((item,index) => {
  198. if (!item.check) {
  199. item.check = true;
  200. }
  201. })
  202. },
  203. skuCheck(name,length,parent,select){
  204. var goodsSku = app.goodsSku;
  205. if (length == '1') { // 单选
  206. goodsSku[parent].list.forEach((item,index) => {
  207. item.check = true;
  208. if (index == select) {
  209. item.check = false;
  210. app.skuInfo = goodsSku[parent].name+":"+item.name;
  211. }
  212. })
  213. } else { // 多选
  214. var data = [];
  215. var checkData = app.skuDataCheck(parent,length);
  216. goodsSku[parent].list.forEach((item,index) => {
  217. if (checkData >= length) {
  218. app.$dialog.showSuccess("清除后可重选~");
  219. return ;
  220. }
  221. if (index == select) {
  222. if (item.check) {
  223. data[parent+'_'+index] = item;
  224. }
  225. item.check = item.check?false:true;
  226. app.totalData.push(data)
  227. }
  228. });
  229. }
  230. app.goodsSku = goodsSku;
  231. },
  232. skuDataCheck(parent,length){
  233. var dataLen = 0;
  234. for (let key in app.totalData) {
  235. if (typeof app.totalData[key] == 'object' || typeof app.totalData[key] == 'array')
  236. {
  237. for (let indx in app.totalData[key]) {
  238. if (indx.includes(parent+"_")) {
  239. dataLen ++;
  240. }
  241. }
  242. }
  243. }
  244. return dataLen;
  245. },
  246. checkTimeEnd(){
  247. app.$refs.timepopup.close()
  248. var day = app.timeData[app.timeIndex];
  249. var fullday = day.full;
  250. var time = day.children[app.childIndex].display;
  251. app.timeStr = fullday+" "+time;
  252. },
  253. timeCheck(index){
  254. app.timeIndex = index;
  255. app.timeChildren = app.timeData[index].children
  256. },
  257. childCheck(index){
  258. app.childIndex = index;
  259. },
  260. getBackInfo(data){
  261. app.addressInfo = data;
  262. },
  263. toAddress(){
  264. uni.navigateTo({
  265. url:"/pages/user/address?type=2"
  266. })
  267. },
  268. selectTime(type){
  269. if (type == 1) {
  270. app.$refs.timepopup.open()
  271. }
  272. if (type == 2) {
  273. app.$refs.timepopup.close()
  274. }
  275. },
  276. getOrder(){
  277. Api.detail({"order":app.order}).then((res)=>{
  278. if (res.code == 0) {
  279. return app.$dialog.showSuccess(res.msg,"none",function(){
  280. uni.navigateBack()
  281. });
  282. }
  283. app.goodsInfo = res.data.order;
  284. app.storeInfo = res.data.store;
  285. app.timeData = res.data.time
  286. app.timeChildren = app.timeData[0].children
  287. app.goodsSku = res.data.specs;
  288. });
  289. },
  290. toDetail(){
  291. uni.navigateTo({
  292. url:"/pages/order/store?type=1&order="+app.order
  293. })
  294. },
  295. }
  296. }
  297. </script>
  298. <style>
  299. page{height: 100vh;overflow: auto;}
  300. .order-type{height: 80upx;display: flex;align-items: center;line-height: 80upx;background-color: #fff;gap: 20upx;}
  301. .order-type .type-item{text-align: center;width: 50%;font-size: 32upx;color: #333;position: relative;border-left: 2upx solid #f8f8f8;}
  302. .order-type .type-item.active{color: #224d7a;font-weight: bold;}
  303. .order-type .type-item.active::after{content: "";position: absolute;left: 40%;width: 20%;bottom: -5upx;height: 10upx;background-color: #224d7a;}
  304. .addressInfo{border-top: 8upx solid #224d7a;}
  305. .addressInfo .empty-data{display: flex;align-items: center;font-size: 28upx;width: 100%;}
  306. .addressInfo .empty-data .contact-name{display: flex;align-items: center;font-size: 30upx;color: #333;margin-bottom: 20upx;}
  307. .addressInfo .empty-data .contact-name .mobile{margin-left: 20upx;}
  308. .addressInfo .empty-data .desc{font-size: 26upx;color: #666;}
  309. .addressInfo .empty-data .left image{width: 40upx;height: 40upx;margin-right: 20upx;vertical-align: middle;}
  310. .addressInfo .empty-data .right image{width: 40upx;height: 40upx;vertical-align: middle;}
  311. .addressInfo .empty-data .right{margin-left: auto;margin-right: 0;}
  312. .time-body{height: 30vh;display: flex;align-items: center;}
  313. .time-body .time-left{width: 30%;background-color: #F5FAFD;height: 100%;overflow-y: auto;}
  314. .time-body .time-left .time-left-item{padding: 10upx;text-align: center;}
  315. .time-body .time-left .time-left-item.active{background-color: #fff;color: #224d7a;}
  316. .time-body .time-left .time-left-item.active .name{color: #224d7a;}
  317. .time-body .time-left .time-left-item.active .desc{color: #224d7a;}
  318. .time-body .time-left .time-left-item .name{font-size: 28upx;color: #333;}
  319. .time-body .time-left .time-left-item .desc{font-size: 24upx;color: #666;}
  320. .time-body .time-right{width: calc(70% - 80upx);padding:0 40upx;background-color: #fff;height: 100%;overflow-y: auto;}
  321. .time-body .time-right .time-right-item{background-color: #F6FAFD;border: 2upx solid #ccc;height: 66upx;line-height: 66upx;text-align: center;font-size: 28upx;color: #333;margin-top: 20upx;border-radius: 10upx;}
  322. .time-body .time-right .time-right-item.active{color: #224d7a;border: 2upx solid #224d7a;}
  323. .time-select .title{height: 100upx;line-height: 100upx;display: flex;align-items: center;justify-content: space-between;font-size: 28upx;padding: 0 20upx;font-weight: bold;}
  324. .time-select image{width: 40upx;height: 40upx;vertical-align: middle;}
  325. .time-btn{padding: 20upx;}
  326. .location,.order-time{background-color: #fff;border-radius: 20upx;padding: 20upx;width: calc(95% - 40upx);margin: 20upx auto;display: flex;align-items: center;justify-content: space-between;}
  327. .location .right image{width: 40upx;height: 40upx;vertical-align: middle;}
  328. .location .name{font-size: 32upx;color: #333;font-weight: bold;margin-bottom: 20upx;}
  329. .location .desc{color: #666;font-size: 28upx;display: flex;align-items: center;}
  330. .location .desc image{width: 40upx;height: 40upx;margin-right: 20upx;}
  331. .goods,.order-msg,.addressInfo{background-color: #fff;border-radius: 20upx;padding: 20upx;width: calc(95% - 40upx);margin: 20upx auto;}
  332. .goods .goods-info{display: flex;align-items: center;}
  333. .goods .goods-info .info{flex: 1;margin-left: 20upx;}
  334. .goods .goods-info .image image{width: 160upx;height: 160upx;}
  335. .goods .goods-info .name{font-size: 32upx;color: #333;line-height: 46upx;font-weight: bold;margin-bottom: 20upx;}
  336. .goods .goods-info .desc{color: #666;font-size: 28upx;line-height: 48upx;}
  337. .goods .goods-item{display: flex;align-items: center;line-height: 80upx;justify-content: space-between;font-size: 28upx;color: #333;}
  338. .goods .goods-item .right.red{color: #f00;}
  339. .order-time .title{font-size: 28upx;}
  340. .order-time image{width: 40upx;height: 40upx;vertical-align: middle;}
  341. .order-time .msg{display: flex;align-items: center;font-size: 28upx;color: #333;}
  342. .order-msg .title{color: #333;font-size: 28upx;border-bottom: 2upx solid #f8f8f8;margin-bottom: 20upx;padding-bottom: 20upx;}
  343. .order-msg .textarea{width: 100%;height: 100upx;font-size: 28upx;}
  344. .flx-footer{position: fixed;bottom: 0;background-color: #fff;padding: 20upx;border-top: 2upx solid #f8f8f8;left: 0;right: 0;}
  345. .flx-footer .footer-safe {height: env(safe-area-inset-bottom);width: 100%;}
  346. .flx-footer .btn,.time-btn .btn{font-size: 28rpx;height: 80upx;border-radius: 10upx;line-height: 80upx;text-align: center;width: 100%;color: #333;background-color: #224d7a;color: #fff;border:2upx solid #224d7a;}
  347. .flx-footer .btn[disabled],.flx-footer .btn.disabled{background-color: rgba(34, 77, 122, 0.3);}
  348. .flx-footer .footer-btn{display: flex;align-items: center;justify-content: space-between;}
  349. .flx-footer .footer-btn text.desc{color: #666;font-size: 24upx;}
  350. .flx-footer .footer-btn text.money{color: #f00;font-size: 28upx;font-weight: bold;}
  351. .flx-footer .footer-btn .price{color: #333;font-size: 28upx;}
  352. .goods_skus{
  353. padding: 20upx 20upx 0 20upx;
  354. background-color: #fff;border-radius: 20upx;width: calc(95% - 40upx);margin: 0 auto;
  355. }
  356. .goods_skus .sku_name{
  357. font-size: 32upx;
  358. color: #000;
  359. font-weight: bold;
  360. line-height: 60upx;
  361. display: flex;
  362. align-items: center;
  363. }
  364. .goods_skus .sku_name .right{
  365. margin-left: auto;
  366. margin-right: 0;
  367. font-size: 26upx;
  368. color: #666;
  369. display: flex;
  370. align-items: center;
  371. }
  372. .goods_skus .sku_name .right image{
  373. width: 30upx;
  374. height: 30upx;
  375. margin-right: 10upx;
  376. }
  377. .goods_skus .sku_list{
  378. display: flex;
  379. align-items: center;
  380. margin: 10upx 0;
  381. flex-wrap: wrap;
  382. }
  383. .goods_skus .sku_list .sku_item.active{
  384. background: linear-gradient(90deg, rgba(34, 77, 122, 1) 0%, rgba(25, 97, 173, 1) 100%);
  385. color: #fff;
  386. }
  387. .goods_skus .sku_list .sku_item{
  388. background-color: #f8f8f8;
  389. padding: 10upx 20upx;
  390. margin-right: 20upx;
  391. margin-bottom: 20upx;
  392. border-radius: 5upx;
  393. font-size: 28upx;
  394. }
  395. </style>