MaterialInAdd.vue 18 KB

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