index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. @click="showSex = true; hideKeyboard()">
  18. <u-input v-model="formData.workStatus" placeholder="请输入" :disabled="isview" />
  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="!formData.id" @click="submit('customForm')" type="primary" shape="circle" size="large"
  65. 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="请选择动火作业执行人" @close="showExecutor = false"
  75. @select="clickExecutor">
  76. </u-action-sheet>
  77. <u-action-sheet :show="showOrg" :actions="orgaction" title="请选择单位" class="org-choice popups" @close="showOrg = false"
  78. @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: '',
  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. orgaction: [], //单位
  157. showOrg: false
  158. }
  159. },
  160. onReady() {
  161. this.$refs.customForm.setRules(this.rules);
  162. },
  163. mounted() {
  164. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  165. this.wheight = data.height
  166. }).exec()
  167. },
  168. onLoad(option) {
  169. this.formData.orgName = option.orgName ? option.orgName : ''
  170. this.formData.orgId = option.orgId ? option.orgId : ''
  171. this.orgaction = option.orgaction ? JSON.parse(option.orgaction) : []
  172. this.actionsSex.map(i => i.name = i.label)
  173. uni.setNavigationBarTitle({
  174. title: option.title
  175. })
  176. if (option.editData) {
  177. this.isedit = true
  178. this.isview = false
  179. this.parentId = option.editData
  180. this.getData()
  181. // this.formData = JSON.parse(option.editData)
  182. } else if (option.viewData) {
  183. this.isview = true
  184. this.parentId = option.viewData
  185. this.getData()
  186. // this.formData = JSON.parse(option.viewData)
  187. } else {
  188. this.isedit = false
  189. this.isview = false
  190. }
  191. // 获取动火作业执行人数据
  192. let arrOrg = []
  193. arrOrg.push(this.formData.orgId)
  194. fireSpecialPage({
  195. pageNo: 1,
  196. pageSize: 100,
  197. orgIds: arrOrg,
  198. }).then(response => {
  199. console.log(response, 'sdsdsd');
  200. this.actionsExecutor = response.data ? response.data.list : []
  201. this.actionsExecutor.map(i => {
  202. i.name = i.empName
  203. })
  204. });
  205. console.log(this.isedit, 'ffffffff', this.isview);
  206. },
  207. methods: {
  208. clickExecutor(e) { //动火台账执行人
  209. this.formData.executor = e.name
  210. },
  211. //查看已上传附件
  212. viewSee(val) {
  213. downSee(val)
  214. },
  215. // 移出图片函数
  216. async deleteFile(e) {
  217. this.formData.attId = [];
  218. // console.log('移除了:');
  219. },
  220. selectFile(e) {
  221. let promises = [];
  222. for (let i = 0; i < e.tempFilePaths.length; i++) {
  223. const promise = uploadFile(e.tempFilePaths, i, this);
  224. promises.push(promise);
  225. }
  226. Promise.all(promises).then(result => {
  227. // 处理上传文件成功的结果
  228. }).catch(error => {
  229. // 处理上传文件失败的错误
  230. });
  231. },
  232. closeImage() {
  233. this.formData.attId = []
  234. this.formData.att = ''
  235. this.$forceUpdate()
  236. },
  237. sexSelect(e) {
  238. this.formData.workStatus = e.name
  239. },
  240. orgSelect(e) {
  241. this.formData.orgName = e.name
  242. this.formData.orgId = e.value
  243. },
  244. hideKeyboard() {
  245. uni.hideKeyboard()
  246. },
  247. getData() {
  248. fireWorkIdGet({
  249. id: this.parentId
  250. }).then(response => {
  251. this.formData = response.data
  252. console.log(response, 'response')
  253. })
  254. },
  255. bindDateChange(e) {
  256. this.formData.workBegin = e.detail.value
  257. },
  258. bindDateChange2(e) {
  259. console.log(e.detail, '3');
  260. this.formData.workEnd = e.detail.value
  261. },
  262. submit(ref) {
  263. this.formData.att = this.formData.attId? this.formData.attId.join('') :this.formData.att
  264. this.$refs[ref].validate().then(res => {
  265. console.log(this.isview, 'this.formDatathis.isview');
  266. if (this.isedit) {
  267. fireWorkUpdate(JSON.stringify(this.formData)).then(res => {
  268. this.$modal.msg('修改成功')
  269. this.isedit = false
  270. setTimeout(() => {
  271. uni.navigateBack()
  272. }, 400)
  273. })
  274. } else if (this.isview) {
  275. this.isview = false
  276. uni.navigateBack()
  277. } else {
  278. fireWorkCreate(JSON.stringify(this.formData)).then(response => {
  279. this.$modal.msg('新增成功')
  280. setTimeout(() => {
  281. uni.navigateBack()
  282. }, 400)
  283. })
  284. }
  285. }).catch(err => {
  286. console.log(err);
  287. })
  288. }
  289. }
  290. }
  291. </script>
  292. <style lang="scss" scoped>
  293. body {
  294. background-color: #f5f7f9;
  295. }
  296. page {
  297. background-color: #f5f7f9 !important;
  298. }
  299. .uni-container {
  300. // height: 100vh;
  301. background-color: #f5f7f9 !important;
  302. }
  303. /deep/.uni-card {
  304. position: relative;
  305. box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.15);
  306. border-radius: 30rpx;
  307. }
  308. .example {
  309. overflow-y: auto;
  310. }
  311. .juli-bottom {
  312. /deep/ .u-form-item__body__left__content__label {
  313. color: #000 !important;
  314. }
  315. }
  316. .org-choice {
  317. /deep/.u-action-sheet {
  318. overflow-y: auto;
  319. height: 1000rpx;
  320. background-color: #fff;
  321. }
  322. }
  323. .selectBtn {
  324. width: 200rpx;
  325. margin-left: 0;
  326. font-size: 30rpx;
  327. background-color: #4cb2b6;
  328. }
  329. .popups{
  330. /deep/.u-action-sheet {
  331. overflow-y: auto;
  332. height: 1000rpx;
  333. background-color: #fff;
  334. }
  335. }
  336. .example {
  337. overflow-y: auto;
  338. }
  339. </style>s