viseadd.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <template>
  2. <view>
  3. <uni-forms ref="form" labelPosition="left" labelAlign="left" @submit="submitForm">
  4. <view class="uni-form-item uni-column">
  5. <view class="title"><text class="uni-form-item__title">签证编号</text></view>
  6. <view class="uni-input-wrapper">
  7. <input class="uni-input" focus placeholder="请填写签证编号" v-model="viseId" />
  8. </view>
  9. </view>
  10. <view class="uni-form-item uni-column">
  11. <view class="title"><text class="uni-form-item__title">签证名称</text></view>
  12. <view class="uni-input-wrapper">
  13. <input class="uni-input" focus placeholder="请填写签证名称" v-model="viseName" />
  14. </view>
  15. </view>
  16. <view class="uni-form-item uni-column">
  17. <view class="title"><text class="uni-form-item__title">申请单</text></view>
  18. <view class="uni-input-wrapper ">
  19. <input class="uni-input-small" v-model="requisitionName" />
  20. <a href='javascript:;' @click='getRequisition' class="uni-icon"><i class="fa fa-search" aria-hidden="true"></i></a>
  21. </view>
  22. </view>
  23. <view class="uni-form-item uni-column">
  24. <view class="title"><text class="uni-form-item__title">关联合同</text></view>
  25. <view class="uni-input-wrapper ">
  26. <input class="uni-input-small" disabled=true v-model="contractName" />
  27. <a href='javascript:;' @click='getType' class="uni-icon"><i class="fa fa-search" aria-hidden="true"></i></a>
  28. </view>
  29. </view>
  30. <view class="uni-form-item uni-column">
  31. <view class="title"><text class="uni-form-item__title">税率</text></view>
  32. <view class="uni-input-wrapper">
  33. </view>
  34. </view>
  35. <view class="uni-form-item uni-column">
  36. <view class="title"><text class="uni-form-item__title">是否可抵扣</text></view>
  37. <view class="uni-input-wrapper">
  38. </view>
  39. </view>
  40. <view class="uni-form-item uni-column">
  41. <view class="title"><text class="uni-form-item__title">签证日期</text></view>
  42. <view class="uni-input-wrapper" style="justify-content: left;">
  43. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" v-model="viseDate" style="width: 100%;">
  44. <view class="uni-input">{{date}}</view>
  45. </picker>
  46. </view>
  47. </view>
  48. <view class="uni-form-item uni-column">
  49. <view class="title"><text class="uni-form-item__title">办理期限</text></view>
  50. <view class="uni-input-wrapper" style="justify-content: left;">
  51. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" v-model="endDate" style="width: 100%;">
  52. <view class="uni-input">{{date}}</view>
  53. </picker>
  54. </view>
  55. </view>
  56. <view class="uni-form-item uni-column">
  57. <view class="title"><text class="uni-form-item__title">签证类型</text></view>
  58. <view class="uni-input-wrapper" style="justify-content: left;">
  59. <picker mode="selector" :value="index" :range="array" range-key="name" @change="bindPickerChange" v-model="viseType" name="changeType" style="width: 100%;">
  60. <view class="uni-input">{{array.length>0?array[index]:''}}</view>
  61. </picker>
  62. </view>
  63. </view>
  64. <view class="uni-form-item uni-column">
  65. <view class="title"><text class="uni-form-item__title">暂估金额</text></view>
  66. <view class="uni-input-wrapper">
  67. <input class="uni-input" focus value="0" v-model="estimateCash" type="digit" />
  68. </view>
  69. </view>
  70. <view class="uni-form-item uni-column">
  71. <view class="title"><text class="uni-form-item__title">报送金额</text></view>
  72. <view class="uni-input-wrapper">
  73. <input class="uni-input" focus value="0" v-model="reportCash" type="digit"/>
  74. </view>
  75. </view>
  76. <view class="uni-form-item uni-column">
  77. <view class="title"><text class="uni-form-item__title">签证原因</text></view>
  78. <view class="uni-textarea">
  79. <textarea focus placeholder="签证原因" v-model="reason" auto-height="true" />
  80. </view>
  81. </view>
  82. <view class="uni-form-item uni-column">
  83. <view class="title"><text class="uni-form-item__title">备注</text></view>
  84. <view class="uni-textarea">
  85. <textarea focus placeholder="请写备注" v-model="remark" auto-height="true" />
  86. </view>
  87. </view>
  88. <view class="uni-form-item uni-column">
  89. <view class="title" style="background-color: #efefef;"><text class="uni-form-item__title">上传文件</text></view>
  90. <view class="content">
  91. <g-upload ref='gUpload' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :control='control' :columnNum="columnNum" :maxCount="maxCount"></g-upload>
  92. </view>
  93. </view>
  94. <uni-section title="费用明细" type="line">
  95. </uni-section>
  96. <view class="uni-btn-v uni-column">
  97. <button type="primary" form-type="submit" style="border-radius: 15px;" >提交</button>
  98. </view>
  99. </uni-forms>
  100. </view>
  101. </template>
  102. <script>
  103. import {GetQianzhengDropDown} from "@/common/api/requisitionApi.js";
  104. import {GetUserDepartment} from "@/common/api/commonApi.js";
  105. import {Decimal} from 'decimal.js'; //decimal计算
  106. var sourceType = [
  107. ['camera'],
  108. ['album'],
  109. ['camera', 'album']
  110. ]
  111. var sizeType = [
  112. ['compressed'],
  113. ['original'],
  114. ['compressed', 'original']
  115. ]
  116. export default {
  117. data() {
  118. return {
  119. viseId:'',
  120. viseName:'',
  121. requisitionCode:'', //申请单编号
  122. requisitionName:'', //申请单名称
  123. contractCode:'',
  124. contractName:'',
  125. viseDate:this.$util.getDate({
  126. format: true
  127. }),
  128. endDate:this.$util.getDate({
  129. format: true
  130. }),
  131. viseType:'',
  132. userCode:this.$store.state.user.userCode, //经办人编号
  133. unitCode:this.$store.state.departmentCode, //经办部门
  134. estimateCash:0.00,
  135. reportCash:0.00,
  136. reason:'',
  137. remark:'',
  138. contractList:[],
  139. title: 'choose/previewImage',
  140. imageList: [],
  141. sourceTypeIndex: 2,
  142. sourceType: ['拍照', '相册', '拍照或相册'],
  143. sizeTypeIndex: 2,
  144. sizeType: ['压缩', '原图', '压缩或原图'],
  145. countIndex: 5,
  146. count: [1, 2, 3, 4, 5],
  147. title1: 'picker',
  148. array: [],
  149. index: 0,
  150. date: this.$util.getDate({
  151. format: true
  152. }),
  153. startDate:this.$util.getDate('start'),
  154. endDate:this.$util.getDate('end'),
  155. control: true,
  156. columnNum: 3,
  157. imgList: [],
  158. urlList:[],
  159. maxCount:5
  160. }
  161. },
  162. onLoad(){
  163. //console.info(page.path);
  164. console.info(uni.getStorageSync('storage_state'));
  165. //console.info(this);
  166. this.$util.persistLogin(this);
  167. //console.info(this.$store.state.user);
  168. },
  169. onUnload() {
  170. this.imageList = [],
  171. this.sourceTypeIndex = 2,
  172. this.sourceType = ['拍照', '相册', '拍照或相册'],
  173. this.sizeTypeIndex = 2,
  174. this.sizeType = ['压缩', '原图', '压缩或原图'],
  175. this.countIndex = 5;
  176. },
  177. created: function() {
  178. this.GetDropDown();
  179. },
  180. updated:function(){
  181. },
  182. methods: {
  183. /**
  184. * 手动提交
  185. * @param {Object} form
  186. */
  187. submitForm(e) {
  188. console.info('submitForm');
  189. let _this=this;
  190. if(this.requisitionName==='')
  191. {
  192. uni.showToast({
  193. icon:"none",
  194. title:"请填写申请单名称",
  195. duration:3000
  196. });
  197. return;
  198. }
  199. if(this.requisitionName.length>50)
  200. {
  201. uni.showToast({
  202. icon:"none",
  203. title:"申请单名称不能多于50字",
  204. duration:3000
  205. });
  206. return;
  207. }
  208. if(this.requisitionDate===""){
  209. uni.showToast({
  210. icon:"none",
  211. title:"申请日期不能为空",
  212. duration:3000
  213. });
  214. return;
  215. }
  216. if(this.changeType===""){
  217. uni.showToast({
  218. icon:"none",
  219. title:"签证类型不能为空",
  220. duration:3000
  221. });
  222. return;
  223. }
  224. if(this.requisitionReason===""){
  225. uni.showToast({
  226. icon:"none",
  227. title:"原因不能为空",
  228. duration:3000
  229. });
  230. return;
  231. }
  232. if(this.requisitionReason.length>5000){
  233. uni.showToast({
  234. icon:"none",
  235. title:"原因不能超过500字",
  236. duration:3000
  237. });
  238. return;
  239. }
  240. if(this.remark!==""){
  241. if(this.remark.length>500){
  242. uni.showToast({
  243. icon:"none",
  244. title:"签备注不能超过500字",
  245. duration:3000
  246. });
  247. return;
  248. }
  249. }
  250. var requisitionDTO={requisitionName:this.requisitionName,requisitionDate:this.requisitionDate,changeType:this.changeType,requisitionReason:this.requisitionReason,remark:this.remark,person:this.userCode,unitCode:this.unitCode,projectCode:this.$store.state.projectCode};
  251. var list1=this.contractList;
  252. let list=[];
  253. list1.forEach(function(item,index,array){
  254. list.push({requisitionCode:'',contractCode:item.contractCode,estimateCash:new Decimal(item.estimateCash).toFixed(2)-0 });
  255. //list.push({requisitionCode:'',contractCode:item.contractCode,estimateCash: 220});
  256. });
  257. console.info("【list】");
  258. console.info(list);
  259. if(list.length<=0){
  260. uni.showToast({
  261. title:"请添加关联合同",
  262. icon:"none",
  263. duration:3000
  264. });
  265. return;
  266. }
  267. //return;
  268. var data={Requisition:requisitionDTO,List:list};
  269. //var strList=JSON.stringify(list);
  270. //var strData=JSON.stringify(data);
  271. InsertRequisition(data).then((res)=>{
  272. console.info("提交应答");
  273. console.info(res);
  274. if(res){
  275. //上传图片
  276. _this.uploadFileToServe(res) ;
  277. uni.navigateTo({
  278. url:'/pages/template/requisitionlist/requisitionlist'
  279. })
  280. }
  281. else{
  282. uni.showToast({
  283. title:'添加失败,重新操作',
  284. icon:'none',
  285. duration:3000
  286. })
  287. }
  288. });
  289. },
  290. /*
  291. 获取申请单
  292. */
  293. getRequisition() {
  294. let _this = this;
  295. //console.info('gettype',_this);
  296. _this.saveTemp(_this);
  297. //创建名字为fire的监听器,监听子页面传值事件
  298. uni.$on('requisition', function(data) {
  299. console.info("监听getRequisition子页面的传值", data);
  300. console.info('监听',_this);
  301. _this.getTemp(_this);
  302. _this.requisitionCode=data[0].requisitionCode;
  303. _this.requisitionName=data[0].requisitionName;
  304. _this.$nextTick(function(){
  305. //更新dom
  306. });
  307. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  308. uni.$off("requisition");
  309. });
  310. uni.navigateTo({
  311. url: '/pages/template/SelectRelationRequision/SelectRelationRequision'
  312. });
  313. },
  314. bindPickerChange: function(e) {
  315. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  316. //console.info(e.detail);
  317. this.index = e.detail.value;
  318. this.changeType=this.array[this.index];
  319. console.info(this.changeType);
  320. },
  321. bindDateChange: function(e) {
  322. this.date = e.detail.value;
  323. this.requisitionDate=this.date;
  324. console.info(this.date);
  325. },
  326. sourceTypeChange: function(e) {
  327. this.sourceTypeIndex = parseInt(e.detail.value)
  328. },
  329. sizeTypeChange: function(e) {
  330. this.sizeTypeIndex = parseInt(e.detail.value)
  331. },
  332. countChange: function(e) {
  333. this.countIndex = e.detail.value;
  334. },
  335. chooseImage: async function() {
  336. console.info("chooseImage");
  337. // #ifdef APP-PLUS
  338. // TODO 选择相机或相册时 需要弹出actionsheet,目前无法获得是相机还是相册,在失败回调中处理
  339. if (this.sourceTypeIndex !== 2) {
  340. let status = await this.checkPermission();
  341. if (status !== 1) {
  342. return;
  343. }
  344. }
  345. // #endif
  346. console.info(this.imageList);
  347. if (this.imageList.length === 5) {
  348. let isContinue = await this.isFullImg();
  349. console.log("是否继续?", isContinue);
  350. if (!isContinue) {
  351. return;
  352. }
  353. }
  354. uni.chooseImage({
  355. sourceType: sourceType[this.sourceTypeIndex],
  356. sizeType: sizeType[this.sizeTypeIndex],
  357. count: this.imageList.length + this.count[this.countIndex] > 5 ? 5 - this.imageList.length : this.count[this.countIndex],
  358. success: (res) => {
  359. console.info("res.tempFiles");
  360. console.info(res.tempFiles);
  361. this.imageList = this.imageList.concat(res.tempFilePaths);
  362. console.info(this.imageList);
  363. },
  364. fail: (err) => {
  365. // #ifdef APP-PLUS
  366. if (err['code'] && err.code !== 0 && this.sourceTypeIndex === 2) {
  367. this.checkPermission(err.code);
  368. }
  369. // #endif
  370. // #ifdef MP
  371. uni.getSetting({
  372. success: (res) => {
  373. let authStatus = false;
  374. switch (this.sourceTypeIndex) {
  375. case 0:
  376. authStatus = res.authSetting['scope.camera'];
  377. break;
  378. case 1:
  379. authStatus = res.authSetting['scope.album'];
  380. break;
  381. case 2:
  382. authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera'];
  383. break;
  384. default:
  385. break;
  386. }
  387. if (!authStatus) {
  388. uni.showModal({
  389. title: '授权失败',
  390. content: 'Hello uni-app需要从您的相机或相册获取图片,请在设置界面打开相关权限',
  391. success: (res) => {
  392. if (res.confirm) {
  393. uni.openSetting()
  394. }
  395. }
  396. })
  397. }
  398. }
  399. })
  400. // #endif
  401. }
  402. })
  403. },
  404. isFullImg: function() {
  405. return new Promise((res) => {
  406. uni.showModal({
  407. content: "已经有5张图片了,是否清空现有图片?",
  408. success: (e) => {
  409. if (e.confirm) {
  410. this.imageList = [];
  411. res(true);
  412. } else {
  413. res(false)
  414. }
  415. },
  416. fail: () => {
  417. res(false)
  418. }
  419. })
  420. })
  421. },
  422. previewImage: function(e) {
  423. var current = e.target.dataset.src
  424. uni.previewImage({
  425. current: current,
  426. urls: this.imageList
  427. })
  428. },
  429. GetDropDown:function(){
  430. let that=this;
  431. GetQianzhengDropDown().then((res)=>{
  432. console.info(res);
  433. res.forEach(function(item,index,array){
  434. that.$set(that.array,index,item);
  435. });
  436. });
  437. },
  438. delRow:function(index){
  439. console.info(index);
  440. console.info(this.contractList[index]);
  441. this.contractList.splice(index,1);
  442. },
  443. /*
  444. 上传后返回的值:
  445. list:上传后图片数组
  446. v:返回当前上传图片的临时路径
  447. */
  448. chooseFile(list, v) {
  449. console.log("上传图片_list:", list)
  450. console.log("上传图片_v:", v);
  451. this.urlList=list;
  452. console.info("urlList",this.urlList);
  453. },
  454. /*
  455. 删除图片:
  456. list:删除返回删除后剩余的图片数组
  457. eq:返回删除的数组
  458. */
  459. imgDelete(list, eq) {
  460. console.log("删除图片_list:", list);
  461. console.log("删除图片_eq:", eq);
  462. this.urlList=list;
  463. console.info("urlList",this.urlList);
  464. },
  465. /*
  466. 执行上传服务:
  467. urlList:要上传的图片:数组类型
  468. */
  469. uploadFileToServe(masterCode) {
  470. let _this=this;
  471. var urlList=_this.urlList;
  472. if (!urlList || urlList.length <= 0) {
  473. return;
  474. };
  475. //console.info(urlList);
  476. //return;
  477. for (let i = 0; i < urlList.length; i++) {
  478. uni.uploadFile({
  479. url: '/api/Common/UploadImage',
  480. filePath: urlList[i],
  481. name: 'file',
  482. formData: {
  483. createPerson:_this.$store.state.user.userCode,
  484. masterCode:masterCode,
  485. attachMentType:'RequisitionAttach'
  486. },
  487. headers: {
  488. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
  489. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  490. },
  491. success: (uploadFileRes) => {
  492. console.log("图片上传:",uploadFileRes.data);
  493. }
  494. });
  495. }
  496. },
  497. saveTemp(_this){ //临时存
  498. uni.setStorage({
  499. key:'viseId',
  500. data:_this.viseId
  501. });
  502. uni.setStorage({
  503. key:'viseName',
  504. data:_this.viseName
  505. });
  506. uni.setStorage({
  507. key:'requisitionCode',
  508. data:_this.requisitionCode
  509. });
  510. uni.setStorage({
  511. key:'requisitionName',
  512. data:_this.requisitionName
  513. });
  514. uni.setStorage({
  515. key:'contractName',
  516. data:_this.contractName
  517. });
  518. uni.setStorage({
  519. key:'contractCode',
  520. data:_this.contractCode
  521. });
  522. uni.setStorage({
  523. key:'viseDate',
  524. data:_this.viseDate
  525. });
  526. uni.setStorage({
  527. key:'endDate',
  528. data:_this.endDate
  529. });
  530. uni.setStorage({
  531. key:'viseType',
  532. data:_this.viseType
  533. });
  534. uni.setStorage({
  535. key:'estimateCash',
  536. data:_this.estimateCash
  537. });
  538. uni.setStorage({
  539. key:'reportCash',
  540. data:_this.reportCash
  541. });
  542. uni.setStorage({
  543. key:'reason',
  544. data:_this.reason
  545. });
  546. uni.setStorage({
  547. key:'remark',
  548. data:_this.remark
  549. });
  550. },
  551. getTemp(_this){ //获取缓存,重新给表单赋值
  552. _this.viseId=uni.getStorageSync('viseId');
  553. _this.viseName=uni.getStorageSync('viseName');
  554. _this.requisitionCode=uni.getStorageSync('requisitionCode');
  555. _this.requisitionName=uni.getStorageSync('requisitionName');
  556. _this.contractName=uni.getStorageSync('contractName');
  557. _this.contractCode=uni.getStorageSync('contractCode');
  558. _this.viseDate=uni.getStorageSync('viseDate');
  559. _this.endDate=uni.getStorageSync('endDate');
  560. _this.viseType=uni.getStorageSync('viseType');
  561. _this.estimateCash=uni.getStorageSync('estimateCash');
  562. _this.reportCash=uni.getStorageSync('reportCash');
  563. _this.reason=uni.getStorageSync('reason');
  564. _this.remark=uni.getStorageSync('remark');
  565. },
  566. }
  567. }
  568. </script>
  569. <style scoped>
  570. /* 头条小程序组件内不能引入字体 */
  571. /* #ifdef MP-TOUTIAO */
  572. @font-face {
  573. font-family: uniicons;
  574. font-weight: normal;
  575. font-style: normal;
  576. src: url("~@/static/uni.ttf") format("truetype");
  577. }
  578. /* #endif */
  579. page {
  580. display: flex;
  581. flex-direction: column;
  582. box-sizing: border-box;
  583. background-color: #efeff4;
  584. min-height: 100%;
  585. height: auto;
  586. }
  587. view {
  588. font-size: 14px;
  589. line-height: inherit;
  590. }
  591. .uni-form-item__title {
  592. font-size: 16px;
  593. line-height: 24px;
  594. }
  595. .uni-input-wrapper {
  596. /* #ifndef APP-NVUE */
  597. display: flex;
  598. /* #endif */
  599. padding: 8px 13px;
  600. flex-direction: row;
  601. flex-wrap: nowrap;
  602. background-color: #FFFFFF;
  603. }
  604. .title{
  605. background-color: #efefef;
  606. }
  607. .uni-input {
  608. height: 28px;
  609. line-height: 28px;
  610. font-size: 15px;
  611. padding: 0px;
  612. flex: 1;
  613. background-color: #FFFFFF;
  614. }
  615. .uni-icon {
  616. font-family: uniicons;
  617. font-size: 24px;
  618. font-weight: normal;
  619. font-style: normal;
  620. width: 24px;
  621. height: 24px;
  622. line-height: 24px;
  623. color: #999999;
  624. }
  625. .uni-eye-active {
  626. color: #007AFF;
  627. }
  628. .uni-btn-v{
  629. position: fixed;
  630. bottom: 0;
  631. width:100%;
  632. }
  633. .header-slot-box {
  634. font-size:15px;
  635. margin: 5px 5px;
  636. width:20%;
  637. justify-content: center;
  638. }
  639. .body-slot-box {
  640. font-size:15px;
  641. margin: 5px 5px;
  642. width:40%;
  643. justify-content: center;
  644. }
  645. .footer-slot-box {
  646. font-size:15px;
  647. margin: 5px 5px;
  648. width:40%;
  649. justify-content: center;
  650. }
  651. .uni-textarea textarea{
  652. font-size:15px;
  653. }
  654. .content {
  655. padding: 40rpx;
  656. background-color: #fff;
  657. }
  658. /* 上传控件 */
  659. .uploadControl {
  660. border: 1rpx solid #eee;
  661. border-radius: 10rpx;
  662. width: 130rpx;
  663. display: block;
  664. height: 130rpx;
  665. text-align: center;
  666. line-height: 130rpx;
  667. font-size: 30rpx;
  668. color: #888;
  669. background-color: #eeeeee;
  670. }
  671. </style>