exchange.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view class="wrap">
  3. <u-navbar title="礼品兑换" :placeholder="true" bgColor="rgba(255,255,255,0.3)" leftText="返回" :autoBack="true" titleStyle="font-weight:bold;color:#7a5831"></u-navbar>
  4. <view class="main" v-if="hasLoad">
  5. <view class="gift-view">
  6. <view class="b-left">
  7. <image :src="giftData.cover_url" mode="aspectFill"></image>
  8. </view>
  9. <view class="b-main">
  10. <view class="b-title">{{ giftData.name }}</view>
  11. <view class="b-spec" v-if="giftData.spec_data">
  12. <view class="s-tit">规格:</view>
  13. <view class="s-value">{{ giftData.spec_data.name }}</view>
  14. </view>
  15. <view class="b-fund">
  16. <view class="s-worth" v-if="giftData.order_worth > 0">价值 {{ giftData.order_worth }}元</view>
  17. </view>
  18. </view>
  19. </view>
  20. <template v-if="giftData.type == 1">
  21. <view class="box">
  22. <view class="b-row">
  23. <view class="b-tit">领取方式</view>
  24. <view class="b-cont f-option">
  25. <picker @change="onFilter" :value="gainMethodIndex" :range="gainMethodList" range-key="name">
  26. <view class="b-main">
  27. <view class="s-cont">{{ gainMethodList[gainMethodIndex].name }}</view>
  28. <view class="iconfont icon-more"></view>
  29. </view>
  30. </picker>
  31. </view>
  32. </view>
  33. <view class="b-row" v-if="gainMethodList[gainMethodIndex].value == 1 && giftData.offline_place">
  34. <view class="b-tit">领取地点</view>
  35. <view class="b-cont f-text">{{ giftData.offline_place }}</view>
  36. </view>
  37. <view class="b-address" v-if="gainMethodList[gainMethodIndex].value == 2">
  38. <view class="b-row">
  39. <view class="b-tit">收件人:</view>
  40. <view class="b-cont">
  41. <input type="text" value="" placeholder="请填写收件人姓名" @input="onInputText" data-field="name" />
  42. </view>
  43. </view>
  44. <view class="b-row">
  45. <view class="b-tit">手机号:</view>
  46. <view class="b-cont">
  47. <input type="text" value="" placeholder="请填写收件人手机号" @input="onInputText" data-field="phone" />
  48. </view>
  49. </view>
  50. <view class="b-row">
  51. <view class="b-tit">所在地区:</view>
  52. <view class="b-cont f-area">
  53. <area-picker v-on:getAddressResultObj="getAddressResultObj" :addressList.sync="addressList">
  54. <div class="b-areas">
  55. <view class="b-item">
  56. <view class="s-cont">{{ addressList[0] }}</view>
  57. </view>
  58. <view class="b-item">
  59. <view class="s-cont">{{ addressList[1] }}</view>
  60. </view>
  61. <view class="b-item">
  62. <view class="s-cont">{{ addressList[2] }}</view>
  63. </view>
  64. </div>
  65. </area-picker>
  66. </view>
  67. </view>
  68. <view class="b-row">
  69. <view class="b-tit">详细地址:</view>
  70. <view class="b-cont f-textarea">
  71. <textarea placeholder="请填写详细地址,包括门牌号" auto-height @input="onInputText" data-field="address"></textarea>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="line"></view>
  76. <!-- <view class="b-row f-fund">
  77. <view class="b-tit">剩余机会:</view>
  78. <view class="b-cont">
  79. <view class="s-num">{{chanceData.chance_left}}</view>
  80. </view>
  81. </view> -->
  82. </view>
  83. <view class="box">
  84. <view class="b-row">
  85. <view class="b-tit">留言:</view>
  86. <view class="b-cont f-textarea">
  87. <textarea placeholder="这里填写内容" auto-height @input="onInputText" data-field="note"></textarea>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <!-- <view class="box" v-else>
  93. <view class="b-row f-fund">
  94. <view class="b-tit">剩余机会:</view>
  95. <view class="b-cont">
  96. <view class="s-num">{{chanceData.chance_left}}</view>
  97. </view>
  98. </view>
  99. </view> -->
  100. <view class="navbar">
  101. <view class="b-action">
  102. <view class="s-exchange" @click="onExchange" v-if="amountEnough">确认兑换</view>
  103. <view class="s-exchange f-disable" v-else>机会不足</view>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 加载中 -->
  108. <load-more :loadingType="loadingType" :loadingText="loadingText" :top="300"></load-more>
  109. </view>
  110. </template>
  111. <script>
  112. import { getPreview, exchange } from '@/service/api/gift.js';
  113. import mixinsCommon from '@/mixins/common.js';
  114. import mixinsAuth from '../../mixins/auth.js';
  115. export default {
  116. mixins: [mixinsCommon, mixinsAuth],
  117. data() {
  118. return {
  119. disable: {
  120. submit: false
  121. },
  122. giftData: {},
  123. chanceData: {},
  124. orderData: {},
  125. formData: {
  126. gift_id: 0,
  127. gift_spec_id: 0,
  128. gain_method: 0,
  129. name: '',
  130. phone: '',
  131. province: '',
  132. city: '',
  133. area: '',
  134. address: '',
  135. note: ''
  136. },
  137. gainMethodList: [
  138. {
  139. value: 2,
  140. name: '快递邮寄'
  141. }
  142. ],
  143. gainMethodIndex: 0,
  144. hasLoad: false,
  145. loadingType: 1,
  146. loadingText: '',
  147. addressList: ['', '', '']
  148. };
  149. },
  150. onLoad(options) {
  151. this.loadPreview(options.gift_id, options.spec_id);
  152. this.formData.gift_id = options.gift_id;
  153. this.formData.gift_spec_id = options.spec_id;
  154. },
  155. computed: {
  156. amountEnough() {
  157. return this.chanceData.chance_left > 0;
  158. }
  159. },
  160. methods: {
  161. loadPreview(giftId, specId) {
  162. getPreview(giftId, specId).then(([err, res]) => {
  163. console.log('getPreview', err, res);
  164. if (!err) {
  165. this.hasLoad = true;
  166. this.loadingType = -1;
  167. this.giftData = res.gift_data;
  168. res.chance_data.chance_left = 100;
  169. this.chanceData = res.chance_data;
  170. this.orderData = res.order_data;
  171. // 领取方式
  172. if (this.giftData.gain_methods) {
  173. this.gainMethodList = [];
  174. if (this.giftData.gain_methods.indexOf('2') !== -1) {
  175. console.log('test2');
  176. this.gainMethodList.push({
  177. value: 2,
  178. name: '快递邮寄'
  179. });
  180. console.log(this.gainMethodList);
  181. }
  182. if (this.giftData.gain_methods.indexOf('1') !== -1) {
  183. console.log('test1');
  184. this.gainMethodList.push({
  185. value: 1,
  186. name: '线下领取'
  187. });
  188. }
  189. }
  190. this.formData.gain_method = this.gainMethodList[this.gainMethodIndex].value;
  191. } else {
  192. this.loadingType = 3;
  193. this.loadingText = err.data.msg || '加载失败';
  194. }
  195. });
  196. },
  197. onExchange() {
  198. if (this.disable.submit) {
  199. return;
  200. }
  201. if (this.giftData.type == 1) {
  202. if (this.formData.gain_method == 2) {
  203. if (!this.formData.name) {
  204. return this.$logic.showToast('收件人不能为空');
  205. }
  206. if (!this.formData.phone) {
  207. return this.$logic.showToast('手机号不能为空');
  208. }
  209. if (!this.formData.province || !this.formData.city || !this.formData.area) {
  210. return this.$logic.showToast('所在地区不能为空');
  211. }
  212. if (!this.formData.address) {
  213. return this.$logic.showToast('详细地址不能为空');
  214. }
  215. }
  216. } else {
  217. this.formData.gain_method = 3;
  218. }
  219. this.disable.submit = true;
  220. exchange(this.formData).then(([err, res]) => {
  221. console.log('exchange', err, res);
  222. this.disable.submit = false;
  223. if (!err) {
  224. uni.reLaunch({
  225. url: '/answer_pages/gift/order_detail?submit=1&id=' + res.id
  226. });
  227. }
  228. });
  229. },
  230. // 输入内容
  231. onInputText(e) {
  232. console.log('onInputText', e);
  233. this.formData[e.target.dataset.field] = e.detail.value;
  234. },
  235. getAddressResultObj(e) {
  236. console.log('getAddressResultObj', e);
  237. this.addressList = [e.province.name, e.city.name, e.county.name];
  238. this.formData.province = e.province.name;
  239. this.formData.city = e.city.name;
  240. this.formData.area = e.county.name;
  241. },
  242. onFilter(e) {
  243. console.log('onFilter', e.detail.value);
  244. this.gainMethodIndex = e.detail.value;
  245. this.formData.gain_method = this.gainMethodList[this.gainMethodIndex].value;
  246. }
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. // page {
  252. // padding-bottom: env(safe-area-inset-bottom);
  253. // background: $pq-bg-color;
  254. // }
  255. .wrap {
  256. }
  257. .gift-view {
  258. background: #fff;
  259. padding: 30upx;
  260. display: flex;
  261. .b-left {
  262. width: 160upx;
  263. height: 160upx;
  264. image {
  265. width: 160upx;
  266. height: 160upx;
  267. }
  268. }
  269. .b-main {
  270. margin-left: 30upx;
  271. flex: 1;
  272. display: flex;
  273. flex-direction: column;
  274. .b-title {
  275. font-size: 28upx;
  276. color: #333;
  277. }
  278. .b-spec {
  279. margin-top: 20upx;
  280. display: flex;
  281. align-items: center;
  282. .s-tit {
  283. font-size: 24upx;
  284. color: #999;
  285. }
  286. .s-value {
  287. margin-left: 10upx;
  288. font-size: 24upx;
  289. color: #666;
  290. }
  291. }
  292. .b-fund {
  293. margin-top: 20upx;
  294. display: flex;
  295. align-items: baseline;
  296. .s-worth {
  297. font-size: 24upx;
  298. color: #999;
  299. }
  300. }
  301. }
  302. }
  303. .box {
  304. margin-top: 30upx;
  305. background: #fff;
  306. .b-row {
  307. padding: 30upx;
  308. display: flex;
  309. justify-content: space-between;
  310. &.f-fund {
  311. padding: 40upx 30upx;
  312. .b-cont {
  313. .s-num {
  314. font-size: 32upx;
  315. color: #da5650;
  316. }
  317. }
  318. }
  319. .b-tit {
  320. font-size: 28upx;
  321. width: 160upx;
  322. }
  323. .b-cont {
  324. // flex: 1;
  325. display: flex;
  326. align-items: center;
  327. &.f-option {
  328. .b-main {
  329. display: flex;
  330. align-items: center;
  331. .s-cont {
  332. font-size: 28upx;
  333. }
  334. .iconfont {
  335. margin-left: 10upx;
  336. }
  337. }
  338. }
  339. &.f-textarea {
  340. textarea {
  341. width: 530upx;
  342. font-size: 28upx;
  343. }
  344. }
  345. &.f-text {
  346. font-size: 28upx;
  347. color: #666;
  348. }
  349. }
  350. }
  351. .b-address {
  352. .b-row {
  353. border-bottom: 1upx solid #eee;
  354. &:last-child {
  355. border-bottom: none;
  356. }
  357. .b-tit {
  358. color: #666;
  359. width: 160upx;
  360. }
  361. .b-cont {
  362. flex: 1;
  363. &.f-area {
  364. .b-areas {
  365. display: flex;
  366. align-items: center;
  367. }
  368. .b-item {
  369. margin-right: 40upx;
  370. .s-cont {
  371. font-size: 28upx;
  372. }
  373. }
  374. }
  375. textarea {
  376. width: 530upx;
  377. height: 200upx;
  378. }
  379. }
  380. }
  381. }
  382. .line {
  383. width: 100%;
  384. height: 16upx;
  385. background-image: url(https://huli-app.wenlvti.net/app_static/wuyuan/static/wenwu/answer/imgs/line-bg.png);
  386. background-repeat: repeat-x;
  387. background-size: auto 100%;
  388. image {
  389. width: 100%;
  390. height: 20upx;
  391. }
  392. }
  393. input {
  394. font-size: 28upx;
  395. }
  396. .input-placeholder {
  397. font-size: 28upx;
  398. }
  399. }
  400. .navbar {
  401. position: fixed;
  402. left: 0;
  403. bottom: 0;
  404. width: 100%;
  405. height: 100upx;
  406. background: #fff;
  407. border-top: 1upx solid #f6f6f6;
  408. display: flex;
  409. align-items: center;
  410. justify-content: space-between;
  411. .b-action {
  412. flex: 1;
  413. .s-exchange {
  414. background: #da5650;
  415. height: 100upx;
  416. padding: 0 60upx;
  417. line-height: 100upx;
  418. font-size: 30upx;
  419. color: #fff;
  420. letter-spacing: 4upx;
  421. text-align: center;
  422. }
  423. }
  424. }
  425. </style>