MaterialInAdd.vue 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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="2000"></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. console.info('engineeringError', _this.engineeringError);
  690. return;
  691. }
  692. if (res.length > 0) {
  693. res.forEach(function(item, index, arr) {
  694. //给工程材料集合赋值
  695. _this.$set(_this.engineeringMaterials, index, item);
  696. });
  697. uni.setStorage({
  698. key: 'engineeringMaterials',
  699. data: _this.engineeringMaterials
  700. });
  701. console.info('engineeringMaterials', _this.engineeringMaterials);
  702. }
  703. else{
  704. uni.showModal({
  705. title:'警告',
  706. content:'所选工程合同不包含任何材料,或者合同状态不正确',
  707. showCancel:false
  708. });
  709. return;
  710. }
  711. });
  712. _this.isCache=true;
  713. console.info("监听工程合同子页面结束");
  714. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  715. uni.$off("engineeringContract");
  716. });
  717. uni.navigateTo({
  718. url: '/pages/template/SelectEgineeringContract/SelectEgineeringContract?projectCode=' + projectCode
  719. });
  720. },
  721. /* 获取供应商名称 */
  722. getSupplierName(supplierCode, supplierTypeCode) {
  723. console.info('getSupplierName');
  724. console.info('supplierCode', supplierCode);
  725. console.info('supplierTypeCode', supplierTypeCode);
  726. let that = this;
  727. if (supplierCode && supplierTypeCode) {
  728. getSupplierNameAndType(supplierCode, supplierTypeCode).then(res => {
  729. console.info('getSupplierNameAndType', res);
  730. that.supplierName = res;
  731. });
  732. }
  733. },
  734. saveTemp(_this) { //临时存
  735. uni.setStorage({
  736. key: 'intypeName',
  737. data: _this.intypeName
  738. });
  739. uni.setStorage({
  740. key: 'intypeCode',
  741. data: _this.intypeCode
  742. });
  743. uni.setStorage({
  744. key: 'inDate',
  745. data: _this.inDate
  746. });
  747. uni.setStorage({
  748. key: 'contractCode',
  749. data: _this.contractCode
  750. });
  751. uni.setStorage({
  752. key: 'contractName',
  753. data: _this.contractName
  754. });
  755. uni.setStorage({
  756. key: 'supplierCode',
  757. data: _this.supplierCode
  758. });
  759. uni.setStorage({
  760. key: 'supplierName',
  761. data: _this.supplierName
  762. });
  763. uni.setStorage({
  764. key: 'contract',
  765. data: _this.contract
  766. });
  767. uni.setStorage({
  768. key: 'usercode',
  769. data: _this.usercode
  770. });
  771. uni.setStorage({
  772. key: 'imageList',
  773. data: _this.imageList
  774. });
  775. uni.setStorage({
  776. key: 'engineeringContractCode',
  777. data: _this.engineeringContractCode
  778. });
  779. uni.setStorage({
  780. key: 'engineeringContractName',
  781. data: _this.engineeringContractName
  782. });
  783. uni.setStorage({
  784. key: 'engineeringError',
  785. data: _this.engineeringError
  786. });
  787. uni.setStorage({
  788. key: 'engineeringMaterials',
  789. data: _this.engineeringMaterials
  790. });
  791. uni.setStorage({
  792. key: 'outtypeName',
  793. data: _this.outtypeName
  794. });
  795. uni.setStorage({
  796. key: 'outtypeCode',
  797. data: _this.outtypeCode
  798. });
  799. uni.setStorage({
  800. key: 'materials',
  801. data: _this.materials
  802. });
  803. },
  804. getTemp(_this) { //获取缓存,重新给表单赋值
  805. if (uni.getStorageSync('intypeCode')) {
  806. _this.intypeCode = uni.getStorageSync('intypeCode');
  807. _this.intypeName = uni.getStorageSync('intypeName');
  808. _this.inDate = uni.getStorageSync('inDate');
  809. _this.contractCode = uni.getStorageSync('contractCode');
  810. _this.contractName = uni.getStorageSync('contractName');
  811. _this.supplierCode = uni.getStorageSync('supplierCode');
  812. _this.supplierName = uni.getStorageSync('supplierName');
  813. _this.supplierCode = uni.getStorageSync('supplierCode');
  814. _this.usercode = uni.getStorageSync('usercode');
  815. _this.contract = uni.getStorageSync('contract');
  816. _this.engineeringContractCode = uni.getStorageSync('engineeringContractCode');
  817. _this.engineeringContractName = uni.getStorageSync('engineeringContractName');
  818. _this.engineeringContract=uni.getStorageSync("engineeringContract");
  819. _this.engineeringError = uni.getStorageSync('engineeringError');
  820. _this.engineeringMaterials = uni.getStorageSync('engineeringMaterials');
  821. _this.outtypeCode = uni.getStorageSync('outtypeCode');
  822. _this.outtypeName = uni.getStorageSync('outtypeName');
  823. _this.materials=uni.getStorageSync("materials");
  824. }
  825. },
  826. }
  827. }
  828. </script>
  829. <style scoped>
  830. /* 头条小程序组件内不能引入字体 */
  831. /* #ifdef MP-TOUTIAO */
  832. @font-face {
  833. font-family: uniicons;
  834. font-weight: normal;
  835. font-style: normal;
  836. src: url("~@/static/uni.ttf") format("truetype");
  837. }
  838. /* #endif */
  839. page {
  840. display: flex;
  841. flex-direction: column;
  842. box-sizing: border-box;
  843. background-color: #efeff4;
  844. min-height: 100%;
  845. height: auto;
  846. }
  847. view {
  848. font-size: 14px;
  849. line-height: inherit;
  850. }
  851. .uni-form-item__title {
  852. font-size: 16px;
  853. line-height: 24px;
  854. }
  855. .uni-input-wrapper {
  856. /* #ifndef APP-NVUE */
  857. display: flex;
  858. /* #endif */
  859. padding: 8px 13px;
  860. flex-direction: row;
  861. flex-wrap: nowrap;
  862. background-color: #FFFFFF;
  863. }
  864. .title {
  865. background-color: #efefef;
  866. padding: 5px 20px;
  867. }
  868. .uni-input {
  869. height: 28px;
  870. line-height: 28px;
  871. font-size: 15px;
  872. padding: 5px;
  873. flex: 1;
  874. background-color: #FFFFFF;
  875. }
  876. .uni-input-small {
  877. height: 28px;
  878. line-height: 28px;
  879. font-size: 15px;
  880. padding: 5px;
  881. flex: 1;
  882. width: 270px;
  883. background-color: #FFFFFF;
  884. }
  885. .uni-icon {
  886. height: 28px;
  887. line-height: 28px;
  888. font-size: 20px;
  889. padding-right: 15px;
  890. color: #5555ff;
  891. width: 50px;
  892. }
  893. .uni-eye-active {
  894. color: #007AFF;
  895. }
  896. .uni-btn-v {
  897. position: fixed;
  898. bottom: 0;
  899. width: 100%;
  900. }
  901. .header-slot-box {
  902. font-size: 15px;
  903. margin: 5px 5px;
  904. width: 20%;
  905. justify-content: center;
  906. }
  907. .body-slot-box {
  908. font-size: 15px;
  909. margin: 5px 5px;
  910. width: 40%;
  911. justify-content: center;
  912. }
  913. .footer-slot-box {
  914. font-size: 15px;
  915. margin: 5px 5px;
  916. width: 40%;
  917. justify-content: center;
  918. }
  919. .uni-textarea textarea {
  920. font-size: 15px;
  921. }
  922. .content {
  923. padding: 40rpx;
  924. background-color: #fff;
  925. }
  926. /* 上传控件 */
  927. .uploadControl {
  928. border: 1rpx solid #eee;
  929. border-radius: 10rpx;
  930. width: 130rpx;
  931. display: block;
  932. height: 130rpx;
  933. text-align: center;
  934. line-height: 130rpx;
  935. font-size: 30rpx;
  936. color: #888;
  937. background-color: #eeeeee;
  938. }
  939. .bg1 {
  940. background-color: #EFEFEF;
  941. }
  942. </style>