requisitionadd.vue 18 KB

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