upload.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 v-for="(item,index) in verification" :key="index">
  11. <view class="imgList" v-if="item.key=='resource_ids'">
  12. <view class="img-title">请上传pdf文件</view>
  13. <view class="img-box">
  14. <view class="htz-image-upload-Item" v-if="pdfUrl!=''" v-for="(item,index) in pdfUrl" :key="index">
  15. <image class="img" src="/static/images/pdf.png" @click="imgPreview(index)"></image>
  16. <view class="htz-image-upload-Item-del" @click="imgDel(index)">×</view>
  17. </view>
  18. <view class="htz-image-upload-Item htz-image-upload-Item-add" @click="upload" v-if="pdfUrl.length < number">
  19. +
  20. </view>
  21. </view>
  22. </view>
  23. <view class="imgList" v-if="item.key=='prove_files'">
  24. <view class="img-title">{{item.name}}</view>
  25. <view class="img-box">
  26. <view class="htz-image-upload-Item" v-if="cailiao_pdfUrl!=''" v-for="(item,index) in cailiao_pdfUrl" :key="index">
  27. <image class="img" src="/static/images/pdf.png" @click="imgPreview(index)"></image>
  28. <view class="htz-image-upload-Item-del" @click="imgDel_cailiao(index)">×</view>
  29. </view>
  30. <view class="htz-image-upload-Item htz-image-upload-Item-add" @click="upload_cailiao" v-if="cailiao_pdfUrl==''">
  31. +
  32. </view>
  33. </view>
  34. </view>
  35. <view class="table" v-if="item.key!='resource_ids' && item.key!='prove_files' && item.key!='grade_id' && item.key!='award_day' && item.key!='position_grade'">
  36. <view class="text-box">
  37. <text class="input-key">{{item.name}}:</text><input type="text" v-model="item.fenshu" class="input-val" placeholder-style="color:darkgray;"
  38. :placeholder="'请输入'+item.name" />
  39. </view>
  40. </view>
  41. <view class="table" v-if="item.key=='grade_id'">
  42. <view class="text-box" style="display: flex;align-items: center;justify-content: space-between;">
  43. <text class="input-key">{{item.name}}:</text>
  44. <picker mode="selector" :range="extra.position_grade" @change="gradeChange"
  45. class="input1" :value="position_grade">
  46. <view class="uni-input" style="font-size: 33upx;color: darkgray;">{{grade}}</view>
  47. </picker>
  48. </view>
  49. </view>
  50. <view class="table" v-if="item.key=='award_day'">
  51. <view class="text-box" style="display: flex;align-items: center;justify-content: space-between;">
  52. <text class="input-key">{{item.name}}:</text>
  53. <picker mode="date" :value="time" @change="birthDateChange" class="input1">
  54. <view class="uni-input" style="font-size: 33upx;color: darkgray;">{{time}}</view>
  55. </picker>
  56. </view>
  57. </view>
  58. <view class="table" v-if="item.key=='position_grade'">
  59. <view class="text-box" style="display: flex;align-items: center;justify-content: space-between;">
  60. <text class="input-key">{{item.name}}:</text>
  61. <picker mode="selector" :range="extra.position_grade" @change="gradeChange"
  62. class="input1" :value="position_grade">
  63. <view class="uni-input" style="font-size: 33upx;color: darkgray;">{{grade}}</view>
  64. </picker>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="submit" @click="saveSubmit()">
  69. 保存
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. var app = getApp()
  77. import navBar from '../../components/navBar/navbar.vue';
  78. import configData from '../../config.js'
  79. export default {
  80. data() {
  81. return {
  82. uploadLists: [],
  83. max: 1,
  84. url: "",
  85. resource_ids: [],
  86. staff_id: '',
  87. baseUrl: configData.data.baseUrl + '/upload',
  88. fenshu: '',
  89. pdfUrl:[],
  90. uploadPdf:[],
  91. ids:[],
  92. typeId:'',
  93. verification:[],
  94. number:9,
  95. time:'选择日期',
  96. extra:[],
  97. grade:'请选择',
  98. position_grade:0,
  99. gradeValue:'',
  100. cailiao_ids:[],
  101. cailiao_pdfUrl:''
  102. }
  103. },
  104. components: {
  105. navBar
  106. },
  107. onLoad(options) {
  108. console.log(options)
  109. this.typeId = options.id
  110. this.verification = JSON.parse(options.verification)
  111. if(options.extra!='undefined'){
  112. this.extra = JSON.parse(options.extra)
  113. }
  114. if(options.number!='undefined'){
  115. this.number = Number(options.number)
  116. }else{
  117. if(options.id==5){
  118. this.number = 1
  119. }
  120. }
  121. console.log(this.extra)
  122. console.log(this.verification)
  123. //#ifdef H5
  124. console.log('ceshi-------h5')
  125. //#endif
  126. //#ifdef APP-PLUS
  127. console.log('ceshi-------app')
  128. //#endif
  129. app.request('/authorization', '', 'get').then(res => {
  130. this.staff_id = res.data.data.staff_id
  131. console.log(res, '------------------')
  132. })
  133. },
  134. methods: {
  135. backLast: function() {
  136. uni.navigateBack()
  137. },
  138. upload() {
  139. var that = this
  140. console.log(this.number)
  141. uni.chooseFile({
  142. count: this.number,
  143. extension: ['.pdf'],
  144. success(res) {
  145. console.log(res)
  146. that.pdfUrl= that.pdfUrl.concat(res.tempFilePaths)
  147. that.uploadFiles(res.tempFilePaths[0])
  148. }
  149. })
  150. },
  151. upload_cailiao() {
  152. var that = this
  153. console.log(this.number)
  154. uni.chooseFile({
  155. count: this.number,
  156. extension: ['.pdf'],
  157. success(res) {
  158. console.log(res)
  159. that.cailiao_pdfUrl= res.tempFilePaths
  160. that.cailiao_uploadFiles(res.tempFilePaths[0])
  161. }
  162. })
  163. },
  164. imgDel_cailiao(index){
  165. var list = this.cailiao_pdfUrl
  166. var id = this.cailiao_ids
  167. list.splice(index,1)
  168. id.splice(index,1)
  169. this.cailiao_pdfUrl = list
  170. this.cailiao_ids = id
  171. },
  172. cailiao_uploadFiles(url) {
  173. uni.uploadFile({
  174. url: this.baseUrl, //仅为示例,非真实的接口地址
  175. filePath: url,
  176. fileType: 'file',
  177. formData: {
  178. file_type: 'file'
  179. },
  180. header: this.headers,
  181. success: (uploadFileRes) => {
  182. console.log(uploadFileRes)
  183. var data = JSON.parse(uploadFileRes.data)
  184. console.log(data)
  185. this.cailiao_ids = data.data.url
  186. },
  187. })
  188. },
  189. uploadFiles(url) {
  190. uni.uploadFile({
  191. url: this.baseUrl, //仅为示例,非真实的接口地址
  192. filePath: url,
  193. fileType: 'file',
  194. formData: {
  195. file_type: 'file'
  196. },
  197. header: this.headers,
  198. success: (uploadFileRes) => {
  199. console.log(uploadFileRes)
  200. var data = JSON.parse(uploadFileRes.data)
  201. console.log(data)
  202. this.ids = this.ids.concat(data.data.id)
  203. },
  204. })
  205. },
  206. imgDel(index){
  207. var list = this.pdfUrl
  208. var id = this.ids
  209. list.splice(index,1)
  210. id.splice(index,1)
  211. this.pdfUrl = list
  212. this.ids = id
  213. },
  214. //上传保存图片
  215. saveSubmit: function() {
  216. console.log(this.verification, "________")
  217. // if (!this.pdfUrl) {
  218. // uni.showToast({
  219. // title: '请上传文件~',
  220. // icon: 'none'
  221. // })
  222. // } else {
  223. //页面循环展示的数据
  224. const obj = new Object()
  225. for(var i=0;i<this.verification.length;i++){
  226. obj[this.verification[i].key] = this.verification[i].fenshu
  227. if(this.verification[i].key == 'resource_ids'){
  228. obj.resource_ids = this.ids
  229. }
  230. if(this.verification[i].key == 'prove_files'){
  231. obj.prove_files = this.cailiao_ids
  232. }
  233. if(this.verification[i].key == 'award_day'){
  234. obj.award_day = this.time
  235. }
  236. if(this.verification[i].key == 'grade_id'){
  237. obj.grade_id = this.gradeValue
  238. }
  239. if(this.verification[i].key == 'position_grade'){
  240. obj.position_grade = this.gradeValue
  241. }
  242. }
  243. obj.staff_id = this.staff_id
  244. obj.examine_question_id = this.typeId
  245. console.log(obj)
  246. for(var key in obj){
  247. if(!obj[key]){
  248. uni.showToast({
  249. title:'请完善信息表!',
  250. icon:'none'
  251. })
  252. return
  253. }
  254. }
  255. app.request('/examine/store', obj, 'post').then(res => {
  256. console.log(res, "上传成功")
  257. if(res.statusCode==200){
  258. uni.showToast({
  259. title:'上传成功',
  260. icon:'none'
  261. })
  262. uni.navigateBack()
  263. }else{
  264. uni.showToast({
  265. title:res.data.message,
  266. icon:'none'
  267. })
  268. }
  269. })
  270. // }
  271. },
  272. birthDateChange: function(e) {
  273. console.log(e)
  274. this.time = e.detail.value
  275. },
  276. gradeChange(e){
  277. console.log(e)
  278. var index = Number(e.detail.value)+1
  279. this.grade = this.extra.position_grade[index]
  280. this.gradeValue = index
  281. },
  282. }
  283. }
  284. </script>
  285. <style lang="scss">
  286. page {
  287. background-color: #EFF1F6;
  288. padding-bottom: 20px;
  289. }
  290. .navbar {
  291. font-size: 32upx;
  292. height: 100upx;
  293. line-height: 100upx;
  294. color: #888888;
  295. position: relative;
  296. position: fixed;
  297. top: 0;
  298. z-index: 9999999;
  299. width: 100%;
  300. background-color: #FFFFFF;
  301. text-align: center;
  302. border-bottom: solid 2upx #EFF1F6;
  303. .back {
  304. height: 100upx;
  305. width: 100upx;
  306. text-align: center;
  307. // background-color: #007AFF;
  308. position: absolute;
  309. float: left;
  310. left: 0upx;
  311. font-size: 32upx;
  312. }
  313. }
  314. .upload-home {
  315. background-color: #EFF1F6;
  316. width: 100%;
  317. height: 100%;
  318. .table {
  319. background-color: #FFFFFF;
  320. font-size: 28upx;
  321. margin-top: 10upx;
  322. padding: 10upx 30upx;
  323. .title {
  324. color: #666;
  325. font-size: 30upx;
  326. display: block;
  327. padding-bottom: 30upx;
  328. border-bottom: 1px solid #EFF1F6;
  329. }
  330. .text-box {
  331. margin-top: 20upx;
  332. .input-key {
  333. display: inline-block;
  334. height: 80upx;
  335. line-height: 80upx;
  336. width: 160upx;
  337. vertical-align: top;
  338. color: #555;
  339. font-size: 32upx;
  340. }
  341. .input-val {
  342. display: inline-block;
  343. height: 80upx;
  344. line-height: 80upx;
  345. vertical-align: top;
  346. width: calc(100% - 160upx);
  347. text-align: right;
  348. color: darkgray;
  349. font-size: 32upx;
  350. }
  351. }
  352. // .left {
  353. // flex: 0 0 150upx;
  354. // }
  355. // .right {
  356. // flex: 1;
  357. // height: 80upx;
  358. // // border-bottom: solid 2upx #fabeb9;
  359. // line-height: 80upx;
  360. // }
  361. }
  362. .imgList {
  363. background-color: #fff;
  364. padding: 30upx;
  365. margin-top: 10upx;
  366. .remark {
  367. font-size: 26upx;
  368. padding-top: 20upx;
  369. color: #555;
  370. }
  371. .img-title {
  372. color: #666;
  373. font-size: 30upx;
  374. display: block;
  375. position: relative;
  376. .down-tmp {
  377. color: red;
  378. position: absolute;
  379. right: 0;
  380. a {
  381. text-decoration: none;
  382. color: red;
  383. }
  384. }
  385. }
  386. .img-box {
  387. margin-top: 20upx;
  388. background-color: #F3F3F3;
  389. border-radius: 10upx;
  390. padding: 15upx;
  391. .list-img {}
  392. }
  393. }
  394. .submit {
  395. padding: 25upx 0;
  396. width: 90%;
  397. margin: 0 auto;
  398. margin-top: 100upx;
  399. margin-bottom: 50upx;
  400. text-align: center;
  401. font-size: 32upx;
  402. color: #FFFFFF;
  403. background-color: #e61916;
  404. border-radius: 10upx;
  405. }
  406. .img-box {
  407. display: flex;
  408. flex-wrap: wrap;
  409. }
  410. .htz-image-upload-Item {
  411. width: 160rpx;
  412. height: 160rpx;
  413. margin: 13rpx;
  414. border-radius: 10rpx;
  415. position: relative;
  416. }
  417. .htz-image-upload-Item image {
  418. width: 100%;
  419. height: 100%;
  420. border-radius: 10rpx;
  421. }
  422. .htz-image-upload-Item-add {
  423. font-size: 105rpx;
  424. /* line-height: 160rpx; */
  425. text-align: center;
  426. border: 1px dashed #d9d9d9;
  427. color: #d9d9d9;
  428. }
  429. .htz-image-upload-Item-del {
  430. background-color: #f5222d;
  431. font-size: 24rpx;
  432. position: absolute;
  433. width: 35rpx;
  434. height: 35rpx;
  435. line-height: 35rpx;
  436. text-align: center;
  437. top: 0;
  438. right: 0;
  439. z-index: 100;
  440. color: #fff;
  441. }
  442. }
  443. </style>