addEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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">
  6. <uni-forms ref="valiForm" class="forms_style" :rules="rules" :model="state.formData" border
  7. labelWidth="160rpx" label-align="right">
  8. <uni-forms-item label="学年学期:" required name="schoolYearId">
  9. <uni-data-select v-model="state.formData.schoolYearId" :clear="false" placeholder="请选择学年学期"
  10. :localdata="state.schoolYearData" style="width: 320rpx;" @change="ChangSchoolYear"></uni-data-select>
  11. </uni-forms-item>
  12. <uni-forms-item label="归属分类:" required name="departmentId">
  13. <uni-data-select v-model="state.formData.departmentId" :clear="false" placeholder="请选择归属分类"
  14. :localdata="state.departmentData" style="width: 320rpx;"
  15. @change="GetMaterialCategoryData"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="材料类目:" required name="materialCategory">
  18. <uni-data-select v-model="state.formData.materialCategory" :clear="false" placeholder="请选择材料类目"
  19. :localdata="state.materialCategoryData" style="width: 320rpx;"></uni-data-select>
  20. </uni-forms-item>
  21. <uni-forms-item label="任务名称:" required name="taskName">
  22. <uni-easyinput v-model="state.formData.taskName" :maxlength="100" placeholder="请输入任务名称" />
  23. </uni-forms-item>
  24. <uni-forms-item label="采集要求:" required name="collectionRequire">
  25. <uni-easyinput type="textarea" v-model="state.formData.collectionRequire"
  26. :style="state.easyinputStyle" placeholder="请输入采集要求"
  27. placeholderStyle="font-weight: 400;font-size: 28rpx;color: #999999;"></uni-easyinput>
  28. </uni-forms-item>
  29. <uni-forms-item label="采集周期:" required name="taskTime">
  30. <uni-datetime-picker type="daterange" :clear-icon="false" v-model="state.formData.taskTime"
  31. placeholder="请选择采集周期" style="width: 480rpx;" />
  32. </uni-forms-item>
  33. <uni-forms-item label="审核机制:" required name="auditMechanism">
  34. <uni-data-checkbox v-model="state.formData.auditMechanism" selectedColor="#2E64FA"
  35. selectedTextColor="#333333" :localdata="state.radioList"></uni-data-checkbox>
  36. </uni-forms-item>
  37. <uni-forms-item label="审核人:" required name="taskAuditors" v-if="state.formData.auditMechanism === 1">
  38. <zxz-uni-data-select v-model="state.formData.taskAuditors" collapse-tags :collapse-tags-num="1"
  39. filterable multiple dataKey="teacherName" dataValue="teacherId" :clear="false"
  40. :localdata="state.auditorsData"></zxz-uni-data-select>
  41. </uni-forms-item>
  42. <uni-forms-item label="采集对象:" required name="targetType">
  43. <view class="forms_target">
  44. <view class="target_left">
  45. <text class="left_text">{{targetTypeObj[state.formData.targetType]}}</text>
  46. <text class="left_text">已选32人</text>
  47. </view>
  48. <view class="target_right">
  49. <text>选择采集对象</text>
  50. <uni-icons class="right_icon" type="right"></uni-icons>
  51. </view>
  52. </view>
  53. </uni-forms-item>
  54. </uni-forms>
  55. </view>
  56. <view class="page_foot"><button class="btn_submit" type="primary" :loading="state.loading"
  57. @click="honorTypeConfirm">确认</button></view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import navBar from '@/components/navBar.vue';
  62. import uniForms from '@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue';
  63. import uniFormsItem from '@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue';
  64. import uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue';
  65. import uniDataSelect from '@/uni_modules/uni-data-select/components/uni-data-select/uni-data-select.vue';
  66. import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue';
  67. import zxzUniDataSelect from '@/uni_modules/zxz-uni-data-select/components/zxz-uni-data-select/zxz-uni-data-select.vue';
  68. import uniIcons from '@/uni_modules/uni-icons/components/uni-icons/uni-icons.vue';
  69. import {
  70. getSchoolYearList,
  71. getCategoryList,
  72. queryTeacherInfo,
  73. getCollectionTaskInfo,
  74. insertCollectionTask,
  75. UpdateCollectionTask
  76. } from '@/reqApi/notification.js';
  77. import {
  78. reactive,
  79. ref,
  80. onMounted,
  81. nextTick
  82. } from 'vue';
  83. import {
  84. onLoad
  85. } from '@dcloudio/uni-app';
  86. const state = reactive({
  87. taskId: '', //任务id
  88. title: '', //标题
  89. type: '',
  90. formData: {
  91. schoolId:'',
  92. schoolYearId: '', //学年学期
  93. schoolYearCode:'',//学年学期code
  94. departmentId: '', //归属分类
  95. materialCategory: '', //材料类目
  96. taskName: '', //任务名称
  97. collectionRequire: '', //采集要求
  98. taskTime: [], //采集周期
  99. auditMechanism: 1, //审核机制 0-无需审核 1-需要审核
  100. taskAuditors: [], //审核人
  101. targetType:1,//采集对象 1-按部门,2-按学科,3-按年级,4-按权限,5-按学生
  102. },
  103. schoolYearData:[],//学年学期
  104. departmentData:[],//归属分类
  105. materialCategoryData:[],//材料类目
  106. auditorsData:[],//审核人
  107. radioList:[{//审核机制
  108. text:'需审核',
  109. value:1
  110. },{
  111. text:'无审核',
  112. value:0
  113. }],
  114. easyinputStyle: {
  115. color: '#303133',
  116. borderColor: '#E9E9E9'
  117. },
  118. loading: false
  119. })
  120. const targetTypeObj = {
  121. 1:'按部门',
  122. 2:'按学科',
  123. 3:'按年级',
  124. 4:'按权限',
  125. 5:'按学生'
  126. }
  127. const rules = ref({
  128. schoolYearId: {rules: [{required: true,errorMessage: '请选择学年学期'}]},
  129. departmentId: {rules: [{required: true,errorMessage: '请选择归属分类'}]},
  130. materialCategory: {rules: [{required: true,errorMessage: '请选择材料类目'}]},
  131. taskName: {rules: [{required: true,errorMessage: '请输入任务名称'}]},
  132. collectionRequire: {rules: [{required: true,errorMessage: '请输入采集要求'}]},
  133. taskTime: {rules: [{required: true,errorMessage: '请输入采集周期'}]},
  134. auditMechanism: {rules: [{required: true,errorMessage: '请选择审核机制'}]},
  135. targetType: {rules: [{required: true,errorMessage: '请选择采集对象'}]},
  136. });
  137. onLoad(async(option) => {
  138. state.taskId = option.taskId;
  139. state.title = state.taskId ? '编辑采集任务' : '新增采集任务';
  140. uni.setStorageSync('isLoadCollectTaskOverview', false); //返回列表页是否重新加载列表
  141. fetchSchoolYearList();//学年学期列表
  142. QueryTeacherInfo();//审核人
  143. await fetchCategoryList();//归属分类
  144. if(state.taskId){
  145. GetCollectionTaskInfo();
  146. }
  147. })
  148. // 学年学期列表
  149. const fetchSchoolYearList = async () => {
  150. try {
  151. const res = await getSchoolYearList();
  152. if (res.data && Array.isArray(res.data)) {
  153. const resData = res.data;
  154. state.schoolYearData = resData.map(item=>({
  155. ...item,
  156. text:item.schoolYearName,
  157. value:item.id
  158. }))
  159. const schoolYearId = state.schoolYearData?.[0]?.value || '';
  160. const schoolYearCode = state.schoolYearData?.[0]?.schoolYearCode || '';
  161. state.formData.schoolYearId = schoolYearId;//默认值学年id
  162. state.formData.schoolYearCode = schoolYearCode;//默认值学年code
  163. }
  164. } catch (error) {
  165. console.error('获取学年学期列表失败:', error);
  166. }
  167. };
  168. //改变学年学期
  169. const ChangSchoolYear = (val) => {
  170. state.formData.schoolYearId = val;//学年id
  171. state.formData.schoolYearCode = state.schoolYearData.find(item=>item.id==val)?.schoolYearCode || '';//学年code
  172. }
  173. // 归属分类
  174. const fetchCategoryList = async () => {
  175. try {
  176. const res = await getCategoryList();
  177. if (res.data && Array.isArray(res.data)) {
  178. const categoryData = res.data;
  179. state.departmentData = categoryData.map(item=>({
  180. ...item,
  181. text:item.categoryName,
  182. value:item.id
  183. }))
  184. const schoolId = state.departmentData?.[0]?.schoolId || '';
  185. state.formData.schoolId = schoolId;
  186. }
  187. } catch (error) {
  188. console.error('获取分类列表失败:', error);
  189. }
  190. };
  191. //改变归属分类
  192. const GetMaterialCategoryData = (val) => {
  193. const materialCategoryData = state.departmentData.find(item=>val == item.id)?.childList || [];
  194. state.materialCategoryData = materialCategoryData.map(item=>({
  195. ...item,
  196. text:item.categoryName,
  197. value:item.id
  198. }))
  199. }
  200. //审核人
  201. const QueryTeacherInfo = () => {
  202. queryTeacherInfo('').then(res=>{
  203. if(res.code == 200){
  204. state.auditorsData = res?.data || [];
  205. }
  206. })
  207. }
  208. //详情
  209. const GetCollectionTaskInfo = () => {
  210. getCollectionTaskInfo(state.taskId).then(res=>{
  211. if(res.code == 200){
  212. const resData = res?.data || null;
  213. state.formData.schoolId = resData?.schoolId || '';
  214. state.formData.schoolYearId = resData?.schoolYearId || '';//学年学期
  215. state.formData.schoolYearCode = resData?.schoolYearCode || '';//学年学期code
  216. state.formData.departmentId = resData?.departmentId || '';//学年学期code
  217. Object.keys(state.formData).forEach(key=>{
  218. if(key == 'taskTime'){//采集周期
  219. state.formData.taskTime = [resData.startTime,resData.endTime];
  220. }else if(key == 'taskAuditors'){//审核人
  221. const taskAuditorsList = resData?.taskAuditors || [];
  222. state.formData.taskAuditors = taskAuditorsList.map(item=>item.auditorId);
  223. }else{
  224. state.formData[key] = resData[key];
  225. if(key=='departmentId'){
  226. GetMaterialCategoryData(resData.departmentId);
  227. }
  228. }
  229. })
  230. }
  231. })
  232. }
  233. //提交
  234. const honorTypeConfirm = () => {
  235. let ruleList = {};
  236. if(state.formData.auditMechanism == 1){//审核人
  237. const taskAuditors = {
  238. taskAuditors: {rules: [{required: true,errorMessage: '请选择审核人'}]}
  239. }
  240. ruleList = {...rules.value,...taskAuditors};
  241. }else{
  242. ruleList = {...rules.value}
  243. }
  244. for (const key in ruleList) {
  245. if (state.formData?.[key] === "" || state.formData?.[key] === null || state.formData?.[key] && state.formData?.[key]?.length === 0) {
  246. const errorMessage = ruleList[key].rules[0].errorMessage;
  247. uni.showToast({
  248. title: errorMessage,
  249. icon: 'none'
  250. })
  251. return false
  252. }
  253. }
  254. state.loading = true;
  255. const auditorsData = state.auditorsData.filter(item=>state.formData.taskAuditors.includes(item.teacherId));
  256. const taskAuditors = auditorsData.map(item=>({
  257. auditorId:item.teacherId,
  258. auditorName:item.teacherName
  259. }))
  260. let params = {
  261. schoolId: state.formData.schoolId,
  262. schoolYearId: state.formData.schoolYearId,
  263. schoolYearCode: state.formData.schoolYearCode,
  264. departmentId: state.formData.departmentId,
  265. materialCategory: state.formData.materialCategory,
  266. taskName: state.formData.taskName,
  267. collectionRequire: state.formData.collectionRequire,
  268. startTime: state.formData.taskTime[0],
  269. endTime: state.formData.taskTime[1],
  270. targetType: state.formData.targetType,
  271. auditMechanism: state.formData.auditMechanism,//审核机制 0-无需审核 1-需要审核
  272. taskAuditors: taskAuditors,//审核人
  273. taskTargets: []//采集对象明细
  274. }
  275. if (state.taskId) {
  276. params.id = state.taskId;
  277. UpdateCollectionTask(params).then(res => {
  278. if (res.code == 200) {
  279. uni.showToast({
  280. title: '编辑成功!',
  281. icon: 'none'
  282. })
  283. uni.setStorageSync('isLoadCollectTaskOverview', true); //返回列表页是否重新加载列表
  284. GoBack();
  285. }
  286. }).finally(() => {
  287. state.loading = false;
  288. })
  289. } else { //新建
  290. insertCollectionTask(params).then(res => {
  291. if (res.code == 200) {
  292. uni.showToast({
  293. title: '新建成功!',
  294. icon: 'none'
  295. })
  296. uni.setStorageSync('isLoadCollectTaskOverview', true); //返回列表页是否重新加载列表
  297. GoBack();
  298. }
  299. }).finally(() => {
  300. state.loading = false;
  301. })
  302. }
  303. }
  304. const GoBack = () => {
  305. uni.navigateBack({
  306. delta: 1
  307. });
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .page_body {
  312. height: 100%;
  313. min-height: auto;
  314. overflow: hidden;
  315. }
  316. .page_content {
  317. height: calc(100% - 250rpx);
  318. overflow: auto;
  319. }
  320. .forms_style {
  321. :deep(.uni-forms-item) {
  322. &.uni-forms-item--border {
  323. border-top: 0;
  324. border-bottom: 2rpx solid #F3F3F3;
  325. align-items: center;
  326. }
  327. .forms_target{
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. .target_left{
  332. flex:1;
  333. font-weight: 400;
  334. font-size: 28rpx;
  335. color: #2E64FA;
  336. .left_text{
  337. flex-shrink: 0;
  338. &:last-child{
  339. margin-left: 8rpx;
  340. }
  341. }
  342. }
  343. .target_right{
  344. flex-shrink: 0;
  345. font-weight: 400;
  346. font-size: 28rpx;
  347. color: #2E64FA;
  348. display: inline-flex;
  349. align-items: center;
  350. gap:8rpx;
  351. .right_icon{
  352. font-size: 24rpx;
  353. color: #2E64FA !important;
  354. }
  355. }
  356. }
  357. }
  358. }
  359. .page_foot {
  360. position: fixed;
  361. left: 0;
  362. right: 0;
  363. bottom: 0;
  364. padding: 20rpx 24rpx;
  365. background-color: #FFFFFF;
  366. .btn_submit {
  367. width: 100%;
  368. height: 88rpx;
  369. display: flex;
  370. justify-content: center;
  371. align-items: center;
  372. background-color: #2E64FA !important;
  373. border-radius: 20rpx;
  374. color: #FFFFFF;
  375. font-size: 28rpx;
  376. }
  377. }
  378. </style>