MaterialInAdd.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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-small" disabled=true v-model="intypeName" />
  8. <a href='javascript:;' @click='getType' class="uni-icon"><i class="fa fa-search" aria-hidden="true"></i></a>
  9. </view>
  10. </view>
  11. <view class="uni-form-item uni-column">
  12. <view class="title"><text class="uni-form-item__title">入库日期</text></view>
  13. <view class="uni-input-wrapper" style="justify-content: left;">
  14. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" v-model="inDate" name="requisitionDate"
  15. style="width: 100%;">
  16. <view class="uni-input">{{date}}</view>
  17. </picker>
  18. </view>
  19. </view>
  20. <view class="uni-form-item uni-column">
  21. <view class="title"><text class="uni-form-item__title">材料合同</text></view>
  22. <view class="uni-input-wrapper">
  23. <input class="uni-input-small" disabled=true v-model="contractName" />
  24. <a href='javascript:;' @click='getContract(projectCode)' class="uni-icon"><i class="fa fa-search" aria-hidden="true"></i></a>
  25. </view>
  26. </view>
  27. <view class="uni-form-item uni-column">
  28. <view class="title"><text class="uni-form-item__title">供应单位</text></view>
  29. <view class="uni-textarea">
  30. <input class="uni-input-small" disabled=true v-model="supplierName" />
  31. </view>
  32. </view>
  33. <view class="uni-form-item uni-column">
  34. <view class="title"><text class="uni-form-item__title">领料类型</text></view>
  35. <view class="uni-input-wrapper ">
  36. <input class="uni-input-small" disabled=true v-model="outtypeName" />
  37. <a href='javascript:;' @click='getOutType' class="uni-icon"><i class="fa fa-search" aria-hidden="true"></i></a>
  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">
  43. <input class="uni-input-small" disabled=true v-model="engineeringContractName" />
  44. <a href='javascript:;' @click='getEngineeringContract(projectCode)' class="uni-icon"><i class="fa fa-search"
  45. aria-hidden="true"></i></a>
  46. </view>
  47. </view>
  48. <view class="uni-form-item uni-column">
  49. <view class="title" style="background-color: #efefef;"><text class="uni-form-item__title">附件</text></view>
  50. <view class="content">
  51. <g-upfile ref='gUpfile' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :control='control'
  52. :columnNum="columnNum" :maxCount="maxCount" @limitFileSizeList='limitFileSizeList' @limitFileTypeList='limitFileTypeList' :maxFileSize="20000"></g-upfile>
  53. </view>
  54. </view>
  55. <uni-section title="入库明细" type="line">
  56. <button type="default" @click="openWindow" size="mini">添加材料</button>
  57. </uni-section>
  58. <view class="uni-form-item uni-column">
  59. <t-table border="2" border-color="#999999">
  60. <t-tr font-size="14" color="#999999" align="left">
  61. <t-th align="left">名称</t-th>
  62. <t-th align="left">入库数量</t-th>
  63. <t-th align="left">不合格数量</t-th>
  64. <t-th align="center" style="width: 50px !important;">操作</t-th>
  65. </t-tr>
  66. <t-tr font-size="12" color="#999999" align="right" v-for="(item,index) in materials" :key="index">
  67. <t-td align="left">{{ item.materialName }}</t-td>
  68. <t-td align="left"><input class="uni-input-small" type="digit" v-model="item.inQty" style="width:50px;" /></t-td>
  69. <t-td align="left"><input class="uni-input-small" type="digit" v-model="item.noQty" style="width:50px;" /></t-td>
  70. <t-td align="center" style="width: 50px !important;"><i class="fa fa-window-close" aria-hidden="true" @click="delRow(index)"
  71. style="font-size:20px;cursor: pointer;color: #999;margin-left:15px;" title="删除"></i></t-td>
  72. </t-tr>
  73. </t-table>
  74. </view>
  75. <view style="margin-bottom: 120px;">
  76. </view>
  77. <view class="uni-btn-v uni-column">
  78. <button type="primary" form-type="submit" style="border-radius: 15px;">提交</button>
  79. </view>
  80. </uni-forms>
  81. </view>
  82. </template>
  83. <script>
  84. import {
  85. getSupplierNameAndType
  86. } from "@/common/api/commonApi.js";
  87. import {
  88. Decimal
  89. } from 'decimal.js'; //decimal计算
  90. import {
  91. GetMaterials,
  92. InsertMaterialIn,
  93. GetMaterialsForOut
  94. } from '@/common/api/MaterialInOut.js';
  95. import tTable from '@/components/t-table/t-table.vue';
  96. import tTh from '@/components/t-table/t-th.vue';
  97. import tTr from '@/components/t-table/t-tr.vue';
  98. import tTd from '@/components/t-table/t-td.vue';
  99. export default {
  100. components: {
  101. tTable,
  102. tTh,
  103. tTr,
  104. tTd
  105. },
  106. data() {
  107. return {
  108. isCache:false,
  109. intypeCode: '',
  110. intypeName: '',
  111. inDate: this.$util.getDate({
  112. format: true
  113. }),
  114. contractName: '',
  115. contractCode: '',
  116. supplierName: '',
  117. contract: {},
  118. userCode: this.$util.getState(this, "userCode"), //用户编号
  119. projectCode: this.$util.getState(this, "projectCode"),
  120. personName: this.$store.state.user.userName, //申办人
  121. unitCode: this.$store.state.departmentCode, //申办部门
  122. unitCodeName: this.$store.state.departmentName, //申办部门名
  123. contractList: [], //合同
  124. materials: [], //材料
  125. outtypecode: '', //领料类型编码
  126. outtypeName: '', //领料类型名
  127. engineeringContractName: '', //工程合同名
  128. engineeringContractCode: '', //工程合同编码
  129. engineeringContract: {}, //工程合同数据集合
  130. engineeringMaterials: [], //工程材料
  131. engineeringError: '', //获取工程材料返回的错误信息
  132. title: 'choose/previewImage',
  133. imageList: [],
  134. sourceTypeIndex: 2,
  135. sourceType: ['拍照', '相册', '拍照或相册'],
  136. sizeTypeIndex: 2,
  137. sizeType: ['压缩', '原图', '压缩或原图'],
  138. countIndex: 5,
  139. count: [1, 2, 3, 4, 5],
  140. title1: 'picker',
  141. array: [],
  142. index: 0,
  143. date: this.$util.getDate({
  144. format: true
  145. }),
  146. startDate: this.$util.getDate('start'),
  147. endDate: this.$util.getDate('end'),
  148. control: true,
  149. columnNum: 3,
  150. imgList: [],
  151. urlList: [],
  152. maxCount: 5
  153. }
  154. },
  155. onLoad() {
  156. //console.info(page.path);
  157. console.info(uni.getStorageSync('storage_state'));
  158. //console.info(this);
  159. this.$util.persistLogin(this);
  160. //console.info(this.$store.state.user);
  161. },
  162. onUnload() {
  163. this.imageList = [],
  164. this.countIndex = 5;
  165. },
  166. created: function() {
  167. console.info('created');
  168. console.info("isCache",this.isCache);
  169. if(this.isCache){
  170. this.getTemp(this);
  171. }
  172. },
  173. mounted: function() {
  174. console.info('mounted');
  175. //console.info('intype',this.intypeCode);
  176. },
  177. updated: function() {
  178. console.info('updated');
  179. console.info('contract', this.contract);
  180. if (this.contract) {
  181. if (this.contract.length > 0) {
  182. this.getSupplierName(this.contract[0].supplierCode, this.contract[0].supplierTypeCode);
  183. }
  184. }
  185. },
  186. methods: {
  187. /**
  188. * 手动提交
  189. * @param {Object} form
  190. */
  191. submitForm(e) {
  192. console.info('submitForm');
  193. let _this = this;
  194. if (this.intypeCode == "") {
  195. uni.showToast({
  196. title: '请选择入库类型',
  197. duration: 3000,
  198. icon: 'none'
  199. });
  200. return;
  201. }
  202. if (this.inDate == "") {
  203. uni.showToast({
  204. title: '请选择入库日期',
  205. duration: 3000,
  206. icon: 'none'
  207. });
  208. return;
  209. }
  210. if (this.contractCode == "") {
  211. uni.showToast({
  212. title: '请选择材料合同',
  213. duration: 3000,
  214. icon: 'none'
  215. });
  216. return;
  217. }
  218. if (!this.userCode) {
  219. uni.showToast({
  220. title: '用户登录已失效,请重新登录',
  221. duration: 3000,
  222. icon: 'none'
  223. });
  224. return;
  225. }
  226. if (!this.contract) {
  227. uni.showToast({
  228. title: '请重新选择材料合同',
  229. duration: 3000,
  230. icon: 'none'
  231. });
  232. return;
  233. }
  234. if (this.outtypeCode == "") {
  235. uni.showToast({
  236. title: '请选择领料类型',
  237. duration: 3000,
  238. icon: 'none'
  239. });
  240. return;
  241. }
  242. if (this.engineeringContractCode == "") {
  243. uni.showToast({
  244. title: '请选择工程合同',
  245. duration: 3000,
  246. icon: 'none'
  247. });
  248. return;
  249. }
  250. console.info("工程合同engineeringMaterials",this.engineeringMaterials);
  251. if (this.engineeringMaterials.length<=0) {
  252. uni.showToast({
  253. title: '请重新选择工程合同',
  254. duration: 3000,
  255. icon: 'none'
  256. });
  257. return;
  258. }
  259. console.info("engineeringError",this.engineeringError);
  260. if (this.engineeringError != "") {
  261. uni.showToast({
  262. title: _this.engineeringError,
  263. duration: 3000,
  264. icon: 'none'
  265. });
  266. return;
  267. }
  268. //材料入库单主表
  269. var materialIn = {
  270. projectCode: this.projectCode,
  271. groupCode: this.intypeCode,
  272. inDate: this.inDate,
  273. inPerson: this.userCode,
  274. inputPerson: this.userCode,
  275. contractCode: this.contractCode,
  276. supplierCode: this.contract[0].supplierCode,
  277. supplierTypeCode: this.contract[0].supplierTypeCode,
  278. supplierTypeId: this.contract[0].supplierTypeId
  279. };
  280. //材料领料单主表
  281. var materialOut = {
  282. projectCode: this.projectCode,
  283. groupCode: this.outtypeCode,
  284. outDate: this.inDate,
  285. outPerson: this.userCode,
  286. inputPerson: this.userCode,
  287. contractCode: this.engineeringContractCode,
  288. doSupplierCode: this.engineeringContract[0].supplierCode,
  289. supplierTypeCode: this.engineeringContract[0].supplierTypeCode,
  290. supplierTypeId: this.engineeringContract[0].supplierTypeId
  291. };
  292. console.info('materials', this.materials);
  293. var list1 = this.materials;
  294. console.info('list1', list1);
  295. //入库单材料明细
  296. let list = [];
  297. let isLessThan = true;
  298. list1.forEach(function(item, index, array) {
  299. if (item.inQty <= 0) {
  300. console.info('入库数量不能小于等于0');
  301. isLessThan = false;
  302. return;
  303. }
  304. list.push({
  305. materialCode: item.materialCode,
  306. unit: item.unit,
  307. inQty: new Decimal(item.inQty).toFixed(2) - 0,
  308. inPrice: new Decimal(item.standardPrice).toFixed(2) - 0,
  309. noPassQty: new Decimal(item.noQty).toFixed(2) - 0,
  310. });
  311. //list.push({requisitionCode:'',contractCode:item.contractCode,estimateCash: 220});
  312. });
  313. if (!isLessThan) {
  314. uni.showToast({
  315. title: '入库数量不能小于等于0',
  316. duration: 3000,
  317. icon: 'none'
  318. });
  319. return;
  320. }
  321. console.info("【list】", list);
  322. if (list.length <= 0) {
  323. uni.showToast({
  324. title: "请添加材料",
  325. icon: "none",
  326. duration: 3000
  327. });
  328. return;
  329. }
  330. let enginList = this.engineeringMaterials;
  331. if (enginList.length <= 0) {
  332. uni.showToast({
  333. title: '请重新选择工程合同',
  334. duration: 3000,
  335. icon: 'none'
  336. });
  337. return;
  338. }
  339. console.info("材料", list1);
  340. console.info('工程材料', enginList);
  341. for(var i=0;i<enginList.length;i++) //遍历工程材料列表
  342. {
  343. for(var j=0;j<list1.length;j++){
  344. if(list1[j].materialCode==enginList[i].materialCode){
  345. break; //中断循环,返回外层
  346. }
  347. else if(list1[j].materialCode!=enginList[i].materialCode){
  348. if(j==list1.length-1){ //内层循环够了一遍,不匹配任何元素
  349. uni.showModal({
  350. title:'警告',
  351. content:'工程合同中所获取的材料在材料合同中不存在',
  352. showCancel:false
  353. });
  354. }
  355. }
  356. }
  357. }
  358. let clist1 = []; //添加的材料列表
  359. let mlist1 = []; //工程合同中材料列表
  360. list1.forEach(function(item, index, arr) {
  361. clist1.push(item.materialCode);
  362. });
  363. enginList.forEach(function(item, index, arr) {
  364. mlist1.push({
  365. materialCode: item.materialCode,
  366. materialName: item.materialName
  367. });
  368. });
  369. console.info('添加的材料列表', clist1);
  370. console.info('工程合同中材料列表', mlist1);
  371. let noMaterials = [];
  372. mlist1.forEach(function(item, index, arr) {
  373. if (clist1.indexOf(item.materialCode) == -1) {
  374. noMaterials.push(item.materialName);
  375. return;
  376. }
  377. });
  378. if (noMaterials.length > 0) {
  379. uni.showToast({
  380. title: noMaterials.join(),
  381. duration: 3000,
  382. icon: 'none'
  383. });
  384. return;
  385. }
  386. //return;
  387. var data = {
  388. materialIn: materialIn,
  389. materialOut: materialOut,
  390. mDetailList: list
  391. };
  392. console.info('data', data);
  393. //return;
  394. //var strList=JSON.stringify(list);
  395. //var strData=JSON.stringify(data);
  396. InsertMaterialIn(data).then((res) => {
  397. console.info("提交应答返回值", res);
  398. if (res) {
  399. //上传图片
  400. //_this.uploadFileToServe(res);
  401. uni.navigateTo({
  402. url: '/pages/template/GetMaterialIns/GetMaterialIns'
  403. })
  404. } else {
  405. uni.showToast({
  406. title: '添加失败,重新操作',
  407. icon: 'none',
  408. duration: 3000
  409. })
  410. }
  411. });
  412. },
  413. bindPickerChange: function(e) {
  414. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  415. //console.info(e.detail);
  416. this.index = e.detail.value;
  417. this.changeType = this.array[this.index];
  418. console.info(this.changeType);
  419. },
  420. bindDateChange: function(e) {
  421. this.date = e.detail.value;
  422. this.requisitionDate = this.date;
  423. console.info(this.date);
  424. },
  425. GetDropDown: function() {
  426. let that = this;
  427. GetQianzhengDropDown().then((res) => {
  428. console.info(res);
  429. res.forEach(function(item, index, array) {
  430. that.$set(that.array, index, item);
  431. });
  432. that.changeType = that.array[0];
  433. });
  434. },
  435. openWindow: function() {
  436. let _this = this;
  437. //console.info('监听事件外部this');
  438. //console.info(this);
  439. _this.saveTemp(_this);
  440. if (_this.contractCode == undefined || _this.contractCode == '') {
  441. uni.showToast({
  442. title: '请选择材料合同',
  443. icon: 'none',
  444. duration: 3000
  445. });
  446. return;
  447. }
  448. //创建名字为fire的监听器,监听子页面传值事件
  449. uni.$on('materials', function(data) {
  450. console.info("监听materials子页面的传值", data);
  451. //从子页面返回父页面,原来表单已经填写的值会丢失,因此需要重新赋值
  452. _this.getTemp(_this);
  453. _this.materials = [];
  454. data.forEach(function(item, index, array) {
  455. //console.info("foreach");
  456. _this.$set(_this.materials, index, item);
  457. });
  458. uni.setStorage({
  459. key: 'materials',
  460. data: _this.materials
  461. });
  462. _this.isCache=true;
  463. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  464. uni.$off("materials");
  465. console.info("监听materials子页面的传值结束");
  466. });
  467. //打开子页面
  468. uni.navigateTo({
  469. url: "/pages/template/selectmaterials/selectmaterials?contractCode=" + _this.contractCode
  470. })
  471. },
  472. delRow: function(index) {
  473. console.info("删除");
  474. console.info(this.materials[index]);
  475. this.materials.splice(index, 1);
  476. },
  477. /*
  478. 上传后返回的值:
  479. list:上传后图片数组
  480. v:返回当前上传图片的临时路径
  481. */
  482. chooseFile(list, v) {
  483. console.log("上传图片_list:", list)
  484. console.log("上传图片_v:", v);
  485. this.urlList = list;
  486. console.info("urlList", this.urlList);
  487. },
  488. /*
  489. 删除图片:
  490. list:删除返回删除后剩余的图片数组
  491. eq:返回删除的数组
  492. */
  493. imgDelete(list, eq) {
  494. console.log("删除图片_list:", list);
  495. console.log("删除图片_eq:", eq);
  496. this.urlList = list;
  497. console.info("urlList", this.urlList);
  498. },
  499. /*限制文件大小列表*/
  500. limitFileSizeList(list){
  501. console.info('limitFileSizeList:',list);
  502. if(list){
  503. if(list.length>0){
  504. uni.showModal({
  505. title:'警告',
  506. content: list.join()+' 文件大小超过2000KB',
  507. showCancel:false
  508. });
  509. }
  510. }
  511. },
  512. /*限制文件类型列表*/
  513. limitFileTypeList(list,allowFileType){
  514. console.info('limitFileTypeList:',list);
  515. console.info('limitFileTypeList:',allowFileType);
  516. if(list){
  517. if(list.length>0){
  518. uni.showModal({
  519. title:'警告',
  520. content: list.join()+' 文件类型必须是'+allowFileType.join(),
  521. showCancel:false
  522. });
  523. }
  524. }
  525. },
  526. /*
  527. 执行上传服务:
  528. urlList:要上传的图片:数组类型
  529. */
  530. uploadFileToServe(masterCode) {
  531. let _this = this;
  532. var urlList = _this.urlList;
  533. if (!urlList || urlList.length <= 0) {
  534. return;
  535. };
  536. //console.info(urlList);
  537. //return;
  538. for (let i = 0; i < urlList.length; i++) {
  539. uni.uploadFile({
  540. url: '/api/Requisition/UploadImage',
  541. filePath: urlList[i],
  542. name: 'file',
  543. formData: {
  544. createPerson: _this.$store.state.user.userCode,
  545. masterCode: masterCode
  546. },
  547. headers: {
  548. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
  549. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  550. },
  551. success: (uploadFileRes) => {
  552. console.log("图片上传:", uploadFileRes.data);
  553. }
  554. });
  555. }
  556. },
  557. /*
  558. 获取入库类型
  559. */
  560. getType() {
  561. let _this = this;
  562. console.info('gettype', _this);
  563. _this.saveTemp(_this);
  564. //创建名字为fire的监听器,监听子页面传值事件
  565. uni.$on('intype', function(data) {
  566. console.info("监听intype子页面的传值", data);
  567. //console.info('监听', _this);
  568. _this.getTemp(_this);
  569. _this.intypeCode = data[0].id;
  570. _this.intypeName = data[0].name;
  571. uni.setStorage({
  572. key: 'intypeCode',
  573. data: _this.intypeCode
  574. });
  575. uni.setStorage({
  576. key: 'intypeName',
  577. data: _this.intypeName
  578. });
  579. console.info(data[0].id, data[0].name);
  580. console.info(_this.intypeCode, _this.intypeName);
  581. _this.isCache=true;
  582. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  583. uni.$off("intype");
  584. });
  585. uni.navigateTo({
  586. url: '/pages/tree/tree?classCode=1503'
  587. });
  588. },
  589. /*
  590. 获取领料类型
  591. */
  592. getOutType() {
  593. let _this = this;
  594. console.info('gettype', _this);
  595. _this.saveTemp(_this);
  596. //创建名字为fire的监听器,监听子页面传值事件
  597. uni.$on('outtype', function(data) {
  598. console.info("监听outtype子页面的传值", data);
  599. console.info('监听', _this);
  600. _this.getTemp(_this);
  601. _this.outtypeCode = data[0].id;
  602. _this.outtypeName = data[0].name;
  603. uni.setStorage({
  604. key: 'outtypeCode',
  605. data: _this.outtypeCode
  606. });
  607. uni.setStorage({
  608. key: 'outtypeName',
  609. data: _this.outtypeName
  610. });
  611. _this.isCache=true;
  612. console.info(data[0].id, data[0].name);
  613. console.info(_this.outtypeCode, _this.outtypeName);
  614. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  615. uni.$off("outtype");
  616. });
  617. uni.navigateTo({
  618. url: '/pages/treeout/treeout?classCode=1505'
  619. });
  620. },
  621. /*获取材料合同*/
  622. getContract(projectCode) {
  623. console.info('getContract', projectCode);
  624. let _this = this;
  625. _this.saveTemp(_this); //表单存入缓存
  626. //创建名字为fire的监听器,监听子页面传值事件
  627. uni.$on('contract', function(data) {
  628. console.info("监听contract子页面的传值", data);
  629. _this.getTemp(_this); //自缓存中取出表单数据,重新赋值
  630. _this.contractCode = data[0].contractCode;
  631. _this.contractName = data[0].contractName;
  632. _this.contract = data;
  633. uni.setStorage({
  634. key: 'contractCode',
  635. data: _this.contractCode
  636. });
  637. uni.setStorage({
  638. key: 'contractName',
  639. data: _this.contractName
  640. });
  641. uni.setStorage({
  642. key: 'contract',
  643. data: _this.contract
  644. });
  645. _this.isCache=true;
  646. console.info('_this.contract', _this.contract);
  647. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  648. uni.$off("contract");
  649. });
  650. uni.navigateTo({
  651. url: '/pages/template/SelectContract/SelectContract?projectCode=' + projectCode
  652. });
  653. },
  654. /*获取工程合同*/
  655. getEngineeringContract(projectCode) {
  656. console.info('getEngineeringContract', projectCode);
  657. let _this = this;
  658. _this.saveTemp(_this); //表单存入缓存
  659. //创建名字为fire的监听器,监听子页面传值事件
  660. uni.$on('engineeringContract', function(data) {
  661. console.info("监听工程合同子页面开始");
  662. console.info("监听engineeringContract子页面的传值", data);
  663. _this.getTemp(_this); //自缓存中取出表单数据,重新赋值
  664. _this.engineeringContractCode = data[0].contractCode;
  665. _this.engineeringContractName = data[0].contractName;
  666. _this.engineeringContract = data;
  667. uni.setStorage({
  668. key: 'engineeringContractCode',
  669. data: _this.engineeringContractCode
  670. });
  671. uni.setStorage({
  672. key: 'engineeringContractName',
  673. data: _this.engineeringContractName
  674. });
  675. uni.setStorage({
  676. key: 'engineeringContract',
  677. data: _this.engineeringContract
  678. });
  679. console.info('engineeringContract', _this.engineeringContract);
  680. //获取工程材料列表
  681. GetMaterialsForOut(_this.$util.getState(_this, 'projectCode'), data[0].contractCode).then(res => {
  682. console.info("GetMaterialsForOut",res);
  683. if (typeof res == 'string') {
  684. _this.engineeringError = res;
  685. uni.setStorage({
  686. key: 'engineeringError',
  687. data: _this.engineeringError
  688. });
  689. uni.showModal({
  690. title:'警告',
  691. content:_this.engineeringError,
  692. showCancel:false
  693. });
  694. _this.engineeringContractCode = "";
  695. _this.engineeringContractName = "";
  696. _this.engineeringContract = {};
  697. console.info('engineeringError', _this.engineeringError);
  698. return;
  699. }
  700. if (res.length > 0) {
  701. res.forEach(function(item, index, arr) {
  702. //给工程材料集合赋值
  703. _this.$set(_this.engineeringMaterials, index, item);
  704. });
  705. uni.setStorage({
  706. key: 'engineeringMaterials',
  707. data: _this.engineeringMaterials
  708. });
  709. console.info('engineeringMaterials', _this.engineeringMaterials);
  710. }
  711. else{
  712. uni.showModal({
  713. title:'警告',
  714. content:'所选工程合同不包含任何材料,或者合同状态不正确',
  715. showCancel:false
  716. });
  717. return;
  718. }
  719. });
  720. _this.isCache=true;
  721. console.info("监听工程合同子页面结束");
  722. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  723. uni.$off("engineeringContract");
  724. });
  725. uni.navigateTo({
  726. url: '/pages/template/SelectEgineeringContract/SelectEgineeringContract?projectCode=' + projectCode
  727. });
  728. },
  729. /* 获取供应商名称 */
  730. getSupplierName(supplierCode, supplierTypeCode) {
  731. console.info('getSupplierName');
  732. console.info('supplierCode', supplierCode);
  733. console.info('supplierTypeCode', supplierTypeCode);
  734. let that = this;
  735. if (supplierCode && supplierTypeCode) {
  736. getSupplierNameAndType(supplierCode, supplierTypeCode).then(res => {
  737. console.info('getSupplierNameAndType', res);
  738. that.supplierName = res;
  739. });
  740. }
  741. },
  742. saveTemp(_this) { //临时存
  743. uni.setStorage({
  744. key: 'intypeName',
  745. data: _this.intypeName
  746. });
  747. uni.setStorage({
  748. key: 'intypeCode',
  749. data: _this.intypeCode
  750. });
  751. uni.setStorage({
  752. key: 'inDate',
  753. data: _this.inDate
  754. });
  755. uni.setStorage({
  756. key: 'contractCode',
  757. data: _this.contractCode
  758. });
  759. uni.setStorage({
  760. key: 'contractName',
  761. data: _this.contractName
  762. });
  763. uni.setStorage({
  764. key: 'supplierCode',
  765. data: _this.supplierCode
  766. });
  767. uni.setStorage({
  768. key: 'supplierName',
  769. data: _this.supplierName
  770. });
  771. uni.setStorage({
  772. key: 'contract',
  773. data: _this.contract
  774. });
  775. uni.setStorage({
  776. key: 'usercode',
  777. data: _this.usercode
  778. });
  779. uni.setStorage({
  780. key: 'imageList',
  781. data: _this.imageList
  782. });
  783. uni.setStorage({
  784. key: 'engineeringContractCode',
  785. data: _this.engineeringContractCode
  786. });
  787. uni.setStorage({
  788. key: 'engineeringContractName',
  789. data: _this.engineeringContractName
  790. });
  791. uni.setStorage({
  792. key: 'engineeringError',
  793. data: _this.engineeringError
  794. });
  795. uni.setStorage({
  796. key: 'engineeringMaterials',
  797. data: _this.engineeringMaterials
  798. });
  799. uni.setStorage({
  800. key: 'outtypeName',
  801. data: _this.outtypeName
  802. });
  803. uni.setStorage({
  804. key: 'outtypeCode',
  805. data: _this.outtypeCode
  806. });
  807. uni.setStorage({
  808. key: 'materials',
  809. data: _this.materials
  810. });
  811. },
  812. getTemp(_this) { //获取缓存,重新给表单赋值
  813. if (uni.getStorageSync('intypeCode')) {
  814. _this.intypeCode = uni.getStorageSync('intypeCode');
  815. _this.intypeName = uni.getStorageSync('intypeName');
  816. _this.inDate = uni.getStorageSync('inDate');
  817. _this.contractCode = uni.getStorageSync('contractCode');
  818. _this.contractName = uni.getStorageSync('contractName');
  819. _this.supplierCode = uni.getStorageSync('supplierCode');
  820. _this.supplierName = uni.getStorageSync('supplierName');
  821. _this.supplierCode = uni.getStorageSync('supplierCode');
  822. _this.usercode = uni.getStorageSync('usercode');
  823. _this.contract = uni.getStorageSync('contract');
  824. _this.engineeringContractCode = uni.getStorageSync('engineeringContractCode');
  825. _this.engineeringContractName = uni.getStorageSync('engineeringContractName');
  826. _this.engineeringContract=uni.getStorageSync("engineeringContract");
  827. _this.engineeringError = uni.getStorageSync('engineeringError');
  828. _this.engineeringMaterials = uni.getStorageSync('engineeringMaterials');
  829. _this.outtypeCode = uni.getStorageSync('outtypeCode');
  830. _this.outtypeName = uni.getStorageSync('outtypeName');
  831. _this.materials=uni.getStorageSync("materials");
  832. }
  833. },
  834. }
  835. }
  836. </script>
  837. <style scoped>
  838. /* 头条小程序组件内不能引入字体 */
  839. /* #ifdef MP-TOUTIAO */
  840. @font-face {
  841. font-family: uniicons;
  842. font-weight: normal;
  843. font-style: normal;
  844. src: url("~@/static/uni.ttf") format("truetype");
  845. }
  846. /* #endif */
  847. page {
  848. display: flex;
  849. flex-direction: column;
  850. box-sizing: border-box;
  851. background-color: #efeff4;
  852. min-height: 100%;
  853. height: auto;
  854. }
  855. view {
  856. font-size: 14px;
  857. line-height: inherit;
  858. }
  859. .uni-form-item__title {
  860. font-size: 16px;
  861. line-height: 24px;
  862. }
  863. .uni-input-wrapper {
  864. /* #ifndef APP-NVUE */
  865. display: flex;
  866. /* #endif */
  867. padding: 8px 13px;
  868. flex-direction: row;
  869. flex-wrap: nowrap;
  870. background-color: #FFFFFF;
  871. }
  872. .title {
  873. background-color: #efefef;
  874. padding: 5px 20px;
  875. }
  876. .uni-input {
  877. height: 28px;
  878. line-height: 28px;
  879. font-size: 15px;
  880. padding: 5px;
  881. flex: 1;
  882. background-color: #FFFFFF;
  883. }
  884. .uni-input-small {
  885. height: 28px;
  886. line-height: 28px;
  887. font-size: 15px;
  888. padding: 5px;
  889. flex: 1;
  890. width: 270px;
  891. background-color: #FFFFFF;
  892. }
  893. .uni-icon {
  894. height: 28px;
  895. line-height: 28px;
  896. font-size: 20px;
  897. padding-right: 15px;
  898. color: #5555ff;
  899. width: 50px;
  900. }
  901. .uni-eye-active {
  902. color: #007AFF;
  903. }
  904. .uni-btn-v {
  905. position: fixed;
  906. bottom: 0;
  907. width: 100%;
  908. }
  909. .header-slot-box {
  910. font-size: 15px;
  911. margin: 5px 5px;
  912. width: 20%;
  913. justify-content: center;
  914. }
  915. .body-slot-box {
  916. font-size: 15px;
  917. margin: 5px 5px;
  918. width: 40%;
  919. justify-content: center;
  920. }
  921. .footer-slot-box {
  922. font-size: 15px;
  923. margin: 5px 5px;
  924. width: 40%;
  925. justify-content: center;
  926. }
  927. .uni-textarea textarea {
  928. font-size: 15px;
  929. }
  930. .content {
  931. padding: 40rpx;
  932. background-color: #fff;
  933. }
  934. /* 上传控件 */
  935. .uploadControl {
  936. border: 1rpx solid #eee;
  937. border-radius: 10rpx;
  938. width: 130rpx;
  939. display: block;
  940. height: 130rpx;
  941. text-align: center;
  942. line-height: 130rpx;
  943. font-size: 30rpx;
  944. color: #888;
  945. background-color: #eeeeee;
  946. }
  947. .bg1 {
  948. background-color: #EFEFEF;
  949. }
  950. </style>