exchangePrize.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <template>
  2. <view class="exchangePrize">
  3. <!-- 表单 -->
  4. <view class="form">
  5. <uni-forms :modelValue="formData">
  6. <uni-forms-item name="type" v-if="isPhy == 1">
  7. <view class="selectType" @click="openSelect">
  8. <view class="uni-input" @click="openSelect">
  9. <text v-if="formData.type==''||formData.type==null"
  10. style="color: #999999 ;font-size: 30rpx;">请选择配送方式</text>
  11. <text v-if="formData.type!=''" style="font-size: 30rpx;">{{formData.type}}</text>
  12. </view>
  13. <image src="/static/icon/right.png"
  14. style="width: 14rpx;height: 24rpx;position: absolute;top:22rpx;right: 30rpx;">
  15. </image>
  16. </view>
  17. </uni-forms-item>
  18. <uni-forms-item name="name" v-if="formData.type!=''||isVerification==true">
  19. <uni-easyinput type="text" v-model="Data.receiver" placeholder="联系人" />
  20. </uni-forms-item>
  21. <uni-forms-item name="phone" v-if="formData.type!=''||isVerification==true">
  22. <uni-easyinput type="number" v-model="Data.phone" placeholderStyle='color:#333,font-size:32rpx'
  23. placeholder="联系电话" maxlength=11 />
  24. </uni-forms-item>
  25. <uni-forms-item name="region" v-if="formData.type=='快递配送'">
  26. <pickerAddress @change="change">
  27. <!-- <uni-easyinput type="text" v-model="formData.region" placeholder="所在地区" /> -->
  28. <view class="selectType">
  29. <view class="uni-input">
  30. <text v-if="formData.region==''||formData.region==null"
  31. style="color: #999999 ; font-size: 30rpx; ">所在地区</text>
  32. <text style="font-size: 30rpx;" v-if="Data.area_id!=''">{{formData.region}}</text>
  33. </view>
  34. <image src="/static/icon/right.png"
  35. style="width: 14rpx;height: 24rpx;position: absolute;top:22rpx;right: 30rpx;">
  36. </image>
  37. </view>
  38. </pickerAddress>
  39. </uni-forms-item>
  40. <uni-forms-item name="region" v-if="formData.type=='快递配送'">
  41. <textarea placeholder-style="#999" class="text-area" type="text" placeholder="详细地址"
  42. v-model="Data.address" />
  43. </uni-forms-item>
  44. <uni-forms-item name="region" v-if="formData.type=='到店自提'||isVerification==true">
  45. <view class="selectType" @click="openShop">
  46. <view class="uni-input">
  47. <text v-if="formData.shop==''||formData.shop==null"
  48. style="color: #999999 ; font-size: 30rpx; ">请选择门店</text>
  49. <text style="font-size: 30rpx;" v-if="formData.shop!=''">{{formData.shop}}</text>
  50. <text class="distance" v-if="formData.shop!=''">{{formData.distanceToMe}}km</text>
  51. </view>
  52. <image src="/static/icon/right.png"
  53. style="width: 14rpx;height: 24rpx;position: absolute;top:22rpx;right: 30rpx;">
  54. </image>
  55. </view>
  56. </uni-forms-item>
  57. </uni-forms>
  58. </view>
  59. <!-- 奖品信息 -->
  60. <view class="msg">
  61. <view class="title">
  62. <text>奖品信息</text>
  63. </view>
  64. <view class="shopCard">
  65. <image :src="coverImg"></image>
  66. <view style="margin-left: 24rpx;">
  67. <text class="name">{{prizeDetail[0].name}}</text>
  68. <!-- <text class="tag">礼盒装 </text> -->
  69. </view>
  70. </view>
  71. <view class="shopNumber">
  72. <text>件数</text>
  73. <text>1件</text>
  74. </view>
  75. </view>
  76. <!-- 兑换按钮 -->
  77. <view class="bottombtn" @click="goExDetail">
  78. <view class="btnitem">
  79. <text>确认兑换</text>
  80. </view>
  81. </view>
  82. <!-- 配送方式-->
  83. <uni-popup ref="Recipient" type="bottom" mask-background-color=" rgba(0,0,0,0.7);">
  84. <view class="pop">
  85. <view class="popuptitle">
  86. <view @click="cancelBtn" style="width: 68rpx;color: #999;font-size: 32rpx;">
  87. <text>取消</text>
  88. </view>
  89. <view>
  90. <text style="font-weight: bold; font-size: 32rpx; color: #080F18; ">配送方式</text>
  91. </view>
  92. <view @click="sureBtn" style="width: 68rpx;"><text
  93. style="font-size: 32rpx; color: #FF6200;line-height: 34rpx">确定</text></view>
  94. </view>
  95. <view class="chooselag">
  96. <view @click="companyed(item.name,index)" class="language" v-for="(item,index) in typeSelect "
  97. :key="index" :class="[activeIndex === index?'sgActive': ''] ">
  98. <text>{{item.name}}</text>
  99. </view>
  100. </view>
  101. </view>
  102. </uni-popup>
  103. <!-- 门店选择-->
  104. <uni-popup ref="shopSelected" type="bottom" mask-background-color=" rgba(0,0,0,0.7);">
  105. <view class="pop">
  106. <view class="popuptitle">
  107. <view @click="cancelShopBtn" style="width: 68rpx;color: #999;font-size: 32rpx;">
  108. <text>取消</text>
  109. </view>
  110. <view>
  111. <text style="font-weight: bold; font-size: 32rpx; color: #080F18; ">配送方式</text>
  112. </view>
  113. <view @click="sureShopBtn" style="width: 68rpx;"><text
  114. style="font-size: 32rpx; color: #FF6200;line-height: 34rpx">确定</text></view>
  115. </view>
  116. <view class="chooselag">
  117. <view @click="companyedShop(item.name,item.id,item.distanceToMe,index)" class="language"
  118. v-for="(item,index) in hotelList" :key="index" :class="[activeIndex2 === index?'sgActive': ''] ">
  119. <text>{{item.name}}</text>
  120. </view>
  121. </view>
  122. </view>
  123. </uni-popup>
  124. </view>
  125. </template>
  126. <script>
  127. import pickerAddress from '@/uni_modules/hu-pickerAddress/hu-pickerAddress.vue'
  128. export default {
  129. components: {
  130. pickerAddress
  131. },
  132. data() {
  133. return {
  134. //经纬度
  135. latitude: '',
  136. longitude: '',
  137. //实物奖品和线下奖品区分
  138. isPhy: '',
  139. activeIndex: '',
  140. activeIndex2: '',
  141. coverImg: '',
  142. prizeDetail: '',
  143. //产品
  144. id: '',
  145. // 是否核销
  146. isVerification: false,
  147. // 表单数据
  148. formData: {
  149. type: '',
  150. region: '',
  151. shop: '',
  152. distanceToMe: ''
  153. },
  154. // 配送方式
  155. typeSelect: [{
  156. name: '快递配送',
  157. }, {
  158. name: '到店自提',
  159. }],
  160. // 选择门店
  161. hotelList: [],
  162. // 表单数据
  163. Data: {
  164. order_id: '', //订单id
  165. // 快递类型(1.快递发货 2.到店自提也是线下核销)
  166. express_type: '',
  167. // 收货人
  168. receiver: "",
  169. // 联系电话
  170. phone: '',
  171. // 地址ID,最小行政单位地区ID,express_type=1时必传
  172. area_id: '',
  173. // 详细地址,express_type=1时必传
  174. address: '',
  175. //门店ID,express_type=2时必传
  176. hotel_id: 0,
  177. },
  178. }
  179. },
  180. onLoad(o) {
  181. if (o.id) {
  182. this.id = o.id
  183. this.isPhy = o.isPhy
  184. console.log(this.id);
  185. if (this.isPhy == 1) {
  186. //实物奖品
  187. this.getPrizeList(0)
  188. } else {
  189. //虚拟奖品
  190. this.getPrizeList(1)
  191. }
  192. }
  193. },
  194. methods: {
  195. space(lat1, lng1, lat2, lng2) {
  196. var radLat1 = lat1 * Math.PI / 180.0;
  197. var radLat2 = lat2 * Math.PI / 180.0;
  198. var a = radLat1 - radLat2;
  199. var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  200. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  201. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  202. s = s * 6378.137;
  203. s = Math.round(s * 10000) / 10000;
  204. return s // 单位千米
  205. },
  206. //门店列表
  207. getHotel() {
  208. this.$api.hotel.getHotelList({
  209. page: 1,
  210. type: 2,
  211. latitude: this.latitude,
  212. longitude: this.longitude
  213. }).then(res => {
  214. this.hotelList = res.data.data
  215. this.hotelList.map(item => {
  216. item.distanceToMe = this.space(this.latitude, this.longitude, item.latitude, item
  217. .longitude).toFixed(1);
  218. return item;
  219. })
  220. console.log(this.hotelList, '-------->this.hotelList');
  221. })
  222. },
  223. //获取定位
  224. goLocation() {
  225. let _this = this
  226. uni.getLocation({
  227. type: "gcj02", //返回可以用于wx.openLocation的经纬度
  228. success: function(res) {
  229. _this.latitude = res.latitude
  230. _this.longitude = res.longitude
  231. },
  232. fail: function(res) {
  233. console.log(res)
  234. }
  235. })
  236. },
  237. //订单兑换
  238. goExDetail() {
  239. if (this.formData.type == '' && this.isPhy == 1) {
  240. uni.showToast({
  241. icon: 'none',
  242. title: '请选择配送方式'
  243. })
  244. return
  245. }
  246. if (this.Data.receiver == '') {
  247. uni.showToast({
  248. icon: 'none',
  249. title: '请填写联系人'
  250. })
  251. return
  252. }
  253. if (this.Data.phone == '') {
  254. uni.showToast({
  255. icon: 'none',
  256. title: '请填写联系电话'
  257. })
  258. return
  259. }
  260. if (this.formData.region == '' && this.Data.express_type == 1) {
  261. uni.showToast({
  262. icon: 'none',
  263. title: '请填写所在地区'
  264. })
  265. return
  266. }
  267. if (this.Data.address == '' && this.Data.express_type == 1) {
  268. uni.showToast({
  269. icon: 'none',
  270. title: '请填写详细地址'
  271. })
  272. return
  273. }
  274. if (this.Data.hotel_id == '' && this.Data.express_type == 2) {
  275. uni.showToast({
  276. icon: 'none',
  277. title: '请选择门店'
  278. })
  279. return
  280. }
  281. if(this.isPhy == 1){
  282. if(this.Data.express_type == 1){
  283. this.$api.product.orderExchange({
  284. ...this.Data
  285. }).then(res => {
  286. if (res.code == 0) {
  287. uni.navigateTo({
  288. url: '/pages/my/prize/exchangeDetail'
  289. })
  290. } else {
  291. uni.showToast({
  292. icon: 'none',
  293. title: res.msg
  294. })
  295. }
  296. })
  297. }else{
  298. let obj ={}
  299. obj.express_type = this.Data.express_type
  300. obj.order_id = this.Data.order_id
  301. obj.receiver = this.Data.receiver
  302. obj.phone = this.Data.phone
  303. obj.hotel_id = this.Data.hotel_id
  304. this.$api.product.orderExchange({
  305. ...obj
  306. }).then(res => {
  307. if (res.code == 0) {
  308. uni.navigateTo({
  309. url: '/pages/my/prize/exchangeDetail'
  310. })
  311. } else {
  312. uni.showToast({
  313. icon: 'none',
  314. title: res.msg
  315. })
  316. }
  317. })
  318. }
  319. }else{
  320. let obj ={}
  321. obj.express_type = this.Data.express_type
  322. obj.order_id = this.Data.order_id
  323. obj.receiver = this.Data.receiver
  324. obj.phone = this.Data.phone
  325. obj.hotel_id = this.Data.hotel_id
  326. this.$api.product.orderExchange({
  327. ...obj
  328. }).then(res => {
  329. if (res.code == 0) {
  330. uni.navigateTo({
  331. url: '/pages/my/prize/exchangeDetail'
  332. })
  333. } else {
  334. uni.showToast({
  335. icon: 'none',
  336. title: res.msg
  337. })
  338. }
  339. })
  340. }
  341. },
  342. //打开门店弹框
  343. openShop() {
  344. this.$refs.shopSelected.open('bottom')
  345. },
  346. companyedShop(i, id, distance,index) {
  347. this.typestatus2 = i
  348. this.activeIndex2= index
  349. this.distanceToMe1 = distance
  350. this.Data.hotel_id = id
  351. },
  352. //确定按钮
  353. sureShopBtn() {
  354. if (this.typestatus2 == undefined) {
  355. uni.showToast({
  356. icon: "none",
  357. title: '请选择门店'
  358. })
  359. } else {
  360. this.formData.shop = this.typestatus2
  361. this.formData.distanceToMe = this.distanceToMe1
  362. this.$refs.shopSelected.close()
  363. }
  364. },
  365. //取消按钮
  366. cancelShopBtn() {
  367. this.$refs.shopSelected.close()
  368. },
  369. change(ret) {
  370. this.formData.region = ret.data.join('-')
  371. this.Data.area_id = ret.code[2]
  372. },
  373. //取消按钮
  374. cancelBtn() {
  375. this.$refs.Recipient.close()
  376. },
  377. //选择配送方式
  378. companyed(i, index) {
  379. this.typestatus1 = i
  380. this.activeIndex = index
  381. console.log(i, this.activeIndex)
  382. if (index == 0) {
  383. this.Data.express_type = 1
  384. } else if (index == 1) {
  385. this.Data.express_type = 2
  386. this.goLocation()
  387. setTimeout(() => {
  388. this.getHotel()
  389. }, 1000)
  390. }
  391. },
  392. //确定按钮
  393. sureBtn() {
  394. if (this.typestatus1 == undefined) {
  395. uni.showToast({
  396. icon: "none",
  397. title: '请选择配送方式'
  398. })
  399. } else {
  400. this.formData.type = this.typestatus1
  401. this.$refs.Recipient.close()
  402. }
  403. },
  404. // 打开配送弹框
  405. openSelect() {
  406. this.$refs.Recipient.open('bottom')
  407. },
  408. // 获取奖品列表
  409. getPrizeList(type) {
  410. this.$api.lottery.getDrawRecord({
  411. is_virtual: type,
  412. page: 0
  413. }).then(res => {
  414. if (this.isPhy == 2) {
  415. this.isVerification = true
  416. this.Data.express_type = 2
  417. this.goLocation()
  418. setTimeout(() => {
  419. this.getHotel()
  420. }, 1000)
  421. }
  422. this.prizeDetail = res.data.data.filter(item => {
  423. return item.id == this.id
  424. })
  425. this.coverImg = this.prizeDetail[0].img_urls
  426. this.Data.order_id = this.prizeDetail[0].order_id
  427. })
  428. },
  429. }
  430. }
  431. </script>
  432. <style lang="scss" scoped>
  433. $pageColor:#F9F9F9;
  434. $bgColor:#FFFFFF;
  435. @mixin flexlayout {
  436. display: flex;
  437. align-items: center;
  438. justify-content: center;
  439. }
  440. .exchangePrize {
  441. height: 100%;
  442. background: $bgColor;
  443. }
  444. .distance {
  445. position: absolute;
  446. right: 60rpx;
  447. top: 15rpx;
  448. }
  449. ::v-deep .uni-forms-item {
  450. margin-bottom: 24rpx;
  451. }
  452. ::v-deep .uni-forms-item__content {
  453. font-size: 30rpx;
  454. border: 2rpx solid #EAEAEA;
  455. padding: 18rpx 0;
  456. border-radius: 8rpx;
  457. background-color: #fff;
  458. }
  459. ::v-deep .is-input-border {
  460. border: none;
  461. }
  462. .form {
  463. background: $pageColor;
  464. width: 750rpx;
  465. padding: 24rpx 30rpx 12rpx 30rpx;
  466. box-sizing: border-box;
  467. .selectType {
  468. width: 690rpx;
  469. height: 68rpx;
  470. background: #FFFFFF;
  471. display: flex;
  472. align-items: center;
  473. padding-left: 20rpx;
  474. box-sizing: border-box;
  475. position: relative;
  476. }
  477. }
  478. .msg {
  479. width: 750rpx;
  480. height: 700rpx;
  481. background: $bgColor;
  482. border-radius: 12rpx 12rpx 0px 0px;
  483. padding: 32rpx 30rpx;
  484. .title {
  485. margin-bottom: 24rpx;
  486. text {
  487. font-size: 32rpx;
  488. font-family: PingFang-SC-Bold, PingFang-SC;
  489. font-weight: bold;
  490. color: #080F18;
  491. }
  492. }
  493. .shopCard {
  494. margin-top: 28rpx;
  495. width: 694rpx;
  496. height: 164rpx;
  497. background: #F4F5F6;
  498. border-radius: 10rpx;
  499. display: flex;
  500. align-items: center;
  501. image {
  502. width: 132rpx;
  503. height: 132rpx;
  504. margin-left: 16rpx;
  505. display: inline-block;
  506. border-radius: 10rpx;
  507. }
  508. .name {
  509. font-size: 28rpx;
  510. font-family: PingFangSC-Medium, PingFang SC;
  511. font-weight: 500;
  512. color: #080F18;
  513. display: block;
  514. }
  515. .tag {
  516. font-size: 24rpx;
  517. font-family: PingFang-SC-Medium, PingFang-SC;
  518. font-weight: 500;
  519. color: #666666;
  520. }
  521. }
  522. .shopNumber {
  523. display: flex;
  524. justify-content: space-between;
  525. align-items: center;
  526. margin-top: 25rpx;
  527. text {
  528. font-size: 26rpx;
  529. font-family: PingFang-SC-Medium, PingFang-SC;
  530. font-weight: 500;
  531. color: #000000;
  532. }
  533. }
  534. }
  535. .bottombtn {
  536. width: 690rpx;
  537. height: 92rpx;
  538. background: linear-gradient(270deg, #FF6200 0%, #FF9342 100%);
  539. border-radius: 12rpx;
  540. margin-left: 30rpx;
  541. position: fixed;
  542. bottom: 72rpx;
  543. @include flexlayout();
  544. .btnitem {
  545. @include flexlayout();
  546. text {
  547. font-size: 30rpx;
  548. font-family: PingFang-SC-Bold, PingFang-SC;
  549. font-weight: bold;
  550. color: $bgColor;
  551. }
  552. }
  553. }
  554. .pop {
  555. width: 100%;
  556. height: 616rpx;
  557. background: #FFFFFF;
  558. border-radius: 16rpx 16rpx 0 0;
  559. overflow: scroll;
  560. .popuptitle {
  561. position: fixed;
  562. top: 0;
  563. display: flex;
  564. width: 100%;
  565. padding: 0 30rpx;
  566. height: 122rpx;
  567. background: #fff;
  568. display: flex;
  569. align-items: center;
  570. justify-content: space-between;
  571. image {
  572. display: inline-block;
  573. width: 33rpx;
  574. height: 33rpx;
  575. border-radius: 1rpx;
  576. }
  577. }
  578. .chooselag {
  579. flex-direction: column;
  580. justify-content: center;
  581. align-items: center;
  582. background: #FFFFFF;
  583. padding: 0 30rpx;
  584. overflow-y: scroll;
  585. margin-top: 122rpx;
  586. .language {
  587. width: 100%;
  588. font-size: 32rpx;
  589. font-weight: 400;
  590. color: #777777;
  591. border-bottom: 1rpx #E2E4EA solid;
  592. display: flex;
  593. align-items: center;
  594. justify-content: center;
  595. padding-top: 40rpx;
  596. padding-bottom: 40rpx;
  597. }
  598. .sgActive{
  599. color: #FF6200 !important;
  600. font-weight: bold !important;
  601. }
  602. }
  603. }
  604. .text-area {
  605. width: 100%;
  606. height: 130rpx;
  607. padding: 0rpx 20rpx;
  608. background: #FFFFFF;
  609. border-radius: 8rpx;
  610. font-size: 30rpx;
  611. color: #000;
  612. line-height: 30rpx;
  613. }
  614. ::v-deep .uni-icons {
  615. color: #c0c4cc !important;
  616. font-size: 24px !important;
  617. }
  618. ::v-deep .uni-easyinput__content-input {
  619. color: #333333;
  620. font-size: 30rpx;
  621. }
  622. ::v-deep .uni-easyinput__placeholder-class {
  623. color: #999 !important;
  624. font-size: 30rpx !important;
  625. }
  626. </style>