requisitionadd.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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,GetzzSupplierEx} 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. this.GetzzSupplierEx();
  153. //表示从子页面获取了数值,返回父页面有可能会造成页面刷新导致表单数据丢失,需要从缓存中读取表单数据
  154. if(this.needFormCach){
  155. this.getTemp(this);
  156. }
  157. },
  158. updated:function(){
  159. },
  160. methods: {
  161. input(form, name, value) {
  162. this.$refs[form].setValue(name, value)
  163. },
  164. /**
  165. * 手动提交
  166. * @param {Object} form
  167. */
  168. submitForm(e) {
  169. console.info('submitForm');
  170. let _this=this;
  171. if(this.requisitionName==='')
  172. {
  173. uni.showToast({
  174. icon:"none",
  175. title:"请填写申请单名称",
  176. duration:3000
  177. });
  178. return;
  179. }
  180. if(this.requisitionName.length>50)
  181. {
  182. uni.showToast({
  183. icon:"none",
  184. title:"申请单名称不能多于50字",
  185. duration:3000
  186. });
  187. return;
  188. }
  189. if(this.requisitionDate===""){
  190. uni.showToast({
  191. icon:"none",
  192. title:"申请日期不能为空",
  193. duration:3000
  194. });
  195. return;
  196. }
  197. if(this.changeType===""){
  198. uni.showToast({
  199. icon:"none",
  200. title:"签证类型不能为空",
  201. duration:3000
  202. });
  203. return;
  204. }
  205. if(this.requisitionReason===""){
  206. uni.showToast({
  207. icon:"none",
  208. title:"原因不能为空",
  209. duration:3000
  210. });
  211. return;
  212. }
  213. if(this.requisitionReason.length>500){
  214. uni.showToast({
  215. icon:"none",
  216. title:"原因不能超过500字",
  217. duration:3000
  218. });
  219. return;
  220. }
  221. if(this.remark!==""){
  222. if(this.remark.length>500){
  223. uni.showToast({
  224. icon:"none",
  225. title:"签备注不能超过500字",
  226. duration:3000
  227. });
  228. return;
  229. }
  230. }
  231. if(this.$util.isEmpty(this.userCode)||this.$util.isEmpty(this.unitCode)){
  232. uni.showToast({
  233. icon:"none",
  234. title:"登录人信息丢失,请重新登录再操作",
  235. duration:4000
  236. });
  237. return;
  238. }
  239. let requisitionType=this.$util.getQuery("type")-0;
  240. 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};
  241. var list1=this.contractList;
  242. let list=[];
  243. list1.forEach(function(item,index,array){
  244. list.push({requisitionCode:'',contractCode:item.contractCode,estimateCash:new Decimal(item.estimateCash).toFixed(2)-0 });
  245. //list.push({requisitionCode:'',contractCode:item.contractCode,estimateCash: 220});
  246. });
  247. console.info("【list】");
  248. console.info(list);
  249. if(list.length<=0){
  250. uni.showToast({
  251. title:"请添加关联合同",
  252. icon:"none",
  253. duration:3000
  254. });
  255. return;
  256. }
  257. //return;
  258. var data={Requisition:requisitionDTO,List:list};
  259. //var strList=JSON.stringify(list);
  260. //var strData=JSON.stringify(data);
  261. InsertRequisition(data).then((res)=>{
  262. console.info("提交应答");
  263. console.info(res);
  264. if(res){
  265. //上传图片
  266. _this.uploadFileToServe(res) ;
  267. uni.navigateTo({
  268. url:'/pages/template/requisitionlist/requisitionlist?type='+requisitionType
  269. })
  270. }
  271. else{
  272. uni.showToast({
  273. title:'添加失败,重新操作',
  274. icon:'none',
  275. duration:3000
  276. })
  277. }
  278. });
  279. },
  280. //获取供应商明细
  281. GetzzSupplierEx:function(){
  282. let that=this;
  283. let id=this.$util.getQuery("zzSupplierExid");
  284. if(id!=null&&id!=""){
  285. GetzzSupplierEx(id).then((res)=>{
  286. if(typeof res!='string')
  287. {
  288. that.requisitionName=res.entity.title;
  289. that.requisitionReason=res.entity.reason;
  290. }
  291. });
  292. }
  293. },
  294. bindPickerChange: function(e) {
  295. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  296. //console.info(e.detail);
  297. this.index = e.detail.value;
  298. this.changeType=this.array[this.index];
  299. console.info(this.changeType);
  300. },
  301. bindDateChange: function(e) {
  302. this.date = e.detail.value;
  303. this.requisitionDate=this.date;
  304. console.info(this.date);
  305. },
  306. countChange: function(e) {
  307. this.countIndex = e.detail.value;
  308. },
  309. GetDropDown:function(){
  310. let that=this;
  311. let type=this.$util.getQuery("type")-0;
  312. GetQianzhengDropDown(type).then((res)=>{
  313. console.info(res);
  314. res.forEach(function(item,index,array){
  315. that.$set(that.array,index,item);
  316. });
  317. that.changeType=that.array[0];
  318. });
  319. },
  320. GetDepartment:function(){
  321. let that=this;
  322. GetUserDepartment('100340').then((res)=>{
  323. console.info(res);
  324. that.unitCodeName=res;
  325. });
  326. },
  327. openWindow:function(){
  328. let _this=this;
  329. console.info('监听事件外部this');
  330. console.info(this);
  331. this.saveTemp(_this);
  332. //创建名字为fire的监听器,监听子页面传值事件
  333. uni.$once('fire', function(data) {
  334. console.info("监听fire子页面的传值",data);
  335. //修改数据
  336. _this.contractList=[];
  337. data.forEach(function(item,index,array){
  338. //console.info("foreach");
  339. _this.$set(_this.contractList,index,item);
  340. });
  341. uni.setStorage({
  342. key:'contractList',
  343. data:_this.contractList
  344. });
  345. //dom还没更新
  346. _this.getTemp(_this);
  347. _this.needFormCach=true;
  348. console.info("监听子页面的传值结束");
  349. });
  350. //打开子页面
  351. uni.navigateTo({
  352. url:"/pages/template/GetRelationContract/GetRelationContract"
  353. })
  354. },
  355. /* 获取this.$data缓存值 */
  356. getTemp(_this){
  357. if(uni.getStorageSync('requisitionName')){
  358. _this.requisitionName=uni.getStorageSync('requisitionName');
  359. _this.requisitionDate=uni.getStorageSync('requisitionDate');
  360. _this.requisitionReason=uni.getStorageSync('requisitionReason');
  361. _this.changeType=uni.getStorageSync('changeType');
  362. _this.remark=uni.getStorageSync('remark');
  363. _this.imageList=uni.getStorageSync('imageList');
  364. _this.contractList=uni.getStorageSync('contractList');
  365. }
  366. },
  367. /* 给$data重新赋值 */
  368. saveTemp(_this){
  369. uni.setStorage({
  370. key:'requisitionName',
  371. data:_this.requisitionName
  372. });
  373. uni.setStorage({
  374. key:'requisitionDate',
  375. data:_this.requisitionDate
  376. });
  377. uni.setStorage({
  378. key:'changeType',
  379. data:_this.changeType
  380. });
  381. uni.setStorage({
  382. key:'requisitionReason',
  383. data:_this.requisitionReason
  384. });
  385. uni.setStorage({
  386. key:'remark',
  387. data:_this.remark
  388. });
  389. uni.setStorage({
  390. key:'imageList',
  391. data:_this.imageList
  392. });
  393. },
  394. delRow:function(index){
  395. console.info(index);
  396. console.info(this.contractList[index]);
  397. this.contractList.splice(index,1);
  398. },
  399. /*
  400. 上传后返回的值:
  401. list:上传后图片数组
  402. v:返回当前上传图片的临时路径
  403. */
  404. chooseFile(list, v) {
  405. console.log("上传图片_list:", list)
  406. console.log("上传图片_v:", v);
  407. this.urlList=list;
  408. console.info("urlList",this.urlList);
  409. },
  410. /*
  411. 删除图片:
  412. list:删除返回删除后剩余的图片数组
  413. eq:返回删除的数组
  414. */
  415. imgDelete(list, eq) {
  416. console.log("删除图片_list:", list);
  417. console.log("删除图片_eq:", eq);
  418. this.urlList=list;
  419. console.info("urlList",this.urlList);
  420. },
  421. /*限制文件大小列表*/
  422. limitFileSizeList(list){
  423. console.info('limitFileSizeList:',list);
  424. if(list){
  425. if(list.length>0){
  426. uni.showModal({
  427. title:'警告',
  428. content: list.join()+' 文件大小超过2000KB',
  429. showCancel:false
  430. });
  431. }
  432. }
  433. },
  434. /*限制文件类型列表*/
  435. limitFileTypeList(list,allowFileType){
  436. console.info('limitFileTypeList:',list);
  437. console.info('limitFileTypeList:',allowFileType);
  438. if(list){
  439. if(list.length>0){
  440. uni.showModal({
  441. title:'警告',
  442. content: list.join()+' 文件类型必须是'+allowFileType.join(),
  443. showCancel:false
  444. });
  445. }
  446. }
  447. },
  448. /*
  449. 执行上传服务:
  450. urlList:要上传的图片:数组类型
  451. */
  452. uploadFileToServe(masterCode) {
  453. let _this=this;
  454. var urlList=_this.urlList;
  455. if (!urlList || urlList.length <= 0) {
  456. return;
  457. };
  458. //console.info(urlList);
  459. //return;
  460. for (let i = 0; i < urlList.length; i++) {
  461. uni.uploadFile({
  462. url: '/api/Common/UploadImage',
  463. filePath: urlList[i],
  464. name: 'file',
  465. formData: {
  466. createPerson:_this.$store.state.user.userCode,
  467. masterCode:masterCode,
  468. attachMentType:'RequisitionAttach'
  469. },
  470. headers: {
  471. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
  472. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  473. },
  474. success: (uploadFileRes) => {
  475. console.log("图片上传:",uploadFileRes.data);
  476. }
  477. });
  478. }
  479. }
  480. }
  481. }
  482. </script>
  483. <style scoped>
  484. /* 头条小程序组件内不能引入字体 */
  485. /* #ifdef MP-TOUTIAO */
  486. @font-face {
  487. font-family: uniicons;
  488. font-weight: normal;
  489. font-style: normal;
  490. src: url("~@/static/uni.ttf") format("truetype");
  491. }
  492. /* #endif */
  493. page {
  494. display: flex;
  495. flex-direction: column;
  496. box-sizing: border-box;
  497. background-color: #efeff4;
  498. min-height: 100%;
  499. height: auto;
  500. }
  501. view {
  502. font-size: 14px;
  503. line-height: inherit;
  504. }
  505. .uni-form-item__title {
  506. font-size: 16px;
  507. line-height: 24px;
  508. }
  509. .uni-input-wrapper {
  510. /* #ifndef APP-NVUE */
  511. display: flex;
  512. /* #endif */
  513. padding: 8px 13px;
  514. flex-direction: row;
  515. flex-wrap: nowrap;
  516. background-color: #FFFFFF;
  517. }
  518. .title{
  519. background-color: #efefef;
  520. }
  521. .uni-input {
  522. height: 28px;
  523. line-height: 28px;
  524. font-size: 15px;
  525. padding: 0px;
  526. flex: 1;
  527. background-color: #FFFFFF;
  528. }
  529. .uni-icon {
  530. font-family: uniicons;
  531. font-size: 24px;
  532. font-weight: normal;
  533. font-style: normal;
  534. width: 24px;
  535. height: 24px;
  536. line-height: 24px;
  537. color: #999999;
  538. }
  539. .uni-eye-active {
  540. color: #007AFF;
  541. }
  542. .uni-btn-v{
  543. position: fixed;
  544. bottom: 0;
  545. width:100%;
  546. }
  547. .header-slot-box {
  548. font-size:15px;
  549. margin: 5px 5px;
  550. width:20%;
  551. justify-content: center;
  552. }
  553. .body-slot-box {
  554. font-size:15px;
  555. margin: 5px 5px;
  556. width:40%;
  557. justify-content: center;
  558. }
  559. .footer-slot-box {
  560. font-size:15px;
  561. margin: 5px 5px;
  562. width:40%;
  563. justify-content: center;
  564. }
  565. .uni-textarea textarea{
  566. font-size:15px;
  567. }
  568. .content {
  569. padding: 40rpx;
  570. background-color: #fff;
  571. }
  572. /* 上传控件 */
  573. .uploadControl {
  574. border: 1rpx solid #eee;
  575. border-radius: 10rpx;
  576. width: 130rpx;
  577. display: block;
  578. height: 130rpx;
  579. text-align: center;
  580. line-height: 130rpx;
  581. font-size: 30rpx;
  582. color: #888;
  583. background-color: #eeeeee;
  584. }
  585. </style>