editPlan.vue 11 KB

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