mattersAdd.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. *@description: 新增资讯
  3. *@author: yh Fu
  4. *@date: 2024-03-04 14:45:49
  5. *@version: V1.0.5
  6. */
  7. <template>
  8. <view>
  9. <uni-forms :rules="rules" :value="formData" ref="form" validate-trigger="bind" err-show-type="undertext" class="uniForm">
  10. <uni-group title="基本信息" top="0">
  11. <uni-forms-item name="title" required label="事项标题">
  12. <uni-easyinput type="text" :inputBorder="true" v-model="formData.title" placeholder="请输入事项标题"></uni-easyinput>
  13. </uni-forms-item>
  14. <!-- 使用原生input,需要绑定binddata -->
  15. <uni-forms-item name="content" required label="正文">
  16. <uni-easyinput type="textarea" v-model="formData.content" :maxlength="50" @blur="binddata('textDetails', $event.detail.value)" placeholder="请输入正文"></uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item label="电话" name="phone">
  19. <uni-easyinput v-model="formData.phone" placeholder="请输入电话" />
  20. </uni-forms-item>
  21. <uni-forms-item name="address" label="地址">
  22. <uni-easyinput type="text" :inputBorder="true" v-model="formData.address" placeholder="请输入地址"></uni-easyinput>
  23. </uni-forms-item>
  24. <uni-forms-item name="type" label="主题类型" required label-width="30%">
  25. <uni-data-select
  26. style="width: 30%;margin: auto;"
  27. v-model="formData.type"
  28. placeholder="请选择主题类型"
  29. field="deptName as value, deptName as text"
  30. :localdata="topicTypeList"
  31. ></uni-data-select>
  32. </uni-forms-item>
  33. <uni-forms-item name="department" label="所属部门" required label-width="30%">
  34. <uni-data-select
  35. style="width: 30%;margin: auto;"
  36. v-model="formData.department"
  37. placeholder="请选择所属部门"
  38. field="name as value, name as text"
  39. :localdata="departmentList"
  40. ></uni-data-select>
  41. </uni-forms-item>
  42. <uni-forms-item name="picture" label="图片">
  43. <upload :imgArr="imageList" :fileSize="1" :limit="3" @updateImg="updateImg"></upload>
  44. </uni-forms-item>
  45. </uni-group>
  46. <view>
  47. <!-- <button @click="submitForm('form')">校验表单</button>
  48. <button size="mini" @click="validateField('form')">只校验用户名和邮箱项</button>
  49. <button size="mini" @click="clearValidate('form', 'name')">移除用户名的校验结果</button>
  50. <button size="mini" @click="clearValidate('form')">移除全部表单校验结果</button>
  51. <button @click="resetForm">重置表单</button> -->
  52. <button @click="submitForm('form')">新增</button>
  53. </view>
  54. </uni-forms>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. getListTopicType,
  60. getListDepts ,
  61. } from '@/api/me/matters/matters.js'
  62. import upload from '@/components/upload/index.vue'
  63. import {addsc} from '@/api/handleAffairs/matter.js'
  64. export default {
  65. components: {
  66. upload
  67. },
  68. created(){
  69. getListTopicType().then(e => {
  70. e.rows.forEach(v => {
  71. this.topicTypeList.push({
  72. text:v.deptName,
  73. value:v.deptName
  74. })
  75. })
  76. })
  77. getListDepts().then(e => {
  78. e.rows.forEach(v => {
  79. this.departmentList.push({
  80. text:v.name,
  81. value:v.name
  82. })
  83. })
  84. })
  85. },
  86. data() {
  87. return {
  88. formData: {
  89. title: '',
  90. textDetails: '',
  91. address:'',
  92. phone:'',
  93. content:'',
  94. picture:'',
  95. isGovernment: false,
  96. isTop: false,
  97. country: 2,
  98. weight: 120,
  99. birth: '',
  100. type:'',
  101. department:''
  102. },
  103. imageList:[],
  104. topicTypeList:[],
  105. departmentList:[],
  106. show: false,
  107. rules: {
  108. title: {
  109. rules: [{
  110. required: true,
  111. errorMessage: '请输入标题'
  112. },
  113. {
  114. minLength: 1,
  115. errorMessage: '标题不得为空'
  116. }
  117. ]
  118. },
  119. content: {
  120. rules: [{
  121. required: true,
  122. errorMessage: '请输入正文'
  123. },
  124. {
  125. minLength: 1,
  126. errorMessage: '正文不得为空'
  127. }
  128. ]
  129. },
  130. type: {
  131. rules: [{
  132. required: true,
  133. errorMessage: '请选择主题类型'
  134. },
  135. {
  136. minLength: 1,
  137. errorMessage: '主题类型不得为空'
  138. }
  139. ]
  140. },
  141. department: {
  142. rules: [{
  143. required: true,
  144. errorMessage: '请选择所属部门'
  145. },
  146. {
  147. minLength: 1,
  148. errorMessage: '所属部门不得为空'
  149. }
  150. ]
  151. },
  152. // textDetails: {
  153. // rules: [{
  154. // required: true,
  155. // errorMessage: '请输入正文'
  156. // },
  157. // {
  158. // minLength: 10,
  159. // errorMessage: '正文不得少于 {minLength} 字'
  160. // }
  161. // ]
  162. // },
  163. }
  164. }
  165. },
  166. methods: {
  167. submitForm(form) {
  168. this.$refs[form]
  169. .submit()
  170. .then(res => {
  171. console.log("222222222222222222", res);
  172. uni.showModal({
  173. title: '确认',
  174. content: '是否添加该事项?',
  175. success: (res) => {
  176. console.log("1111111111111", res);
  177. if (res.confirm) {
  178. // 用户点击确定按钮
  179. addsc(this.formData).then(response => {
  180. console.log("7777777", this.formData);
  181. this.$modal.msgSuccess("新增成功");
  182. uni.navigateBack();
  183. }).catch(error => {
  184. console.error("新增方法出错:", error);
  185. });
  186. } else if (res.cancel) {
  187. // 用户点击取消按钮
  188. uni.showToast({
  189. title: '已取消',
  190. icon: 'none'
  191. });
  192. }
  193. }
  194. });
  195. })
  196. .catch(error => {
  197. console.error("表单提交出错:", error);
  198. });
  199. },
  200. // submitForm(form) {
  201. // this.$refs[form]
  202. // .submit()
  203. // .then(res => {
  204. // console.log('表单的值:', res)
  205. // uni.showToast({
  206. // title: '验证成功'
  207. // })
  208. // })
  209. // .catch(errors => {
  210. // console.error('验证失败:', errors)
  211. // })
  212. // },
  213. resetForm() {
  214. this.$refs.form.resetFields()
  215. },
  216. // validateField(form) {
  217. // this.$refs[form]
  218. // .validateField(['name', 'email'])
  219. // .then(res => {
  220. // uni.showToast({
  221. // title: '验证成功'
  222. // })
  223. // console.log('表单的值:', res)
  224. // })
  225. // .catch(errors => {
  226. // console.error('验证失败:', errors)
  227. // })
  228. // },
  229. updateImg(imgList){
  230. this.imageList = imgList;
  231. // this.formData.picture =this.imageList
  232. // this.formData.picture = JSON.stringify(this.imageList);
  233. const pictureString = '"' + this.imageList.join('","') + '"';
  234. // 将转换后的字符串赋值给 this.formData.picture
  235. this.formData.picture = pictureString;
  236. // console.log("1111111111111",)
  237. },
  238. // clearValidate(form, name) {
  239. // if (!name) name = []
  240. // this.$refs[form].clearValidate(name)
  241. // }
  242. }
  243. }
  244. </script>
  245. <style lang="scss">
  246. .uniForm{
  247. .uni-forms-item{
  248. margin: auto;
  249. .uni-forms-item__content{
  250. margin: auto;
  251. }
  252. }
  253. }
  254. .radioView{
  255. margin: auto;
  256. .uni-forms-item__content{
  257. margin: auto;
  258. }
  259. }
  260. .uni-input-border {
  261. padding: 0 10px;
  262. height: 35px;
  263. width: 100%;
  264. font-size: 14px;
  265. color: #666;
  266. border: 1px #e5e5e5 solid;
  267. border-radius: 5px;
  268. box-sizing: border-box;
  269. }
  270. </style>