tasks_details.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="container uni-container">
  3. <view class=" flex flex-direction width100">
  4. <text class="text-xl font-weight-700">任务介绍</text>
  5. <!-- <view class="">
  6. 任务介绍
  7. </view> -->
  8. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  9. <u--form ref="uForm" :model="formData" labelPosition="left" labelWidth="70" labelAlign="right">
  10. <u-form-item label="任务名称" prop="name" ref="item1">
  11. <text class="text-cut padding-sm">{{formData.name}}</text>
  12. </u-form-item>
  13. <u-form-item label="发布单位" prop="unit" ref="item1">
  14. <text class="text-cut padding-sm"> {{formData.unit}}</text>
  15. </u-form-item>
  16. <u-form-item label="时间" prop="starttime" ref="item1">
  17. <text class="text-cut padding-sm"> {{formData.starttime}}--{{formData.endtime}}</text>
  18. </u-form-item>
  19. <u-form-item label="状态" prop="status" ref="item1">
  20. <text class="text-cut padding-sm"
  21. :style="{color:(formData.status==='0'||formData.status==='3'?'red':formData.status==='1'?'green':'blue')}">
  22. {{statusListTran(formData.status)}}</text>
  23. </u-form-item>
  24. <u-form-item label="任务描述" prop="introduction" ref="item1">
  25. <text class=" padding-sm"> {{formData.introduction}}</text>
  26. </u-form-item>
  27. <text class="text-xl text-black font-weight-700">任务完成详情</text>
  28. <u-form-item label="结果描述" prop="resultdescription" ref="item1">
  29. <text v-if="formData.status=='1'||formData.status=='2'" class=" padding-sm">
  30. {{formData.resultdescription}}</text>
  31. <u--textarea v-if="formData.status=='0'||formData.status=='3'" v-model="formData.resultdescription"
  32. placeholder="请输入内容" count height="100">
  33. </u--textarea>
  34. </u-form-item>
  35. <u-form-item label="附件" prop="sex" ref="item1">
  36. <u-album v-if="formData.status=='1'||formData.status=='2'" :urls="formData.img"></u-album>
  37. <u-upload v-if="formData.status=='0'||formData.status=='3'" :fileList="fileList1"
  38. @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10"></u-upload>
  39. </u-form-item>
  40. <!-- <u-form-item label="附件" prop="sex" ref="item1" >
  41. <u-upload ref="uUpload" :action="action" :auto-upload="true" :file-list="listImg"
  42. @on-remove="onRemove" @on-success="onSuccess" :max-size="2 * 1024 * 1024" max-count="9"
  43. width="300" height="300" :multiple="false" :limitstatus="limitstatus"></u-upload>
  44. </u-form-item> -->
  45. </u--form>
  46. <!-- 审核时不通过时提交 -->
  47. <view class="position-fixed">
  48. <u-button v-if="formData.status=='3'" shape="circle" size="small" color="#2563EB" text="确认提交"
  49. customStyle="margin-top: 50px" @click="submit">
  50. </u-button>
  51. </view>
  52. <!-- 待完成任务 提交 -->
  53. <view class="position-fixed">
  54. <uni-row :gutter="20" v-if="formData.status=='0'">
  55. <uni-col :span="12">
  56. <u-button @click="submit" shape="circle" size="small" color="#2563EB" text="确认提交"></u-button>
  57. </uni-col>
  58. <uni-col :span="12">
  59. <!-- <u-modal :show="show" :title="title" :content='content' :asyncClose="true" @cancel="cancel" @confirm="confirm" :showCancelButton='true' :showConfirmButton='true'></u-modal> -->
  60. <u-button @click="errorSubmit" shape="circle" size="small" color="#ff7980" text="生成隐患"></u-button>
  61. </uni-col>
  62. </uni-row>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import config from '@/config'
  69. import {
  70. getTaskDetails,
  71. getTaskSubmit,
  72. getTaskErrorsubmit,
  73. } from "@/api/task";
  74. import {
  75. uploadAvatar
  76. } from "@/api/system/user"
  77. import {
  78. getTasDetails
  79. } from "@/api/task";
  80. let that = null;
  81. const baseUrl = config.baseUrl + config.baseApi;
  82. export default {
  83. data() {
  84. return {
  85. statusList: {
  86. 0: "未完成",
  87. 1: "已完成",
  88. 2: "审核中",
  89. 3: "审核未通过"
  90. },
  91. // 自定义表单数据
  92. formData: {
  93. id: '',
  94. name: '',
  95. unit: '',
  96. starttime: '',
  97. endtime: '',
  98. status: '',
  99. introduction: '',
  100. resultdescription: '',
  101. img: [],
  102. },
  103. fileList1: [],
  104. limitstatus: ['png', 'jpg', 'jpeg'], // 允许的图片后缀
  105. rules: {
  106. name: [{
  107. status: 'string',
  108. required: true,
  109. message: '请填写姓名',
  110. trigger: ['blur', 'change']
  111. }, {
  112. min: 2,
  113. max: 12,
  114. message: '长度在2-12个字符之间'
  115. // // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明
  116. // validator: (rule, value, callback) => {
  117. // // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
  118. // return uni.$u.test.chinese(value);
  119. // },
  120. // message: "姓名必须为中文",
  121. // // 触发器可以同时用blur和change,二者之间用英文逗号隔开
  122. // trigger: ["change", "blur"],
  123. }],
  124. code: {
  125. status: 'string',
  126. required: true,
  127. len: 4,
  128. message: '请填写4位验证码',
  129. trigger: ['blur']
  130. },
  131. },
  132. }
  133. },
  134. computed: {},
  135. //目的页面接收
  136. //这里用onshow()也可以
  137. onLoad(options) {
  138. var data = options.id;
  139. this.getData(data)
  140. },
  141. // onLoad: function(option) {
  142. // that = this;
  143. // const eventChannel = this.getOpenerEventChannel();
  144. // // eventChannel.emit('acceptDataFromOpenedPage', {
  145. // // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  146. // eventChannel.on('acceptDataFromOpenerPage', function(val) {
  147. // that.getData(val.id)
  148. // })
  149. // },
  150. onReady() {
  151. //onReady 为uni-app支持的生命周期之一
  152. // console.log('this.$refs.uForm', this.$refs.uForm);
  153. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  154. this.$refs.uForm.setRules(this.rules)
  155. },
  156. methods: {
  157. // =================数据转换==================
  158. statusListTran(val) { //status状态转换
  159. return this.statusList[val]
  160. },
  161. // =============获取数据===================s
  162. // 获取数据
  163. getData(id) {
  164. this.loading = true
  165. getTaskDetails({
  166. id: id
  167. }).then(response => {
  168. // 为数据赋值:通过展开运算符的形式,进行新旧数据的拼接
  169. this.formData = response.data
  170. this.loading = false;
  171. });
  172. },
  173. // ==============照片处理=================
  174. // 删除图片
  175. deletePic(event) {
  176. this[`fileList${event.name}`].splice(event.index, 1)
  177. },
  178. // 新增图片
  179. async afterRead(event) {
  180. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  181. let lists = [].concat(event.file)
  182. let fileListLen = this[`fileList${event.name}`].length
  183. lists.map((item) => {
  184. this[`fileList${event.name}`].push({
  185. ...item,
  186. status: 'uploading',
  187. message: '上传中'
  188. })
  189. })
  190. for (let i = 0; i < lists.length; i++) {
  191. const result = await this.uploadFilePromise(lists[i].url)
  192. let item = this[`fileList${event.name}`][fileListLen]
  193. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  194. status: 'success',
  195. message: '',
  196. url: result
  197. }))
  198. fileListLen++
  199. }
  200. },
  201. uploadFilePromise(url) {
  202. let data = {
  203. name: 'avatarFile',
  204. filePath: url
  205. }
  206. return uploadAvatar(data).then(response => {
  207. uni.showToast({
  208. title: "成功",
  209. icon: 'success'
  210. })
  211. })
  212. // return new Promise((resolve, reject) => {
  213. // let a = uni.uploadFile({
  214. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  215. // filePath: url,
  216. // name: 'file',
  217. // formData: {
  218. // user: 'test'
  219. // },
  220. // success: (res) => {
  221. // setTimeout(() => {
  222. // resolve(res.data.data)
  223. // }, 1000)
  224. // }
  225. // });
  226. // })
  227. },
  228. // ==============照片处理结束==================
  229. // ==============提交================================
  230. // 待完成任务提交
  231. submit() {
  232. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  233. this.$refs.uForm.validate().then(res => {
  234. getTaskSubmit(this.formData).then(response => {
  235. uni.showLoading({
  236. title: response.data.msg
  237. });
  238. setTimeout(() => {
  239. uni.hideLoading();
  240. this.$tab.navigateTo('/pagesA/fire/check_tasks/index')
  241. }, 2000);
  242. });
  243. }).catch(errors => {
  244. uni.$u.toast('校验失败')
  245. })
  246. },
  247. // 隐患提交
  248. errorSubmit() {
  249. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  250. this.$refs.uForm.validate().then(res => {
  251. getTaskErrorsubmit(this.formData).then(response => {
  252. uni.showLoading({
  253. title: response.data.msg
  254. });
  255. setTimeout(() => {
  256. uni.hideLoading();
  257. this.$tab.navigateTo('/pagesA/fire/check_tasks/index')
  258. }, 2000);
  259. });
  260. }).catch(errors => {
  261. uni.$u.toast('校验失败')
  262. })
  263. },
  264. }
  265. }
  266. </script>
  267. <style lang="scss">
  268. /deep/ .u-form-item__body {
  269. padding: 5rpx 0rpx;
  270. }
  271. /deep/ .u-form-item {
  272. font-size: 13px;
  273. }
  274. </style>