index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="uni-container">
  3. <view class="example container" :style="'height: ' + (screenHeight - wheight - 85) + 'px'">
  4. <u--form ref="customForm" :model="formData" labelPosition="left" labelWidth="100%" labelAlign="left">
  5. <view class="juli-bottom">
  6. <u-form-item label="所属单位" prop="orgName" @click="showOrg = true; hideKeyboard()" :required="true">
  7. <u-input v-model="formData.orgName" placeholder="请输入" :disabled="isview" />
  8. </u-form-item>
  9. <u-form-item label="动火部位" prop="workReason" :required="true">
  10. <u-input v-model="formData.workReason" placeholder="请输入" :disabled="isview" />
  11. </u-form-item>
  12. <u-form-item label="动火作业执行人" prop="executor" :required="true"
  13. style="position: relative;">
  14. <view slot="label" style="display: flex;">
  15. <text style="color:#000;font-size: 15px;"><text style="color: red;margin-right: 4px">*</text>动火作业执行人</text>
  16. <u-button @click="onAddPerson" shape="circle" size="mini" style="margin-bottom: 10px;width: 80px;" :custom-style="{backgroundColor: '#4CB2B6',color:'#fff',padding:'12px 0'}">新增人员</u-button>
  17. </view>
  18. <view class="" @click="addPerson">
  19. <u-input v-model="formData.executor" placeholder="请选择" :disabled="isview" />
  20. </view>
  21. </u-form-item>
  22. <u-form-item label="动火台账状态" prop="workStatus" :required="true" v-if="isview">
  23. <u-input v-model="formData.workStatus" placeholder="请选择" :disabled="isview" />
  24. <!-- @click="showSex = true; hideKeyboard()" -->
  25. </u-form-item>
  26. <picker mode="date" :value="dateTime" @change="bindDateChange" :disabled="isview">
  27. <view class="datatime-street">
  28. <u-form-item label="动火开始时间" prop="workBegin" :required="true">
  29. <u-input v-model="formData.workBegin" placeholder="动火结束时间" class="add-date"
  30. :disabled="isview" />
  31. </u-form-item>
  32. </view>
  33. </picker>
  34. <picker mode="date" @change="bindDateChange2" :disabled="isview">
  35. <view class="datatime-street">
  36. <u-form-item label="动火结束时间" prop="workEnd" :required="true">
  37. <u-input v-model="formData.workEnd" placeholder="动火结束时间" class="add-date"
  38. :disabled="isview" />
  39. </u-form-item>
  40. </view>
  41. </picker>
  42. <u-form-item label="附件">
  43. <!-- 选择文件上传,limit="1则最多选择一张图片,del-icon隐藏删除按钮 -->
  44. <uni-file-picker v-model="formData.attId" del-icon limit="1" auto-upload file-mediatype="all"
  45. @select="selectFile" @delete="deleteFile" :disabled="isview">
  46. <button type="primary" class="selectBtn" :disabled="isview">选择文件</button>
  47. <!-- 加载中 -->
  48. <isLodingModel v-if="loading"></isLodingModel>
  49. </uni-file-picker>
  50. </u-form-item>
  51. <u-form-item label="已上传附件:" v-if="formData.att" labelWidth="150">
  52. <u-icon name="close" color="#4CB2B6" size="24" @click="closeImage()" v-if="!isview">
  53. </u-icon>
  54. <!-- #ifdef MP-WEIXIN -->
  55. <text style="color:#00a3f4;cursor: pointer;margin-left: 20px !important;"
  56. @click.native="viewSee(formData.att)">点击预览文件</text>
  57. <!-- #endif -->
  58. <!-- #ifdef H5 -->
  59. <a style="color:#00a3f4;cursor: pointer;margin-left: 20px !important;"
  60. @click="viewSee(formData.att)">点击预览文件</a>
  61. <!-- #endif -->
  62. </u-form-item>
  63. </view>
  64. </u--form>
  65. </view>
  66. <view class="heigthButton">
  67. <u-button v-if="isedit" @click="submit('customForm')" type="primary" shape="circle" size="large"
  68. color="#4CB2B6" text="确认修改" style="width:200px">
  69. </u-button>
  70. <u-button v-else-if="!isedit&&!isview" @click="submit('customForm')" type="primary" shape="circle"
  71. size="large" color="#4CB2B6" text="确认新增" style="width:200px">
  72. </u-button>
  73. <u-button v-else-if="isview" @click="submit('customForm')" type="primary" shape="circle" size="large"
  74. color="#4CB2B6" text="返回" style="width:200px">
  75. </u-button>
  76. </view>
  77. <u-action-sheet :show="showSex" :actions="actionsSex" title="请选择动火台账状态" @close="showSex = false"
  78. @select="sexSelect">
  79. </u-action-sheet>
  80. <u-action-sheet :show="showExecutor" :actions="actionsExecutor" class="popups" title="请选择动火作业执行人"
  81. @close="showExecutor = false" @select="clickExecutor">
  82. </u-action-sheet>
  83. <u-action-sheet :show="showOrg" :actions="orgaction" title="请选择单位" class="org-choice popups"
  84. @close="showOrg = false" @select="orgSelect"></u-action-sheet>
  85. </view>
  86. </template>
  87. <script>
  88. import {
  89. fireWorkUpdate,
  90. fireWorkCreate,
  91. fireWorkIdGet,
  92. fireSpecialPage, //动火执行人
  93. } from '@/api/fireSpecial';
  94. import {
  95. NumericRule,
  96. downSee,
  97. uploadFile
  98. } from '@/utils/common.js';
  99. import config from '@/config'
  100. import {
  101. DICT_TYPE,
  102. getDictDatas
  103. } from "@/utils/dict";
  104. const baseUrlImg = config.baseUrlImg
  105. export default {
  106. data() {
  107. return {
  108. screenHeight: this.$screenHeight,
  109. wheight: '',
  110. showExecutor: false, //动火台账执行人
  111. actionsExecutor: [],
  112. formData: {
  113. orgName: '',
  114. orgId: '',
  115. workReason: '',
  116. executor: '',
  117. workStatus: '0',
  118. workBegin: '',
  119. workEnd: '',
  120. att: '',
  121. attId: [],
  122. img1:''
  123. },
  124. loading: '',
  125. rules: {
  126. workReason: [{
  127. type: 'string',
  128. required: true,
  129. message: '动火部位不能为空',
  130. trigger: ['blur', 'change']
  131. }],
  132. executor: [{
  133. type: 'string',
  134. required: true,
  135. message: '动火作业执行人不能为空',
  136. trigger: ['blur', 'change']
  137. }],
  138. workStatus: [{
  139. type: 'string',
  140. required: true,
  141. message: '动火台账状态不能为空',
  142. trigger: ['blur', 'change']
  143. }],
  144. workBegin: [{
  145. type: 'string',
  146. required: true,
  147. message: '动火开始时间不能为空',
  148. trigger: ['blur', 'change']
  149. }],
  150. workEnd: [{
  151. type: 'string',
  152. required: true,
  153. message: '动火结束时间不能为空',
  154. trigger: ['blur', 'change']
  155. }],
  156. // empName: NumericRule(),
  157. },
  158. isedit: '',
  159. isview: '',
  160. dateTime: '',
  161. showSex: false,
  162. actionsSex: getDictDatas(DICT_TYPE.FIRE_WORK_STATUS), //性别
  163. workStatus: getDictDatas(DICT_TYPE.FIRE_WORK_STATUS), //台账状态
  164. orgaction: [], //单位
  165. showOrg: false
  166. }
  167. },
  168. onReady() {
  169. this.$refs.customForm.setRules(this.rules);
  170. },
  171. mounted() {
  172. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  173. this.wheight = data.height
  174. }).exec()
  175. },
  176. onLoad(option) {
  177. this.formData.orgName = option.orgName ? option.orgName : ''
  178. this.formData.orgId = option.orgId ? option.orgId : ''
  179. this.orgaction = option.orgaction ? JSON.parse(option.orgaction) : []
  180. this.actionsSex.map(i => i.name = i.label)
  181. uni.setNavigationBarTitle({
  182. title: option.title
  183. })
  184. if (option.editData) {
  185. this.isedit = true
  186. this.isview = false
  187. this.parentId = option.editData
  188. this.getData()
  189. // this.formData = JSON.parse(option.editData)
  190. } else if (option.viewData) {
  191. this.isview = true
  192. this.parentId = option.viewData
  193. this.getData()
  194. // this.formData = JSON.parse(option.viewData)
  195. } else {
  196. this.isedit = false
  197. this.isview = false
  198. }
  199. },
  200. onShow() {
  201. // 获取动火作业执行人数据
  202. let arrOrg = []
  203. arrOrg.push(this.formData.orgId)
  204. fireSpecialPage({
  205. pageNo: 1,
  206. pageSize: 100,
  207. orgIds: arrOrg,
  208. }).then(response => {
  209. this.actionsExecutor = response.data ? response.data.list : []
  210. this.actionsExecutor.map(i => {
  211. i.name = i.empName
  212. })
  213. });
  214. },
  215. methods: {
  216. onAddPerson(){
  217. uni.navigateTo({
  218. url: `/pagesB/fire/fireSpecial/addSpecial/index?title=新增特种人员`
  219. })
  220. },
  221. addPerson() {
  222. this.showExecutor = true;
  223. uni.hideKeyboard()
  224. },
  225. clickExecutor(e) { //动火台账执行人
  226. this.formData.executor = e.name
  227. },
  228. //查看已上传附件
  229. viewSee(val) {
  230. downSee(val)
  231. },
  232. // 移出图片函数
  233. async deleteFile(e) {
  234. this.formData.attId = [];
  235. },
  236. selectFile(e) {
  237. let promises = [];
  238. for (let i = 0; i < e.tempFilePaths.length; i++) {
  239. const promise = uploadFile(e.tempFilePaths, i, this);
  240. promises.push(promise);
  241. }
  242. Promise.all(promises).then(result => {
  243. // 处理上传文件成功的结果
  244. }).catch(error => {
  245. // 处理上传文件失败的错误
  246. });
  247. },
  248. closeImage() {
  249. this.formData.attId = []
  250. this.formData.att = ''
  251. this.$forceUpdate()
  252. },
  253. sexSelect(e) {
  254. this.formData.workStatus = e.name
  255. },
  256. orgSelect(e) {
  257. this.formData.orgName = e.name
  258. this.formData.orgId = e.value
  259. },
  260. hideKeyboard() {
  261. uni.hideKeyboard()
  262. },
  263. getData() {
  264. fireWorkIdGet({
  265. id: this.parentId
  266. }).then(response => {
  267. this.formData = response.data
  268. this.workStatus.map(i => {
  269. if (this.formData.workStatus == i.value)
  270. this.formData.workStatus = i.label
  271. })
  272. })
  273. },
  274. bindDateChange(e) {
  275. this.formData.workBegin = e.detail.value
  276. },
  277. bindDateChange2(e) {
  278. this.formData.workEnd = e.detail.value
  279. },
  280. submit(ref) {
  281. const end = new Date(this.formData.workEnd).getTime()
  282. const start = new Date(this.formData.workBegin).getTime()
  283. if (start > end) {
  284. return this.$modal.msg('结束时间不能小于开始时间')
  285. }
  286. this.$refs[ref].validate().then(res => {
  287. if (this.formData.attId && this.formData.attId.length > 0) {
  288. this.formData.att = this.formData.attId[0];
  289. } else {
  290. this.formData.att = this.formData.att;
  291. }
  292. if (this.isedit) {
  293. fireWorkUpdate(JSON.stringify(this.formData)).then(res => {
  294. this.$modal.msg('修改成功')
  295. this.isedit = false
  296. setTimeout(() => {
  297. uni.navigateBack()
  298. }, 400)
  299. })
  300. } else if (this.isview) {
  301. this.isview = false
  302. uni.navigateBack()
  303. } else {
  304. fireWorkCreate(JSON.stringify(this.formData)).then(response => {
  305. this.$modal.msg('新增成功')
  306. setTimeout(() => {
  307. uni.navigateBack()
  308. }, 400)
  309. })
  310. }
  311. }).catch(err => {})
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. body {
  318. background-color: #f5f7f9;
  319. }
  320. page {
  321. background-color: #f5f7f9 !important;
  322. }
  323. .uni-container {
  324. // height: 100vh;
  325. background-color: #f5f7f9 !important;
  326. }
  327. /deep/.uni-card {
  328. position: relative;
  329. box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.15);
  330. border-radius: 30rpx;
  331. }
  332. .example {
  333. overflow-y: auto;
  334. }
  335. .juli-bottom {
  336. /deep/ .u-form-item__body__left__content__label {
  337. color: #000 !important;
  338. }
  339. }
  340. .org-choice {
  341. /deep/.u-action-sheet {
  342. overflow-y: auto;
  343. height: 1000rpx;
  344. background-color: #fff;
  345. }
  346. }
  347. .selectBtn {
  348. width: 200rpx;
  349. margin-left: 0;
  350. font-size: 30rpx;
  351. background-color: #4cb2b6;
  352. }
  353. .popups {
  354. /deep/.u-action-sheet {
  355. overflow-y: auto;
  356. height: 1000rpx;
  357. background-color: #fff;
  358. }
  359. }
  360. .example {
  361. overflow-y: auto;
  362. }
  363. </style>s