createTask.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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=uni.getStorageSync("userInfo")||''
  286. if (options.rejectionInfo) {
  287. this.rejectionInfo = decodeURIComponent(options.rejectionInfo)
  288. }
  289. // 获取用户信息
  290. // 加载信息
  291. this.companyId = this.userInfo.companyId || 1
  292. // 设置默认日期为当天
  293. this.formData.planStartTime = this.formatDateTime(new Date());
  294. this.formData.planEndTime = this.formatDateTime(new Date());
  295. },
  296. computed: {
  297. taskTypeDisplayText() {
  298. console.log('计算taskTypeDisplayText, formData.taskType:', this.formData.taskType);
  299. console.log('计算taskTypeDisplayText, taskTypeOriginalData:', this.taskTypeOriginalData);
  300. if (!this.formData.taskType || !this.taskTypeOriginalData) {
  301. return '';
  302. }
  303. const selectedType = this.taskTypeOriginalData.find(item => item.dictValue === this.formData.taskType);
  304. console.log('找到的selectedType:', selectedType);
  305. return selectedType ? selectedType.dictLabel : '';
  306. },
  307. institutionDisplayText() {
  308. if (!this.formData.deptId || !this.companyData) {
  309. return '';
  310. }
  311. const selectedItem = this.companyData.find(item => item.deptId === this.formData.deptId);
  312. return selectedItem ? selectedItem.deptName : '';
  313. },
  314. costAllocationDisplayText() {
  315. if (!this.formData.costShareId || !this.companyData) {
  316. return '';
  317. }
  318. const selectedItem = this.companyData.find(item => item.deptId === this.formData.costShareId);
  319. return selectedItem ? selectedItem.deptName : '';
  320. },
  321. belongingProjectDisplayText() {
  322. console.log('计算belongingProjectDisplayText:', this.formData.projectId, this.projectData);
  323. if (!this.formData.projectId || !this.projectData) {
  324. console.log('formData.projectId或projectData为空');
  325. return '';
  326. }
  327. const selectedItem = this.projectData.find(item => item.id === this.formData.projectId);
  328. console.log('找到的项目:', selectedItem);
  329. return selectedItem ? selectedItem.projectName : '';
  330. },
  331. productNameDisplayText() {
  332. if (!this.formData.productId || !this.productList) {
  333. return '';
  334. }
  335. const selectedItem = this.productList.find(item => item.id === this.formData.productId);
  336. return selectedItem ? selectedItem.productName : '';
  337. },
  338. belongTypeDisplayText() {
  339. if (!this.formData.belongType || !this.belongTypeList) {
  340. return '';
  341. }
  342. const selectedItem = this.belongTypeList.find(item => item.dictValue === this.formData.belongType);
  343. return selectedItem ? selectedItem.dictLabel : '';
  344. }
  345. },
  346. methods: {
  347. //任务类型
  348. queryAllData(){
  349. return new Promise((resolve, reject) => {
  350. if(!this.formData.productId){
  351. uni.showToast({
  352. title: '请先选择产品',
  353. icon: 'none'
  354. })
  355. resolve();
  356. return
  357. }
  358. let data={
  359. companyId:this.userInfo.companyId||'',
  360. deptId:this.formData.deptId||'',
  361. productId:this.formData.productId||'',
  362. }
  363. queryAllData(data).then(res => {
  364. if (res.code === 200) {
  365. // 处理任务类型
  366. this.taskType = res.data || []
  367. console.log('company接口返回数据:', res)
  368. // 处理taskTypeIds,获取对应的字典数据
  369. if (res.data && res.data.length > 0) {
  370. const firstData = res.data[0];
  371. if (firstData.taskTypeIds) {
  372. // 分割taskTypeIds为数组
  373. const taskTypeIdsArray = firstData.taskTypeIds.split(',');
  374. // 从字典表中筛选出对应的项
  375. const filteredTaskTypes = this.taskTypeDict.filter(item =>
  376. taskTypeIdsArray.includes(item.dictValue)
  377. );
  378. // 保存原始数据(包含dictLabel和dictValue)
  379. this.taskTypeOriginalData = filteredTaskTypes;
  380. // 提取dictLabel并放到taskTypeColumns中
  381. const taskTypeLabels = filteredTaskTypes.map(item => item.dictLabel);
  382. this.taskTypeColumns = [taskTypeLabels];
  383. console.log('处理后的taskTypeColumns:', this.taskTypeColumns);
  384. console.log('任务类型原始数据:', this.taskTypeOriginalData);
  385. }
  386. }
  387. }
  388. resolve(res);
  389. }).catch(err => {
  390. console.error('获取任务类型失败:', err);
  391. reject(err);
  392. });
  393. });
  394. },
  395. //获取公司所有产品
  396. async queryAllProduct(){
  397. return new Promise((resolve, reject) => {
  398. let data={
  399. companyId:this.userInfo.companyId||'',
  400. }
  401. queryAllProduct(data).then(res => {
  402. if (res.code === 200) {
  403. // 处理公司所有产品数据
  404. this.productList = res.data || []
  405. console.log('company接口返回数据:', res)
  406. }
  407. resolve(res);
  408. }).catch(err => {
  409. console.error('获取公司所有产品失败:', err);
  410. reject(err);
  411. });
  412. });
  413. },
  414. // 归属项目
  415. async getAllData(){
  416. return new Promise((resolve, reject) => {
  417. let data={
  418. companyId:this.userInfo.companyId||'',
  419. deptId:this.userInfo.deptId||'',
  420. productCode:this.userInfo.productCode||''
  421. }
  422. getAllData(data).then(res => {
  423. if (res.code === 200) {
  424. // 处理公司项目设置列表数据
  425. this.companyList = res.data || []
  426. // 保存项目数据用于显示
  427. this.projectData = res.data || []
  428. console.log('company接口返回数据:', res)
  429. console.log('companyList数据结构:', this.companyList)
  430. }
  431. resolve(res);
  432. }).catch(err => {
  433. console.error('获取公司项目设置失败:', err);
  434. reject(err);
  435. });
  436. });
  437. },
  438. async company() {
  439. return new Promise((resolve, reject) => {
  440. try {
  441. uni.showLoading({
  442. title: '加载中...'
  443. })
  444. // 调用company接口获取公司项目设置列表
  445. company(this.companyId).then(companyRes => {
  446. uni.hideLoading()
  447. if (companyRes.code === 200) {
  448. // 处理公司项目设置列表数据
  449. this.companyData = companyRes.data || []
  450. console.log('company接口返回数据:', companyRes)
  451. // 这里可以根据接口返回的数据进行页面初始化,比如填充项目列表
  452. }
  453. resolve(companyRes);
  454. }).catch(e => {
  455. uni.hideLoading()
  456. console.error('加载信息失败', e)
  457. uni.showToast({
  458. title: '网络错误',
  459. icon: 'none'
  460. })
  461. reject(e);
  462. });
  463. } catch (e) {
  464. uni.hideLoading()
  465. console.error('加载信息失败', e)
  466. uni.showToast({
  467. title: '网络错误',
  468. icon: 'none'
  469. })
  470. reject(e);
  471. }
  472. });
  473. },
  474. submitInfo() {
  475. info(this.userInfo.companyId).then(res => {
  476. if (res.code === 200) {
  477. console.log('公司项目设置:', res.data);
  478. // 处理公司项目设置数据
  479. }
  480. }).catch(err => {
  481. console.error('获取公司项目设置失败:', err);
  482. });
  483. },
  484. handlePrimarySelect(index) {
  485. this.activePrimaryIndex = index;
  486. this.currentSecondaryOptions = this.primaryOptions[index].children || [];
  487. this.selectedSecondaryItem = '';
  488. },
  489. handleSecondarySelect(item) {
  490. this.selectedSecondaryItem = item;
  491. this.selectedPrimaryItem = this.primaryOptions[this.activePrimaryIndex];
  492. },
  493. handleConfirm() {
  494. if (this.selectedSecondaryItem) {
  495. const displayText = `${this.selectedPrimaryItem.name} > ${this.selectedSecondaryItem}`;
  496. this.formData.belongType = displayText;
  497. this.showTaskPopup = false;
  498. } else {
  499. uni.showToast({
  500. title: '请选择二级部门',
  501. icon: 'none'
  502. });
  503. }
  504. },
  505. closePopup() {
  506. this.showBelongingPopup = false;
  507. this.searchKeyword = '';
  508. this.selectedIndex = -1;
  509. },
  510. selectProject(project, index) {
  511. this.selectedIndex = index;
  512. this.selectedProject = project;
  513. this.formData.belongingProject = project.name;
  514. setTimeout(() => {
  515. this.showBelongingPopup = false;
  516. this.searchKeyword = '';
  517. this.selectedIndex = -1;
  518. }, 300);
  519. },
  520. async showPicker(title, data) {
  521. // 根据不同的title调用对应的请求方法
  522. if (title === '任务归属' || title === '费用分摊') {
  523. // 调用company()获取任务归属和费用分摊数据
  524. await this.company();
  525. data = this.companyData;
  526. } else if (title === '归属项目') {
  527. // 调用getAllData()获取归属项目数据
  528. await this.getAllData();
  529. data = this.companyList;
  530. console.log('归属项目数据:', data);
  531. } else if (title === '产品代码') {
  532. // 调用queryAllProduct()获取产品代码数据
  533. await this.queryAllProduct();
  534. data = this.productList;
  535. } else if (title === '任务类型') {
  536. // queryAllData()获取任务类型数据
  537. await this.queryAllData();
  538. // 使用处理后的taskTypeColumns作为数据
  539. data = this.taskTypeColumns;
  540. console.log('任务类型数据:', data);
  541. } else if (title === '归属类型') {
  542. // 归属类型数据已经在onLoad中获取
  543. data = this.belongTypeList;
  544. console.log('归属类型数据:', data);
  545. }
  546. // 处理任务归属和费用分摊数据,将deptStr作为显示文本
  547. if ((title === '任务归属' || title === '费用分摊') && data && data.length > 0) {
  548. // 转换为picker需要的格式
  549. this.pickerData = [data.map(item => item.deptName)]
  550. // 保存原始数据,用于后续获取deptId
  551. this.originalCompanyData = data
  552. } else if (title === '归属项目' && data && data.length > 0) {
  553. // 处理归属项目数据,将projectName作为显示文本
  554. this.pickerData = [data.map(item => item.projectName)]
  555. // 保存原始数据,用于后续获取productId
  556. this.originalCompanyData = data
  557. } else if (title === '产品代码' && data && data.length > 0) {
  558. // 处理产品代码数据,将productName作为显示文本
  559. this.pickerData = [data.map(item => item.productName)]
  560. // 保存原始数据,用于后续获取productCode
  561. this.originalCompanyData = data
  562. } else if (title === '归属类型' && data && data.length > 0) {
  563. // 处理归属类型数据,将dictLabel作为显示文本
  564. this.pickerData = [data.map(item => item.dictLabel)]
  565. // 保存原始数据,用于后续获取dictType
  566. this.originalCompanyData = data
  567. } else {
  568. this.pickerData = data
  569. this.originalCompanyData = null
  570. }
  571. this.pickerTitle = title
  572. console.log('打开picker, pickerTitle:', this.pickerTitle);
  573. console.log('pickerData:', this.pickerData);
  574. this.showPickerVisible = true
  575. },
  576. confirm(e) {
  577. console.log('confirm事件返回值:', e);
  578. console.log('pickerTitle:', this.pickerTitle);
  579. console.log('e.value:', e.value);
  580. if (e.value && e.value.length > 0) {
  581. if (this.pickerTitle === '费用分摊') {
  582. // e.value[0]是选中的文本值(deptName)
  583. const selectedDeptStr = e.value[0];
  584. console.log('选中的费用分摊文本:', selectedDeptStr);
  585. console.log('originalCompanyData:', this.originalCompanyData);
  586. // 从originalCompanyData中找到对应的项
  587. const selectedItem = this.originalCompanyData.find(item => item.deptName === selectedDeptStr);
  588. if (selectedItem) {
  589. // 保存deptId到表单(存储id值)
  590. this.formData.costShareId = selectedItem.deptId;
  591. console.log('设置formData.costShareId为:', selectedItem.deptId);
  592. } else {
  593. this.formData.costShareId = '';
  594. console.log('未找到对应的费用分摊');
  595. }
  596. } else if (this.pickerTitle === '任务类型') {
  597. // e.value[0]是选中的文本值(dictLabel)
  598. const selectedLabel = e.value[0];
  599. console.log('选中的任务类型文本:', selectedLabel);
  600. console.log('taskTypeOriginalData:', this.taskTypeOriginalData);
  601. // 从taskTypeOriginalData中找到对应的项
  602. const selectedType = this.taskTypeOriginalData.find(item => item.dictLabel === selectedLabel);
  603. if (selectedType) {
  604. this.formData.taskType = selectedType.dictValue;
  605. console.log('设置formData.taskType为:', selectedType.dictValue);
  606. } else {
  607. }
  608. } else if (this.pickerTitle === '任务归属' && this.originalCompanyData) {
  609. // e.value[0]是选中的文本值(deptName)
  610. const selectedDeptStr = e.value[0];
  611. console.log('选中的任务归属文本:', selectedDeptStr);
  612. console.log('originalCompanyData:', this.originalCompanyData);
  613. // 从originalCompanyData中找到对应的项
  614. const selectedItem = this.originalCompanyData.find(item => item.deptName === selectedDeptStr);
  615. if (selectedItem) {
  616. // 保存deptId到表单(存储id值)
  617. this.formData.deptId = selectedItem.deptId;
  618. console.log('设置formData.deptId为:', selectedItem.deptId);
  619. } else {
  620. }
  621. } else if (this.pickerTitle === '归属项目' && this.originalCompanyData) {
  622. // e.value[0]是选中的文本值(projectName)
  623. const selectedProjectName = e.value[0];
  624. console.log('选中的归属项目文本:', selectedProjectName);
  625. console.log('originalCompanyData:', this.originalCompanyData);
  626. // 从originalCompanyData中找到对应的项
  627. const selectedItem = this.originalCompanyData.find(item => item.projectName === selectedProjectName);
  628. if (selectedItem) {
  629. // 保存id到表单(存储id值)
  630. this.formData.projectId = selectedItem.id;
  631. // 保存productId到表单
  632. this.formData.productId = selectedItem.productId;
  633. console.log('设置formData.projectId为:', selectedItem.id);
  634. } else {
  635. }
  636. } else if (this.pickerTitle === '产品代码' && this.originalCompanyData) {
  637. // e.value[0]是选中的文本值(productName)
  638. const selectedProductName = e.value[0];
  639. console.log('选中的产品代码文本:', selectedProductName);
  640. console.log('originalCompanyData:', this.originalCompanyData);
  641. // 从originalCompanyData中找到对应的项
  642. const selectedItem = this.originalCompanyData.find(item => item.productName === selectedProductName);
  643. if (selectedItem) {
  644. // 保存id到表单
  645. this.formData.productId = selectedItem.id;
  646. // 保存id用于获取任务类型
  647. console.log('设置formData.productId为:', selectedItem.id);
  648. } else {
  649. }
  650. } else if (this.pickerTitle === '归属类型' && this.originalCompanyData) {
  651. // e.value[0]是选中的文本值(dictLabel)
  652. const selectedLabel = e.value[0];
  653. console.log('选中的归属类型文本:', selectedLabel);
  654. console.log('originalCompanyData:', this.originalCompanyData);
  655. // 从originalCompanyData中找到对应的项
  656. const selectedItem = this.originalCompanyData.find(item => item.dictLabel === selectedLabel);
  657. if (selectedItem) {
  658. // 保存dictValue到表单的belongType字段
  659. this.formData.belongType = selectedItem.dictValue;
  660. console.log('设置formData.belongType为:', selectedItem.dictValue);
  661. } else {
  662. console.log('未找到对应的归属类型');
  663. }
  664. }
  665. }
  666. this.showPickerVisible = false
  667. },
  668. cancel() {
  669. this.showPickerVisible = false
  670. },
  671. toNext() {
  672. // 表单验证
  673. if (!this.formData.deptId) {
  674. uni.showToast({
  675. title: '请选择任务归属',
  676. icon: 'none'
  677. })
  678. return
  679. }
  680. if (!this.formData.projectId) {
  681. uni.showToast({
  682. title: '请选择归属项目',
  683. icon: 'none'
  684. })
  685. return
  686. }
  687. if (!this.formData.productId) {
  688. uni.showToast({
  689. title: '请选择产品代码',
  690. icon: 'none'
  691. })
  692. return
  693. }
  694. if (!this.formData.costShareId) {
  695. uni.showToast({
  696. title: '请选择费用分摊',
  697. icon: 'none'
  698. })
  699. return
  700. }
  701. if (!this.formData.belongType) {
  702. uni.showToast({
  703. title: '请选择归属类型',
  704. icon: 'none'
  705. })
  706. return
  707. }
  708. if (!this.formData.taskType) {
  709. uni.showToast({
  710. title: '请选择任务类型',
  711. icon: 'none'
  712. })
  713. return
  714. }
  715. if (!this.formData.planStartTime) {
  716. uni.showToast({
  717. title: '请选择计划开始时间',
  718. icon: 'none'
  719. })
  720. return
  721. }
  722. if (!this.formData.planEndTime) {
  723. uni.showToast({
  724. title: '请选择计划结束时间',
  725. icon: 'none'
  726. })
  727. return
  728. }
  729. // 如果开启了任务备注,则备注为必填
  730. if (this.formData.addRemark && !this.formData.remark) {
  731. uni.showToast({
  732. title: '请输入任务备注',
  733. icon: 'none'
  734. })
  735. return
  736. }
  737. // 保存任务表单数据到本地存储
  738. uni.setStorageSync('taskFormData', JSON.stringify(this.formData))
  739. uni.navigateTo({
  740. url: '/pages_task/selectCustomer'
  741. })
  742. },
  743. onStartTimeConfirm(e) {
  744. this.formData.planStartTime = this.formatDateTime(e.value);
  745. this.showStartTimePicker = false;
  746. },
  747. onEndTimeConfirm(e) {
  748. this.formData.planEndTime = this.formatDateTime(e.value);
  749. this.showEndTimePicker = false;
  750. },
  751. formatDateTime(timestamp) {
  752. const date = new Date(timestamp);
  753. const year = date.getFullYear();
  754. const month = String(date.getMonth() + 1).padStart(2, '0');
  755. const day = String(date.getDate()).padStart(2, '0');
  756. // const hours = String(date.getHours()).padStart(2, '0');
  757. // const minutes = String(date.getMinutes()).padStart(2, '0');
  758. // const seconds = String(date.getSeconds()).padStart(2, '0');
  759. // ${hours}:${minutes}:${seconds}
  760. return `${year}-${month}-${day}`;
  761. }
  762. }
  763. }
  764. </script>
  765. <style lang="scss" scoped>
  766. .container {
  767. min-height: 100vh;
  768. background: #F7F8FA;
  769. display: flex;
  770. flex-direction: column;
  771. position: relative;
  772. &::before {
  773. content: '';
  774. position: absolute;
  775. top: 0;
  776. left: 0;
  777. right: 0;
  778. width: 100%;
  779. height: 544rpx;
  780. background: linear-gradient(180deg, #E4EFFE 0%, rgba(228, 239, 254, 0) 100%);
  781. }
  782. .content {
  783. flex: 1;
  784. box-sizing: border-box;
  785. .rejection-banner {
  786. display: flex;
  787. align-items: center;
  788. padding: 24rpx;
  789. background: #FF5030;
  790. color: #fff;
  791. margin: 24rpx;
  792. border-radius: 8rpx;
  793. .rejection-icon {
  794. width: 40rpx;
  795. height: 40rpx;
  796. border-radius: 50%;
  797. background: rgba(255, 255, 255, 0.3);
  798. display: flex;
  799. align-items: center;
  800. justify-content: center;
  801. font-size: 24rpx;
  802. margin-right: 16rpx;
  803. }
  804. .rejection-text {
  805. flex: 1;
  806. font-size: 28rpx;
  807. line-height: 1.5;
  808. }
  809. }
  810. .form-section {
  811. background: #fff;
  812. margin: 20rpx;
  813. border-radius: 16rpx;
  814. padding: 32rpx;
  815. .form-item {
  816. display: flex;
  817. justify-content: space-between;
  818. align-items: center;
  819. border-bottom: 1px solid #EBEDF0;
  820. padding: 30rpx 0;
  821. &:last-child {
  822. border-bottom: 0;
  823. }
  824. .form-label {
  825. display: flex;
  826. align-items: center;
  827. font-size: 28rpx;
  828. color: #333;
  829. margin-bottom: 16rpx;
  830. .required {
  831. color: #CF3546;
  832. margin-right: 4rpx;
  833. }
  834. }
  835. .txt {
  836. font-size: 28rpx;
  837. color: #333333;
  838. }
  839. .form-input {
  840. flex: 1;
  841. font-size: 28rpx;
  842. color: #C8C9CC;
  843. &.placeholder {
  844. color: #C8C9CC;
  845. }
  846. &.picker-input {
  847. display: flex;
  848. align-items: center;
  849. justify-content: flex-end;
  850. }
  851. .icon {
  852. width: 36rpx;
  853. height: 36rpx;
  854. }
  855. }
  856. .form-textarea {
  857. flex: 1;
  858. font-size: 28rpx;
  859. color: #333;
  860. padding: 16rpx;
  861. border: 1px solid #EBEDF0;
  862. border-radius: 8rpx;
  863. min-height: 200rpx;
  864. resize: none;
  865. box-sizing: border-box;
  866. &::placeholder {
  867. color: #C8C9CC;
  868. }
  869. }
  870. }
  871. }
  872. }
  873. .next-button {
  874. text-align: center;
  875. font-size: 32rpx;
  876. color: #FFFFFF;
  877. height: 88rpx;
  878. line-height: 88rpx;
  879. background: #388BFF;
  880. border-radius: 200rpx;
  881. margin: 32rpx;
  882. }
  883. }
  884. ::v-deep .u-popup__content {
  885. border-radius: 40rpx 40rpx 0 0 !important;
  886. }
  887. .popup-content {
  888. border-radius: 40rpx 40rpx 0rpx 0rpx;
  889. height: 70vh;
  890. background-color: #fff;
  891. .popup-header {
  892. padding: 40rpx 30rpx 20rpx;
  893. text-align: center;
  894. .close-icon {
  895. width: 44rpx;
  896. height: 44rpx;
  897. position: absolute;
  898. right: 32rpx;
  899. }
  900. flex-shrink: 0;
  901. .title {
  902. font-size: 32rpx;
  903. font-weight: 600;
  904. color: #333;
  905. }
  906. .popup-title {
  907. font-size: 32rpx;
  908. font-weight: 600;
  909. color: #333;
  910. }
  911. }
  912. .search-box {
  913. display: flex;
  914. align-items: center;
  915. background: #F7F8FA;
  916. border-radius: 38rpx;
  917. padding: 16rpx 28rpx;
  918. margin-bottom: 24rpx;
  919. .icon {
  920. width: 26rpx;
  921. height: 26rpx;
  922. margin-right: 10rpx;
  923. }
  924. }
  925. .project-list {
  926. height: calc(100% - 200rpx);
  927. .project-item {
  928. display: flex;
  929. justify-content: space-between;
  930. align-items: center;
  931. padding: 28rpx 0;
  932. font-size: 28rpx;
  933. border-bottom: 1rpx solid #eee;
  934. &:active {
  935. background-color: #f9f9f9;
  936. }
  937. &.active {
  938. .project-name {
  939. font-weight: 500;
  940. color: #388BFF;
  941. }
  942. .icon {
  943. opacity: 1;
  944. }
  945. }
  946. .project-name {
  947. color: #333;
  948. transition: all 0.2s ease;
  949. }
  950. .icon {
  951. width: 36rpx;
  952. height: 36rpx;
  953. opacity: 0;
  954. transition: opacity 0.2s ease;
  955. }
  956. }
  957. }
  958. .two-level-container {
  959. display: flex;
  960. flex: 1;
  961. border-top: 1rpx solid #f5f5f5;
  962. .primary-list {
  963. width: 40%;
  964. background-color: #f8f9fa;
  965. .primary-item {
  966. padding: 28rpx 20rpx;
  967. background: #F2F3F5;
  968. &:active {
  969. background: #FFFFFF;
  970. }
  971. &.primary-active {
  972. position: relative;
  973. background-color: #fff;
  974. &::before {
  975. content: '';
  976. position: absolute;
  977. top: 50%;
  978. left: 0;
  979. transform: translateY(-50%);
  980. width: 8rpx;
  981. height: 32rpx;
  982. background: #388BFF;
  983. }
  984. .primary-text {
  985. font-weight: 500;
  986. }
  987. }
  988. .primary-text {
  989. font-size: 28rpx;
  990. color: #666;
  991. }
  992. }
  993. }
  994. .secondary-list {
  995. width: 60%;
  996. padding: 0 20rpx;
  997. .secondary-item {
  998. display: flex;
  999. justify-content: space-between;
  1000. align-items: center;
  1001. padding: 28rpx 10rpx;
  1002. font-size: 28rpx;
  1003. color: #333;
  1004. &.secondary-active {
  1005. font-weight: 500;
  1006. color: #388BFF;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. .popup-footer {
  1012. padding: 20rpx 30rpx 40rpx;
  1013. background-color: #fff;
  1014. border-top: 1rpx solid #f5f5f5;
  1015. flex-shrink: 0;
  1016. .confirm-btn {
  1017. width: 100%;
  1018. height: 88rpx;
  1019. line-height: 88rpx;
  1020. background-color: #2979ff;
  1021. color: #fff;
  1022. font-size: 32rpx;
  1023. border-radius: 200rpx 200rpx 200rpx 200rpx;
  1024. &:active {
  1025. opacity: 0.8;
  1026. }
  1027. }
  1028. }
  1029. }
  1030. @media (prefers-color-scheme: dark) {
  1031. .popup-content {
  1032. background-color: #1e1e1e;
  1033. .popup-header {
  1034. .title,
  1035. .popup-title {
  1036. color: #fff;
  1037. }
  1038. }
  1039. .two-level-container {
  1040. .primary-list {
  1041. background-color: #2d2d2d;
  1042. border-right-color: #3d3d3d;
  1043. .primary-item {
  1044. border-bottom-color: #3d3d3d;
  1045. &:active {
  1046. background-color: #3d3d3d;
  1047. }
  1048. &.primary-active {
  1049. background-color: #3d3d3d;
  1050. .primary-text {
  1051. color: #2979ff;
  1052. }
  1053. }
  1054. .primary-text {
  1055. color: #ccc;
  1056. }
  1057. }
  1058. }
  1059. .secondary-list {
  1060. .secondary-item {
  1061. border-bottom-color: #3d3d3d;
  1062. &:active {
  1063. background-color: #3d3d3d;
  1064. }
  1065. &.secondary-active {
  1066. background-color: #2d2d2d;
  1067. }
  1068. .secondary-text {
  1069. color: #fff;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. .popup-footer {
  1075. background-color: #1e1e1e;
  1076. border-top-color: #3d3d3d;
  1077. }
  1078. }
  1079. }
  1080. </style>