123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <template>
- <!-- 军令状 -->
- <view class="pledge">
- <image :src="imgUrl" class="pledgeBg" @longpress="downLoad == true ? downloadImg() : ''"></image>
- <view class="pop" v-if="popShow">
- <view class="pop_con">
- <view class="pop_title">承诺书</view>
- <view class="promise_info">
- <view class="flexV">
- <text>每周零售产品套数:</text>
- <input type="number" v-model="count" />
- </view>
- <view class="flexV">
- <text>自愿发红包金额:</text>
- <input type="number" v-model="sum" />
- </view>
- </view>
- <view class="promise_btn" @click="subPromise">提交承诺</view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { subPromise, promiseBook } from '../../api/promise.js';
- export default {
- data() {
- return {
- count: '', //产品套数
- sum: '', //红包金额
- popShow: false, //是否显示承诺弹窗
- userInfo: {}, //用户信息
- imgUrl: '../../static/imgs/pledge.png', //军令状背景图
- downLoad: false //是否长按下载图片
- };
- },
- onShow() {
- if (!uni.getStorageSync('userInfo')) {
- uni.redirectTo({
- url: '../index/index'
- });
- return false;
- }
- this.userInfo = uni.getStorageSync('userInfo');
- this.getPromie();
- },
- methods: {
- // 获取承诺书
- getPromie() {
- promiseBook()
- .then(res => {
- if (res.code != 200) {
- uni.showModal({
- content: res.message,
- showCancel: false
- });
- return false;
- }
- if (res.code == 200 && res.data.img) {
- this.imgUrl = res.data.img;
- this.downLoad = true;
- } else {
- this.popShow = true;
- }
- })
- .catch(err => {
- console.log(err);
- });
- },
- //下载图片
- async downloadImg() {
- console.log(this.imgUrl);
- await uni.showLoading({
- title: '下载中'
- });
- // 1.将远程文件下载到小程序的内存中,tempFilePath
- const result1 = await uni.downloadFile({
- url: this.imgUrl
- });
- console.log(result1);
- const { tempFilePath } = result1[1];
- // 2.将小程序内存中的临时文件下载到本地上
- const result2 = await uni.saveImageToPhotosAlbum({
- filePath: tempFilePath,
- success: () => {
- uni.showModal({
- content: '下载成功',
- showCancel: false
- });
- },
- fail: err => {
- if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
- uni.showModal({
- title: '提示',
- content: '您好,请先授权,再保存此图片。',
- showCancel: false,
- success: res => {
- if (res.confirm) {
- uni.openSetting({
- success(settingdata) {
- console.log(settingdata);
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- uni.showToast({
- title: '请重新保存图片',
- icon: 'none'
- });
- } else {
- uni.showToast({
- title: '获取权限失败',
- icon: 'none'
- });
- }
- },
- fail: err => {
- console.log(err);
- }
- });
- }
- }
- });
- } else {
- uni.showModal({
- content: '下载失败',
- showCancel: false
- });
- }
- },
- complete() {
- uni.hideLoading();
- }
- });
- },
- /*
- *提交承诺
- * @params promise_num 产品的件数
- * @params gift_money 红包金额
- */
- subPromise() {
- if (!this.count) {
- uni.showModal({
- content: '请输入产品套数',
- showCancel: false
- });
- return false;
- }
- if (!this.sum) {
- uni.showModal({
- content: '请输入红包金额',
- showCancel: false
- });
- return false;
- }
- subPromise({ promise_num: this.count, gift_money: this.sum }).then(res => {
- console.log(res);
- if (res.code == 200) {
- this.imgUrl = res.data.img;
- this.popShow = false;
- } else {
- uni.showModal({
- content: res.message,
- showCancel: false
- });
- }
- });
- }
- }
- };
- </script>
- <style>
- page {
- width: 100%;
- min-height: 100%;
- }
- </style>
- <style lang="scss">
- .pledge {
- height: 100vh;
- width: 100vw;
- overflow: hidden;
- position: relative;
- .pop {
- position: absolute;
- top: 0;
- left: 0;
- height: 100vh;
- width: 100vw;
- background-color: rgba($color: #000000, $alpha: 0.4);
- .pop_con {
- padding: 0 30rpx;
- box-sizing: border-box;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- background-color: #fff;
- z-index: 999;
- width: 600rpx;
- margin: 0 auto;
- height: 450rpx;
- border-radius: 15rpx;
- color: #000;
- .pop_title {
- font-size: 32rpx;
- text-align: center;
- padding: 25rpx 0;
- font-weight: bold;
- }
- .promise_info {
- > view {
- margin-top: 20rpx;
- padding: 15rpx 0;
- text {
- width: 288rpx;
- text-align: right;
- }
- }
- input {
- width: 200rpx;
- border: 1rpx solid #cccccc;
- border-radius: 8rpx;
- padding: 10rpx;
- }
- }
- .promise_btn {
- width: 400rpx;
- height: 66rpx;
- line-height: 66rpx;
- margin: 35rpx auto 0;
- color: #fff;
- background-color: #fc1304;
- border-radius: 44rpx;
- text-align: center;
- }
- }
- }
- .pledgeBg {
- height: 100%;
- width: 100%;
- }
- // .pledge_con {
- // color: #fff;
- // view {
- // position: absolute;
- // bottom: 28vh;
- // right: 28vw;
- // }
- // .money {
- // bottom: 21vh;
- // right: 33vw;
- // }
- // .name {
- // bottom: 14vh;
- // right: 28vw;
- // }
- // .year {
- // bottom: 6vh;
- // right: 41vw;
- // }
- // .month {
- // bottom: 6vh;
- // right: 30vw;
- // }
- // .day {
- // bottom: 6vh;
- // right: 19vw;
- // }
- // .share {
- // bottom: 4vh;
- // left: 7vw;
- // display: flex;
- // align-items: center;
- // image {
- // height: 64rpx;
- // width: 64rpx;
- // }
- // text {
- // color: #e6a805;
- // font-size: 28rpx;
- // margin-left: 11rpx;
- // font-weight: bold;
- // }
- // }
- // }
- }
- </style>
|