createTask.vue 36 KB

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