taskDanger.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <view class="form search-image-content zhcx-table">
  3. <uni-forms :modelValue="formData" ref="form" :rules="rules">
  4. <uni-forms-item label="标题" name="dangerTitle" required>
  5. <uni-easyinput type="text" v-model="formData.dangerTitle" placeholder="请填写隐患标题" />
  6. </uni-forms-item>
  7. <uni-forms-item label="等级">
  8. <radio-group v-model="formData.dangerLevel" style="transform:scale(0.85)" @change="radioChange">
  9. <label>
  10. <radio value="2" /><text>重大隐患</text>
  11. </label>
  12. <label>
  13. <radio value="1" checked="true" /><text>一般隐患</text>
  14. </label>
  15. </radio-group>
  16. </uni-forms-item>
  17. <uni-forms-item label="隐患来源">
  18. <picker @change="bindPickerChange" :value="index" :range="array">
  19. <view class="uni-input">{{array[index]}}</view>
  20. </picker>
  21. </uni-forms-item>
  22. <uni-forms-item label="隐患类别">
  23. <picker :range="dangerCatList" range-key="dangerCatTitle" @change="bindPickerChangeCat" :value="indexs">
  24. <view class="uni-input">{{dangerCatList[indexs].dangerCatTitle}}</view>
  25. </picker>
  26. </uni-forms-item>
  27. <uni-forms-item label="所属部门">
  28. <uni-data-picker :localdata="groupItem" popup-title="请选择隐患所属部门" @change="onchange"
  29. @nodeclick="onnodeclick"></uni-data-picker>
  30. </uni-forms-item>
  31. <uni-forms-item label="截止时间">
  32. <uni-datetime-picker class="uni-datetime" @change="onChangeDateTime"></uni-datetime-picker>
  33. </uni-forms-item>
  34. <uni-forms-item label="隐患照片">
  35. <p class="tip">支持各类图片,文件不大于10M</p>
  36. <view class="zhcx-upload" @click="uploadBt">
  37. <div class="icon"></div>
  38. <text class="uploadTitle">点击上传</text>
  39. </view>
  40. <view class="attachList" v-if="formData.attachList.length>0">
  41. <image class="dangerimage" :src="formData.attachList[0].thumbnailsFileUrl" mode="widthFix"></image>
  42. </view>
  43. </uni-forms-item>
  44. <uni-forms-item label="描述" name="dangerDesc">
  45. <textarea name="dangerDesc" v-model="formData.dangerDesc" placeholder-style="color:grey"
  46. placeholder="请输入隐患描述" />
  47. </uni-forms-item>
  48. <p>下一关:评审任务</p>
  49. <uni-forms-item label="执行人" name="operator">
  50. <!-- <uni-forms-item label="所属部门">
  51. <uni-data-picker :localdata="userList" popup-title="请选择执行人" @change="onchange"
  52. @nodeclick="onnodeclick"></uni-data-picker>
  53. </uni-forms-item> -->
  54. <picker :range="userList" range-key="accountRealName" @change="bindPickerChangeUser" :value="indexUser">
  55. <view class="uni-input">{{userList[indexUser].accountRealName}}</view>
  56. </picker>
  57. </uni-forms-item>
  58. <uni-forms-item label="说明" name="actionRemark">
  59. <textarea name="actionRemark" v-model="formData.actionRemark" placeholder-style="color:grey"
  60. placeholder="请输入隐患说明/备注" />
  61. </uni-forms-item>
  62. </uni-forms>
  63. <view class="uni-btn-v">
  64. <!--<button type="primary" @click="submit">提交</button>-->
  65. <button v-for="(item,index) in flowData.taskIns.actionList" :key="index" type="primary"
  66. @click="submit('form', item.actionId, item.actionCode)">{{ item.actionTitle }} </button>
  67. <button type="default" @click="Cancel()">取消</button>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import { upload } from '@/api/index';
  73. import graceChecker from "@/libs/graceChecker.js"
  74. import { getGroupTree, getDangerCatList, getUserList, add, createDangerIns } from "@/api/danger.js"
  75. import { toTreeText } from "@/libs/tool.js"
  76. export default {
  77. data() {
  78. const currentDate = this.getDate({
  79. format: true
  80. })
  81. return {
  82. riskPointId: '',
  83. taskId: '',
  84. date: currentDate,
  85. groupItem: [],
  86. FilePaths: [],
  87. userList: [{}, { accountRealName: '' }],
  88. dangerCatList: [{ dangerCatTitle: '' }],
  89. index: 0,
  90. indexs: 0,
  91. indexUser: 1,
  92. array: ['自查', '内部反馈', '上级检查', '政府执法'],
  93. rules: {
  94. dangerTitle: {
  95. rules: [{
  96. required: true,
  97. errorMessage: '请输入隐患标题',
  98. }]
  99. },
  100. dangerDeadLine: {
  101. rules: [{
  102. required: true,
  103. errorMessage: '请选择截止时间',
  104. }]
  105. },
  106. operator:{
  107. rules: [{
  108. required: true,
  109. errorMessage: '请选择执行人',
  110. }]
  111. },
  112. validateTrigger: 'submit'
  113. },
  114. formData: {
  115. dangerId: undefined,
  116. groupId: undefined, // 所属部门
  117. riskPointId: undefined, // 风险点:所属区域
  118. dangerCode: '', // 隐患编码
  119. dangerTitle: '', // 隐患标题
  120. dangerCatId: undefined, // 隐患类别ID
  121. dangerLevel: 1, // 隐患等级
  122. dangerDesc: '', // 描述
  123. dangerDeadLine: '', // 截止时间
  124. dangerSource: 0, // 隐患来源
  125. wfDefId: undefined,
  126. wfInsId: undefined,
  127. taskDefId: undefined,
  128. taskInsId: undefined,
  129. taskCode: '',
  130. actionId: undefined,
  131. actionCode: '',
  132. groupIdTo: undefined,
  133. positionIdTo: undefined,
  134. accountIdTo: undefined, // 执行人
  135. actionRemark: '', // 说明
  136. attachList: []
  137. },
  138. flowData: {
  139. taskIns: {
  140. actionList: []
  141. }
  142. },
  143. }
  144. },
  145. computed: {
  146. startDate() {
  147. return this.getDate('start');
  148. },
  149. endDate() {
  150. return this.getDate('end');
  151. },
  152. },
  153. filters:{
  154. previewImage(val){
  155. let imgsrc=val.split("$");
  156. return imgsrc[0];
  157. }
  158. },
  159. onLoad(options) {
  160. //调用页面请求数据接口
  161. this.riskPointId = options.riskPointId;
  162. console.log("riskPointId", options.riskPointId)
  163. this.taskId = options.taskId;
  164. console.log("taskId", options.taskId)
  165. this.groupTree();
  166. this.getDangerCatList();
  167. this.getUserList();
  168. this.createDangerIns();
  169. },
  170. methods: {
  171. Cancel() {
  172. //取消
  173. uni.navigateBack();
  174. },
  175. handleSelectUser(item) {
  176. this.formData.accountIdTo = item.accountId
  177. this.formData.groupIdTo = item.groupId
  178. this.formData.positionIdTo = item.positionId
  179. console.log("item", item);
  180. },
  181. radioChange: function(evt) {
  182. this.formData.dangerLevel = evt.detail.value
  183. console.log("evt.detail.value", evt.detail.value)
  184. },
  185. bindPickerChange: function(e1) {
  186. this.index = e1.target.value
  187. console.log("隐患来源", this.index)
  188. this.formData.dangerSource = this.index
  189. },
  190. bindPickerChangeCat: function(e2) {
  191. this.indexs = e2.target.value
  192. console.log("隐患类别", this.indexs)
  193. this.formData.dangerCatId = this.dangerCatList[this.indexs].dangerCatId
  194. },
  195. bindPickerChangeUser: function(e3) {
  196. this.indexUser = e3.target.value
  197. console.log("执行人", this.indexUser)
  198. this.formData.accountId = this.userList[this.indexUser].accountId
  199. this.formData.accountId = this.userList[this.indexUser].accountId
  200. this.formData.accountIdTo = this.userList[this.indexUser].accountId
  201. this.formData.groupIdTo = this.userList[this.indexUser].groupId
  202. this.formData.positionIdTo = this.userList[this.indexUser].positionId
  203. },
  204. //初始化流程 写死流程ID
  205. createDangerIns() {
  206. createDangerIns(1).then((resp) => {
  207. const { code, data, msg } = resp
  208. if (code === 0) {
  209. this.flowData = data
  210. this.formData.wfDefId = data.wfDefId
  211. this.formData.wfInsId = data.wfInsId
  212. this.formData.taskDefId = data.taskIns.taskDefId
  213. this.formData.taskInsId = data.taskIns.taskInsId
  214. this.formData.taskCode = data.taskIns.taskCode
  215. } else {
  216. this.$message.error(msg)
  217. }
  218. }).catch((error) => {
  219. console.log(error)
  220. })
  221. },
  222. /**z
  223. * 提交
  224. */
  225. submit(formName, actionId, actionCode) {
  226. this.$refs.form.validate().then(res => {
  227. const riskPointId=this.riskPointId;
  228. const taskId=this.taskId;
  229. this.formData.actionId = actionId;
  230. this.formData.actionCode = actionCode;
  231. this.formData.riskPointId = riskPointId;
  232. if(this.formData.groupIdS)
  233. {
  234. this.formData.groupId = this.formData.groupIdS[this.formData.groupIdS.length - 1].value;
  235. }
  236. const entRiskPointMeasure=uni.getStorageSync("entRiskPointMeasure");
  237. const formData={...this.formData,...entRiskPointMeasure,taskId}
  238. add(formData).then((resp) => {
  239. const { code, data, msg } = resp
  240. if (code === 0) {
  241. uni.navigateTo({
  242. url: `/views/entRiskPointCheck/table?taskId=${taskId}&riskPointId=${riskPointId}`,
  243. });
  244. } else {
  245. uni.showToast({
  246. icon: 'error',
  247. title: msg
  248. })
  249. }
  250. })
  251. }).catch(err => {
  252. let errorMessage="请检查信息";
  253. if(typeof err==="object"){
  254. errorMessage=err[0].errorMessage;
  255. }
  256. if(errorMessage.length>7){errorMessage='请检查填写信息!'}
  257. uni.showToast({
  258. icon: 'none',
  259. title: errorMessage
  260. })
  261. })
  262. },
  263. formReset: function(e) {
  264. console.log('清空数据')
  265. },
  266. bindDateChange: function(e) {
  267. this.date = e.target.value
  268. },
  269. getDate(type) {
  270. const date = new Date();
  271. let year = date.getFullYear();
  272. let month = date.getMonth() + 1;
  273. let day = date.getDate();
  274. if (type === 'start') {
  275. year = year - 0;
  276. } else if (type === 'end') {
  277. year = year + 2;
  278. }
  279. month = month > 9 ? month : '0' + month;
  280. day = day > 9 ? day : '0' + day;
  281. return `${year}-${month}-${day}`;
  282. },
  283. onchange(e) {
  284. const value = e.detail.value
  285. this.formData.groupIdS = value
  286. },
  287. onChangeDateTime(e) {
  288. this.formData.dangerDeadLine = e
  289. console.log("dangerDeadLine", e)
  290. },
  291. onnodeclick(node) {},
  292. //初始化group
  293. groupTree() {
  294. getGroupTree().then((res) => {
  295. if (res.data) {
  296. let temp = toTreeText(res.data)
  297. this.groupItem = temp;
  298. } else {
  299. console.log("group无数据,请检查!")
  300. }
  301. });
  302. },
  303. //隐患类别列表
  304. getDangerCatList() {
  305. getDangerCatList().then((resp) => {
  306. const { code, data } = resp
  307. if (code === 0) {
  308. this.dangerCatList = data
  309. //默认值
  310. this.formData.dangerCatId = this.dangerCatList[0].dangerCatId
  311. }
  312. }).catch((error) => {
  313. console.log(error)
  314. })
  315. },
  316. //用户列表
  317. getUserList() {
  318. getUserList().then((resp) => {
  319. const { code, data } = resp
  320. if (code === 0) {
  321. this.userList = data
  322. this.formData.accountId = this.userList[1].accountId
  323. this.formData.accountIdTo = this.userList[1].accountId
  324. this.formData.groupIdTo = this.userList[1].groupId
  325. this.formData.positionIdTo = this.userList[1].positionId
  326. }
  327. }).catch((error) => {
  328. console.log(error)
  329. })
  330. },
  331. //上传入口
  332. uploadBt() {
  333. uni.chooseImage({
  334. success: (chooseImageRes) => {
  335. const tempFilePaths = chooseImageRes.tempFilePaths;
  336. this.uploadSubmit(tempFilePaths[0])
  337. }
  338. });
  339. },
  340. uploadSubmit(filePath) {
  341. upload({ filePath }).then((res) => {
  342. let result=JSON.parse(res);
  343. if(result.code===0){
  344. let attachList=[];
  345. let path=result.data.path;
  346. let thumbnailsFileUrl=path.split('$')[0];
  347. let fileUrl=path.split('$')[1];
  348. let uploadImgInfo={
  349. thumbnailsFileUrl,
  350. fileUrl,
  351. fileSize:result.data.size,
  352. fileExt:result.data.ext,
  353. fileTitle:result.data.oriFileName,
  354. opCode:0
  355. };
  356. attachList.push(uploadImgInfo);
  357. this.$set(this.formData,'attachList',attachList)
  358. }else{
  359. uni.showToast({
  360. title: result.msg||"上传失败"
  361. })
  362. }
  363. }).catch((msg) => {
  364. uni.showToast({
  365. title: "上传失败"
  366. })
  367. })
  368. },
  369. }
  370. }
  371. </script>
  372. <style lang="scss" scoped>
  373. .form {
  374. padding: 0rpx 10px;
  375. .dangerimage{
  376. display: block;
  377. width: 200upx;
  378. height: 200upx;
  379. }
  380. padding-top: 100upx;
  381. .head {
  382. padding-left: 59upx;
  383. font-size: 30upx;
  384. color: #333;
  385. }
  386. .tip {
  387. padding: 8upx 0 16upx 59upx;
  388. font-size: 24upx;
  389. color: #3584FF;
  390. }
  391. }
  392. </style>