edit_drill.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view class=" uni-container" v-if="formData.orgName">
  3. <view class="example container" :style="'height: ' + (screenHeight - wheight - 75) + 'px'">
  4. <!-- 自定义表单校验 1-->
  5. <u--form ref="customForm" :rules="customRules" :model="formData" labelPosition="left" labelWidth="150" labelAlign="left">
  6. <view class=" flex flex-direction width100">
  7. <u-form-item label="培训演练标题 " prop="drillTitle" :required="true">
  8. <u-input v-model="formData.drillTitle" placeholder="请输入培训演练标题" />
  9. </u-form-item>
  10. <u-form-item
  11. label="所属单位"
  12. @click="
  13. showSex5 = true;
  14. hideKeyboard();
  15. "
  16. prop="orgName"
  17. :required="true">
  18. <u--input v-model="formData.orgName" disabled disabledColor="#ffffff" placeholder="请选择所属单位"></u--input>
  19. </u-form-item>
  20. <u-form-item
  21. :required="true"
  22. label="记录类型"
  23. prop="drillType"
  24. @click="
  25. showSex = true;
  26. hideKeyboard();
  27. "
  28. >
  29. <u--input v-model="formData.drillTypeName" disabled disabledColor="#ffffff" placeholder="请选择记录类型"></u--input>
  30. </u-form-item>
  31. <u-form-item label="培训演练内容 " prop="drillContent">
  32. <u-textarea auto-height maxlength=-1 v-model="formData.drillContent" placeholder="请输入培训演练内容"></u-textarea>
  33. </u-form-item>
  34. <u-form-item label="培训演练时间" prop="drillDate">
  35. <uni-datetime-picker
  36. :show="unitTime"
  37. v-model="formData.drillDate"
  38. type="datetime"
  39. closeOnClickOverlay
  40. @confirm="ActiveUnitTime"
  41. @cancel="unitTime = false"
  42. @change="changetime"
  43. @close="unitTime = false"
  44. ></uni-datetime-picker>
  45. </u-form-item>
  46. <u-form-item label="培训演练地点" prop="drillPlace">
  47. <u-input v-model="formData.drillPlace" placeholder="请输入培训演练地点" />
  48. </u-form-item>
  49. <u-form-item label="培训演练讲师">
  50. <u-input v-model="formData.drillLecturer" placeholder="请输入培训演练讲师" />
  51. </u-form-item>
  52. <u-form-item label="参与人员数量">
  53. <u-input v-model="formData.participant" placeholder="请输入参与人员数量" />
  54. </u-form-item>
  55. <u-form-item label="附件">
  56. <!-- 选择文件上传 -->
  57. <uni-file-picker
  58. v-model="formData.File"
  59. del-icon
  60. limit="1"
  61. auto-upload
  62. file-mediatype="all"
  63. @select="select"
  64. @delete="deleteFile"
  65. >
  66. <button type="primary" class="selectBtn">选择附件</button>
  67. <!-- 加载中 -->
  68. <isLodingModel v-if="loading"></isLodingModel>
  69. </uni-file-picker>
  70. </u-form-item>
  71. </view>
  72. </u--form>
  73. <u-action-sheet
  74. :show="showSex"
  75. :actions="actions2"
  76. title="记录类型"
  77. @close="showSex = false"
  78. @select="sexSelect2"
  79. ></u-action-sheet>
  80. <u-action-sheet
  81. :show="showSex5"
  82. :actions="actions5"
  83. title="请选择单位"
  84. @close="showSex5 = false"
  85. @select="sexSelect5"
  86. ></u-action-sheet>
  87. </view>
  88. <uni-row class="heigthButton">
  89. <u-button
  90. @click="submit('customForm')"
  91. type="primary"
  92. shape="circle"
  93. size="large"
  94. color="#4CB2B6"
  95. text="确认修改"
  96. ></u-button>
  97. </uni-row>
  98. </view>
  99. </template>
  100. <script>
  101. import {
  102. updateDrill,// 更新
  103. getOrgId,
  104. upload, //上传文件
  105. } from '@/api/drill';
  106. import { DICT_TYPE, getDictDatas } from '@/utils/dict';
  107. import { getAccessToken } from '@/utils/auth';
  108. import config from '@/config';
  109. import store from '@/store';
  110. import { uploadAvatar } from '@/api/system/user';
  111. const baseUrl = config.baseUrl;
  112. var that = null;
  113. export default {
  114. data() {
  115. return {
  116. showSex: false, //有无避难层
  117. showSex5: false, //所属单位
  118. actions: [],
  119. actions2: getDictDatas(DICT_TYPE.TRAIN_DRILL),
  120. actions5: [],
  121. // 每页数据量
  122. pageSize: 5,
  123. // 当前页
  124. pageNo: 1,
  125. // 数据总量
  126. total: 0,
  127. unitTime:false,
  128. loading: false,
  129. title: '生成隐患',
  130. content: '确认将此检查项目生成为隐患',
  131. // 自定义表单数据
  132. formData: {
  133. status: '0',
  134. File:[]
  135. },
  136. // 自定义表单校验规则
  137. customRules: {
  138. drillTitle: {
  139. type: 'string',
  140. required: true,
  141. message: '培训演练标题不能为空',
  142. trigger: ['blur', 'change']
  143. },
  144. drillType: {
  145. type: 'string',
  146. message: '记录类型不能为空',
  147. trigger: ['blur', 'change']
  148. },
  149. },
  150. screenHeight: this.$screenHeight,
  151. wheight: ''
  152. };
  153. },
  154. computed: {},
  155. mounted() {
  156. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  157. this.wheight = data.height
  158. }).exec()
  159. },
  160. watch: {
  161. loading: {
  162. handler(newLength, oldLength) {
  163. this.$modal.isLoadingModel(this.loading)
  164. },
  165. immediate: true
  166. }
  167. },
  168. onLoad: function(option) {
  169. this.actions2.map(i => {
  170. i.name = i.label;
  171. i.id = i.value;
  172. });
  173. // 在 vue页面,向起始页通过事件传递数据
  174. var data = option.id;
  175. that = this;
  176. const eventChannel = this.getOpenerEventChannel();
  177. eventChannel.on('acceptDataFromOpenerPage', function(val) {
  178. that.formData = val;
  179. console.log(val,'val33333333333');
  180. var File = that.formData.File = []
  181. if(that.formData.attId !='' ){
  182. File.push({
  183. url: that.formData.attId,
  184. name: that.formData.attId
  185. });
  186. }else{
  187. File =null
  188. }
  189. console.log('edit页面的val的值', that.formData);
  190. if(that.formData.drillType == 1){
  191. that.formData.drillTypeName = '培训'
  192. }else if(that.formData.drillType == 2){
  193. that.formData.drillTypeName = '演练'
  194. }
  195. });
  196. // 获取单位id
  197. getOrgId({
  198. pageNo: this.pageNo,
  199. pageSize: this.pageSize,
  200. userId: this.$store.state.user.id
  201. }).then(response => {
  202. console.log(response, 'response');
  203. // 取到用户对应的单位名称与id
  204. response.data.map(v => {
  205. if(this.formData.orgId==v.dwid){
  206. this.formData.orgName=v.orgName
  207. }
  208. this.actions5.push({
  209. id: v.id,
  210. name: v.orgName
  211. });
  212. });
  213. });
  214. },
  215. onReady() {
  216. this.$refs.customForm.setRules(this.customRules);
  217. },
  218. methods: {
  219. submit(ref) {
  220. this.$refs[ref]
  221. .validate()
  222. .then(res => {
  223. this.formData['status'] = 0;
  224. if(this.formData.File.length!=0&&this.formData.File[0].url){
  225. this.formData.attId = this.formData.File[0].url.toString();
  226. }else{
  227. this.formData.attId=''
  228. }
  229. if(this.formData.drillDate&&this.formData.drillDate.indexOf(":") === -1){
  230. this.formData.drillDate= this.formData.drillDate + ' 00:00:00'
  231. }
  232. var jsdata = JSON.stringify(this.formData);
  233. console.log(jsdata, 'jsdatajsdatajsdata');
  234. updateDrill(jsdata).then(response => {
  235. console.log('response.data.msg,', response.data);
  236. uni.showLoading({
  237. title: response.data.msg
  238. });
  239. setTimeout(() => {
  240. console.log('修改成功!');
  241. uni.hideLoading();
  242. uni.navigateBack({
  243. delta:2
  244. })
  245. }, 0);
  246. });
  247. })
  248. .catch(err => {
  249. console.log('err错误信息为:', err);
  250. uni.showToast({
  251. icon:'none',
  252. title:'错误!'+ err[0].message
  253. })
  254. });
  255. },
  256. // 上传图片 获取上传状态
  257. // 选择上传触发函数
  258. select(e) {
  259. // 根据所选图片的个数,多次调用上传函数
  260. let promises = [];
  261. for (let i = 0; i < e.tempFilePaths.length; i++) {
  262. const promise = this.uploadFiles(e.tempFilePaths, i);
  263. promises.push(promise);
  264. }
  265. Promise.all(promises).then(result => {});
  266. },
  267. // 上传函数
  268. async uploadFiles(tempFilePaths, i) {
  269. const that = this;
  270. this.loading = true
  271. await uni.uploadFile({
  272. url: baseUrl + '/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
  273. filePath: tempFilePaths[i],
  274. name: 'file',
  275. header: {
  276. Authorization: 'Bearer ' + getAccessToken()
  277. }, //请求token
  278. success: res => {
  279. console.log('res', res);
  280. let data = JSON.parse(res.data);
  281. // 返回的url
  282. var fileLink = data.data;
  283. const code = data.code;
  284. // 如果成功,将返回的data数据给 formdata
  285. if (code == 0) {
  286. that.formData.File.push({
  287. url: fileLink,
  288. name: fileLink
  289. });
  290. uni.showToast({
  291. title: '文件上传成功!'
  292. });
  293. that.loading = false
  294. // that.formData.attId = fileLink
  295. }
  296. // this.formData.attId = this.formData.attId.toString();
  297. },
  298. fail: () => {
  299. console.log('err');
  300. uni.showToast({
  301. icon:'error',
  302. title: '文件上传失败!'
  303. });
  304. }
  305. });
  306. },
  307. // 移出图片函数
  308. async deleteFile(e) {
  309. console.log(e);
  310. this.formData.attId = '';
  311. console.log('移除了:', this.formData.attId);
  312. },
  313. // 隐藏键盘
  314. hideKeyboard() {
  315. uni.hideKeyboard();
  316. },
  317. // 记录类型
  318. sexSelect2(e) {
  319. this.formData.drillType = e.value;
  320. this.formData.drillTypeName = e.label;
  321. console.log(this.formData.drillType );
  322. },
  323. // 单位成立时间
  324. ActiveUnitTime(e) {
  325. this.unitTime = false;
  326. console.log(e.value, e.mode);
  327. let value = new Date(e.value);
  328. this.formData.drillDate = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM');
  329. },
  330. changetime(e) {
  331. console.log('change', e);
  332. },
  333. // 所属单位
  334. sexSelect5(e) {
  335. this.formData.orgId = e.id;
  336. this.formData.orgName = e.name;
  337. console.log(this.formData.orgId);
  338. },
  339. // 生成隐患弹出层 //暂存为草稿箱弹出层
  340. cancel() {
  341. this.show = false;
  342. },
  343. confirm() {
  344. setTimeout(() => {
  345. // 0.5秒后自动关闭
  346. this.show = false;
  347. }, 500);
  348. },
  349. // 触底的事件
  350. scrolltolower() {
  351. // 判断是否还有下一页数据
  352. if (this.pageNo * this.pageSize >= this.total)
  353. return uni.showToast({
  354. title: `数据加载完毕`
  355. });
  356. // 判断是否正在请求其它数据,如果是,则不发起额外的请求
  357. if (this.loading) return;
  358. this.pageNo += 1;
  359. this.showCheckboxShow(this.pageNo);
  360. }
  361. }
  362. };
  363. </script>
  364. <style lang="scss" scoped>
  365. page {
  366. height: 100%;
  367. background-color: #f5f7f9;
  368. position: relative;
  369. }
  370. .buttomBorder {
  371. height: 0px;
  372. border: 1px dashed #cbd5e1;
  373. }
  374. /deep/ .uni-section .uni-section-header {
  375. padding: 0px;
  376. }
  377. /deep/ .u-form-item__body {
  378. font-weight: 500;
  379. flex-direction: column !important;
  380. }
  381. /deep/ .u-form-item__body__left__content__label {
  382. margin-bottom: 16rpx;
  383. font-size: 30rpx !important;
  384. color: #274647 !important;
  385. }
  386. .arrow-icon {
  387. //主动检查箭头
  388. position: absolute;
  389. right: 14px;
  390. top: 49px;
  391. transform: rotate(90deg);
  392. }
  393. /deep/ .u-input[data-v-fdbb9fe6],
  394. /deep/ .u-input.data-v-fdbb9fe6,/deep/ .u-input {
  395. background-color: #fff;
  396. }
  397. /deep/.u-button[data-v-3bf2dba7],
  398. /deep/.u-button.data-v-3bf2dba7,/deep/.u-button{
  399. width: 60% !important;
  400. }
  401. //弹框样式
  402. .btnList {
  403. // width: 40%;
  404. display: flex;
  405. // display:flex;
  406. .u-button[data-v-3bf2dba7] {
  407. width: 30%;
  408. }
  409. }
  410. /deep/ .u-popup__content {
  411. //弹出的宽高
  412. height: 100%;
  413. }
  414. /deep/ .u-form-item__body__right__message {
  415. //校验的文字的位置
  416. margin-left: 10rpx !important;
  417. }
  418. /deep/ .uicon-close {
  419. //关闭按钮背景色
  420. background-color: rgba(199, 203, 210, 0.9);
  421. border-radius: 10%;
  422. }
  423. .checkbox {
  424. .checkbox-item {
  425. box-sizing: border-box;
  426. padding-top: 40px;
  427. }
  428. }
  429. //侧边联动
  430. .page-body {
  431. display: flex;
  432. background: #fff;
  433. overflow: hidden;
  434. }
  435. .nav {
  436. display: flex;
  437. width: 100%;
  438. }
  439. .nav-left {
  440. width: 25%;
  441. background: #fafafa;
  442. }
  443. .nav-left-item {
  444. height: 100upx;
  445. border-right: solid 1px #f1f1f1;
  446. border-bottom: solid 1px #f1f1f1;
  447. font-size: 30upx;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. }
  452. /deep/.nav-right-item[data-v-73caef23],/deep/.nav-right-item {
  453. display: flex;
  454. flex-wrap: wrap;
  455. }
  456. .nav-left-item:last-child {
  457. border-bottom: none;
  458. }
  459. .nav-right {
  460. width: 75%;
  461. }
  462. .box {
  463. display: block;
  464. overflow: hidden;
  465. border-bottom: 20upx solid #f3f3f3;
  466. /* min-height: 100vh; */
  467. /*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
  468. }
  469. .box:last-child {
  470. border: none;
  471. // min-height: 100vh;
  472. }
  473. .nav-right-item {
  474. margin-top: 20px;
  475. // width: 28%;
  476. // min-height: 200upx;
  477. float: left;
  478. text-align: center;
  479. padding: 11upx;
  480. font-size: 28upx;
  481. background: #fff;
  482. /deep/.u-checkbox__icon-wrap[data-v-532d01c7],/deep/.u-checkbox__icon-wrap {
  483. //复选框的样式
  484. margin: 0 20rpx;
  485. }
  486. /deep/ uni-view[data-v-3d1b15f2] {
  487. //复选框上线的间距
  488. margin: 20rpx 0 !important;
  489. }
  490. // /deep/ .u-checkbox__icon-wrap--square{
  491. // margin: 20rpx;
  492. // }
  493. .u-checkbox-label--right[data-v-532d01c7],.u-checkbox-label--right {
  494. margin-right: 40rpx;
  495. }
  496. }
  497. .nav-right-item image {
  498. width: 150upx;
  499. height: 150upx;
  500. }
  501. .active {
  502. font-weight: 700;
  503. color: #274647;
  504. background: #fff;
  505. border-right: 0;
  506. }
  507. ::-webkit-scrollbar {
  508. /*取消小程序的默认导航条样式*/
  509. width: 0;
  510. height: 0;
  511. color: transparent;
  512. }
  513. .selectBtn {
  514. width: 200rpx;
  515. margin-left: 0;
  516. font-size: 30rpx;
  517. background-color: #4cb2b6;
  518. }
  519. /deep/.u-action-sheet {
  520. overflow-y: auto;
  521. height: 1000rpx;
  522. background-color: #fff;
  523. }
  524. .example{
  525. overflow-y: auto;
  526. }
  527. </style>