SafeQualityCheckEdit.vue 15 KB

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