upload.vue 12 KB

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