edit_drill.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. var File = that.formData.File = []
  180. if(that.formData.attId !='' ){
  181. File.push({
  182. url: that.formData.attId,
  183. name: that.formData.attId
  184. });
  185. }else{
  186. File =null
  187. }
  188. if(that.formData.drillType == 1){
  189. that.formData.drillTypeName = '培训'
  190. }else if(that.formData.drillType == 2){
  191. that.formData.drillTypeName = '演练'
  192. }
  193. });
  194. // 获取单位id
  195. getOrgId({
  196. pageNo: this.pageNo,
  197. pageSize: this.pageSize,
  198. userId: this.$store.state.user.id
  199. }).then(response => {
  200. // 取到用户对应的单位名称与id
  201. response.data.map(v => {
  202. if(this.formData.orgId==v.dwid){
  203. this.formData.orgName=v.orgName
  204. }
  205. this.actions5.push({
  206. id: v.id,
  207. name: v.orgName
  208. });
  209. });
  210. });
  211. },
  212. onReady() {
  213. this.$refs.customForm.setRules(this.customRules);
  214. },
  215. methods: {
  216. submit(ref) {
  217. this.$refs[ref]
  218. .validate()
  219. .then(res => {
  220. this.formData['status'] = 0;
  221. if(this.formData.File.length!=0&&this.formData.File[0].url){
  222. this.formData.attId = this.formData.File[0].url.toString();
  223. }else{
  224. this.formData.attId=''
  225. }
  226. if(this.formData.drillDate&&this.formData.drillDate.indexOf(":") === -1){
  227. this.formData.drillDate= this.formData.drillDate + ' 00:00:00'
  228. }
  229. var jsdata = JSON.stringify(this.formData);
  230. updateDrill(jsdata).then(response => {
  231. uni.showLoading({
  232. title: response.data.msg
  233. });
  234. setTimeout(() => {
  235. uni.hideLoading();
  236. uni.navigateBack({
  237. delta:2
  238. })
  239. }, 0);
  240. });
  241. })
  242. .catch(err => {
  243. uni.showToast({
  244. icon:'none',
  245. title:'错误!'+ err[0].message
  246. })
  247. });
  248. },
  249. // 上传图片 获取上传状态
  250. // 选择上传触发函数
  251. select(e) {
  252. // 根据所选图片的个数,多次调用上传函数
  253. let promises = [];
  254. for (let i = 0; i < e.tempFilePaths.length; i++) {
  255. const promise = this.uploadFiles(e.tempFilePaths, i);
  256. promises.push(promise);
  257. }
  258. Promise.all(promises).then(result => {});
  259. },
  260. // 上传函数
  261. async uploadFiles(tempFilePaths, i) {
  262. const that = this;
  263. this.loading = true
  264. await uni.uploadFile({
  265. url: baseUrl + '/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口
  266. filePath: tempFilePaths[i],
  267. name: 'file',
  268. header: {
  269. Authorization: 'Bearer ' + getAccessToken()
  270. }, //请求token
  271. success: res => {
  272. let data = JSON.parse(res.data);
  273. // 返回的url
  274. var fileLink = data.data;
  275. const code = data.code;
  276. // 如果成功,将返回的data数据给 formdata
  277. if (code == 0) {
  278. that.formData.File.push({
  279. url: fileLink,
  280. name: fileLink
  281. });
  282. uni.showToast({
  283. title: '文件上传成功!'
  284. });
  285. that.loading = false
  286. // that.formData.attId = fileLink
  287. }
  288. // this.formData.attId = this.formData.attId.toString();
  289. },
  290. fail: () => {
  291. uni.showToast({
  292. icon:'error',
  293. title: '文件上传失败!'
  294. });
  295. }
  296. });
  297. },
  298. // 移出图片函数
  299. async deleteFile(e) {
  300. this.formData.attId = '';
  301. },
  302. // 隐藏键盘
  303. hideKeyboard() {
  304. uni.hideKeyboard();
  305. },
  306. // 记录类型
  307. sexSelect2(e) {
  308. this.formData.drillType = e.value;
  309. this.formData.drillTypeName = e.label;
  310. },
  311. // 单位成立时间
  312. ActiveUnitTime(e) {
  313. this.unitTime = false;
  314. let value = new Date(e.value);
  315. this.formData.drillDate = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM');
  316. },
  317. changetime(e) {
  318. },
  319. // 所属单位
  320. sexSelect5(e) {
  321. this.formData.orgId = e.id;
  322. this.formData.orgName = e.name;
  323. },
  324. // 生成隐患弹出层 //暂存为草稿箱弹出层
  325. cancel() {
  326. this.show = false;
  327. },
  328. confirm() {
  329. setTimeout(() => {
  330. // 0.5秒后自动关闭
  331. this.show = false;
  332. }, 500);
  333. },
  334. // 触底的事件
  335. scrolltolower() {
  336. // 判断是否还有下一页数据
  337. if (this.pageNo * this.pageSize >= this.total)
  338. return uni.showToast({
  339. title: `数据加载完毕`
  340. });
  341. // 判断是否正在请求其它数据,如果是,则不发起额外的请求
  342. if (this.loading) return;
  343. this.pageNo += 1;
  344. this.showCheckboxShow(this.pageNo);
  345. }
  346. }
  347. };
  348. </script>
  349. <style lang="scss" scoped>
  350. page {
  351. height: 100%;
  352. background-color: #f5f7f9;
  353. position: relative;
  354. }
  355. .buttomBorder {
  356. height: 0px;
  357. border: 1px dashed #cbd5e1;
  358. }
  359. /deep/ .uni-section .uni-section-header {
  360. padding: 0px;
  361. }
  362. /deep/ .u-form-item__body {
  363. font-weight: 500;
  364. flex-direction: column !important;
  365. }
  366. /deep/ .u-form-item__body__left__content__label {
  367. margin-bottom: 16rpx;
  368. font-size: 30rpx !important;
  369. color: #274647 !important;
  370. }
  371. .arrow-icon {
  372. //主动检查箭头
  373. position: absolute;
  374. right: 14px;
  375. top: 49px;
  376. transform: rotate(90deg);
  377. }
  378. /deep/ .u-input[data-v-fdbb9fe6],
  379. /deep/ .u-input.data-v-fdbb9fe6,/deep/ .u-input {
  380. background-color: #fff;
  381. }
  382. /deep/.u-button[data-v-3bf2dba7],
  383. /deep/.u-button.data-v-3bf2dba7,/deep/.u-button{
  384. width: 60% !important;
  385. }
  386. //弹框样式
  387. .btnList {
  388. // width: 40%;
  389. display: flex;
  390. // display:flex;
  391. .u-button[data-v-3bf2dba7] {
  392. width: 30%;
  393. }
  394. }
  395. /deep/ .u-popup__content {
  396. //弹出的宽高
  397. height: 100%;
  398. }
  399. /deep/ .u-form-item__body__right__message {
  400. //校验的文字的位置
  401. margin-left: 10rpx !important;
  402. }
  403. /deep/ .uicon-close {
  404. //关闭按钮背景色
  405. background-color: rgba(199, 203, 210, 0.9);
  406. border-radius: 10%;
  407. }
  408. .checkbox {
  409. .checkbox-item {
  410. box-sizing: border-box;
  411. padding-top: 40px;
  412. }
  413. }
  414. //侧边联动
  415. .page-body {
  416. display: flex;
  417. background: #fff;
  418. overflow: hidden;
  419. }
  420. .nav {
  421. display: flex;
  422. width: 100%;
  423. }
  424. .nav-left {
  425. width: 25%;
  426. background: #fafafa;
  427. }
  428. .nav-left-item {
  429. height: 100upx;
  430. border-right: solid 1px #f1f1f1;
  431. border-bottom: solid 1px #f1f1f1;
  432. font-size: 30upx;
  433. display: flex;
  434. align-items: center;
  435. justify-content: center;
  436. }
  437. /deep/.nav-right-item[data-v-73caef23],/deep/.nav-right-item {
  438. display: flex;
  439. flex-wrap: wrap;
  440. }
  441. .nav-left-item:last-child {
  442. border-bottom: none;
  443. }
  444. .nav-right {
  445. width: 75%;
  446. }
  447. .box {
  448. display: block;
  449. overflow: hidden;
  450. border-bottom: 20upx solid #f3f3f3;
  451. /* min-height: 100vh; */
  452. /*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
  453. }
  454. .box:last-child {
  455. border: none;
  456. // min-height: 100vh;
  457. }
  458. .nav-right-item {
  459. margin-top: 20px;
  460. // width: 28%;
  461. // min-height: 200upx;
  462. float: left;
  463. text-align: center;
  464. padding: 11upx;
  465. font-size: 28upx;
  466. background: #fff;
  467. /deep/.u-checkbox__icon-wrap[data-v-532d01c7],/deep/.u-checkbox__icon-wrap {
  468. //复选框的样式
  469. margin: 0 20rpx;
  470. }
  471. /deep/ uni-view[data-v-3d1b15f2] {
  472. //复选框上线的间距
  473. margin: 20rpx 0 !important;
  474. }
  475. // /deep/ .u-checkbox__icon-wrap--square{
  476. // margin: 20rpx;
  477. // }
  478. .u-checkbox-label--right[data-v-532d01c7],.u-checkbox-label--right {
  479. margin-right: 40rpx;
  480. }
  481. }
  482. .nav-right-item image {
  483. width: 150upx;
  484. height: 150upx;
  485. }
  486. .active {
  487. font-weight: 700;
  488. color: #274647;
  489. background: #fff;
  490. border-right: 0;
  491. }
  492. ::-webkit-scrollbar {
  493. /*取消小程序的默认导航条样式*/
  494. width: 0;
  495. height: 0;
  496. color: transparent;
  497. }
  498. .selectBtn {
  499. width: 200rpx;
  500. margin-left: 0;
  501. font-size: 30rpx;
  502. background-color: #4cb2b6;
  503. }
  504. /deep/.u-action-sheet {
  505. overflow-y: auto;
  506. height: 1000rpx;
  507. background-color: #fff;
  508. }
  509. .example{
  510. overflow-y: auto;
  511. }
  512. </style>