index.vue 10 KB

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