confirm.vue 14 KB

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