military_order.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <!-- 军令状 -->
  3. <view class="pledge">
  4. <image :src="imgUrl" class="pledgeBg" @longpress="downLoad == true ? downloadImg() : ''"></image>
  5. <view class="pop" v-if="popShow">
  6. <view class="pop_con">
  7. <view class="pop_title">承诺书</view>
  8. <view class="promise_info">
  9. <view class="flexV">
  10. <text>每周零售产品套数:</text>
  11. <input type="number" v-model="count" />
  12. </view>
  13. <view class="flexV">
  14. <text>自愿发红包金额:</text>
  15. <input type="number" v-model="sum" />
  16. </view>
  17. </view>
  18. <view class="promise_btn" @click="subPromise">提交承诺</view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { subPromise, promiseBook } from '../../api/promise.js';
  25. export default {
  26. data() {
  27. return {
  28. count: '', //产品套数
  29. sum: '', //红包金额
  30. popShow: false, //是否显示承诺弹窗
  31. userInfo: {}, //用户信息
  32. imgUrl: '../../static/imgs/pledge.png', //军令状背景图
  33. downLoad: false //是否长按下载图片
  34. };
  35. },
  36. onShow() {
  37. if (!uni.getStorageSync('userInfo')) {
  38. uni.redirectTo({
  39. url: '../index/index'
  40. });
  41. return false;
  42. }
  43. this.userInfo = uni.getStorageSync('userInfo');
  44. this.getPromie();
  45. },
  46. methods: {
  47. // 获取承诺书
  48. getPromie() {
  49. promiseBook()
  50. .then(res => {
  51. if (res.code != 200) {
  52. uni.showModal({
  53. content: res.message,
  54. showCancel: false
  55. });
  56. return false;
  57. }
  58. if (res.code == 200 && res.data.img) {
  59. this.imgUrl = res.data.img;
  60. this.downLoad = true;
  61. } else {
  62. this.popShow = true;
  63. }
  64. })
  65. .catch(err => {
  66. console.log(err);
  67. });
  68. },
  69. //下载图片
  70. async downloadImg() {
  71. console.log(this.imgUrl);
  72. await uni.showLoading({
  73. title: '下载中'
  74. });
  75. // 1.将远程文件下载到小程序的内存中,tempFilePath
  76. const result1 = await uni.downloadFile({
  77. url: this.imgUrl
  78. });
  79. console.log(result1);
  80. const { tempFilePath } = result1[1];
  81. // 2.将小程序内存中的临时文件下载到本地上
  82. const result2 = await uni.saveImageToPhotosAlbum({
  83. filePath: tempFilePath,
  84. success: () => {
  85. uni.showModal({
  86. content: '下载成功',
  87. showCancel: false
  88. });
  89. },
  90. fail: err => {
  91. if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
  92. uni.showModal({
  93. title: '提示',
  94. content: '您好,请先授权,再保存此图片。',
  95. showCancel: false,
  96. success: res => {
  97. if (res.confirm) {
  98. uni.openSetting({
  99. success(settingdata) {
  100. console.log(settingdata);
  101. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  102. uni.showToast({
  103. title: '请重新保存图片',
  104. icon: 'none'
  105. });
  106. } else {
  107. uni.showToast({
  108. title: '获取权限失败',
  109. icon: 'none'
  110. });
  111. }
  112. },
  113. fail: err => {
  114. console.log(err);
  115. }
  116. });
  117. }
  118. }
  119. });
  120. } else {
  121. uni.showModal({
  122. content: '下载失败',
  123. showCancel: false
  124. });
  125. }
  126. },
  127. complete() {
  128. uni.hideLoading();
  129. }
  130. });
  131. },
  132. /*
  133. *提交承诺
  134. * @params promise_num 产品的件数
  135. * @params gift_money 红包金额
  136. */
  137. subPromise() {
  138. if (!this.count) {
  139. uni.showModal({
  140. content: '请输入产品套数',
  141. showCancel: false
  142. });
  143. return false;
  144. }
  145. if (!this.sum) {
  146. uni.showModal({
  147. content: '请输入红包金额',
  148. showCancel: false
  149. });
  150. return false;
  151. }
  152. subPromise({ promise_num: this.count, gift_money: this.sum }).then(res => {
  153. console.log(res);
  154. if (res.code == 200) {
  155. this.imgUrl = res.data.img;
  156. this.popShow = false;
  157. } else {
  158. uni.showModal({
  159. content: res.message,
  160. showCancel: false
  161. });
  162. }
  163. });
  164. }
  165. }
  166. };
  167. </script>
  168. <style>
  169. page {
  170. width: 100%;
  171. min-height: 100%;
  172. }
  173. </style>
  174. <style lang="scss">
  175. .pledge {
  176. height: 100vh;
  177. width: 100vw;
  178. overflow: hidden;
  179. position: relative;
  180. .pop {
  181. position: absolute;
  182. top: 0;
  183. left: 0;
  184. height: 100vh;
  185. width: 100vw;
  186. background-color: rgba($color: #000000, $alpha: 0.4);
  187. .pop_con {
  188. padding: 0 30rpx;
  189. box-sizing: border-box;
  190. position: absolute;
  191. top: 50%;
  192. left: 50%;
  193. transform: translate(-50%, -50%);
  194. background-color: #fff;
  195. z-index: 999;
  196. width: 600rpx;
  197. margin: 0 auto;
  198. height: 450rpx;
  199. border-radius: 15rpx;
  200. color: #000;
  201. .pop_title {
  202. font-size: 32rpx;
  203. text-align: center;
  204. padding: 25rpx 0;
  205. font-weight: bold;
  206. }
  207. .promise_info {
  208. > view {
  209. margin-top: 20rpx;
  210. padding: 15rpx 0;
  211. text {
  212. width: 288rpx;
  213. text-align: right;
  214. }
  215. }
  216. input {
  217. width: 200rpx;
  218. border: 1rpx solid #cccccc;
  219. border-radius: 8rpx;
  220. padding: 10rpx;
  221. }
  222. }
  223. .promise_btn {
  224. width: 400rpx;
  225. height: 66rpx;
  226. line-height: 66rpx;
  227. margin: 35rpx auto 0;
  228. color: #fff;
  229. background-color: #fc1304;
  230. border-radius: 44rpx;
  231. text-align: center;
  232. }
  233. }
  234. }
  235. .pledgeBg {
  236. height: 100%;
  237. width: 100%;
  238. }
  239. // .pledge_con {
  240. // color: #fff;
  241. // view {
  242. // position: absolute;
  243. // bottom: 28vh;
  244. // right: 28vw;
  245. // }
  246. // .money {
  247. // bottom: 21vh;
  248. // right: 33vw;
  249. // }
  250. // .name {
  251. // bottom: 14vh;
  252. // right: 28vw;
  253. // }
  254. // .year {
  255. // bottom: 6vh;
  256. // right: 41vw;
  257. // }
  258. // .month {
  259. // bottom: 6vh;
  260. // right: 30vw;
  261. // }
  262. // .day {
  263. // bottom: 6vh;
  264. // right: 19vw;
  265. // }
  266. // .share {
  267. // bottom: 4vh;
  268. // left: 7vw;
  269. // display: flex;
  270. // align-items: center;
  271. // image {
  272. // height: 64rpx;
  273. // width: 64rpx;
  274. // }
  275. // text {
  276. // color: #e6a805;
  277. // font-size: 28rpx;
  278. // margin-left: 11rpx;
  279. // font-weight: bold;
  280. // }
  281. // }
  282. // }
  283. }
  284. </style>