createTask.vue 36 KB

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