createTask.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. <template>
  2. <view class="container">
  3. <Step :step="currentStep" :stepsData="currentText" />
  4. <scroll-view class="content" scroll-y>
  5. <!-- 驳回意见提示 -->
  6. <view class="rejection-banner" v-if="rejectionInfo">
  7. <view class="rejection-icon">✕</view>
  8. <view class="rejection-text">驳回意见: {{ rejectionInfo }}</view>
  9. </view>
  10. <!-- 基本信息 -->
  11. <view class="form-section">
  12. <view class="form-item">
  13. <view class="form-label">
  14. <text class="required">*</text>
  15. <text>任务归属</text>
  16. </view>
  17. <view class="form-input picker-input" :class="{ placeholder: !formData.deptId }"
  18. @click="showPicker('任务归属',companyData)">
  19. {{ institutionDisplayText || '请选择任务归属' }}
  20. <image class="icon" src="/static/image/icon_more.png"></image>
  21. </view>
  22. </view>
  23. <view class="form-item">
  24. <view class="form-label">
  25. <text class="required">*</text>
  26. <text>归属项目</text>
  27. </view>
  28. <view class="form-input picker-input" :class="{ placeholder: !formData.projectId }"
  29. @click="showPicker('归属项目',companyList)">
  30. {{ belongingProjectDisplayText || '请选择归属项目' }}
  31. <image class="icon" src="/static/image/icon_more.png"></image>
  32. </view>
  33. </view>
  34. <view class="form-item">
  35. <view class="form-label">
  36. <text class="required">*</text>
  37. <text>产品代码</text>
  38. </view>
  39. <view class="form-input picker-input" :class="{ placeholder: !formData.productId }"
  40. @click="showPicker('产品代码',productList)">
  41. {{ productNameDisplayText || '请选择产品代码' }}
  42. <image class="icon" src="/static/image/icon_more.png"></image>
  43. </view>
  44. </view>
  45. <view class="form-item">
  46. <view class="form-label">
  47. <text class="required">*</text>
  48. <text>费用分摊</text>
  49. </view>
  50. <view class="form-input picker-input" :class="{ placeholder: !formData.costShareId }"
  51. @click="showPicker('费用分摊',companyData)">
  52. {{ costAllocationDisplayText || '请选择费用分摊主体' }}
  53. <image class="icon" src="/static/image/icon_more.png"></image>
  54. </view>
  55. </view>
  56. <view class="form-item">
  57. <view class="form-label">
  58. <text>添加任务备注</text>
  59. </view>
  60. <EvanSwitch v-model="formData.addRemark"></EvanSwitch>
  61. </view>
  62. <view class="form-item" v-if="formData.addRemark">
  63. <textarea class="form-textarea" v-model="formData.remark" placeholder="请输入任务备注" rows="4"></textarea>
  64. </view>
  65. <view class="form-item">
  66. <view class="form-label">
  67. <text class="required">*</text>
  68. <text>归属类型</text>
  69. </view>
  70. <view class="form-input picker-input" :class="{ placeholder: !formData.belongType }"
  71. @click="showPicker('归属类型',dictTypeColumns)">
  72. {{ belongTypeDisplayText || '请选择归属类型' }}
  73. <image class="icon" src="/static/image/icon_more.png"></image>
  74. </view>
  75. </view>
  76. <view class="form-item">
  77. <view class="form-label">
  78. <text class="required">*</text>
  79. <text>任务类型</text>
  80. </view>
  81. <view class="form-input picker-input" :class="{ placeholder: !formData.taskType }"
  82. @click="showPicker('任务类型',taskTypeColumns)">
  83. {{ taskTypeDisplayText || '请选择任务类型' }}
  84. <image class="icon" src="/static/image/icon_more.png"></image>
  85. </view>
  86. </view>
  87. <view class="form-item">
  88. <view class="form-label">
  89. <text class="required">*</text>
  90. <text>计划开始时间</text>
  91. </view>
  92. <view class="form-input picker-input" :class="{ placeholder: !formData.planStartTime }"
  93. @click="showStartTimePicker = true">
  94. {{ formData.planStartTime || '请选择计划开始时间' }}
  95. <image class="icon" src="/static/image/icon_more.png"></image>
  96. </view>
  97. </view>
  98. <view class="form-item">
  99. <view class="form-label">
  100. <text class="required">*</text>
  101. <text>计划结束时间</text>
  102. </view>
  103. <view class="form-input picker-input" :class="{ placeholder: !formData.planEndTime }"
  104. @click="showEndTimePicker = true">
  105. {{ formData.planEndTime || '请选择计划结束时间' }}
  106. <image class="icon" src="/static/image/icon_more.png"></image>
  107. </view>
  108. </view>
  109. </view>
  110. </scroll-view>
  111. <view class="next-button" @click="toNext">下一步</view>
  112. <u-picker :title='pickerTitle' :show="showPickerVisible" confirmColor='#576B95' ref="uPicker"
  113. :columns="pickerData" @confirm="confirm" @cancel="cancel">
  114. </u-picker>
  115. <u-datetime-picker :show="showStartTimePicker" v-model="startTimeValue" mode="date"
  116. confirmColor='#576B95' @confirm="onStartTimeConfirm" @cancel="showStartTimePicker = false">
  117. </u-datetime-picker>
  118. <u-datetime-picker :show="showEndTimePicker" v-model="endTimeValue" mode="date"
  119. confirmColor='#576B95' @confirm="onEndTimeConfirm" @cancel="showEndTimePicker = false">
  120. </u-datetime-picker>
  121. <u-popup :show="showBelongingPopup" mode="bottom" round="20" @close="closePopup" closeable>
  122. <view class="popup-content p32">
  123. <view class="popup-header">
  124. <text class="title">归属项目</text>
  125. </view>
  126. <view class="search-box">
  127. <image class="icon" src="/static/image/search.png"></image>
  128. <u-input v-model="searchKeyword" placeholder="请输入归属项目" border="none" clearable />
  129. </view>
  130. <scroll-view scroll-y class="project-list">
  131. <view v-for="(project, index) in filteredProjects" :key="index" class="project-item"
  132. :class="{ active: selectedIndex === index }" @tap="selectProject(project, index)">
  133. <text class="project-name">{{ project.name }}</text>
  134. <image class="icon" src="/static/image/icon_right.png"></image>
  135. </view>
  136. </scroll-view>
  137. </view>
  138. </u-popup>
  139. <u-popup :show="showTaskPopup" mode="bottom" round="16" @close="showTaskPopup = false" safeAreaInsetBottom>
  140. <view class="popup-content">
  141. <view class="popup-header">
  142. <text class="popup-title">任务归属</text>
  143. <image class="close-icon" src="/static/image/icon_cross.png" @click="showTaskPopup=false"></image>
  144. </view>
  145. <view class="two-level-container">
  146. <scroll-view class="primary-list" scroll-y>
  147. <view v-for="(item, index) in primaryOptions" :key="index" class="primary-item"
  148. :class="{ 'primary-active': activePrimaryIndex === index }"
  149. @click="handlePrimarySelect(index)">
  150. <text class="primary-text">{{ item.name }}</text>
  151. </view>
  152. </scroll-view>
  153. <scroll-view class="secondary-list" scroll-y>
  154. <view v-for="(subItem, subIndex) in currentSecondaryOptions" :key="subIndex"
  155. class="secondary-item" :class="{ 'secondary-active': selectedSecondaryItem === subItem }"
  156. @click="handleSecondarySelect(subItem)">
  157. <text class="secondary-text">{{ subItem }}</text>
  158. <u-icon v-if="selectedSecondaryItem === subItem" name="checkbox-mark" color="#2979ff"
  159. size="20" />
  160. </view>
  161. </scroll-view>
  162. </view>
  163. <view class="popup-footer">
  164. <button class="confirm-btn" @click="handleConfirm">确定</button>
  165. </view>
  166. </view>
  167. </u-popup>
  168. </view>
  169. </template>
  170. <script>
  171. import {
  172. company,
  173. getAllData,//获取项目所有数据
  174. queryAllProduct,//获取公司所有产品
  175. queryAllData//获取任务类型
  176. } from '@/api/task.js';
  177. import utils from '@/utils/common.js'
  178. import Step from '@/pages_task/components/step.vue'
  179. import EvanSwitch from '@/components/evan-switch.vue'
  180. export default {
  181. components: {
  182. Step,
  183. EvanSwitch
  184. },
  185. data() {
  186. return {
  187. taskTypeDict:[],//任务类型字典
  188. taskType:[],//任务类型
  189. taskTypeOriginalData:[],//任务类型原始数据(包含dictLabel和dictValue)
  190. companyList:[],//归属项目
  191. projectData:[],//项目数据(持久化存储)
  192. productList:[],//产品列表
  193. companyData:[],
  194. userInfo:{},
  195. showTaskPopup: false,
  196. primaryOptions: [{
  197. id: 1,
  198. name: '中药事业部',
  199. children: ['中药一部', '中药二部', '中药三部', '中药四部']
  200. },
  201. {
  202. id: 2,
  203. name: '事业1组',
  204. children: ['事业1组-项目部', '事业1组-市场部', '事业1组-技术部']
  205. },
  206. ],
  207. activePrimaryIndex: 0,
  208. currentSecondaryOptions: [],
  209. selectedSecondaryItem: '',
  210. selectedPrimaryItem: null,
  211. selectedIndex: -1,
  212. selectedProject: null,
  213. belongingprojects: [{
  214. name: '学术交流项目'
  215. },
  216. {
  217. name: '科学调研项目'
  218. },
  219. {
  220. name: '2026年1月医学研究项目'
  221. },
  222. {
  223. name: '2026年2月医学研究项目'
  224. },
  225. {
  226. name: '2026年3月医学研究项目'
  227. }
  228. ],
  229. searchKeyword: '',
  230. showBelongingPopup: false,
  231. showPickerVisible: false,
  232. costColumns: [
  233. ['主体1', '主体2', '主体3'],
  234. ],
  235. taskTypeColumns: [
  236. // ['类型1', '类型2', '类型3'],
  237. ],
  238. currentStep: 1,
  239. currentText: [{
  240. id: 1,
  241. stepNumber: 1,
  242. title: '填写任务'
  243. },
  244. {
  245. id: 2,
  246. stepNumber: 2,
  247. title: '选择客户'
  248. },
  249. {
  250. id: 3,
  251. stepNumber: 3,
  252. title: '积分设置'
  253. }
  254. ],
  255. rejectionInfo: '',
  256. formData: {
  257. costShareId: '',
  258. planStartTime: '',
  259. planEndTime: '',
  260. belongType: '',
  261. deptId: '',
  262. projectId: '',
  263. productId: '',
  264. taskType: '',
  265. addRemark: false,
  266. remark: ''
  267. },
  268. originalCompanyData: null,
  269. pickerTitle: '默认标题',
  270. pickerData: [],
  271. companyId:'',
  272. showStartTimePicker: false,
  273. showEndTimePicker: false,
  274. startTimeValue: new Date(),
  275. endTimeValue: new Date(),
  276. }
  277. },
  278. onLoad: async function(options) {
  279. try {
  280. this.taskTypeDict = await utils.getDicts("task_type");//任务类型
  281. this.belongTypeList = await utils.getDicts("task_belong_type");//任务类型
  282. } catch (e) {
  283. console.log('获取字典数据失败:', e)
  284. }
  285. this.userInfo=JSON.parse(uni.getStorageSync("userInfo"))||''
  286. if (options.rejectionInfo) {
  287. this.rejectionInfo = decodeURIComponent(options.rejectionInfo)
  288. }
  289. // 获取用户信息
  290. const userInfoStr = uni.getStorageSync('userInfo')
  291. this.userInfo = userInfoStr ? JSON.parse(userInfoStr) : {}
  292. console.log(this.userInfo);
  293. // 加载信息
  294. this.companyId = this.userInfo.companyId || 1
  295. // 设置默认日期为当天
  296. this.formData.planStartTime = this.formatDateTime(new Date());
  297. this.formData.planEndTime = this.formatDateTime(new Date());
  298. },
  299. computed: {
  300. taskTypeDisplayText() {
  301. console.log('计算taskTypeDisplayText, formData.taskType:', this.formData.taskType);
  302. console.log('计算taskTypeDisplayText, taskTypeOriginalData:', this.taskTypeOriginalData);
  303. if (!this.formData.taskType || !this.taskTypeOriginalData) {
  304. return '';
  305. }
  306. const selectedType = this.taskTypeOriginalData.find(item => item.dictValue === this.formData.taskType);
  307. console.log('找到的selectedType:', selectedType);
  308. return selectedType ? selectedType.dictLabel : '';
  309. },
  310. institutionDisplayText() {
  311. if (!this.formData.deptId || !this.companyData) {
  312. return '';
  313. }
  314. const selectedItem = this.companyData.find(item => item.deptId === this.formData.deptId);
  315. return selectedItem ? selectedItem.deptName : '';
  316. },
  317. costAllocationDisplayText() {
  318. if (!this.formData.costShareId || !this.companyData) {
  319. return '';
  320. }
  321. const selectedItem = this.companyData.find(item => item.deptId === this.formData.costShareId);
  322. return selectedItem ? selectedItem.deptName : '';
  323. },
  324. belongingProjectDisplayText() {
  325. console.log('计算belongingProjectDisplayText:', this.formData.projectId, this.projectData);
  326. if (!this.formData.projectId || !this.projectData) {
  327. console.log('formData.projectId或projectData为空');
  328. return '';
  329. }
  330. const selectedItem = this.projectData.find(item => item.id === this.formData.projectId);
  331. console.log('找到的项目:', selectedItem);
  332. return selectedItem ? selectedItem.projectName : '';
  333. },
  334. productNameDisplayText() {
  335. if (!this.formData.productId || !this.productList) {
  336. return '';
  337. }
  338. const selectedItem = this.productList.find(item => item.id === this.formData.productId);
  339. return selectedItem ? selectedItem.productName : '';
  340. },
  341. belongTypeDisplayText() {
  342. if (!this.formData.belongType || !this.belongTypeList) {
  343. return '';
  344. }
  345. const selectedItem = this.belongTypeList.find(item => item.dictValue === this.formData.belongType);
  346. return selectedItem ? selectedItem.dictLabel : '';
  347. }
  348. },
  349. methods: {
  350. //任务类型
  351. queryAllData(){
  352. return new Promise((resolve, reject) => {
  353. if(!this.formData.productId){
  354. uni.showToast({
  355. title: '请先选择产品',
  356. icon: 'none'
  357. })
  358. resolve();
  359. return
  360. }
  361. let data={
  362. companyId:this.userInfo.companyId||'',
  363. deptId:this.formData.deptId||'',
  364. productId:this.formData.productId||'',
  365. }
  366. queryAllData(data).then(res => {
  367. if (res.code === 200) {
  368. // 处理任务类型
  369. this.taskType = res.data || []
  370. console.log('company接口返回数据:', res)
  371. // 处理taskTypeIds,获取对应的字典数据
  372. if (res.data && res.data.length > 0) {
  373. const firstData = res.data[0];
  374. if (firstData.taskTypeIds) {
  375. // 分割taskTypeIds为数组
  376. const taskTypeIdsArray = firstData.taskTypeIds.split(',');
  377. // 从字典表中筛选出对应的项
  378. const filteredTaskTypes = this.taskTypeDict.filter(item =>
  379. taskTypeIdsArray.includes(item.dictValue)
  380. );
  381. // 保存原始数据(包含dictLabel和dictValue)
  382. this.taskTypeOriginalData = filteredTaskTypes;
  383. // 提取dictLabel并放到taskTypeColumns中
  384. const taskTypeLabels = filteredTaskTypes.map(item => item.dictLabel);
  385. this.taskTypeColumns = [taskTypeLabels];
  386. console.log('处理后的taskTypeColumns:', this.taskTypeColumns);
  387. console.log('任务类型原始数据:', this.taskTypeOriginalData);
  388. }
  389. }
  390. }
  391. resolve(res);
  392. }).catch(err => {
  393. console.error('获取任务类型失败:', err);
  394. reject(err);
  395. });
  396. });
  397. },
  398. //获取公司所有产品
  399. async queryAllProduct(){
  400. return new Promise((resolve, reject) => {
  401. let data={
  402. companyId:this.userInfo.companyId||'',
  403. }
  404. queryAllProduct(data).then(res => {
  405. if (res.code === 200) {
  406. // 处理公司所有产品数据
  407. this.productList = res.data || []
  408. console.log('company接口返回数据:', res)
  409. }
  410. resolve(res);
  411. }).catch(err => {
  412. console.error('获取公司所有产品失败:', err);
  413. reject(err);
  414. });
  415. });
  416. },
  417. // 归属项目
  418. async getAllData(){
  419. return new Promise((resolve, reject) => {
  420. let data={
  421. companyId:this.userInfo.companyId||'',
  422. deptId:this.userInfo.deptId||'',
  423. productCode:this.userInfo.productCode||''
  424. }
  425. getAllData(data).then(res => {
  426. if (res.code === 200) {
  427. // 处理公司项目设置列表数据
  428. this.companyList = res.data || []
  429. // 保存项目数据用于显示
  430. this.projectData = res.data || []
  431. console.log('company接口返回数据:', res)
  432. console.log('companyList数据结构:', this.companyList)
  433. }
  434. resolve(res);
  435. }).catch(err => {
  436. console.error('获取公司项目设置失败:', err);
  437. reject(err);
  438. });
  439. });
  440. },
  441. async company() {
  442. return new Promise((resolve, reject) => {
  443. try {
  444. uni.showLoading({
  445. title: '加载中...'
  446. })
  447. // 调用company接口获取公司项目设置列表
  448. company(this.companyId).then(companyRes => {
  449. uni.hideLoading()
  450. if (companyRes.code === 200) {
  451. // 处理公司项目设置列表数据
  452. this.companyData = companyRes.data || []
  453. console.log('company接口返回数据:', companyRes)
  454. // 这里可以根据接口返回的数据进行页面初始化,比如填充项目列表
  455. }
  456. resolve(companyRes);
  457. }).catch(e => {
  458. uni.hideLoading()
  459. console.error('加载信息失败', e)
  460. uni.showToast({
  461. title: '网络错误',
  462. icon: 'none'
  463. })
  464. reject(e);
  465. });
  466. } catch (e) {
  467. uni.hideLoading()
  468. console.error('加载信息失败', e)
  469. uni.showToast({
  470. title: '网络错误',
  471. icon: 'none'
  472. })
  473. reject(e);
  474. }
  475. });
  476. },
  477. submitInfo() {
  478. info(this.userInfo.companyId).then(res => {
  479. if (res.code === 200) {
  480. console.log('公司项目设置:', res.data);
  481. // 处理公司项目设置数据
  482. }
  483. }).catch(err => {
  484. console.error('获取公司项目设置失败:', err);
  485. });
  486. },
  487. handlePrimarySelect(index) {
  488. this.activePrimaryIndex = index;
  489. this.currentSecondaryOptions = this.primaryOptions[index].children || [];
  490. this.selectedSecondaryItem = '';
  491. },
  492. handleSecondarySelect(item) {
  493. this.selectedSecondaryItem = item;
  494. this.selectedPrimaryItem = this.primaryOptions[this.activePrimaryIndex];
  495. },
  496. handleConfirm() {
  497. if (this.selectedSecondaryItem) {
  498. const displayText = `${this.selectedPrimaryItem.name} > ${this.selectedSecondaryItem}`;
  499. this.formData.belongType = displayText;
  500. this.showTaskPopup = false;
  501. } else {
  502. uni.showToast({
  503. title: '请选择二级部门',
  504. icon: 'none'
  505. });
  506. }
  507. },
  508. closePopup() {
  509. this.showBelongingPopup = false;
  510. this.searchKeyword = '';
  511. this.selectedIndex = -1;
  512. },
  513. selectProject(project, index) {
  514. this.selectedIndex = index;
  515. this.selectedProject = project;
  516. this.formData.belongingProject = project.name;
  517. setTimeout(() => {
  518. this.showBelongingPopup = false;
  519. this.searchKeyword = '';
  520. this.selectedIndex = -1;
  521. }, 300);
  522. },
  523. async showPicker(title, data) {
  524. // 根据不同的title调用对应的请求方法
  525. if (title === '任务归属' || title === '费用分摊') {
  526. // 调用company()获取任务归属和费用分摊数据
  527. await this.company();
  528. data = this.companyData;
  529. } else if (title === '归属项目') {
  530. // 调用getAllData()获取归属项目数据
  531. await this.getAllData();
  532. data = this.companyList;
  533. console.log('归属项目数据:', data);
  534. } else if (title === '产品代码') {
  535. // 调用queryAllProduct()获取产品代码数据
  536. await this.queryAllProduct();
  537. data = this.productList;
  538. } else if (title === '任务类型') {
  539. // queryAllData()获取任务类型数据
  540. await this.queryAllData();
  541. // 使用处理后的taskTypeColumns作为数据
  542. data = this.taskTypeColumns;
  543. console.log('任务类型数据:', data);
  544. } else if (title === '归属类型') {
  545. // 归属类型数据已经在onLoad中获取
  546. data = this.belongTypeList;
  547. console.log('归属类型数据:', data);
  548. }
  549. // 处理任务归属和费用分摊数据,将deptStr作为显示文本
  550. if ((title === '任务归属' || title === '费用分摊') && data && data.length > 0) {
  551. // 转换为picker需要的格式
  552. this.pickerData = [data.map(item => item.deptName)]
  553. // 保存原始数据,用于后续获取deptId
  554. this.originalCompanyData = data
  555. } else if (title === '归属项目' && data && data.length > 0) {
  556. // 处理归属项目数据,将projectName作为显示文本
  557. this.pickerData = [data.map(item => item.projectName)]
  558. // 保存原始数据,用于后续获取productId
  559. this.originalCompanyData = data
  560. } else if (title === '产品代码' && data && data.length > 0) {
  561. // 处理产品代码数据,将productName作为显示文本
  562. this.pickerData = [data.map(item => item.productName)]
  563. // 保存原始数据,用于后续获取productCode
  564. this.originalCompanyData = data
  565. } else if (title === '归属类型' && data && data.length > 0) {
  566. // 处理归属类型数据,将dictLabel作为显示文本
  567. this.pickerData = [data.map(item => item.dictLabel)]
  568. // 保存原始数据,用于后续获取dictType
  569. this.originalCompanyData = data
  570. } else {
  571. this.pickerData = data
  572. this.originalCompanyData = null
  573. }
  574. this.pickerTitle = title
  575. console.log('打开picker, pickerTitle:', this.pickerTitle);
  576. console.log('pickerData:', this.pickerData);
  577. this.showPickerVisible = true
  578. },
  579. confirm(e) {
  580. console.log('confirm事件返回值:', e);
  581. console.log('pickerTitle:', this.pickerTitle);
  582. console.log('e.value:', e.value);
  583. if (e.value && e.value.length > 0) {
  584. if (this.pickerTitle === '费用分摊') {
  585. // e.value[0]是选中的文本值(deptName)
  586. const selectedDeptStr = e.value[0];
  587. console.log('选中的费用分摊文本:', selectedDeptStr);
  588. console.log('originalCompanyData:', this.originalCompanyData);
  589. // 从originalCompanyData中找到对应的项
  590. const selectedItem = this.originalCompanyData.find(item => item.deptName === selectedDeptStr);
  591. if (selectedItem) {
  592. // 保存deptId到表单(存储id值)
  593. this.formData.costShareId = selectedItem.deptId;
  594. console.log('设置formData.costShareId为:', selectedItem.deptId);
  595. } else {
  596. this.formData.costShareId = '';
  597. console.log('未找到对应的费用分摊');
  598. }
  599. } else if (this.pickerTitle === '任务类型') {
  600. // e.value[0]是选中的文本值(dictLabel)
  601. const selectedLabel = e.value[0];
  602. console.log('选中的任务类型文本:', selectedLabel);
  603. console.log('taskTypeOriginalData:', this.taskTypeOriginalData);
  604. // 从taskTypeOriginalData中找到对应的项
  605. const selectedType = this.taskTypeOriginalData.find(item => item.dictLabel === selectedLabel);
  606. if (selectedType) {
  607. this.formData.taskType = selectedType.dictValue;
  608. console.log('设置formData.taskType为:', selectedType.dictValue);
  609. } else {
  610. }
  611. } else if (this.pickerTitle === '任务归属' && this.originalCompanyData) {
  612. // e.value[0]是选中的文本值(deptName)
  613. const selectedDeptStr = e.value[0];
  614. console.log('选中的任务归属文本:', selectedDeptStr);
  615. console.log('originalCompanyData:', this.originalCompanyData);
  616. // 从originalCompanyData中找到对应的项
  617. const selectedItem = this.originalCompanyData.find(item => item.deptName === selectedDeptStr);
  618. if (selectedItem) {
  619. // 保存deptId到表单(存储id值)
  620. this.formData.deptId = selectedItem.deptId;
  621. console.log('设置formData.deptId为:', selectedItem.deptId);
  622. } else {
  623. }
  624. } else if (this.pickerTitle === '归属项目' && this.originalCompanyData) {
  625. // e.value[0]是选中的文本值(projectName)
  626. const selectedProjectName = e.value[0];
  627. console.log('选中的归属项目文本:', selectedProjectName);
  628. console.log('originalCompanyData:', this.originalCompanyData);
  629. // 从originalCompanyData中找到对应的项
  630. const selectedItem = this.originalCompanyData.find(item => item.projectName === selectedProjectName);
  631. if (selectedItem) {
  632. // 保存id到表单(存储id值)
  633. this.formData.projectId = selectedItem.id;
  634. // 保存productId到表单
  635. this.formData.productId = selectedItem.productId;
  636. console.log('设置formData.projectId为:', selectedItem.id);
  637. } else {
  638. }
  639. } else if (this.pickerTitle === '产品代码' && this.originalCompanyData) {
  640. // e.value[0]是选中的文本值(productName)
  641. const selectedProductName = e.value[0];
  642. console.log('选中的产品代码文本:', selectedProductName);
  643. console.log('originalCompanyData:', this.originalCompanyData);
  644. // 从originalCompanyData中找到对应的项
  645. const selectedItem = this.originalCompanyData.find(item => item.productName === selectedProductName);
  646. if (selectedItem) {
  647. // 保存id到表单
  648. this.formData.productId = selectedItem.id;
  649. // 保存id用于获取任务类型
  650. console.log('设置formData.productId为:', selectedItem.id);
  651. } else {
  652. }
  653. } else if (this.pickerTitle === '归属类型' && this.originalCompanyData) {
  654. // e.value[0]是选中的文本值(dictLabel)
  655. const selectedLabel = e.value[0];
  656. console.log('选中的归属类型文本:', selectedLabel);
  657. console.log('originalCompanyData:', this.originalCompanyData);
  658. // 从originalCompanyData中找到对应的项
  659. const selectedItem = this.originalCompanyData.find(item => item.dictLabel === selectedLabel);
  660. if (selectedItem) {
  661. // 保存dictValue到表单的belongType字段
  662. this.formData.belongType = selectedItem.dictValue;
  663. console.log('设置formData.belongType为:', selectedItem.dictValue);
  664. } else {
  665. console.log('未找到对应的归属类型');
  666. }
  667. }
  668. }
  669. this.showPickerVisible = false
  670. },
  671. cancel() {
  672. this.showPickerVisible = false
  673. },
  674. toNext() {
  675. // 表单验证
  676. if (!this.formData.deptId) {
  677. uni.showToast({
  678. title: '请选择任务归属',
  679. icon: 'none'
  680. })
  681. return
  682. }
  683. if (!this.formData.projectId) {
  684. uni.showToast({
  685. title: '请选择归属项目',
  686. icon: 'none'
  687. })
  688. return
  689. }
  690. if (!this.formData.productId) {
  691. uni.showToast({
  692. title: '请选择产品代码',
  693. icon: 'none'
  694. })
  695. return
  696. }
  697. if (!this.formData.costShareId) {
  698. uni.showToast({
  699. title: '请选择费用分摊',
  700. icon: 'none'
  701. })
  702. return
  703. }
  704. if (!this.formData.belongType) {
  705. uni.showToast({
  706. title: '请选择归属类型',
  707. icon: 'none'
  708. })
  709. return
  710. }
  711. if (!this.formData.taskType) {
  712. uni.showToast({
  713. title: '请选择任务类型',
  714. icon: 'none'
  715. })
  716. return
  717. }
  718. if (!this.formData.planStartTime) {
  719. uni.showToast({
  720. title: '请选择计划开始时间',
  721. icon: 'none'
  722. })
  723. return
  724. }
  725. if (!this.formData.planEndTime) {
  726. uni.showToast({
  727. title: '请选择计划结束时间',
  728. icon: 'none'
  729. })
  730. return
  731. }
  732. // 如果开启了任务备注,则备注为必填
  733. if (this.formData.addRemark && !this.formData.remark) {
  734. uni.showToast({
  735. title: '请输入任务备注',
  736. icon: 'none'
  737. })
  738. return
  739. }
  740. // 保存任务表单数据到本地存储
  741. uni.setStorageSync('taskFormData', JSON.stringify(this.formData))
  742. uni.navigateTo({
  743. url: '/pages_task/selectCustomer'
  744. })
  745. },
  746. onStartTimeConfirm(e) {
  747. this.formData.planStartTime = this.formatDateTime(e.value);
  748. this.showStartTimePicker = false;
  749. },
  750. onEndTimeConfirm(e) {
  751. this.formData.planEndTime = this.formatDateTime(e.value);
  752. this.showEndTimePicker = false;
  753. },
  754. formatDateTime(timestamp) {
  755. const date = new Date(timestamp);
  756. const year = date.getFullYear();
  757. const month = String(date.getMonth() + 1).padStart(2, '0');
  758. const day = String(date.getDate()).padStart(2, '0');
  759. // const hours = String(date.getHours()).padStart(2, '0');
  760. // const minutes = String(date.getMinutes()).padStart(2, '0');
  761. // const seconds = String(date.getSeconds()).padStart(2, '0');
  762. // ${hours}:${minutes}:${seconds}
  763. return `${year}-${month}-${day}`;
  764. }
  765. }
  766. }
  767. </script>
  768. <style lang="scss" scoped>
  769. .container {
  770. min-height: 100vh;
  771. background: #F7F8FA;
  772. display: flex;
  773. flex-direction: column;
  774. position: relative;
  775. &::before {
  776. content: '';
  777. position: absolute;
  778. top: 0;
  779. left: 0;
  780. right: 0;
  781. width: 100%;
  782. height: 544rpx;
  783. background: linear-gradient(180deg, #E4EFFE 0%, rgba(228, 239, 254, 0) 100%);
  784. }
  785. .content {
  786. flex: 1;
  787. box-sizing: border-box;
  788. .rejection-banner {
  789. display: flex;
  790. align-items: center;
  791. padding: 24rpx;
  792. background: #FF5030;
  793. color: #fff;
  794. margin: 24rpx;
  795. border-radius: 8rpx;
  796. .rejection-icon {
  797. width: 40rpx;
  798. height: 40rpx;
  799. border-radius: 50%;
  800. background: rgba(255, 255, 255, 0.3);
  801. display: flex;
  802. align-items: center;
  803. justify-content: center;
  804. font-size: 24rpx;
  805. margin-right: 16rpx;
  806. }
  807. .rejection-text {
  808. flex: 1;
  809. font-size: 28rpx;
  810. line-height: 1.5;
  811. }
  812. }
  813. .form-section {
  814. background: #fff;
  815. margin: 20rpx;
  816. border-radius: 16rpx;
  817. padding: 32rpx;
  818. .form-item {
  819. display: flex;
  820. justify-content: space-between;
  821. align-items: center;
  822. border-bottom: 1px solid #EBEDF0;
  823. padding: 30rpx 0;
  824. &:last-child {
  825. border-bottom: 0;
  826. }
  827. .form-label {
  828. display: flex;
  829. align-items: center;
  830. font-size: 28rpx;
  831. color: #333;
  832. margin-bottom: 16rpx;
  833. .required {
  834. color: #CF3546;
  835. margin-right: 4rpx;
  836. }
  837. }
  838. .txt {
  839. font-size: 28rpx;
  840. color: #333333;
  841. }
  842. .form-input {
  843. flex: 1;
  844. font-size: 28rpx;
  845. color: #C8C9CC;
  846. &.placeholder {
  847. color: #C8C9CC;
  848. }
  849. &.picker-input {
  850. display: flex;
  851. align-items: center;
  852. justify-content: flex-end;
  853. }
  854. .icon {
  855. width: 36rpx;
  856. height: 36rpx;
  857. }
  858. }
  859. .form-textarea {
  860. flex: 1;
  861. font-size: 28rpx;
  862. color: #333;
  863. padding: 16rpx;
  864. border: 1px solid #EBEDF0;
  865. border-radius: 8rpx;
  866. min-height: 200rpx;
  867. resize: none;
  868. box-sizing: border-box;
  869. &::placeholder {
  870. color: #C8C9CC;
  871. }
  872. }
  873. }
  874. }
  875. }
  876. .next-button {
  877. text-align: center;
  878. font-size: 32rpx;
  879. color: #FFFFFF;
  880. height: 88rpx;
  881. line-height: 88rpx;
  882. background: #388BFF;
  883. border-radius: 200rpx;
  884. margin: 32rpx;
  885. }
  886. }
  887. ::v-deep .u-popup__content {
  888. border-radius: 40rpx 40rpx 0 0 !important;
  889. }
  890. .popup-content {
  891. border-radius: 40rpx 40rpx 0rpx 0rpx;
  892. height: 70vh;
  893. background-color: #fff;
  894. .popup-header {
  895. padding: 40rpx 30rpx 20rpx;
  896. text-align: center;
  897. .close-icon {
  898. width: 44rpx;
  899. height: 44rpx;
  900. position: absolute;
  901. right: 32rpx;
  902. }
  903. flex-shrink: 0;
  904. .title {
  905. font-size: 32rpx;
  906. font-weight: 600;
  907. color: #333;
  908. }
  909. .popup-title {
  910. font-size: 32rpx;
  911. font-weight: 600;
  912. color: #333;
  913. }
  914. }
  915. .search-box {
  916. display: flex;
  917. align-items: center;
  918. background: #F7F8FA;
  919. border-radius: 38rpx;
  920. padding: 16rpx 28rpx;
  921. margin-bottom: 24rpx;
  922. .icon {
  923. width: 26rpx;
  924. height: 26rpx;
  925. margin-right: 10rpx;
  926. }
  927. }
  928. .project-list {
  929. height: calc(100% - 200rpx);
  930. .project-item {
  931. display: flex;
  932. justify-content: space-between;
  933. align-items: center;
  934. padding: 28rpx 0;
  935. font-size: 28rpx;
  936. border-bottom: 1rpx solid #eee;
  937. &:active {
  938. background-color: #f9f9f9;
  939. }
  940. &.active {
  941. .project-name {
  942. font-weight: 500;
  943. color: #388BFF;
  944. }
  945. .icon {
  946. opacity: 1;
  947. }
  948. }
  949. .project-name {
  950. color: #333;
  951. transition: all 0.2s ease;
  952. }
  953. .icon {
  954. width: 36rpx;
  955. height: 36rpx;
  956. opacity: 0;
  957. transition: opacity 0.2s ease;
  958. }
  959. }
  960. }
  961. .two-level-container {
  962. display: flex;
  963. flex: 1;
  964. border-top: 1rpx solid #f5f5f5;
  965. .primary-list {
  966. width: 40%;
  967. background-color: #f8f9fa;
  968. .primary-item {
  969. padding: 28rpx 20rpx;
  970. background: #F2F3F5;
  971. &:active {
  972. background: #FFFFFF;
  973. }
  974. &.primary-active {
  975. position: relative;
  976. background-color: #fff;
  977. &::before {
  978. content: '';
  979. position: absolute;
  980. top: 50%;
  981. left: 0;
  982. transform: translateY(-50%);
  983. width: 8rpx;
  984. height: 32rpx;
  985. background: #388BFF;
  986. }
  987. .primary-text {
  988. font-weight: 500;
  989. }
  990. }
  991. .primary-text {
  992. font-size: 28rpx;
  993. color: #666;
  994. }
  995. }
  996. }
  997. .secondary-list {
  998. width: 60%;
  999. padding: 0 20rpx;
  1000. .secondary-item {
  1001. display: flex;
  1002. justify-content: space-between;
  1003. align-items: center;
  1004. padding: 28rpx 10rpx;
  1005. font-size: 28rpx;
  1006. color: #333;
  1007. &.secondary-active {
  1008. font-weight: 500;
  1009. color: #388BFF;
  1010. }
  1011. }
  1012. }
  1013. }
  1014. .popup-footer {
  1015. padding: 20rpx 30rpx 40rpx;
  1016. background-color: #fff;
  1017. border-top: 1rpx solid #f5f5f5;
  1018. flex-shrink: 0;
  1019. .confirm-btn {
  1020. width: 100%;
  1021. height: 88rpx;
  1022. line-height: 88rpx;
  1023. background-color: #2979ff;
  1024. color: #fff;
  1025. font-size: 32rpx;
  1026. border-radius: 200rpx 200rpx 200rpx 200rpx;
  1027. &:active {
  1028. opacity: 0.8;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. @media (prefers-color-scheme: dark) {
  1034. .popup-content {
  1035. background-color: #1e1e1e;
  1036. .popup-header {
  1037. .title,
  1038. .popup-title {
  1039. color: #fff;
  1040. }
  1041. }
  1042. .two-level-container {
  1043. .primary-list {
  1044. background-color: #2d2d2d;
  1045. border-right-color: #3d3d3d;
  1046. .primary-item {
  1047. border-bottom-color: #3d3d3d;
  1048. &:active {
  1049. background-color: #3d3d3d;
  1050. }
  1051. &.primary-active {
  1052. background-color: #3d3d3d;
  1053. .primary-text {
  1054. color: #2979ff;
  1055. }
  1056. }
  1057. .primary-text {
  1058. color: #ccc;
  1059. }
  1060. }
  1061. }
  1062. .secondary-list {
  1063. .secondary-item {
  1064. border-bottom-color: #3d3d3d;
  1065. &:active {
  1066. background-color: #3d3d3d;
  1067. }
  1068. &.secondary-active {
  1069. background-color: #2d2d2d;
  1070. }
  1071. .secondary-text {
  1072. color: #fff;
  1073. }
  1074. }
  1075. }
  1076. }
  1077. .popup-footer {
  1078. background-color: #1e1e1e;
  1079. border-top-color: #3d3d3d;
  1080. }
  1081. }
  1082. }
  1083. </style>