editPlan.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back"
  4. :title="title" @clickLeft="back">
  5. </uni-nav-bar>
  6. <view class="scrollable-tabs" ref="tabsContainer">
  7. <u-subsection :list="tabs" :current="currentIndex" @change="(e)=>sectionChange(e)"></u-subsection>
  8. </view>
  9. <accessoryList title="配件回收清单" ref="accessoryRef" :itemList="accessList" v-show="currentValue == 2" />
  10. <!-- 需求信息 -->
  11. <DemandInfo :demandForm="demandForm" v-show="currentValue == 3" :itemList="productDetail" />
  12. <!-- 计划信息 -->
  13. <PlanInfo :planForm="planForm" v-show="currentValue == 4" />
  14. <!-- 售后对象 -->
  15. <AfterSales ref="salesRef" v-show="currentValue == 5" :itemList="productDetail" :type="type"
  16. :isReport="isReport" />
  17. <!-- 联系人列表 -->
  18. <ContactList ref="contactRef" :type="type" v-show="currentValue == 6" :itemList="contactInfoVOS"
  19. :isReport="isReport" />
  20. <!-- 方案列表 -->
  21. <SchemeList ref="schemeRef" v-show="currentValue == 7" :type='type' :itemList="costListVOS" pageName="workOrder" />
  22. <!-- 报工信息 -->
  23. <ReportInfo ref="reportInfoRef" :form="reportForm" v-show="currentValue == 1" />
  24. <view :class=" type == 'report' ? 'footerButton footer_button':'footerButton'" v-if="isDisable">
  25. <u-button type="default" text="返回" @click="back"></u-button>
  26. <u-button type="primary" text="报工" v-if="type == 'report'" @click="save('report')"></u-button>
  27. <u-button type="primary" @click="save" text="保存"></u-button>
  28. </view>
  29. <!-- <ba-tree-picker ref="treePicker" :multiple="false" @select-change="confirm" title="选择部门" :localdata="listData"
  30. valueKey="id" textKey="name" childrenKey="children" /> -->
  31. <u-toast ref="uToast"></u-toast>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. getSalesWorkOrderById,
  37. updateScheme,
  38. reportWorkingSalesWorkOrder
  39. } from '@/api/salesServiceManagement/workOrder/index.js';
  40. import {
  41. contactDetail
  42. } from '@/api/saleManage/contact/index.js';
  43. import accessoryList from './accessoryList.vue';
  44. import ReportInfo from './reportInfo.vue';
  45. import AfterSales from '@/pages/salesServiceManagement/demandList/components/AfterSales.vue';
  46. import ContactList from '@/pages/salesServiceManagement/demandList/components/contactList.vue';
  47. import PlanInfo from './planInfo.vue';
  48. import DemandInfo from './demandInfo.vue';
  49. import SchemeList from './schemeList.vue';
  50. import {
  51. getByCode
  52. } from '@/api/pda/common.js';
  53. import {
  54. listOrganizations,
  55. getUserPage
  56. } from '@/api/myTicket/index.js';
  57. let resData = {};
  58. let contractInfo = {};
  59. export default {
  60. components: {
  61. SchemeList,
  62. PlanInfo,
  63. DemandInfo,
  64. AfterSales,
  65. ContactList,
  66. ReportInfo,
  67. accessoryList
  68. },
  69. computed: {
  70. isDisable() {
  71. let flag = this.type != 'view';
  72. return flag;
  73. },
  74. isReport() {
  75. let flag = this.type != 'view' ? true : false;
  76. return flag;
  77. },
  78. currentIndex() {
  79. return this.tabs.findIndex(item => item.id == this.currentValue);
  80. }
  81. },
  82. data() {
  83. return {
  84. title: '修改工单',
  85. type: 'edit',
  86. Usertype: '',
  87. tabs: [{
  88. name: '售后对象',
  89. id: 5
  90. }, {
  91. name: '联系人',
  92. id: 6
  93. },
  94. {
  95. name: '方案',
  96. id: 7
  97. }, {
  98. name: '需求信息',
  99. id: 3
  100. }, {
  101. name: '计划信息',
  102. id: 4
  103. },
  104. ],
  105. listData: [], // 部门数据
  106. userList: [], // 执行人列表
  107. demandForm: {}, // 需求基本信息
  108. planForm: {}, // 计划基本信息
  109. productDetail: [], // 售后对象
  110. contactInfoVOS: [], // 联系人
  111. costListVOS: [], // 方案
  112. currentValue: 5,
  113. accessList: [], // 配件回收
  114. reportForm: {
  115. acceptTime: '',
  116. finishTime: '',
  117. inFactDuration: ''
  118. }
  119. }
  120. },
  121. onLoad(params) {
  122. this.type = params.type;
  123. this.title = params.type == 'view' ? '工单详情' : params.type == 'edit' ? '修改工单' : '报工';
  124. if (params.type == 'report') {
  125. this.tabs.unshift({
  126. name: '报工信息',
  127. id: 1
  128. }, {
  129. name: '配件回收',
  130. id: 2
  131. });
  132. this.currentValue = 1;
  133. }
  134. this.getDetails(params.id);
  135. },
  136. onUnload() {},
  137. created() {},
  138. methods: {
  139. async getDetails(id) {
  140. // await this.getByData();
  141. // this.getDept();
  142. const res = await getSalesWorkOrderById(id);
  143. console.log(res, 'res ----')
  144. this.reportForm = {
  145. acceptTime: res.acceptTime,
  146. finishTime: res.finishTime,
  147. inFactDuration: res.inFactDuration
  148. }
  149. this.accessList = res.accessoryApply?.detailList || []
  150. this.contactData(res.afterSalesDemandVO.contactId, 'init');
  151. resData = res;
  152. this.costListVOS = res.costListVOS;
  153. this.demandData(res.afterSalesDemandVO);
  154. this.planData(res.afterSalesPlanVO);
  155. },
  156. // 工单绑定的客户数据
  157. async contactData(id) {
  158. let {
  159. base
  160. } = await contactDetail(id);
  161. base.contactName = base.name;
  162. contractInfo = base;
  163. },
  164. // 需求数据
  165. async demandData(data) {
  166. this.contactInfoVOS = data.contactInfoVOS || [];
  167. this.productDetail = data.productDetail || [];
  168. let fault_level = await this.getByData('fault_level', data.faultLevel);
  169. this.demandForm = {
  170. code: data.code,
  171. name: data.name,
  172. contactName: data.contactName,
  173. orderCode: data.orderCode,
  174. contactAddress: data.contactAddress,
  175. expectedTime: data.expectedTime,
  176. createUserName: data.createUserName,
  177. associationType:data.associationType,
  178. fault_level,
  179. }
  180. },
  181. // 计划信息
  182. async planData(data) {
  183. let isSyncBill = data.isSyncBill == '0' ? '否' : data.isSyncBill == '1' ? '是' : ''
  184. let urgent = await this.getByData('urgent_type', data.urgent);
  185. this.planForm = {
  186. code: data.code,
  187. name: data.name,
  188. isSyncBill,
  189. executeGroupName: data.executeGroupName,
  190. executeUserName: data.executeUserName,
  191. remark: data.remark,
  192. duration: data.duration,
  193. durationUnit: data.durationUnit,
  194. urgent,
  195. }
  196. },
  197. async getByData(code, value) {
  198. const codeValue = await getByCode(code);
  199. let label = '';
  200. codeValue.forEach((el) => {
  201. if (el[value]) {
  202. label = el[value];
  203. return;
  204. }
  205. })
  206. return label || ''
  207. },
  208. getDept() {
  209. listOrganizations(1).then(data => {
  210. this.listData = data;
  211. })
  212. },
  213. clistData(arrList) {
  214. let list = JSON.parse(JSON.stringify(arrList));
  215. let arr = [];
  216. if (list.length == 0) return list;
  217. list.map((item) => {
  218. this.addData(item, arr);
  219. });
  220. return arr;
  221. },
  222. addData(item, arr) {
  223. let totalCount = item.totalCount ? item.totalCount - 0 : '';
  224. if (!totalCount || totalCount == 1) {
  225. arr.push(item);
  226. return;
  227. }
  228. for (let i = 0; i < totalCount; i++) {
  229. item.totalPrice = item.singlePrice || 0;
  230. item.totalCount = 1;
  231. arr.push(item);
  232. }
  233. },
  234. process(type) {
  235. let productDetail = this.$refs.salesRef.getTabData();
  236. // 点击报工 逻辑
  237. if (type == 'report') {
  238. let flag = true;
  239. productDetail[0]?.faultDetails?.forEach((el) => {
  240. if (!el.faultReason || !el.maintenanceProcess) {
  241. this.$refs.uToast.show({
  242. type: "warning",
  243. message: "故障原因跟维修过程不能为空",
  244. })
  245. this.currentValue = 5;
  246. flag = false;
  247. return;
  248. }
  249. })
  250. if (!flag) {
  251. return flag;
  252. }
  253. }
  254. let contactInfoVOS = this.$refs.contactRef.getTabData();
  255. let costListVOS = this.$refs.schemeRef.getTabData();
  256. // console.log(this.$refs.schemeRef.getTotalPrice(),'this.$refs.schemeRef.getTotalPrice()')
  257. // return
  258. let obj = resData.afterSalesDemandVO;
  259. let data = {
  260. attachments: resData.attachments,
  261. costListVOS: costListVOS,
  262. faultPhenomenon: resData.inFactDuration,
  263. faultReason: resData.faultReason,
  264. id: resData.id,
  265. inFactDuration: resData.inFactDuration,
  266. maintenanceProcess: resData.maintenanceProcess,
  267. totalCost:this.$refs.schemeRef.getTotalPrice(),
  268. salesDemandUpdatePO: {
  269. orderCode: obj.orderCode,
  270. orderId: obj.orderId,
  271. name: obj.name,
  272. faultLevel: obj.faultLevel ? String(obj.faultLevel) : '',
  273. code: obj.code,
  274. expectedTime: obj.expectedTime || '',
  275. contactAddress: obj.contactAddress || '',
  276. id: obj.id,
  277. }
  278. }
  279. productDetail?.map((el) => {
  280. delete el.produceTime;
  281. })
  282. data.salesDemandUpdatePO.productDetail = productDetail;
  283. data.salesDemandUpdatePO.contractInfo = contractInfo;
  284. data.salesDemandUpdatePO.contactInfoVOS = contactInfoVOS;
  285. // 处理报工信息的数据
  286. if (this.type == 'report') {
  287. let reportForm = this.$refs.reportInfoRef.getReportForm();
  288. if (!reportForm.acceptTime || !reportForm.finishTime) {
  289. this.currentValue = 1;
  290. this.$refs.uToast.show({
  291. type: "warning",
  292. message: "请选择开始时间跟结束时间",
  293. })
  294. return false;
  295. }
  296. data = {
  297. ...data,
  298. ...reportForm
  299. }
  300. }
  301. // 报工进来 保存或者报工 数据
  302. if (this.type == 'report' && productDetail[0]?.faultDetails?.length > 0) {
  303. let list = this.$refs.accessoryRef.getTabData() || [];
  304. if (list.length > 0) {
  305. let detailList = this.clistData(list);
  306. // 指定绑定第一条设备信息
  307. let item = data.salesDemandUpdatePO.productDetail[0];
  308. let accessoryApply = {
  309. demandDetailId: item?.id,
  310. categoryCode: item?.categoryCode,
  311. categoryName: item?.categoryName,
  312. contactName: data.salesDemandUpdatePO.contractInfo.name,
  313. contactCode: data.salesDemandUpdatePO.contractInfo.code,
  314. detailList
  315. };
  316. data.accessoryApply = accessoryApply;
  317. }
  318. }
  319. return data;
  320. },
  321. save(type) {
  322. // 获取 报工信息以外的数据
  323. let data = this.process(type);
  324. if (!data) {
  325. return
  326. }
  327. console.log(data, 'data')
  328. uni.showLoading({
  329. title: '加载中'
  330. });
  331. let api = type != 'report' ? updateScheme : reportWorkingSalesWorkOrder;
  332. api(data).then(res => {
  333. this.$refs.uToast.show({
  334. type: "success",
  335. message: "操作成功",
  336. })
  337. uni.hideLoading();
  338. this.back();
  339. }).catch(e => {
  340. uni.hideLoading();
  341. })
  342. },
  343. //返回添加页
  344. backAdd() {
  345. this.back();
  346. // uni.navigateBack();
  347. },
  348. // confirm(data, name) {
  349. // this.form.executeGroupName = name
  350. // this.form.executeGroupId = data[0]
  351. // this.form.executeUserName = ''
  352. // this.form.executeUserId = ''
  353. // this.getUser(data[0])
  354. // },
  355. // getUser(deptCode) {
  356. // getUserPage({
  357. // pageNum: 1,
  358. // size: -1,
  359. // groupId: deptCode
  360. // }).then(data => {
  361. // this.userList = data.list.map(item => {
  362. // item.text = item.name
  363. // item.value = item.id
  364. // return item
  365. // })
  366. // })
  367. // },
  368. sectionChange(index) {
  369. this.currentValue = this.tabs[index].id;
  370. },
  371. }
  372. }
  373. </script>
  374. <style lang="scss" scoped>
  375. /deep/.u-subsection__item__text {
  376. font-size: 28rpx !important;
  377. }
  378. /deep/.u-cell__body__content {
  379. flex: none;
  380. margin-right: 16rpx;
  381. }
  382. /deep/ .time_select .uni-data-tree-input {
  383. width: 200rpx;
  384. }
  385. /deep/ .executor_user {
  386. background: #fff;
  387. }
  388. .footerButton {
  389. width: 100%;
  390. height: 84rpx;
  391. display: flex;
  392. position: fixed;
  393. bottom: 0;
  394. z-index: 10;
  395. justify-content: space-between;
  396. /deep/.u-button {
  397. height: 100%;
  398. width: 50%;
  399. }
  400. >view {
  401. flex: 1;
  402. }
  403. }
  404. .footer_button {
  405. /deep/.u-button {
  406. height: 100%;
  407. width: 30%;
  408. }
  409. }
  410. .scrollable-tabs {
  411. white-space: nowrap;
  412. /* 防止选项卡换行 */
  413. overflow-x: auto;
  414. /* 启用横向滚动 */
  415. -webkit-overflow-scrolling: touch;
  416. /* 优化iOS滚动体验 */
  417. /deep/ .u-subsection {
  418. overflow-x: auto;
  419. }
  420. /deep/ .u-subsection__item__text {
  421. width: 144rpx;
  422. text-align: center;
  423. display: inline-block;
  424. }
  425. }
  426. </style>