SafeQualityCheckEdit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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="projectName" />
  8. </view>
  9. </view>
  10. <view class="uni-form-item uni-column" v-show="type==2">
  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="selector" :value="index" :range="array" range-key="name" @change="bindPickerChange" v-model="inspectType" style="width: 100%;">
  14. <view class="uni-input">{{array.length>0?array[index]:''}}</view>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="uni-form-item uni-column">
  19. <view class="title"><text class="uni-form-item__title">检查日期</text></view>
  20. <view class="uni-input-wrapper" style="justify-content: left;">
  21. <picker mode="date" @change="bindDateChange" v-model="checkDate" style="width: 100%;">
  22. <view class="uni-input">{{checkDate}}</view>
  23. </picker>
  24. </view>
  25. </view>
  26. <view class="uni-form-item uni-column">
  27. <view class="title" style="background-color: #efefef;"><text class="uni-form-item__title">上传文件</text></view>
  28. <view class="content">
  29. <g-upfile ref='gUpfile' :mode="imgList" @chooseFile='chooseFile' @imgDelete='imgDelete' :control='control'
  30. :columnNum="columnNum" :maxCount="maxCount" @limitFileSizeList='limitFileSizeList' @limitFileTypeList='limitFileTypeList' :maxFileSize="20000"></g-upfile>
  31. </view>
  32. </view>
  33. <uni-section :title="detailTitle" type="line">
  34. <button type="default" @click="getRelationItem" size="mini">选择检查项</button>
  35. </uni-section>
  36. <uni-list>
  37. <uni-list-item v-if="itemList" v-for="(item, index) in itemList" :key="index">
  38. <view slot="body" class="slot-box parent-container">
  39. <i class="fa fa-window-close iconClose" aria-hidden="true" @click="delRow(index)" title="删除"></i>
  40. <view class="row">
  41. <view class="column-left">检查项目:</view>
  42. <view class="column-right">{{item.checkContent}}</view>
  43. </view>
  44. <view class="row">
  45. <view class="column-left">检查结果:</view>
  46. <view class="column-right">
  47. <textarea focus v-model="item.checkResult" class="textAreaBorder" placeholder="请输入检查结果" />
  48. </view>
  49. </view>
  50. </view>
  51. </uni-list-item>
  52. </uni-list>
  53. <view style="margin-bottom: 120px;">
  54. </view>
  55. <view class="uni-btn-v uni-column">
  56. <button type="primary" form-type="submit" style="border-radius: 15px;" >提交</button>
  57. </view>
  58. </uni-forms>
  59. </view>
  60. </template>
  61. <script>
  62. import {GetSafeQualityCheckDTO,UpdateSafeQualityCheck} from "@/common/api/SafeQualityCheckApi.js";
  63. import {Decimal} from 'decimal.js'; //decimal计算
  64. export default {
  65. data() {
  66. return {
  67. projectName:'',
  68. inspectType:'',
  69. checkDate:this.$util.getDate({
  70. format: true
  71. }),
  72. entity:{}, //主表对象
  73. itemList:[], //检查明细
  74. imageList: [],
  75. checkType:0, //核对质量安全检查项与主表的类型是否一致
  76. detailTitle:'',
  77. type:0, //检查项目类型
  78. countIndex: 5,
  79. count: [1, 2, 3, 4, 5],
  80. title1: 'picker',
  81. array: ['','抽检','封样'],
  82. index: 0,
  83. control: true,
  84. columnNum: 3,
  85. imgList: [],
  86. urlList:[],
  87. maxCount:5
  88. }
  89. },
  90. onLoad(){
  91. //console.info(page.path);
  92. //console.info(this);
  93. this.$util.persistLogin(this);
  94. //console.info(this.$store.state.user);
  95. },
  96. onUnload() {
  97. },
  98. created: function() {
  99. this.getList();
  100. },
  101. updated:function(){
  102. console.info('updated');
  103. //this.auditType();
  104. },
  105. methods: {
  106. /**
  107. * 手动提交
  108. * @param {Object} form
  109. */
  110. submitForm(e) {
  111. console.info('submitForm');
  112. let _this=this;
  113. if(this.projectName==='')
  114. {
  115. uni.showToast({
  116. icon:"none",
  117. title:"请填写工程名称",
  118. duration:3000
  119. });
  120. return;
  121. }
  122. if(this.type==2){
  123. if(this.$util.isEmpty(this.inspectType) ){
  124. uni.showToast({
  125. icon:"none",
  126. title:"请选择检查类型",
  127. duration:3000
  128. });
  129. return;
  130. }
  131. }
  132. if(this.checkDate==='')
  133. {
  134. uni.showToast({
  135. icon:"none",
  136. title:"请选择检查日期",
  137. duration:3000
  138. });
  139. return;
  140. }
  141. if(this.itemList.length<=0){
  142. uni.showToast({
  143. icon:"none",
  144. title:"请选择质量安全检查项",
  145. duration:3000
  146. });
  147. return;
  148. }
  149. let list=[];
  150. let itemNames=[];
  151. this.itemList.forEach(function(item,index,arr){
  152. if(item.checkResult==null||item.checkResult==''){
  153. itemNames.push(item.checkContent);
  154. return;
  155. }
  156. list.push({checkContent:item.checkContent,checkResult:item.checkResult,dictionaryItemCode:item.dictionaryItemCode,dictionaryNameCode:item.dictionaryNameCode });
  157. });
  158. if(itemNames.length>0){
  159. uni.showToast({
  160. title:itemNames[0]+' 检查结果不能为空',
  161. duration:3000,
  162. icon:"none"
  163. });
  164. return;
  165. }
  166. let inspectType=""; //检查类型
  167. if(this.type==2){
  168. inspectType=this.inspectType;
  169. }
  170. //vise viseCosts
  171. var data1={checkCode:this.entity.checkCode,projectName:this.projectName,checkDate:this.checkDate,inspectType:inspectType };
  172. var data={SafeQualityCheck:data1,ItemList:list};
  173. console.info('data:',data);
  174. //return;
  175. UpdateSafeQualityCheck(data).then((res)=>{
  176. console.info("提交后的response",res);
  177. if(res){
  178. if(res=="-1"){
  179. uni.showToast({
  180. title:'修改失败,记录不存在',
  181. icon:'none',
  182. duration:3000
  183. });
  184. return;
  185. }
  186. if(res=="-2"){
  187. uni.showToast({
  188. title:'非申请状态,不能修改',
  189. icon:'none',
  190. duration:3000
  191. });
  192. return;
  193. }
  194. if(res=="-3"){
  195. uni.showToast({
  196. title:'所选检查项目类型与工程所属项目类型不一致',
  197. icon:'none',
  198. duration:3000
  199. });
  200. return;
  201. }
  202. //上传图片
  203. _this.uploadFileToServe(res) ;
  204. uni.navigateTo({
  205. url:'/pages/template/GetSafeQualityCheckDTOs/GetSafeQualityCheckDTOs?type='+_this.type
  206. })
  207. }
  208. else{
  209. uni.showToast({
  210. title:'修改失败,重新操作',
  211. icon:'none',
  212. duration:3000
  213. })
  214. }
  215. });
  216. },
  217. /* 获取质量安全检查主表和明细表的信息*/
  218. getList(){
  219. let _this=this;
  220. let checkcode=_this.$util.getQuery("id");
  221. //console.info('getList',_this.$util.getQuery("id"));
  222. if(!checkcode){
  223. uni.showToast({
  224. title:'参数错误',
  225. icon:'none',
  226. duration:3000
  227. });
  228. return;
  229. }
  230. GetSafeQualityCheckDTO(checkcode).then(res=>{
  231. console.info('GetSafeQualityCheckDTO',res);
  232. _this.projectName=res.entity.projectName;
  233. _this.checkDate=res.entity.checkDate.substring(0,10);
  234. _this.inspectType=res.entity.inspectType;
  235. if(_this.inspectType=="抽检"){
  236. _this.index=1;
  237. }
  238. else if(_this.inspectType=="封样"){
  239. _this.index=2;
  240. }
  241. _this.entity=res.entity;
  242. _this.itemList=res.list;
  243. let title='';
  244. if(_this.entity.checkType=='SafeCheck'){
  245. title='安全检查修改';
  246. _this.detailTitle='安全检查项目';
  247. _this.type=1;
  248. }
  249. else if(_this.entity.checkType=='QualityCheck'){
  250. title='质量检查修改';
  251. _this.detailTitle='质量检查项目';
  252. _this.type=0;
  253. }
  254. else if(_this.entity.checkType=='MaterialCheck'){
  255. title='材料检查修改';
  256. _this.detailTitle='材料检查项目';
  257. _this.type=2;
  258. }
  259. uni.setNavigationBarTitle({
  260. title:title
  261. });
  262. });
  263. },
  264. auditType(){
  265. if(this.checkType==1){
  266. console.info('jinru1');
  267. uni.showToast({
  268. title:'此修改项是安全检查,不能选择质量检查项',
  269. icon:'none',
  270. duration:3000
  271. });
  272. console.info('jinru1结束');
  273. //this.checkType=0;
  274. }
  275. else if(this.checkType==2){
  276. console.info('jinru2');
  277. uni.showToast({
  278. title:'此修改项是质量检查,不能选择安全检查项',
  279. icon:'none',
  280. duration:3000
  281. });
  282. //this.checkType=0;
  283. }
  284. },
  285. /*
  286. 获取关联项
  287. */
  288. getRelationItem() {
  289. let _this = this;
  290. _this.saveTemp(_this);
  291. //console.info("getRelationItem", _this.$util.getQuery("id"));
  292. let checkCode=_this.$util.getQuery("id");
  293. //创建名字为fire的监听器,监听子页面传值事件
  294. uni.$on('items', function(data) {
  295. console.info("监听getRelationItem子页面的传值", data);
  296. //console.info('监听',_this);
  297. //return;
  298. _this.getTemp(_this);
  299. let itemList=_this.itemList;
  300. let result=[];
  301. if(data) {
  302. //console.info("转换id",_this.$util.getQuery("id"));
  303. //转换
  304. data.forEach(function(item,index,arr){
  305. result.push({checkCode:checkCode,checkContent:item.diName,checkResult:'',dictionaryItemCode:item.diCode,dictionaryNameCode:item.dnCode});
  306. });
  307. console.info("转换",result);
  308. //return;
  309. //let checkType=0;
  310. result.forEach(function(item,index,arr){
  311. item.remark='';
  312. _this.itemList.push(item);
  313. });
  314. console.info("监听后的明细增加",_this.itemList);
  315. }
  316. //接收一次监听,一旦监听到回传值,则清除监听事件,若不清除,会占用资源
  317. uni.$off("items");
  318. });
  319. uni.navigateTo({
  320. url: '/pages/template/SelectCheckProject/SelectCheckProject?type='+_this.type
  321. });
  322. },
  323. delRow: function(index) {
  324. console.info("删除");
  325. console.info(this.itemList[index]);
  326. this.itemList.splice(index, 1);
  327. },
  328. bindPickerChange: function(e) {
  329. //console.log('picker发送选择改变,携带值为:' + e.detail.value);
  330. //console.info(e.detail);
  331. this.index = e.detail.value;
  332. this.inspectType=this.array[this.index];
  333. console.info(this.inspectType);
  334. },
  335. bindDateChange: function(e) {
  336. let date = e.detail.value;
  337. this.checkDate=date;
  338. console.info('bindDateChange',this.checkDate);
  339. },
  340. /*
  341. 上传后返回的值:
  342. list:上传后图片数组
  343. v:返回当前上传图片的临时路径
  344. */
  345. chooseFile(list, v) {
  346. console.log("上传图片_list:", list)
  347. console.log("上传图片_v:", v);
  348. this.urlList=list;
  349. console.info("urlList",this.urlList);
  350. },
  351. /*
  352. 删除图片:
  353. list:删除返回删除后剩余的图片数组
  354. eq:返回删除的数组
  355. */
  356. imgDelete(list, eq) {
  357. console.log("删除图片_list:", list);
  358. console.log("删除图片_eq:", eq);
  359. this.urlList=list;
  360. console.info("urlList",this.urlList);
  361. },
  362. /*限制文件大小列表*/
  363. limitFileSizeList(list){
  364. console.info('limitFileSizeList:',list);
  365. if(list){
  366. if(list.length>0){
  367. uni.showModal({
  368. title:'警告',
  369. content: list.join()+' 文件大小超过2000KB',
  370. showCancel:false
  371. });
  372. }
  373. }
  374. },
  375. /*限制文件类型列表*/
  376. limitFileTypeList(list,allowFileType){
  377. console.info('limitFileTypeList:',list);
  378. console.info('limitFileTypeList:',allowFileType);
  379. if(list){
  380. if(list.length>0){
  381. uni.showModal({
  382. title:'警告',
  383. content: list.join()+' 文件类型必须是'+allowFileType.join(),
  384. showCancel:false
  385. });
  386. }
  387. }
  388. },
  389. /*
  390. 执行上传服务:
  391. urlList:要上传的图片:数组类型
  392. */
  393. uploadFileToServe(code) {
  394. console.info('uploadFileToServe',code)
  395. let _this=this;
  396. var urlList=_this.urlList;
  397. if (!urlList || urlList.length <= 0) {
  398. return;
  399. };
  400. //console.info(urlList);
  401. for (let i = 0; i < urlList.length; i++) {
  402. uni.uploadFile({
  403. url: '/api/Common/UploadImage',
  404. filePath: urlList[i],
  405. name: 'file',
  406. formData: {
  407. createPerson:_this.$store.state.user.userCode,
  408. masterCode:code,
  409. attachMentType:_this.entity.checkType
  410. },
  411. headers: {
  412. 'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
  413. //这里要把content-type设置为multipard/form-data,同时还要设置boundary
  414. },
  415. success: (uploadFileRes) => {
  416. console.log("图片上传:",uploadFileRes.data);
  417. }
  418. });
  419. }
  420. //return;
  421. },
  422. saveTemp(_this){ //临时存
  423. uni.setStorage({
  424. key:'projectName',
  425. data:_this.projectName
  426. });
  427. uni.setStorage({
  428. key:'checkDate',
  429. data:_this.checkDate
  430. });
  431. uni.setStorage({
  432. key:'itemList',
  433. data:_this.itemList
  434. });
  435. },
  436. getTemp(_this){ //获取缓存,重新给表单赋值
  437. _this.projectName=uni.getStorageSync('projectName');
  438. _this.checkDate=uni.getStorageSync('checkDate');
  439. _this.itemList=uni.getStorageSync('itemList');
  440. }
  441. }
  442. }
  443. </script>
  444. <style scoped>
  445. /* 头条小程序组件内不能引入字体 */
  446. /* #ifdef MP-TOUTIAO */
  447. @font-face {
  448. font-family: uniicons;
  449. font-weight: normal;
  450. font-style: normal;
  451. src: url("~@/static/uni.ttf") format("truetype");
  452. }
  453. /* #endif */
  454. page {
  455. display: flex;
  456. flex-direction: column;
  457. box-sizing: border-box;
  458. background-color: #efeff4;
  459. min-height: 100%;
  460. height: auto;
  461. }
  462. view {
  463. font-size: 14px;
  464. line-height: inherit;
  465. }
  466. .uni-form-item__title {
  467. font-size: 16px;
  468. line-height: 24px;
  469. }
  470. .uni-input-wrapper {
  471. /* #ifndef APP-NVUE */
  472. display: flex;
  473. /* #endif */
  474. padding: 8px 13px;
  475. flex-direction: row;
  476. flex-wrap: nowrap;
  477. background-color: #FFFFFF;
  478. }
  479. .title{
  480. background-color: #efefef;
  481. }
  482. .uni-input {
  483. height: 28px;
  484. line-height: 28px;
  485. font-size: 15px;
  486. padding: 0px;
  487. flex: 1;
  488. background-color: #FFFFFF;
  489. }
  490. .uni-icon {
  491. font-family: uniicons;
  492. font-size: 24px;
  493. font-weight: normal;
  494. font-style: normal;
  495. width: 24px;
  496. height: 24px;
  497. line-height: 24px;
  498. margin-left:15px;
  499. color: #999999;
  500. }
  501. .uni-eye-active {
  502. color: #007AFF;
  503. }
  504. .uni-btn-v{
  505. position: fixed;
  506. bottom: 0;
  507. width:100%;
  508. }
  509. .header-slot-box {
  510. font-size:15px;
  511. margin: 5px 5px;
  512. width:20%;
  513. justify-content: center;
  514. }
  515. .body-slot-box {
  516. font-size:15px;
  517. margin: 5px 5px;
  518. width:40%;
  519. justify-content: center;
  520. }
  521. .footer-slot-box {
  522. font-size:15px;
  523. margin: 5px 5px;
  524. width:40%;
  525. justify-content: center;
  526. }
  527. .uni-textarea textarea{
  528. font-size:15px;
  529. }
  530. .content {
  531. padding: 40rpx;
  532. background-color: #fff;
  533. }
  534. /* 上传控件 */
  535. .uploadControl {
  536. border: 1rpx solid #eee;
  537. border-radius: 10rpx;
  538. width: 130rpx;
  539. display: block;
  540. height: 130rpx;
  541. text-align: center;
  542. line-height: 130rpx;
  543. font-size: 30rpx;
  544. color: #888;
  545. background-color: #eeeeee;
  546. }
  547. .topicon >>> .icon{
  548. border: #4CD964 2upx solid;
  549. }
  550. .textAreaBorder{
  551. width: 240px;
  552. text-align: left;
  553. height: 80px;
  554. border:1px solid #10AEFF;
  555. }
  556. /deep/ uni-textarea{
  557. font-size:12px;
  558. }
  559. .iconClose{
  560. font-size:20px;
  561. cursor: pointer;
  562. color: #999;
  563. /* 绝对定位只有配合父容器的相对定位,才能达到预想效果 */
  564. position: absolute;
  565. right: -20rpx;
  566. top: 47rpx;
  567. }
  568. .parent-container{
  569. margin-left: 20rpx;
  570. /* 父容器必须是相对定位,子容器的绝对定位才能达到预想效果 */
  571. position: relative;
  572. width: 100%;
  573. padding-top: 38rpx;
  574. }
  575. .column-right{
  576. text-align: left;
  577. }
  578. </style>