upload.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="">
  3. <view class="navbar">
  4. <view class="back">
  5. <text class="iconfont icon-fanhui " @click="backLast()"></text>
  6. </view>
  7. <text>上传文件</text>
  8. </view>
  9. <view class="upload-home">
  10. <view class="imgList">
  11. <view class="img-title">请拍摄并上传图片<text class="down-tmp"> <a :href="url">点击下载模板</a></text></view>
  12. <!-- <view class="img-title">请拍摄并上传图片<text class="down-tmp" @click="downLoad()">点击下载模板</text></view> -->
  13. <view class="img-box">
  14. <htz-image-upload :max="9" v-model="ceshiData1" :uploadSuccess="zidingyiSuccess" :action="baseUrl+'/upload'"></htz-image-upload>
  15. </view>
  16. <view class="remark">
  17. 拍摄时确保文件照片<text style="color: red;">边缘完整,字体完整,亮度均匀。</text>
  18. </view>
  19. </view>
  20. <view class="table">
  21. <view class="title">请确定文件信息</view>
  22. <view class="text-box">
  23. <text class="input-key">文件名称:</text><input type="text" v-model="steps.name" class="input-val" placeholder="请输入文件名称" />
  24. </view>
  25. </view>
  26. <view class="submit" @click="saveSubmit()">
  27. 保存
  28. </view>
  29. <view class="tips" v-if="tips">
  30. <view class="title">注意事项:</view>
  31. <view class="content">{{tips}}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import navBar from '../../components/navBar/navbar.vue';
  39. var app = getApp()
  40. import configData from '../../config.js'
  41. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
  42. export default {
  43. data() {
  44. return {
  45. uploadLists: [],
  46. max: 1,
  47. chooseNum: 9,
  48. ceshiData: [],
  49. ceshiData1: [],
  50. file_type: {
  51. file_type: 'img'
  52. },
  53. steps: {
  54. name: ""
  55. },
  56. url:"",
  57. resource_ids: [],
  58. staff_id: '',
  59. isShow: false,
  60. tips: '',
  61. baseUrl:configData.data.baseUrl
  62. }
  63. },
  64. components: {
  65. htzImageUpload,
  66. navBar
  67. },
  68. onLoad() {
  69. //#ifdef H5
  70. console.log('ceshi-------h5')
  71. //#endif
  72. //#ifdef APP-PLUS
  73. console.log('ceshi-------app')
  74. //#endif
  75. let steps = uni.getStorageSync('steps')
  76. this.steps = uni.getStorageSync('steps')
  77. this.name = steps.name
  78. app.request('/authorization', '', 'get').then(res => {
  79. this.staff_id = res.data.data.staff_id
  80. console.log(res, '------------------')
  81. })
  82. // this.getTips()
  83. let params = {
  84. key: uni.getStorageSync('steps').key,
  85. }
  86. app.request('/templates', params, 'get').then(res => {
  87. console.log(res.data.data.data[0].resource, "---------------------模板")
  88. this.url = res.data.data.data[0].resource
  89. this.tips = res.data.data.data[0].remark
  90. })
  91. },
  92. methods: {
  93. backLast:function(){
  94. console.log(this.url)
  95. uni.reLaunch({
  96. url:'./fileList'
  97. })
  98. },
  99. downLoad() {
  100. let url = this.url
  101. let dload = document.createElement("a");
  102. dload.download = ''; // 设置下载的文件名,默认是'下载'
  103. dload.href = url;
  104. document.body.appendChild(dload);
  105. dload.click();
  106. dload.remove(); // 下载之后把创建的元素删除
  107. uni.showToast({
  108. title: "正在下载",
  109. icon: "success"
  110. });
  111. },
  112. tiaozhuan: function() {
  113. },
  114. //上传保存图片
  115. saveSubmit: function() {
  116. console.log(this.resource_ids, "________")
  117. if (!this.steps.name) {
  118. uni.showToast({
  119. title: '文件名称不能为空~',
  120. icon: 'none'
  121. })
  122. } else if (!this.resource_ids) {
  123. uni.showToast({
  124. title: '请选择图片~',
  125. icon: 'none'
  126. })
  127. } else {
  128. let ids = JSON.stringify()
  129. let data = {
  130. name: this.steps.name,
  131. key: this.steps.key,
  132. resource_type: 1,
  133. resource_ids: this.resource_ids,
  134. staff_id: this.staff_id,
  135. user_id: uni.getStorageSync('userInfo').id,
  136. organization_id: uni.getStorageSync('userInfo').organization_id
  137. }
  138. console.log(data.resource_ids, 'llllllllllllllllllllll')
  139. app.request('/archives', data, 'post').then(res => {
  140. console.log(res, "上传成功")
  141. if (res.data.code == 200) {
  142. uni.showToast({
  143. title: "上传成功",
  144. icon: 'none'
  145. })
  146. setTimeout(function() {
  147. uni.navigateBack({
  148. })
  149. }, 500)
  150. }
  151. else{
  152. uni.showToast({
  153. title: res.data.message,
  154. icon: 'none'
  155. })
  156. }
  157. })
  158. }
  159. },
  160. zidingyiSuccess(res) {
  161. var _res = JSON.parse(res.data);
  162. if (_res.code == 200) {
  163. let imgId = _res.data.id
  164. // idList.map(item=>{
  165. this.resource_ids.push(imgId)
  166. console.log(this.resource_ids)
  167. return {
  168. success: true,
  169. url: _res.data.url
  170. }
  171. } else {
  172. return {
  173. success: false,
  174. url: ''
  175. }
  176. }
  177. },
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. page {
  183. background-color: #EFF1F6;
  184. }
  185. .navbar {
  186. font-size: 32upx;
  187. height: 100upx;
  188. line-height: 100upx;
  189. color: #888888;
  190. position: relative;
  191. position: fixed;
  192. top: 0;
  193. z-index: 9999999;
  194. width: 100%;
  195. background-color: #FFFFFF;
  196. text-align: center;
  197. border-bottom: solid 2upx #EFF1F6;
  198. .back {
  199. height: 100upx;
  200. width: 100upx;
  201. text-align: center;
  202. // background-color: #007AFF;
  203. position: absolute;
  204. float: left;
  205. left: 0upx;
  206. font-size: 32upx;
  207. }
  208. }
  209. .upload-home {
  210. background-color: #EFF1F6;
  211. width: 100%;
  212. height: 100%;
  213. padding-top: 100upx;
  214. .table {
  215. background-color: #FFFFFF;
  216. font-size: 28upx;
  217. margin-top: 30upx;
  218. padding: 30upx;
  219. .title {
  220. color: #666;
  221. font-size: 30upx;
  222. display: block;
  223. padding-bottom: 30upx;
  224. border-bottom: 1px solid #EFF1F6;
  225. }
  226. .text-box {
  227. margin-top: 20upx;
  228. .input-key {
  229. display: inline-block;
  230. height: 80upx;
  231. line-height: 80upx;
  232. width: 160upx;
  233. vertical-align: top;
  234. color: #555;
  235. font-size: 32upx;
  236. }
  237. .input-val {
  238. display: inline-block;
  239. height: 80upx;
  240. line-height: 80upx;
  241. vertical-align: top;
  242. width: calc(100% - 160upx);
  243. text-align: right;
  244. color: #333;
  245. font-size: 32upx;
  246. }
  247. }
  248. // .left {
  249. // flex: 0 0 150upx;
  250. // }
  251. // .right {
  252. // flex: 1;
  253. // height: 80upx;
  254. // // border-bottom: solid 2upx #fabeb9;
  255. // line-height: 80upx;
  256. // }
  257. }
  258. .imgList {
  259. background-color: #fff;
  260. padding: 30upx;
  261. .remark {
  262. font-size: 26upx;
  263. padding-top: 20upx;
  264. color: #555;
  265. }
  266. .img-title {
  267. color: #666;
  268. font-size: 30upx;
  269. display: block;
  270. position: relative;
  271. .down-tmp {
  272. color: red;
  273. position: absolute;
  274. right: 0;
  275. a{
  276. text-decoration: none;
  277. color: red;
  278. }
  279. }
  280. }
  281. .img-box {
  282. margin-top: 20upx;
  283. background-color: #F3F3F3;
  284. border-radius: 10upx;
  285. padding: 15upx;
  286. .list-img {}
  287. }
  288. }
  289. .submit {
  290. padding: 25upx 0;
  291. width: 90%;
  292. margin: 0 auto;
  293. margin-top: 100upx;
  294. margin-bottom: 50upx;
  295. text-align: center;
  296. font-size: 32upx;
  297. color: #FFFFFF;
  298. background-color: #e61916;
  299. border-radius: 10upx;
  300. }
  301. .htz-image-upload-list {
  302. display: flex;
  303. flex-wrap: wrap;
  304. }
  305. .htz-image-upload-Item {
  306. width: 160rpx;
  307. height: 160rpx;
  308. margin: 13rpx;
  309. border-radius: 10rpx;
  310. position: relative;
  311. }
  312. .htz-image-upload-Item image {
  313. width: 100%;
  314. height: 100%;
  315. border-radius: 10rpx;
  316. }
  317. .htz-image-upload-Item-add {
  318. font-size: 105rpx;
  319. /* line-height: 160rpx; */
  320. text-align: center;
  321. border: 1px dashed #d9d9d9;
  322. color: #d9d9d9;
  323. }
  324. .htz-image-upload-Item-del {
  325. background-color: #f5222d;
  326. font-size: 24rpx;
  327. position: absolute;
  328. width: 35rpx;
  329. height: 35rpx;
  330. line-height: 35rpx;
  331. text-align: center;
  332. top: 0;
  333. right: 0;
  334. z-index: 100;
  335. color: #fff;
  336. }
  337. .tips {
  338. margin: 90upx auto 0;
  339. border: 1px dashed red;
  340. padding: 20upx;
  341. width: 85%;
  342. border-radius: 15upx;
  343. font-size: 28upx;
  344. color: #555;
  345. }
  346. }
  347. </style>