Create.vue 9.6 KB

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