Report.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. <view class="Report">
  5. <uni-card title="模板" extra="可点选下面模板,然后修改填写" padding="0" margin="10px 5px">
  6. <view class="templatewrap">
  7. <view class="template" v-for="(template,templateIdx) in templateList" :key="template.reportingTypeId">
  8. <view class="reportingTypeTitle">{{template.reportingTypeTitle}}</view>
  9. <view class="template-item" v-for="(item,idx) in template.templateList" :key="item.templateId" @click='changeTemplate(item)'
  10. :class="form.templateId===item.templateId?'active':''">
  11. <text class="index">{{idx+1}}.</text>
  12. <text class="word">{{item.templateTitle}}</text>
  13. </view>
  14. </view>
  15. </view>
  16. </uni-card>
  17. <uni-card :title="form.reportingTypeTitle" :extra="form.templateTitle" :note="form.templateDesc" padding="0" margin="10px 5px">
  18. <view class="form-wrap" >
  19. <uni-forms ref="form" label-position="top" :rules="rules" :model="form" :label-width="300">
  20. <uni-forms-item label ="消息标题">
  21. <uni-easyinput v-model="form.reportingSubject" type="textarea" auto-height="true" placeholder="请输入消息标题" :maxlength="150" />
  22. <view class="word-limit">{{form.reportingSubject.length||0}}/150</view>
  23. </uni-forms-item>
  24. <uni-forms-item label ="上报单位" >
  25. <uni-easyinput v-model="form.reportingGroupName" placeholder="请输入上报单位" />
  26. </uni-forms-item>
  27. <uni-forms-item label="请输入消息内容">
  28. <uni-easyinput type="textarea" :maxlength="300"
  29. v-model="form.reportingContent" autoHeight
  30. placeholder="请输入消息内容"></uni-easyinput>
  31. <view class="word-limit">{{form.reportingContent.length||0}}/300</view>
  32. </uni-forms-item>
  33. </uni-forms>
  34. <view class="handle-container">
  35. <button class="save" type="primary" @click="onSubmit">保存</button>
  36. <button class="cancel" type="default" @click="close">取消</button>
  37. </view>
  38. </view>
  39. </uni-card>
  40. </view>
  41. </scroll-view>
  42. </uni-drawer>
  43. </template>
  44. <script>
  45. import reportingApi from '@/api/reporting.js'
  46. export default{
  47. name:"EditReporting",
  48. data(){
  49. return{
  50. defaultTemplateId: 1,
  51. templateList:uni.getStorageSync('reportTemplates')||[],
  52. form:{
  53. templateId: undefined ,
  54. templateTitle: '',
  55. reportingTypeId: '',
  56. reportingTypeTitle: '',
  57. reportingSubject: '',
  58. reportingContent: '',
  59. reportingGroupName: "",
  60. templateDesc: '',
  61. }
  62. }
  63. },
  64. methods:{
  65. resetForm(){
  66. let accountInfo=uni.getStorageSync('accountInfo')
  67. this.form={
  68. templateId: undefined ,
  69. templateTitle: '',
  70. reportingTypeId: '',
  71. reportingTypeTitle: '',
  72. reportingSubject: '',
  73. reportingContent: '',
  74. reportingGroupName: accountInfo&&accountInfo.groupName,
  75. templateDesc: '',
  76. }
  77. },
  78. onSubmit(){
  79. this.$refs.form.validate().then(res=>{
  80. reportingApi.create(this.form).then(()=>{
  81. uni.showToast({
  82. icon:"none",
  83. title:"成功!!"
  84. })
  85. this.$emit('success')
  86. this.close();
  87. })
  88. }).catch(err =>{
  89. uni.showToast({
  90. icon:"none",
  91. title:"请检查填写信息!"
  92. })
  93. })
  94. },
  95. changeTemplate(item){
  96. reportingApi.getTemplateById(item.templateId).then((res)=>{
  97. this.getTemplateData(res.data)
  98. })
  99. },
  100. show(){
  101. this.resetForm()
  102. this.$refs.drawer.open()
  103. if(!uni.getStorageSync('reportTemplates')){
  104. reportingApi.getTemplateByView().then((res)=>{
  105. uni.setStorageSync('reportTemplates',res.data)
  106. this.templateList=res.data
  107. })
  108. }
  109. reportingApi.getTemplateById(this.defaultTemplateId).then((res)=>{
  110. this.getTemplateData(res.data)
  111. })
  112. },
  113. getTemplateData(data){
  114. this.form.templateId = data.templateId
  115. this.form.reportingTitle = data.templateTitle
  116. this.form.reportingTypeId = data.reportingTypeId
  117. this.form.reportingTypeTitle = data.reportingTypeTitle
  118. this.form.reportingSubject = data.templateSubject
  119. this.form.reportingContent = data.templateContent
  120. this.form.templateDesc = data.templateDesc
  121. this.form.templateTitle = data.templateTitle
  122. },
  123. close(){
  124. this.$refs.drawer.close()
  125. }
  126. },
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .scroll-view {
  131. height: 100%;
  132. padding: 20rpx 10rpx;
  133. box-sizing: border-box;
  134. .templatewrap{
  135. padding-top: 16rpx;
  136. .template{
  137. .reportingTypeTitle{
  138. font-weight: 500;
  139. color: #000;
  140. font-size: 30rpx;
  141. }
  142. .template-item{
  143. padding: 10rpx 0 10rpx 24rpx;
  144. &.active{
  145. background-color:rgba(64, 158, 255,1);
  146. .index,.word{
  147. color: #fff;
  148. }
  149. }
  150. .index{
  151. padding-right: 4rpx;
  152. }
  153. .word{
  154. font-size: 24rpx;
  155. color: #999999;
  156. line-height: 1;
  157. }
  158. }
  159. }
  160. }
  161. .form-wrap{
  162. padding:40rpx 0;
  163. .handle-container{
  164. display: flex;
  165. justify-content: center;
  166. align-items: center;
  167. button{
  168. width: 160rpx;
  169. padding: 20rpx 16rpx;
  170. line-height: 1;
  171. font-size: 28rpx;
  172. &.save{
  173. background-color: #007aff;
  174. }
  175. }
  176. }
  177. .word-limit{
  178. text-align: right;
  179. padding: 10rpx 0;
  180. color: #999;
  181. font-size: 26rpx;
  182. }
  183. .attachbox{
  184. display: flex;
  185. flex-wrap: wrap;
  186. .attach{
  187. padding: 16rpx 18rpx;
  188. image,.handle{
  189. display: block;
  190. width: 100rpx;
  191. height: 100rpx;
  192. box-shadow: rgba(0,0,0,0.6);
  193. border: 1rpx solid #ccc;
  194. border-radius: 10px;
  195. overflow: hidden;
  196. box-sizing: border-box;
  197. }
  198. .handle{
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. </style>