uploadEditMyHonor.vue 16 KB

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