uploadEditMyHonor.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <view class="page_body">
  3. <!-- 头部 -->
  4. <nav-bar height="96" :title="state.title" :onlyTitle="true" :showHeaderborder="true" @GoBack="GoBack"></nav-bar>
  5. <view :class="['page_content',{'view':state.type=='view'}]">
  6. <uni-forms ref="valiForm" :class="['forms_style',{'view':state.type=='view'}]" :rules="rules" :model="state.formData" border labelWidth="160rpx" label-align="right">
  7. <uni-forms-item label="荣誉类型:" required name="honorTypeValue">
  8. <template v-if="state.type=='view'">{{state.formData.honorTypeValue}}</template>
  9. <uni-data-select v-else v-model="state.formData.honorTypeValue" :clear="false" placeholder="请选择荣誉类型" :disabled="state.type=='upload'?false:true" :localdata="state.honorTypeData" style="width: 400rpx;" @change="ChangeDataSelect"></uni-data-select>
  10. </uni-forms-item>
  11. <template v-for="item in state.dynamicFormData">
  12. <uni-forms-item :label="`${item.dictName}:`" required :name="`input_${item.id}`">
  13. <template v-if="state.type=='view'">
  14. <template v-if="item.dictType == 1 || item.dictType == 2">{{state.formData[`${item.dictShowType}_${item.id}`]}}</template>
  15. <uni-dateformat v-else :date="state.formData[`${item.dictShowType}_${item.id}`]" format="yyyy-MM-dd"></uni-dateformat>
  16. </template>
  17. <template v-else>
  18. <uni-easyinput v-if="item.dictType == 1" v-model="state.formData[`${item.dictShowType}_${item.id}`]" :disabled="item.onlyRead == 1" :maxlength="100" :placeholder="`请输入${item.dictName}`" :style="{width: item.dictName=='获奖人'?'400rpx':''}" />
  19. <uni-data-select v-else-if="item.dictType == 2" v-model="state.formData[`${item.dictShowType}_${item.id}`]" :clear="false" :placeholder="`请选择${item.dictName}`" :localdata="item.dictList" style="width: 400rpx;"></uni-data-select>
  20. <uni-datetime-picker v-else type="date" :end="todayStr" :clear-icon="false" v-model="state.formData[`${item.dictShowType}_${item.id}`]" placeholder=" " style="width: 400rpx;" />
  21. </template>
  22. </uni-forms-item>
  23. </template>
  24. <uni-forms-item label="荣誉证书:" required name="certPicDatas">
  25. <uv-upload :maxCount="state.type=='view'?state?.formData?.certPicDatas?.length:50" :deletable="state.type!='view'" :fileList="state.formData.certPicDatas" width="240rpx" height="140rpx" multiple :previewFullImage="true" @AfterRead="AfterRead" @delete="DeletePic">
  26. <view class="upload_btn" v-if="state.type!='view'">
  27. <uni-icons class="upload_btn_icon" type="plusempty"></uni-icons>
  28. <view class="upload_btn_text">上传荣誉证书</view>
  29. </view>
  30. </uv-upload>
  31. </uni-forms-item>
  32. <uni-forms-item label="佐证材料:">
  33. </uni-forms-item>
  34. <uni-forms-item label="驳回原因 :" v-if="state.formData.overruleContent">
  35. {{state.formData.overruleContent}}
  36. </uni-forms-item>
  37. <uni-forms-item label="审核人:" v-if="state.type=='view'">
  38. {{state.formData.reviewTeacherName}}
  39. </uni-forms-item>
  40. </uni-forms>
  41. </view>
  42. <view class="page_foot" v-if="state.type!='view'"><button class="btn_submit" type="primary" :loading="state.loading" @click="honorTypeConfirm">确认</button></view>
  43. </view>
  44. </template>
  45. <script setup>
  46. import navBar from '@/components/navBar.vue';
  47. import uniForms from '@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue';
  48. import uniFormsItem from '@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue';
  49. import uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue';
  50. import uniDataSelect from '@/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue';
  51. import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
  52. import uniDateformat from '@/uni_modules/uni-dateformat/components/uni-dateformat/uni-dateformat.vue';
  53. import uvUpload from '@/uni_modules/uv-upload/components/uv-upload/uv-upload.vue';
  54. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  55. import {queryHonorTypeDictList,queryHonorDataDetailById,addHonorCertData,updateHonorCertData} from '@/reqApi/teacherHonor.js';
  56. import { unioformDateTransform,fileSizeConvert } from '@/common/common.js';
  57. import {
  58. reactive,
  59. ref,
  60. onMounted,
  61. nextTick
  62. } from 'vue';
  63. import { onLoad } from '@dcloudio/uni-app';
  64. const state = reactive({
  65. id:'',//荣誉类型id
  66. title:'',//标题
  67. type:'',
  68. formData: {
  69. honorTypeValue: '',//荣誉类型id
  70. certPicDatas:[],//荣誉证书
  71. docDatas:[],//佐证材料
  72. overruleContent:'',//驳回原因
  73. reviewTeacherName:''//审核人
  74. },
  75. honorTypeData:[],//荣誉类型下拉
  76. dynamicFormData:[],//动态表单
  77. dictDatas:[],//动态表单传参
  78. loading:false
  79. })
  80. const todayStr = ref(new Date().toISOString().split('T')[0]);
  81. const rules = ref({
  82. honorTypeValue: { rules: [{ required: true, errorMessage: '请选择荣誉类型' }] },
  83. certPicDatas: { rules: [{ required: true, errorMessage: '请上传荣誉证书' }] },
  84. });
  85. onLoad(async(option) => {
  86. state.id = option.id;
  87. state.type = option.type;
  88. await GetHonorTypeDictList(option.type);//查询荣誉类型下拉数据
  89. if(option.type == 'upload'){
  90. state.title = '上传荣誉';
  91. }else{
  92. if(option.type == 'edit'){
  93. state.title = '修改荣誉';
  94. }else {
  95. state.title = decodeURIComponent(option.honorName);
  96. }
  97. GetHonorDataDetailById();
  98. }
  99. uni.setStorageSync('isLoadMyHonorList', false);//返回列表页是否重新加载我的荣誉列表
  100. })
  101. //查询荣誉类型下拉数据
  102. const GetHonorTypeDictList = async (type) => {
  103. await queryHonorTypeDictList().then(res=>{
  104. if(res.code == 200){
  105. const honorTypeData = res?.data?.honorTypeDictBOS || [];
  106. honorTypeData.forEach(item=>{
  107. item.value = item.id;
  108. item.text = item.honorTypeName;
  109. const honorTypeDictData = item?.honorTypeDictBOS || [];
  110. honorTypeDictData.forEach(itemList=>{
  111. if(itemList.dictType == 2){//单选
  112. itemList.dictShowType = 'radio';
  113. const dictList = itemList?.dictList || [];
  114. dictList.forEach(dic=>{
  115. dic.text = dic.dictName;
  116. dic.value = dic.id
  117. })
  118. }else if(itemList.dictType == 1){//输入框
  119. itemList.dictShowType = 'input';
  120. }else{//日期
  121. itemList.dictShowType = 'datetime';
  122. }
  123. })
  124. })
  125. state.honorTypeData = honorTypeData;//荣誉类型下拉数据;
  126. if(type == 'upload'){//荣誉类型默认值
  127. state.formData.honorTypeValue = honorTypeData?.[0].value || '';//荣誉类型默认值
  128. const honorTypeDictData = honorTypeData?.[0]?.honorTypeDictBOS || [];
  129. SetDynamicFormData(honorTypeDictData);//设置动态表单
  130. }
  131. }else{
  132. state.honorTypeData = [];
  133. }
  134. })
  135. }
  136. //设置动态表单的值
  137. const SetDynamicFormData = (honorTypeDictData) => {
  138. honorTypeDictData.forEach(item=>{
  139. if(item.dictType == 2){//单选
  140. state.formData[`${item.dictShowType}_${item.id}`] = '';
  141. rules.value[`${item.dictShowType}_${item.id}`] = { rules: [{ required: true, errorMessage: `请选择${item.dictName}` }] };
  142. }else {//输入框 日期
  143. const value = item?.dictList?.[0]?.dictName || '';
  144. state.formData[`${item.dictShowType}_${item.id}`] = value;
  145. const placeholder = item.dictType == 1 ? '请输入' : '请选择';
  146. rules.value[`${item.dictShowType}_${item.id}`] = { rules: [{ required: true, errorMessage: `${placeholder}${item.dictName}` }] };
  147. }
  148. })
  149. state.dynamicFormData = honorTypeDictData;//动态表单
  150. }
  151. //改变荣誉类型
  152. const ChangeDataSelect = (val) => {
  153. const selectedHonorType = state.honorTypeData.find(item=>item.id == val);
  154. const honorTypeDictData = selectedHonorType?.honorTypeDictBOS || [];
  155. SetDynamicFormData(honorTypeDictData)
  156. }
  157. //查看荣誉详情接口
  158. const GetHonorDataDetailById = () => {
  159. queryHonorDataDetailById(state.id).then(res=>{
  160. if(res.code == 200){
  161. const honorTypeId = res?.data?.honorTypeId || '';
  162. const honorTypeName = res?.data?.honorTypeName || '';
  163. state.formData.honorTypeValue = state.type=='view'?honorTypeName:honorTypeId;//荣誉类型默认值
  164. //给动态表单设置值
  165. const selectedHonorType = state.honorTypeData.find(item=>item.id == honorTypeId);
  166. const honorTypeDictData = selectedHonorType?.honorTypeDictBOS || [];
  167. state.dynamicFormData = honorTypeDictData;//动态表单
  168. const honorDataList = res?.data?.honorDataList || '';
  169. honorDataList.forEach(item=>{
  170. if(item.dictType == 2){//单选
  171. state.formData[`radio_${item.honorDictLibNameId}`] = state.type!='view'?item.honorDictLibValueId:item.honorDictLibValue;
  172. }else {//输入框 日期
  173. const type = item.dictType == 1 ? 'input' : 'datetime';
  174. state.formData[`${type}_${item.honorDictLibNameId}`] = item.honorDictLibValue;
  175. }
  176. })
  177. const honorDataCertList = res?.data?.honorDataCertList || [];//荣誉证书
  178. state.formData.certPicDatas = honorDataCertList.map(item=>({
  179. ...item,
  180. url:item.picUrl
  181. }));//荣誉证书
  182. state.formData.docDatas = res?.data?.supportDocumentList || [];//佐证材料
  183. state.formData.overruleContent = res?.data?.overruleContent || '';//驳回原因
  184. state.formData.reviewTeacherName = res?.data?.reviewTeacherName || '';//审核人
  185. }
  186. })
  187. }
  188. //提交
  189. const honorTypeConfirm = () => {
  190. for (const key in rules.value) {
  191. if (state.formData?.[key] === "" || state.formData?.[key] === null || state.formData?.[key]&&state.formData?.[key]?.length === 0) {
  192. const errorMessage = rules.value[key].rules[0].errorMessage;
  193. uni.showToast({
  194. title: errorMessage,
  195. icon: 'none'
  196. })
  197. return false
  198. }
  199. }
  200. state.loading = true;
  201. const certPicDatas = state.formData.certPicDatas.map(item=>({
  202. name:item.picName,
  203. url:item.url,
  204. fileSize:item?.fileSize || '',
  205. time:item?.time || '',
  206. }))
  207. const docDatas = state.formData.docDatas.map(item=>({
  208. name:item.documentName,
  209. url:item.documentUrl,
  210. fileSize:item.fileSize,
  211. time:item.createdAt,
  212. }))
  213. const dictDatas = [];
  214. state.dynamicFormData.forEach(item=>{
  215. if(item.dictType == 2){//单选
  216. const valueData = state.formData[`${item.dictShowType}_${item.id}`];
  217. const dictList = item?.dictList || [];
  218. const valueName = dictList.find(dic=>dic.id == valueData);
  219. dictDatas.push({
  220. keyId: item.id,
  221. keyName: item.dictName,
  222. valueId: valueData,
  223. valueName: valueName?.dictName || ''
  224. })
  225. }else{
  226. let valueData = state.formData[`${item.dictShowType}_${item.id}`];
  227. if(state.type == 'upload' && Number(item.dictType) === 0){
  228. valueData = valueData + ' 00:00:00'
  229. }
  230. const dictList = item?.dictList || [];
  231. dictDatas.push({
  232. keyId: item.id,
  233. keyName: item.dictName,
  234. valueId: dictList?.[0]?.id,
  235. valueName: valueData
  236. })
  237. }
  238. })
  239. let params = {
  240. certPicDatas: certPicDatas,
  241. dictDatas: dictDatas,
  242. docDatas:docDatas,
  243. honorTypeId: state.formData.honorTypeValue
  244. }
  245. if(state.id){
  246. params.id = state.id;
  247. updateHonorCertData(params).then(res=>{
  248. if(res.code == 200){
  249. uni.showToast({
  250. title: '修改成功!',
  251. icon: 'none'
  252. })
  253. uni.setStorageSync('isLoadMyHonorList', true);//返回列表页是否重新加载我的荣誉列表
  254. GoBack();
  255. }
  256. }).finally(()=>{
  257. state.loading = false;
  258. })
  259. }else{//新建
  260. addHonorCertData(params).then(res=>{
  261. if(res.code == 200){
  262. uni.showToast({
  263. title: '上传成功!',
  264. icon: 'none'
  265. })
  266. uni.setStorageSync('isLoadMyHonorList', true);//返回列表页是否重新加载我的荣誉列表
  267. GoBack();
  268. }else{
  269. }
  270. }).finally(()=>{
  271. state.loading = false;
  272. })
  273. }
  274. }
  275. // 删除图片
  276. const DeletePic = (event) => {
  277. state.formData.certPicDatas.splice(event.index, 1);
  278. }
  279. // 新增图片
  280. const AfterRead = async(event) => {
  281. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  282. let lists = [].concat(event.file);
  283. let fileListLen = state.formData.certPicDatas.length;
  284. lists.map((item) => {
  285. state.formData.certPicDatas.push({
  286. ...item,
  287. status: 'uploading',
  288. message: '上传中'
  289. })
  290. })
  291. for (let i = 0; i < lists.length; i++) {
  292. const result = await uploadFilePromise(lists[i].url);
  293. if(result.code == 200){
  294. let item = state.formData.certPicDatas[fileListLen]
  295. state.formData.certPicDatas.splice(fileListLen, 1, Object.assign(item, {
  296. status: 'success',
  297. message: '',
  298. picName: result?.data?.fileName,
  299. url:result?.data?.url,
  300. fileSize:fileSizeConvert(lists?.[i]?.size || 0),
  301. time:unioformDateTransform(new Date())
  302. }))
  303. fileListLen++
  304. }
  305. }
  306. }
  307. const uploadFilePromise = (url) => {
  308. return new Promise((resolve, reject) => {
  309. const token = uni.getStorageSync('token'); // 假设从本地存储获取token
  310. let a = uni.uploadFile({
  311. url: '/api/v1/teach/oss/file/oss/upload_filesSele',
  312. filePath: url,
  313. name: 'file',
  314. header:{
  315. Authorization:token
  316. },
  317. success: (res) => {
  318. const resdata = JSON.parse(res.data);
  319. console.log(res,1323)
  320. resolve(resdata)
  321. }
  322. });
  323. })
  324. }
  325. const GoBack = () => {
  326. uni.navigateBack({
  327. delta: 1
  328. });
  329. }
  330. </script>
  331. <style lang="scss" scoped>
  332. .page_body{
  333. height: 100%;
  334. min-height: auto;
  335. overflow: hidden;
  336. }
  337. .page_content{
  338. height: calc(100% - 250rpx);
  339. overflow: auto;
  340. &.view{
  341. height: calc(100% - 96rpx);
  342. }
  343. }
  344. .forms_style{
  345. &.view{
  346. :deep(.uni-forms-item){
  347. &.uni-forms-item--border{
  348. .uni-forms-item__label{
  349. padding-top: 0rpx;
  350. }
  351. }
  352. }
  353. }
  354. :deep(.uni-forms-item){
  355. &.uni-forms-item--border{
  356. border-top: 0;
  357. border-bottom: 2rpx solid #F3F3F3;
  358. .uni-forms-item__label{
  359. align-items: flex-start;
  360. padding-top: 16rpx;
  361. }
  362. }
  363. .uv-upload__wrap{
  364. // flex-direction: row-reverse;
  365. gap: 24rpx 32rpx;
  366. .uv-upload__wrap__preview{
  367. background-color: #FFFFFF;
  368. border-radius: 20rpx;
  369. border: 2rpx solid #CED1D8;
  370. box-sizing: border-box;
  371. margin: 0;
  372. .uv-upload__deletable{
  373. top:10rpx;
  374. right: 10rpx;
  375. background-color: transparent;
  376. height: 32rpx;
  377. width: 32rpx;
  378. border: 2rpx solid #999999;
  379. border-radius: 50%;
  380. .uvicon-close{
  381. color:#999999 !important;
  382. font-size: 11rpx !important;
  383. }
  384. }
  385. .uv-upload__deletable__icon{
  386. transform: scale(1);
  387. top:50%;
  388. right: 50%;
  389. transform: translate(50%, -50%);
  390. }
  391. .uv-upload__success{
  392. border-width: 20rpx;
  393. }
  394. }
  395. .upload_btn{
  396. width: 240rpx;
  397. height: 140rpx;
  398. background-color: #FAFBFF;
  399. border-radius: 20rpx;
  400. border: 2rpx solid #CCCED4;
  401. box-sizing: border-box;
  402. display: flex;
  403. flex-direction: column;
  404. align-items: center;
  405. justify-content: center;
  406. .upload_btn_icon{
  407. font-size: 40rpx !important;
  408. color: #CCCED4 !important;
  409. }
  410. .upload_btn_text{
  411. margin-top: 16rpx;
  412. font-weight: 400;
  413. font-size: 24rpx;
  414. color: #CCCED4;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. .page_foot{
  421. position: fixed;
  422. left:0;
  423. right: 0;
  424. bottom: 0;
  425. padding: 20rpx 24rpx;
  426. background-color:#FFFFFF;
  427. .btn_submit{
  428. width: 100%;
  429. height: 88rpx;
  430. display: flex;
  431. justify-content: center;
  432. align-items: center;
  433. background-color: #2E64FA !important;
  434. border-radius: 20rpx;
  435. color: #FFFFFF;
  436. font-size: 28rpx;
  437. }
  438. }
  439. </style>