promise.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <view class="downloadBox">
  4. <navigator url="/pages/promiseList/promiseList" class="downloadBoxLink">我的承诺书</navigator>
  5. <navigator url="/pages/downBook/downBook" class="downloadBoxLink">下载模板</navigator>
  6. </view>
  7. <view class="fixedTitleBox">
  8. <text class="fixedTitle">请拍摄本人签字的承诺书</text>
  9. <text class="fixedTitle2">确保所有信息真实有效,清晰完整</text>
  10. </view>
  11. <view class="promiseImageBox" >
  12. <image
  13. v-if="images.length>0"
  14. :src="images[0]"
  15. mode="scaleToFill"
  16. class="promiseImage"
  17. @click="preview"
  18. >
  19. </image>
  20. <view @click="toChooseImage" class="add_icon_box" v-else >
  21. <view class="add_icon"></view>
  22. </view>
  23. <view
  24. class="close"
  25. v-if="images.length>0"
  26. @click="deleteImg"
  27. >
  28. </view>
  29. </view>
  30. <view class="preview_icon" v-if="images.length>0">点击图片预览</view>
  31. <view class="btnBox">
  32. <button class="btn" type="default" @click="submitPic">上传</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { downLoad } from "../../api/index.js"
  38. export default {
  39. data(){
  40. return {
  41. images:[],
  42. matchPoint: true
  43. }
  44. },
  45. methods:{
  46. //拍摄
  47. toChooseImage(){
  48. let that=this;
  49. if(!this.matchPoint){
  50. return false;
  51. }
  52. this.matchPoint=false
  53. uni.authorize({
  54. scope:"scope.camera",
  55. success() {
  56. uni.chooseImage({
  57. count: 1,
  58. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  59. sourceType: ['album','camera'], //从相册选择
  60. success: function (res) {
  61. that.images=res.tempFilePaths
  62. }
  63. })
  64. },
  65. complete(){
  66. that.matchPoint=true
  67. }
  68. })
  69. },
  70. preview(){
  71. let urls=this.images
  72. uni.previewImage({
  73. urls:urls
  74. })
  75. },
  76. deleteImg(){
  77. this.images=[]
  78. },
  79. submitPic(){
  80. const that=this
  81. const token = this.$store.state.token
  82. if(!token){
  83. uni.showToast({
  84. title:"token丢失,请重新登录",
  85. icon:"none",
  86. duration:2500
  87. })
  88. }else{
  89. if(!that.images[0]){
  90. uni.showToast({
  91. title:"请先选择要上传的图片",
  92. icon:"none"
  93. })
  94. return false;
  95. }
  96. uni.showLoading({
  97. title: '加载中'
  98. });
  99. uni.uploadFile({
  100. url:"https://helper.qcfun.ximengnaikang.cn/api/user/uploadcommitbook",
  101. // url:"http://192.168.0.15/api/user/uploadcommitbook",
  102. filePath:that.images[0],
  103. name:"file",
  104. header:{
  105. "authorization":"Bearer "+token
  106. },
  107. success:function(res){
  108. uni.hideLoading();
  109. const data=JSON.parse(res.data)
  110. const {error_code,msg} = data
  111. uni.showToast({
  112. title:msg ? msg : '上传失败,请稍后再试',
  113. icon:error_code===200?'success':'none',
  114. duration:2500
  115. })
  116. that.images=[];
  117. },
  118. fail:function(){
  119. uni.hideLoading();
  120. uni.showToast({
  121. title:'上传失败',
  122. icon:'none',
  123. duration:2500
  124. })
  125. }
  126. })
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss">
  133. page{
  134. width: 100%;
  135. height: 100%;
  136. background: $uni-bg-color-normal;
  137. }
  138. .downloadBox{
  139. padding: 60rpx 30rpx 50rpx 30rpx;
  140. display: flex;
  141. justify-content: space-between;
  142. align-items: center;
  143. }
  144. .downloadBoxLink{
  145. font-size: 32rpx;
  146. color: $uni-btn-bg-color;
  147. }
  148. .fixedTitleBox{
  149. text-align: center;
  150. }
  151. .fixedTitle{
  152. display: block;
  153. font-size: 34rpx;
  154. color: #4D4D4D;
  155. }
  156. .fixedTitle2{
  157. display: block;
  158. color: #FE7444;
  159. font-size: 24rpx;
  160. margin-top: 28rpx;
  161. margin-bottom: 57rpx;
  162. }
  163. .promiseImageBox{
  164. width: calc(100% - 200rpx);
  165. height: 436rpx;
  166. border: 1px solid #c1c1c1;
  167. border-radius: 5px;
  168. margin:0 100rpx;
  169. position: relative;
  170. .add_icon_box{
  171. width: 100%;
  172. height: 100%;
  173. display: flex;
  174. justify-content: center;
  175. align-items: center;
  176. }
  177. .add_icon{
  178. content: "";
  179. display: block;
  180. width: 100rpx;
  181. height: 100rpx;
  182. background-image:url("../../static/add.png");
  183. background-size: 100% 100%;
  184. position: absolute;
  185. top: 50%;
  186. left: 50%;
  187. margin-top: -50rpx;
  188. margin-left: -50rpx;
  189. }
  190. .close{
  191. width: 50rpx;
  192. height: 50rpx;
  193. border-radius: 50%;
  194. background: #8d8d8d;
  195. position: absolute;
  196. top: -25rpx;
  197. right: -25rpx;
  198. transform: rotate(45deg);
  199. &:after,&:before{
  200. content: "";
  201. display: block;
  202. width: 30rpx;
  203. height: 4rpx;
  204. border-right: 4rpx;
  205. background: #FFFFFF;
  206. position: absolute;
  207. top: 50%;
  208. left: 50%;
  209. margin-left: -15rpx;
  210. margin-top: -2rpx;
  211. }
  212. &:before{
  213. transform: rotate(90deg);
  214. }
  215. }
  216. }
  217. .promiseImage{
  218. display: block;
  219. width: 100%;
  220. height: 100%;
  221. }
  222. .btn{
  223. margin: 60rpx 100rpx 26rpx 100rpx;
  224. font-size: 32rpx;
  225. }
  226. .btn:nth-of-type(1){
  227. background: $uni-btn-bg-color !important;
  228. color: #FFFFFF !important;
  229. }
  230. .btn:nth-of-type(2){
  231. margin-top: 0;
  232. }
  233. .preview_icon{
  234. display: flex;
  235. align-items: center;
  236. font-size: 24rpx;
  237. justify-content: center;
  238. padding-top: 10px;
  239. &:before{
  240. content: "";
  241. display: block;
  242. width: 40rpx;
  243. height: 40rpx;
  244. background-image: url("../../static/preview.png");
  245. background-size: 100% 100%;
  246. transform: rotate(180deg);
  247. }
  248. }
  249. </style>