Create.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <uni-drawer ref="drawer" mode="left" :mask-click="false" width="85%" :maskClick='true'>
  3. <scroll-view class="scroll-view" scroll-y="true">
  4. <uni-section :title="type==='add'?'隐患登记':'编辑隐患' " type="line"></uni-section>
  5. <view class="form-wrap" >
  6. <uni-forms ref="form" label-position="top" :rules="rules" :model="form" :label-width="300">
  7. <uni-forms-item label ="企业/单位名称" >
  8. <uni-data-select v-model="form.entId" :localdata="ents" placeholder="请选择企业/单位名称" :clear="false"></uni-data-select>
  9. </uni-forms-item>
  10. <uni-card padding="0" margin="5px 0">
  11. <uni-forms-item label ="隐患标题">
  12. <uni-easyinput v-model="form.dangerTitle" placeholder="请输入隐患标题" />
  13. </uni-forms-item>
  14. <!-- <uni-forms-item label ="隐患分类" >
  15. <uni-data-select v-model="form.dangerCatId" :localdata="dangerCats" placeholder="请选择隐患分类" :clear="false"></uni-data-select>
  16. </uni-forms-item> -->
  17. <uni-forms-item label ="分类标签" >
  18. <uni-easyinput v-model="form.dangerTags" placeholder="请输入分类标签" />
  19. </uni-forms-item>
  20. <uni-forms-item label ="隐患等级" >
  21. <uni-data-select v-model="form.dangerLevel" :localdata="dangerLevelOptions" placeholder="请选择隐患等级" :clear="false"></uni-data-select>
  22. </uni-forms-item>
  23. <uni-forms-item label ="发生位置">
  24. <uni-easyinput v-model="form.dangerLocation" placeholder="请输入发生位置" />
  25. </uni-forms-item>
  26. <uni-forms-item label="隐患描述">
  27. <uni-easyinput type="textarea" :maxlength="300"
  28. v-model="form.dangerDesc" autoHeight
  29. placeholder="请输入隐患描述"></uni-easyinput>
  30. <view class="word-limit">{{form.dangerDesc.length||0}}/300</view>
  31. </uni-forms-item>
  32. <uni-forms-item label ="登记时间">
  33. <uni-datetime-picker type="date" v-model="form.submitTime" placeholder="请选择登记时间" />
  34. </uni-forms-item>
  35. </uni-card>
  36. <uni-card padding="0" margin="5px 0">
  37. <uni-forms-item label ="整改期限">
  38. <uni-datetime-picker type="date" v-model="form.dangerDeadLine" placeholder="请选择整改期限" />
  39. </uni-forms-item>
  40. <uni-forms-item label="整改类型">
  41. <uni-data-checkbox
  42. v-model="form.rectifyCat"
  43. :localdata="[{ value: 1, text: '自行整改' },{ value: 2, text: '外协整改' }]" />
  44. </uni-forms-item>
  45. <uni-forms-item label="整改说明">
  46. <uni-easyinput type="textarea" :maxlength="300"
  47. v-model="form.rectifyRemark" autoHeight
  48. placeholder="请输入整改说明"></uni-easyinput>
  49. <view class="word-limit">{{form.rectifyRemark.length||0}}/300</view>
  50. </uni-forms-item>
  51. <uni-forms-item label ="整改完成时间">
  52. <uni-datetime-picker type="date" v-model="form.rectifyTime" placeholder="请选择整改完成时间" />
  53. </uni-forms-item>
  54. </uni-card>
  55. <uni-card padding="0" margin="5px 0">
  56. <uni-forms-item label="验收说明">
  57. <uni-easyinput type="textarea" :maxlength="300"
  58. v-model="form.acceptRemark" autoHeight
  59. placeholder="请输入验收说明"></uni-easyinput>
  60. <view class="word-limit">{{form.acceptRemark.length||0}}/300</view>
  61. </uni-forms-item>
  62. <uni-forms-item label ="验收完成时间">
  63. <uni-datetime-picker type="date" v-model="form.acceptTime" placeholder="请选择验收完成时间" />
  64. </uni-forms-item>
  65. </uni-card>
  66. <uni-forms-item label="附件">
  67. <view class="attachbox">
  68. <view class="attach" v-for="(attach, index) in form.attachList" :key="index"
  69. @click="preview(form.attachList)"
  70. @longpress="delAttach(index)">
  71. <image :src="attach.attachUrl"></image>
  72. </view>
  73. <view class="attach">
  74. <view class="handle" @click="uploadAttach">
  75. <uni-icons type="plusempty" size="40" color="#999999"></uni-icons>
  76. </view>
  77. </view>
  78. </view>
  79. </uni-forms-item>
  80. <uni-forms-item label="是否关闭">
  81. <uni-data-checkbox
  82. v-model="form.status"
  83. :localdata="[{ value: 0, text: '未整改' },{ value: 1, text: '已整改完成' }]" />
  84. </uni-forms-item>
  85. </uni-forms>
  86. <view class="handle-container">
  87. <button class="save" type="primary" @click="onSubmit">保存</button>
  88. <button class="cancel" type="default" @click="close">取消</button>
  89. </view>
  90. </view>
  91. </scroll-view>
  92. </uni-drawer>
  93. </template>
  94. <script>
  95. import dangerApi from '@/api/danger.js'
  96. import { upload } from '@/api/upload.js'
  97. export default{
  98. name:"CreateDanger",
  99. computed:{
  100. ents(){
  101. let ents=this.ent
  102. if(!ents)return []
  103. return ents.map(item=>{
  104. return{
  105. value:item.entId,
  106. text:item.entName
  107. }
  108. })
  109. },
  110. dangerCats(){
  111. let dangerCats=this.danger
  112. if(!dangerCats)return []
  113. return dangerCats.map(item=>{
  114. return{
  115. value:item.dangerCatId,
  116. text:item.dangerCatTitle
  117. }
  118. })
  119. },
  120. },
  121. props:{
  122. ent:{
  123. type:Array,
  124. default:()=>[]
  125. },
  126. danger:{
  127. type:Array,
  128. default:()=>[]
  129. }
  130. },
  131. data(){
  132. return{
  133. type:undefined,
  134. rules:{
  135. entName:{
  136. rules:[
  137. {
  138. required: true,
  139. errorMessage:"请输入企业名称"
  140. }
  141. ],
  142. validateTrigger:'submit'
  143. },
  144. entCatId:{
  145. rules:[
  146. {
  147. required: true,
  148. errorMessage:"请选择企业分类"
  149. }
  150. ],
  151. validateTrigger:'submit'
  152. }
  153. },
  154. dangerLevelOptions:[
  155. { value: 0, text: '末知' },
  156. { value: 1, text: '重大' },
  157. { value: 2, text: '较大' },
  158. { value: 3, text: '一般' },
  159. { value: 4, text: '较小' }
  160. ],
  161. statusOptions:[
  162. { value: 0, text: '未整改' },
  163. { value: 1, text: '已整改完成' }
  164. ],
  165. form:{
  166. entId: undefined,
  167. dangerId: 0,
  168. dangerCatId: 1,
  169. dangerCatTitle: '',
  170. dangerTitle: '',
  171. dangerTags:'',
  172. dangerCode: '',
  173. dangerLocation: '',
  174. dangerLevel: 2,
  175. dangerDesc: '',
  176. submitTime: '',
  177. submitRemark: '',
  178. dangerDeadLine: '',
  179. rectifyTime: '',
  180. dangerReason: '',
  181. rectifyCat: 1,
  182. rectifyRemark: '',
  183. acceptTime: '',
  184. acceptRemark: '',
  185. finishTime: '',
  186. status: 0,
  187. attachList: []
  188. }
  189. }
  190. },
  191. methods:{
  192. resetForm(){
  193. this.form={
  194. entId: undefined,
  195. dangerId: 0,
  196. dangerCatId: 1,
  197. dangerCatTitle: '',
  198. dangerTitle: '',
  199. dangerTags:'',
  200. dangerCode: '',
  201. dangerLocation: '',
  202. dangerLevel: 2,
  203. dangerDesc: '',
  204. submitTime: '',
  205. submitRemark: '',
  206. dangerDeadLine: '',
  207. rectifyTime: '',
  208. dangerReason: '',
  209. rectifyCat: 1,
  210. rectifyRemark: '',
  211. acceptTime: '',
  212. acceptRemark: '',
  213. finishTime: '',
  214. status: 0,
  215. attachList: []
  216. }
  217. },
  218. onSubmit(){
  219. this.$refs.form.validate().then(res=>{
  220. let submitFx=this.type==='add'?dangerApi.create:dangerApi.update
  221. submitFx(this.form).then(()=>{
  222. uni.showToast({
  223. icon:"none",
  224. title:"成功!!"
  225. })
  226. this.$emit('success')
  227. this.close();
  228. })
  229. }).catch(err =>{
  230. uni.showToast({
  231. icon:"none",
  232. title:"请检查填写信息!"
  233. })
  234. })
  235. },
  236. preview(urls=[]){
  237. if(urls.length>0){
  238. urls=urls.map(item=>item.attachUrl);
  239. uni.previewImage({
  240. urls
  241. })
  242. }
  243. },
  244. delAttach(idx){
  245. const self=this;
  246. uni.showModal({
  247. title: '提示',
  248. content: '是否确定删除',
  249. success: function (res) {
  250. if (res.confirm) {
  251. self.form.attachList=self.form.attachList.filter((item,index)=>index!==idx);
  252. }
  253. }
  254. });
  255. },
  256. uploadAttach(){
  257. const self=this;
  258. uni.chooseImage({
  259. count: 1,
  260. sizeType: ['original', 'compressed'],
  261. sourceType: ['album',"camera"], //从相册选择
  262. success:(res)=>{
  263. let filePath=res.tempFilePaths[0]
  264. upload({filePath}).then((resq)=>{
  265. var fileResq=JSON.parse(resq)
  266. let file={
  267. "attachId": fileResq.data.fileId,
  268. "attachName": fileResq.data.fileTitle,
  269. "attachExt": fileResq.data.fileExt,
  270. "attachUrl": fileResq.data.fileUrl,
  271. "attachIcon": fileResq.data.fileIcon
  272. }
  273. self.form.attachList.push(file);
  274. })
  275. }
  276. });
  277. },
  278. show({type,item}){
  279. this.resetForm()
  280. this.type=type
  281. this.$refs.drawer.open()
  282. if(type==='edit'){
  283. dangerApi.getById(item.dangerId).then((res)=>{
  284. this.form={...res.data}
  285. })
  286. }
  287. },
  288. close(){
  289. this.$refs.drawer.close()
  290. }
  291. }
  292. }
  293. </script>
  294. <style lang="scss" scoped>
  295. .scroll-view {
  296. height: 100%;
  297. padding: 20rpx;
  298. box-sizing: border-box;
  299. .form-wrap{
  300. padding:40rpx 20rpx;
  301. .handle-container{
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. button{
  306. width: 160rpx;
  307. padding: 20rpx 16rpx;
  308. line-height: 1;
  309. font-size: 28rpx;
  310. &.save{
  311. background-color: #007aff;
  312. }
  313. }
  314. }
  315. .word-limit{
  316. text-align: right;
  317. padding: 10rpx 0;
  318. color: #999;
  319. font-size: 26rpx;
  320. }
  321. .attachbox{
  322. display: flex;
  323. flex-wrap: wrap;
  324. .attach{
  325. padding: 16rpx 18rpx;
  326. image,.handle{
  327. display: block;
  328. width: 100rpx;
  329. height: 100rpx;
  330. box-shadow: rgba(0,0,0,0.6);
  331. border: 1rpx solid #ccc;
  332. border-radius: 10px;
  333. overflow: hidden;
  334. box-sizing: border-box;
  335. }
  336. .handle{
  337. display: flex;
  338. justify-content: center;
  339. align-items: center;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. </style>