index.vue 10 KB

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