resourceApply.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <template>
  2. <view class="rf-category" style="position: relative;">
  3. <u-toast ref="uToast" />
  4. <!--搜索导航栏-->
  5. <view class="icoStyle">
  6. <u-navbar :back-text="i18n('return')" :title="i18n('resourceApplicationResearch')" :background="barBackground"
  7. back-icon-color="white" title-color="white" :back-text-style="backStyle"></u-navbar>
  8. </view>
  9. <view class="content">
  10. <u-form :model="form" ref="uForm" label-position="top" style="padding: 0 30upx;margin-top: 20upx;">
  11. <!--参观人数-->
  12. <u-form-item required :label="i18n('resourceAttendance')" prop="numberOfVisitors">
  13. <u-input v-model="form.numberOfVisitors" :placeholder="i18n('resourcePleaseEnterTheNumberOfVisitors')"/>
  14. </u-form-item>
  15. <!--参观时间-->
  16. <u-form-item required :label="i18n('resourceVisitTime')" prop="date">
  17. <calendar v-model="show" ref="calendar" @change="change" mode="range"
  18. :start-text="i18n(startText)" :end-text="i18n(endText)" :toolTip="i18n(toolTip)" max-date="2030-12-31"
  19. :range-color="rangeColor" :range-bg-color="rangeBgColor" :active-bg-color="activeBgColor" :btn-type="btnType"
  20. :textzhi="$i18n.locale=='zh'?'至':' To '"
  21. >
  22. </calendar>
  23. <!-- <u-input id="inputDate" v-model="form.date" @focus="inputDate" :placeholder="$i18n.locale=='zh'?'请输入参观时间':'Please enter the time of visit'" />-->
  24. <u-input type="select" id="inputDate" v-model="form.date" @click="inputDate" :placeholder="$i18n.locale=='zh'?'请输入参观时间':'Please enter the time of visit'" />
  25. </u-form-item>
  26. <!--联系人-->
  27. <u-form-item required :label="i18n('resourceTheContact')" prop="contactsName">
  28. <u-input v-model="form.contactsName" :placeholder="i18n('resourcePleaseEnterYourName')"/>
  29. </u-form-item>
  30. <!--申请单位-->
  31. <u-form-item required :label="i18n('resourceToApplyForTheUnit')" prop="affiliatedUnitName">
  32. <u-input v-model="form.affiliatedUnitName" :placeholder="i18n('resourcePleaseEnterTheUnitName')"/>
  33. </u-form-item>
  34. <!--联系电话-->
  35. <u-form-item required :label="i18n('resourceContactPhoneNumber')" prop="contactsNumber">
  36. <u-input v-model="form.contactsNumber" :placeholder="i18n('resourcePleaseEnterYourContactInformation')" type="number"/>
  37. </u-form-item>
  38. <!--邮箱-->
  39. <u-form-item required :label="i18n('resourceEmail')" prop="contactsEmail">
  40. <u-input v-model="form.contactsEmail" :placeholder="i18n('resourcePleaseEnterEmailAddress')"/>
  41. </u-form-item>
  42. <!--其他说明-->
  43. <u-form-item :label="i18n('resourceOtherInstructions')">
  44. <u-input v-model="form.otherInstructions" :placeholder="i18n('resourcePleaseEnterAdditionalInstructions')"/>
  45. </u-form-item>
  46. <!--附件-->
  47. <!--<u-form-item :label="i18n('resourceTheAttachment')" label-width="150">
  48. &lt;!&ndash; <u-upload :action="action" :file-list="fileList" max-count="1"></u-upload>&ndash;&gt;
  49. <view v-show="!form.file" style="height: 66upx;width: 66upx;background-color: #aaaaaa;border-radius: 20upx;" @click="addFile">
  50. <u-icon name="plus" color="white" size="66"></u-icon>
  51. </view>
  52. <view v-show="form.file" style="width: 100%;height: 70upx;border-bottom: 1px solid rgb(192, 196, 204);">
  53. </view>
  54. </u-form-item>-->
  55. </u-form>
  56. <view style="padding: 40upx 60upx;">
  57. <u-button :action="action" :file-list="fileList" type="primary" shape="circle" @click="submitApply">{{i18n('resourceSubmit')}}</u-button>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import rfSearchBar from '@/components/rf-search-bar';
  64. import calendar from './calendar';
  65. export default {
  66. data() {
  67. return {
  68. // bar
  69. barBackground: {
  70. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  71. },
  72. backStyle: {
  73. color: '#fff'
  74. },
  75. // 字典
  76. classify1:'',
  77. classify2:'',
  78. // form
  79. form:{
  80. numberOfVisitors:'',
  81. date:'',
  82. dateOfVisitors:'',
  83. startDateOfVisitors:'',
  84. endDateOfVisitors:'',
  85. contactsName:'',
  86. affiliatedUnitName:'',
  87. contactsNumber:'',
  88. contactsEmail:'',
  89. otherInstructions:'',
  90. file:'',
  91. researchResourcesEntityId:''
  92. },
  93. baseResearchApplication: {
  94. numberOfVisitors:'',
  95. startDateOfVisitors:'',
  96. endDateOfVisitors:'',
  97. contactsName:'',
  98. affiliatedUnitName:'',
  99. contactsNumber:'',
  100. contactsEmail:'',
  101. otherInstructions:'',
  102. file:'',
  103. researchResourcesEntityId:''
  104. },
  105. formRules: {
  106. numberOfVisitors: [
  107. {
  108. required: true,
  109. message: this.i18n('resourcePleaseEnterTheNumberOfVisitors'),
  110. trigger: ['change','blur'],
  111. }
  112. ],
  113. date: [
  114. {
  115. required: true,
  116. message: this.$i18n.locale=='zh'?'请输入参观时间':'Please enter the time of visit',
  117. trigger: ['change','blur'],
  118. }
  119. ],
  120. contactsName: [
  121. {
  122. required: true,
  123. message: this.i18n('resourcePleaseEnterYourName'),
  124. trigger: ['change','blur'],
  125. }
  126. ],
  127. affiliatedUnitName: [
  128. {
  129. required: true,
  130. message: this.i18n('resourcePleaseEnterTheUnitName'),
  131. trigger: ['change','blur'],
  132. }
  133. ],
  134. contactsNumber: [
  135. {
  136. required: true,
  137. message: this.i18n('resourcePleaseEnterYourContactInformation'),
  138. trigger: ['change','blur'],
  139. }
  140. ],
  141. contactsEmail: [
  142. {
  143. required: true,
  144. message: this.i18n('resourcePleaseEnterEmailAddress'),
  145. trigger: ['change','blur'],
  146. }
  147. ],
  148. },
  149. action: 'http://www.example.com/upload',
  150. fileList: [],
  151. // 日期选择
  152. show: false,
  153. startText: 'resourceStart',
  154. endText: 'resourceEnd',
  155. toolTip:'resourceSelectTime',
  156. rangeColor: '#2979ff',
  157. rangeBgColor: 'rgba(41,121,255,0.13)',
  158. activeBgColor: '#2979ff',
  159. btnType: 'primary',
  160. // route
  161. entityId:'',
  162. name:'',
  163. flag:'',
  164. }
  165. },
  166. components: { rfSearchBar , calendar },
  167. onReady() {
  168. this.$refs.uForm.setRules(this.formRules);
  169. },
  170. onLoad:function(options){
  171. this.entityId = options.entityId;
  172. this.name = options.name;
  173. this.flag = options.flag;
  174. },
  175. async onShow() {
  176. await this.getDict();
  177. },
  178. computed:{
  179. token(){
  180. return 'Bearer '+uni.getStorageSync('Auth-Token');
  181. }
  182. },
  183. methods: {
  184. async getDict(){
  185. const res = await this.$myRequest({
  186. url: '/sys/sysDicts',
  187. data: {
  188. type:this.$i18n.locale=="zh"?'RESEARCH_RESULT_TYPE_DICT,RESEARCH_RESOURCE_TYPE_DICT':'RESEARCH_RESULT_TYPE_DICT_EN,RESEARCH_RESOURCE_TYPE_DICT_EN',
  189. }
  190. });
  191. if (res.data) {
  192. let both={
  193. label:this.$t('common.All'),
  194. value:null
  195. };
  196. this.classify1=res.data[0];
  197. this.classify2=res.data[1];
  198. this.classify1.unshift(both);
  199. this.classify2.unshift(both);
  200. }
  201. },
  202. // 输入时间
  203. inputDate(){
  204. this.show = true;
  205. },
  206. change(e) {
  207. this.form.startDateOfVisitors = e.startDate;
  208. this.form.endDateOfVisitors = e.endDate;
  209. this.form.date = e.startDate + " - " + e.endDate;
  210. let inputDate = document.getElementById('inputDate');
  211. inputDate = inputDate.childNodes[0].childNodes[0].childNodes[1];
  212. },
  213. upload(){
  214. uni.chooseFile({
  215. count: 1,
  216. extension:['.pdf'],
  217. success: function (res) {
  218. console.log('res');
  219. console.log(res);
  220. }
  221. });
  222. },
  223. //提交申请
  224. date(date){
  225. let time = new Date(date)
  226. return time.getTime()
  227. },
  228. async submitApply(){
  229. const that = this;
  230. this.$refs.uForm.validate(valid => {
  231. if (valid) {
  232. that.baseResearchApplication.numberOfVisitors = that.form.numberOfVisitors;
  233. that.baseResearchApplication.startDateOfVisitors = that.date(that.form.startDateOfVisitors);
  234. that.baseResearchApplication.endDateOfVisitors = that.date(that.form.endDateOfVisitors);
  235. that.baseResearchApplication.contactsName = that.form.contactsName;
  236. that.baseResearchApplication.affiliatedUnitName = that.form.affiliatedUnitName;
  237. that.baseResearchApplication.contactsNumber = that.form.contactsNumber;
  238. that.baseResearchApplication.contactsEmail = that.form.contactsEmail;
  239. that.baseResearchApplication.otherInstructions = that.form.otherInstructions;
  240. that.baseResearchApplication.file = that.form.file;
  241. that.baseResearchApplication.reserveOne = that.name;
  242. that.baseResearchApplication.status = "1";
  243. that.baseResearchApplication.researchResourcesEntityId = that.entityId;
  244. that.$myRequest({
  245. url: '/resourceshare/baseResearchApplications',
  246. method:'post',
  247. headers: {
  248. token:this.token
  249. },
  250. data: {
  251. baseResearchApplication:JSON.stringify(that.baseResearchApplication)
  252. },
  253. }).then((res)=>{
  254. if(res){
  255. if(res.msg == '请勿重复提交'){
  256. if (this.$i18n.locale == 'zh') {
  257. this.$refs.uToast.show({
  258. title: '请勿重复提交',
  259. type: 'error',
  260. back:true
  261. })
  262. } else {
  263. this.$refs.uToast.show({
  264. title: 'Do not repeat submission',
  265. type: 'error',
  266. back:true
  267. })
  268. }
  269. }else{
  270. uni.redirectTo({
  271. url: `/pages/resourceSharing/resourceApplySuccess?entityId=${this.entityId}`,
  272. });
  273. /*if (this.$i18n.locale == 'zh') {
  274. this.$refs.uToast.show({
  275. title: '申请成功',
  276. type: 'success',
  277. back:true
  278. })
  279. } else {
  280. this.$refs.uToast.show({
  281. title: 'Application approved',
  282. type: 'success',
  283. back:true
  284. })
  285. }*/
  286. }
  287. }
  288. }).catch((error)=>{
  289. if (this.$i18n.locale == 'zh') {
  290. this.$refs.uToast.show({
  291. title: '申请失败',
  292. type: 'error',
  293. back:true
  294. })
  295. } else {
  296. this.$refs.uToast.show({
  297. title: 'Application failed',
  298. type: 'error',
  299. back:true
  300. })
  301. }
  302. });
  303. } else {
  304. if (this.$i18n.locale == 'zh') {
  305. this.$refs.uToast.show({
  306. title: '必填项未填',
  307. type: 'warning',
  308. })
  309. } else {
  310. this.$refs.uToast.show({
  311. title: 'The required fields are not filled in',
  312. type: 'warning',
  313. })
  314. }
  315. }
  316. });
  317. },
  318. async submit(){
  319. this.$myRequest({
  320. url: '/resourceshare/baseResearchApplications',
  321. method:'post',
  322. headers: {
  323. token:this.token
  324. },
  325. data: {
  326. ...that.baseResearchApplication
  327. },
  328. success: (res) => {
  329. // console.log(res.data); // 控制台显示数据信息
  330. if(res){
  331. console.log(res)
  332. }
  333. },
  334. });
  335. if(res){
  336. console.log(res)
  337. }
  338. },
  339. back() {
  340. uni.navigateBack();
  341. },
  342. //中英文切换
  343. i18n (data) {
  344. return this.$t('common.'+data);
  345. },
  346. //** 上传文件类 开始
  347. // 打开系统文件管理器,获取文件返回绝对路径(暂只支持安卓)
  348. addFile(){
  349. let that = this;
  350. // #ifdef APP-PLUS
  351. if (plus.os.name.toLowerCase() != "android") {
  352. uni.showModal({
  353. title: '提示',
  354. content: '仅支持Android平台',
  355. success: function(res) {}
  356. });
  357. return false
  358. }
  359. let main = plus.android.runtimeMainActivity();
  360. let Intent = plus.android.importClass("android.content.Intent");
  361. let fileIntent = new Intent(Intent.ACTION_GET_CONTENT)
  362. //fileIntent.setType(“image/*”);//选择图片
  363. //fileIntent.setType(“audio/*”); //选择音频
  364. //fileIntent.setType(“video/*”); //选择视频 (mp4 3gp 是android支持的视频格式)
  365. //fileIntent.setType(“video/*;image/*”);//同时选择视频和图片
  366. fileIntent.setType("*/*"); //无类型限制
  367. fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
  368. main.startActivityForResult(fileIntent, 1);
  369. // 获取回调
  370. main.onActivityResult = function(requestCode, resultCode, data) {
  371. let Activity = plus.android.importClass("android.app.Activity");
  372. let ContentUris = plus.android.importClass("android.content.ContentUris");
  373. let Cursor = plus.android.importClass("android.database.Cursor");
  374. let Uri = plus.android.importClass("android.net.Uri");
  375. let Build = plus.android.importClass("android.os.Build");
  376. let Environment = plus.android.importClass("android.os.Environment");
  377. let DocumentsContract = plus.android.importClass("android.provider.DocumentsContract");
  378. let MediaStore = plus.android.importClass("android.provider.MediaStore");
  379. // 给系统导入 contentResolver
  380. let contentResolver = main.getContentResolver()
  381. plus.android.importClass(contentResolver);
  382. // 返回路径
  383. let path = '';
  384. if (resultCode == Activity.RESULT_OK) {
  385. let uri = data.getData()
  386. if ("file" == uri.getScheme().toLowerCase()) { //使用第三方应用打开
  387. path = uri.getPath();
  388. return;
  389. }
  390. if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { //4.4以后
  391. path = getPath(this, uri);
  392. } else { //4.4以下下系统调用方法
  393. path = getRealPathFromURI(uri)
  394. }
  395. // 回调
  396. that.resultPath(path)
  397. }
  398. // 4.4 以上 从Uri 获取文件绝对路径
  399. function getPath(context, uri) {
  400. let isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
  401. let scheme = uri.getScheme().toLowerCase()
  402. if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
  403. // ExternalStorageProvider
  404. if (isExternalStorageDocument(uri)) {
  405. let docId = DocumentsContract.getDocumentId(uri);
  406. let split = docId.split(":");
  407. let type = split[0];
  408. // 如果是手机内部存储
  409. if ("primary" == type.toLowerCase()) {
  410. return Environment.getExternalStorageDirectory() + "/" + split[1];
  411. } else {
  412. return '/storage/' + type + "/" + split[1];
  413. }
  414. }
  415. // DownloadsProvider
  416. else if (isDownloadsDocument(uri)) {
  417. let id = DocumentsContract.getDocumentId(uri);
  418. let split = id.split(":");
  419. return split[1]
  420. // let contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), id);
  421. // return getDataColumn(context, contentUri, null, null);
  422. }
  423. // MediaProvider
  424. else if (isMediaDocument(uri)) {
  425. let docId = DocumentsContract.getDocumentId(uri);
  426. let split = docId.split(":");
  427. let type = split[0];
  428. let contentUri = null;
  429. if ("image" == type.toLowerCase()) {
  430. contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
  431. } else if ("video" == type.toLowerCase()) {
  432. contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
  433. } else if ("audio" == type.toLowerCase()) {
  434. contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
  435. }
  436. let selection = "_id=?";
  437. let selectionArgs = [split[1]];
  438. return getDataColumn(context, contentUri, selection, selectionArgs);
  439. }
  440. }
  441. // MediaStore (and general)
  442. else if ("content" == scheme) {
  443. return getDataColumn(context, uri, null, null);
  444. }
  445. // File
  446. else if ("file" == scheme) {
  447. return uri.getPath();
  448. }
  449. }
  450. // 4.4 以下 获取 绝对路径
  451. function getRealPathFromURI(uri) {
  452. let res = null
  453. let proj = [MediaStore.Images.Media.DATA]
  454. let cursor = contentResolver.query(uri, proj, null, null, null);
  455. if (null != cursor && cursor.moveToFirst()) {;
  456. let column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  457. res = cursor.getString(column_index);
  458. cursor.close();
  459. }
  460. return res;
  461. }
  462. // 通过uri 查找出绝对路径
  463. function getDataColumn(context, uri, selection, selectionArgs) {
  464. let cursor = null;
  465. let column = "_data";
  466. let projection = [column];
  467. // let contentResolver = context.getContentResolver()
  468. // plus.android.importClass(contentResolver);
  469. cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
  470. if (cursor != null && cursor.moveToFirst()) {
  471. let column_index = cursor.getColumnIndexOrThrow(column);
  472. return cursor.getString(column_index);
  473. }
  474. }
  475. function isExternalStorageDocument(uri) {
  476. return "com.android.externalstorage.documents" == uri.getAuthority() ? true : false
  477. }
  478. function isDownloadsDocument(uri) {
  479. return "com.android.providers.downloads.documents" == uri.getAuthority() ? true : false
  480. }
  481. function isMediaDocument(uri) {
  482. return "com.android.providers.media.documents" == uri.getAuthority() ? true : false
  483. }
  484. }
  485. // #endif
  486. },
  487. // 上传调用
  488. resultPath(e){
  489. // e 为解析出来的文件本地路径
  490. let that =this;
  491. let fIndex =e.lastIndexOf(".");
  492. let fileType =e.substr(fIndex+1); //文件后缀
  493. //判断是否为图片
  494. function isAssetTypeAnImage(ext) {
  495. return ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(ext.toLowerCase()) !== -1;
  496. }
  497. //判断是否为文档
  498. function isAssetFile(ext) {
  499. return ['txt','pdf','doc','xls','xlsx','ppt','docx'].indexOf(ext.toLowerCase()) !== -1;
  500. }
  501. //图片上传调用
  502. /*if(isAssetTypeAnImage(fileType)){
  503. that.form.numberOfVisitors = e
  504. uni.uploadFile({
  505. // url: this.$Base_Url + '/api/work_img', //仅为示例,非真实的接口地址
  506. // url: this.$Base_Url + '/api/work_img', //仅为示例,非真实的接口地址
  507. filePath:"file:/"+ e,
  508. name: 'img',
  509. formData: {},
  510. header:{ //仅为示例,非真实的请求header
  511. // 'nktjj_session': uni.getStorageSync("c") || '',
  512. //"cookie": 'nktjj_session=' + uni.getStorageSync("c") || '',
  513. // 'X-Requested-With': 'XMLHttpRequest',
  514. // 'Content-Type': 'application/json; charset=UTF-8'
  515. },
  516. success: (uploadFileRes) => {
  517. that.form.contactsName = uploadFileRes
  518. //这里会有一个坑
  519. //如果是上传完就要预览图片,若后端没有返回线上路径,需要你通过通过访问本地图片路径
  520. //请在取得的本地路径前 加上一个“file://”
  521. let abc ="file://"+e; //本地路径
  522. let imgUrl= JSON.parse(uploadFileRes.data).data.imgUrl; //后端返回的值
  523. }
  524. });
  525. }*/
  526. //文档上传调用
  527. if(isAssetFile(fileType)){
  528. that.form.numberOfVisitors = e
  529. uni.uploadFile({
  530. // url: this.$Base_Url + '/api/work_file', //仅为示例,非真实的接口地址
  531. url: this.$Base_Url + '/api/work_file', //仅为示例,非真实的接口地址
  532. filePath:"file:/"+ e,
  533. name: 'file',
  534. formData: {},
  535. header:{ //仅为示例,非真实的请求header
  536. // 'nktjj_session': uni.getStorageSync("c") || '',
  537. //"cookie": 'nktjj_session=' + uni.getStorageSync("c") || '',
  538. // 'X-Requested-With': 'XMLHttpRequest',
  539. // 'Content-Type': 'application/json; charset=UTF-8'
  540. },
  541. success: (uploadFileRes) => {
  542. that.form.contactsName = uploadFileRes
  543. let fileId= JSON.parse(uploadFileRes.data).data.file_id;
  544. }
  545. });
  546. }
  547. },
  548. //** 上传文件类 结束
  549. }
  550. }
  551. </script>
  552. <style lang="scss" scoped>
  553. .rf-category {
  554. background-color: #F3F4F5;
  555. /* #ifdef APP-PLUS */
  556. /*margin-top: calc(20upx + var(--status-bar-height));*/
  557. /* #endif */
  558. .icoStyle {
  559. display: flex;
  560. align-items:center;
  561. }
  562. .content{
  563. background-color: white;
  564. }
  565. }
  566. </style>