formCreate.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="container">
  3. <uni-forms ref="form" :rules="rules" :model="form" labelWidth="80px" :label-position="alignment">
  4. <uni-forms-item label="申请人">
  5. <uni-easyinput v-model="form.employeeName" disabled />
  6. </uni-forms-item>
  7. <uni-forms-item label="部门">
  8. <uni-easyinput v-model="form.deptName" disabled />
  9. </uni-forms-item>
  10. <uni-forms-item label="职位">
  11. <uni-easyinput v-model="form.position" disabled />
  12. </uni-forms-item>
  13. <uni-forms-item label="手机号">
  14. <uni-easyinput v-model="form.employeePhone" disabled />
  15. </uni-forms-item>
  16. <uni-forms-item label="事项标题" required name="title">
  17. <uni-easyinput maxlength="20" v-model="form.title" placeholder="请输入申请的简要标题" />
  18. </uni-forms-item>
  19. <uni-forms-item label="详细描述" required name="description">
  20. <uni-easyinput maxlength="200" type="textarea" v-model="form.description" placeholder="请输入详细描述" />
  21. </uni-forms-item>
  22. <uni-forms-item label="附件">
  23. <view class="upload-wrap">
  24. <button type="primary" size="mini" @click="handleUploadClick">点击上传</button>
  25. <xe-upload ref="XeUpload" :options="uploadOptions" @callback="handleUploadCallback"></xe-upload>
  26. <view class="mgb-16 file-wrap" v-for="(item, index) in fileList" :key="index">
  27. <view class="btn-click file-line" @click="handlePreview(item)">
  28. <view class="file-info">
  29. <image :src="icons.file" mode="aspectFill" class="file-icon" />
  30. <text class="file-name">{{ item.name || title[type] }}</text>
  31. </view>
  32. <image :src="icons.close" mode="aspectFill" class="file-icon"
  33. @click.stop="handleDeleteFile(index)" />
  34. </view>
  35. </view>
  36. </view>
  37. </uni-forms-item>
  38. <uni-forms-item label="备注">
  39. <uni-easyinput maxlength="200" type="textarea" v-model="form.remarks" placeholder="请输入备注" />
  40. </uni-forms-item>
  41. </uni-forms>
  42. <view class="button-group">
  43. <button type="primary" size="mini" @click="submit('form')">提交</button>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { uploadFile } from "@/api/system/user"
  49. export default {
  50. data() {
  51. return {
  52. alignment:'top',
  53. uploadOptions: {},
  54. fileList: [],
  55. icons: {
  56. close: '/static/icon_close.png',
  57. file: '/static/icon_file.png',
  58. },
  59. // 表单数据
  60. form: {
  61. employeeName: undefined,
  62. deptName: undefined,
  63. position: undefined,
  64. employeePhone: undefined,
  65. title: undefined,
  66. fileIdList: undefined,
  67. remarks: undefined,
  68. peopleList: '',
  69. },
  70. // 校验规则
  71. rules: {
  72. title: {
  73. rules: [{
  74. required: true,
  75. errorMessage: '请输入申请的简要标题'
  76. }, ]
  77. },
  78. description: {
  79. rules: [{
  80. required: true,
  81. errorMessage: '请输入详细描述'
  82. }, ]
  83. }
  84. },
  85. }
  86. },
  87. onLoad() {},
  88. methods: {
  89. handleUploadClick() {
  90. this.$refs.XeUpload.upload('file');
  91. },
  92. handleUploadCallback(e) {
  93. console.log('UploadCallback', e);
  94. let data = { filePath: e.data[0].tempFilePath}
  95. uploadFile(data).then(response => {
  96. const tmpFiles = ([response.data] || []).map(({ id, url, name, type }) => {
  97. return {
  98. id,
  99. url,
  100. name,
  101. type,
  102. };
  103. });
  104. this.fileList.push(...tmpFiles);
  105. })
  106. },
  107. // 预览
  108. handlePreview(val) {
  109. console.log('PreviewFile', val);
  110. if (val.type == 'image/png' || val.type == 'image/jpg') {
  111. return uni.previewImage({
  112. current: 0,
  113. urls: [val.url],
  114. });
  115. }else{
  116. }
  117. },
  118. handleDeleteFile(index) {
  119. this.fileList.splice(index, 1);
  120. },
  121. submit(ref) {
  122. console.log(this.form);
  123. this.$refs[ref].validate().then(res => {
  124. console.log('success', res);
  125. uni.showToast({
  126. title: `校验通过`
  127. })
  128. }).catch(err => {
  129. console.log('err', err);
  130. })
  131. },
  132. }
  133. }
  134. </script>
  135. <style lang="scss">
  136. .container {
  137. padding: 15px;
  138. background-color: #fff;
  139. }
  140. .segmented-control {
  141. margin-bottom: 15px;
  142. }
  143. .button-group {
  144. margin-top: 15px;
  145. display: flex;
  146. justify-content: space-around;
  147. }
  148. .form-item {
  149. display: flex;
  150. align-items: center;
  151. flex: 1;
  152. }
  153. .button {
  154. display: flex;
  155. align-items: center;
  156. height: 35px;
  157. line-height: 35px;
  158. margin-left: 10px;
  159. }
  160. </style>
  161. <style lang="scss" scoped>
  162. .btn-click {
  163. transition: all 0.3s;
  164. opacity: 1;
  165. }
  166. .btn-click:active {
  167. opacity: 0.5;
  168. }
  169. .mgb-16 {
  170. margin-bottom: 16rpx;
  171. &:last-child {
  172. margin-bottom: 0;
  173. }
  174. }
  175. .upload-wrap {
  176. width: 100%;
  177. border-radius: 16rpx;
  178. background: white;
  179. // padding: 32rpx;
  180. .upload-btn {
  181. width: 100%;
  182. height: 176rpx;
  183. border: 2rpx dashed #AAAAAA;
  184. background: #FAFAFA;
  185. border-radius: 16rpx;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. flex-direction: column;
  190. .upload-icon {
  191. width: 48rpx;
  192. height: 48rpx;
  193. margin-bottom: 8rpx;
  194. }
  195. .upload-text {
  196. font-size: 26rpx;
  197. color: #9E9E9E;
  198. line-height: 40rpx;
  199. }
  200. }
  201. .file-wrap {
  202. .file-line {
  203. width: 100%;
  204. background: #F5F5F5;
  205. border-radius: 8rpx;
  206. padding: 16rpx;
  207. font-size: 26rpx;
  208. color: #1A1A1A;
  209. line-height: 40rpx;
  210. display: flex;
  211. align-items: center;
  212. justify-content: space-between;
  213. .file-info {
  214. width: 90%;
  215. display: flex;
  216. align-items: center;
  217. .file-name {
  218. max-width: 80%;
  219. padding-left: 16rpx;
  220. overflow: hidden;
  221. text-overflow: ellipsis;
  222. white-space: nowrap;
  223. }
  224. }
  225. .file-icon {
  226. width: 40rpx;
  227. height: 40rpx;
  228. flex-shrink: 0;
  229. }
  230. .file-empty {
  231. color: #999999;
  232. }
  233. }
  234. }
  235. }
  236. </style>