requisitionadd.vue 16 KB

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