editPlan.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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" />
  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. fault_level,
  178. }
  179. },
  180. // 计划信息
  181. async planData(data) {
  182. let isSyncBill = data.isSyncBill == '0' ? '否' : data.isSyncBill == '1' ? '是' : ''
  183. let urgent = await this.getByData('urgent_type', data.urgent);
  184. this.planForm = {
  185. code: data.code,
  186. name: data.name,
  187. isSyncBill,
  188. executeGroupName: data.executeGroupName,
  189. executeUserName: data.executeUserName,
  190. remark: data.remark,
  191. duration: data.duration,
  192. durationUnit: data.durationUnit,
  193. urgent,
  194. }
  195. },
  196. async getByData(code, value) {
  197. const codeValue = await getByCode(code);
  198. let label = '';
  199. codeValue.forEach((el) => {
  200. if (el[value]) {
  201. label = el[value];
  202. return;
  203. }
  204. })
  205. return label || ''
  206. },
  207. getDept() {
  208. listOrganizations(1).then(data => {
  209. this.listData = data;
  210. })
  211. },
  212. clistData(arrList) {
  213. let list = JSON.parse(JSON.stringify(arrList));
  214. let arr = [];
  215. if (list.length == 0) return list;
  216. list.map((item) => {
  217. this.addData(item, arr);
  218. });
  219. return arr;
  220. },
  221. addData(item, arr) {
  222. let totalCount = item.totalCount ? item.totalCount - 0 : '';
  223. if (!totalCount || totalCount == 1) {
  224. arr.push(item);
  225. return;
  226. }
  227. for (let i = 0; i < totalCount; i++) {
  228. item.totalPrice = item.singlePrice || 0;
  229. item.totalCount = 1;
  230. arr.push(item);
  231. }
  232. },
  233. process(type) {
  234. let productDetail = this.$refs.salesRef.getTabData();
  235. // 点击报工 逻辑
  236. if (type == 'report') {
  237. let flag = true;
  238. productDetail[0].faultDetails.forEach((el) => {
  239. if (!el.faultReason || !el.maintenanceProcess) {
  240. this.$refs.uToast.show({
  241. type: "warning",
  242. message: "故障原因跟维修过程不能为空",
  243. })
  244. this.currentValue = 5;
  245. flag = false;
  246. return;
  247. }
  248. })
  249. if (!flag) {
  250. return flag;
  251. }
  252. }
  253. let contactInfoVOS = this.$refs.contactRef.getTabData();
  254. let costListVOS = this.$refs.schemeRef.getTabData();
  255. let obj = resData.afterSalesDemandVO;
  256. let data = {
  257. attachments: resData.attachments,
  258. costListVOS: costListVOS,
  259. faultPhenomenon: resData.inFactDuration,
  260. faultReason: resData.faultReason,
  261. id: resData.id,
  262. inFactDuration: resData.inFactDuration,
  263. maintenanceProcess: resData.maintenanceProcess,
  264. salesDemandUpdatePO: {
  265. orderCode: obj.orderCode,
  266. orderId: obj.orderId,
  267. name: obj.name,
  268. faultLevel: obj.faultLevel ? String(obj.faultLevel) : '',
  269. code: obj.code,
  270. expectedTime: obj.expectedTime || '',
  271. contactAddress: obj.contactAddress || '',
  272. id: obj.id,
  273. }
  274. }
  275. productDetail.map((el) => {
  276. delete el.produceTime;
  277. })
  278. data.salesDemandUpdatePO.productDetail = productDetail;
  279. data.salesDemandUpdatePO.contractInfo = contractInfo;
  280. data.salesDemandUpdatePO.contactInfoVOS = contactInfoVOS;
  281. // 处理报工信息的数据
  282. if (this.type == 'report') {
  283. let reportForm = this.$refs.reportInfoRef.getReportForm();
  284. if (!reportForm.acceptTime || !reportForm.finishTime) {
  285. this.currentValue = 1;
  286. this.$refs.uToast.show({
  287. type: "warning",
  288. message: "请选择开始时间跟结束时间",
  289. })
  290. return false;
  291. }
  292. data = {
  293. ...data,
  294. ...reportForm
  295. }
  296. }
  297. // 报工进来 保存或者报工 数据
  298. if (this.type == 'report' && productDetail[0].faultDetails.length > 0) {
  299. let list = this.$refs.accessoryRef.getTabData() || [];
  300. if (list.length > 0) {
  301. let detailList = this.clistData(list);
  302. // 指定绑定第一条设备信息
  303. let item = data.salesDemandUpdatePO.productDetail[0];
  304. let accessoryApply = {
  305. demandDetailId: item.id,
  306. categoryCode: item.categoryCode,
  307. categoryName: item.categoryName,
  308. contactName: data.salesDemandUpdatePO.contractInfo.name,
  309. contactCode: data.salesDemandUpdatePO.contractInfo.code,
  310. detailList
  311. };
  312. data.accessoryApply = accessoryApply;
  313. }
  314. }
  315. return data;
  316. },
  317. save(type) {
  318. // 获取 报工信息以外的数据
  319. let data = this.process(type);
  320. if (!data) {
  321. return
  322. }
  323. console.log(data, 'data')
  324. uni.showLoading({
  325. title: '加载中'
  326. });
  327. let api = type != 'report' ? updateScheme : reportWorkingSalesWorkOrder;
  328. api(data).then(res => {
  329. this.$refs.uToast.show({
  330. type: "success",
  331. message: "操作成功",
  332. })
  333. uni.hideLoading();
  334. this.back();
  335. }).catch(e => {
  336. uni.hideLoading();
  337. })
  338. },
  339. //返回添加页
  340. backAdd() {
  341. this.back();
  342. // uni.navigateBack();
  343. },
  344. // confirm(data, name) {
  345. // this.form.executeGroupName = name
  346. // this.form.executeGroupId = data[0]
  347. // this.form.executeUserName = ''
  348. // this.form.executeUserId = ''
  349. // this.getUser(data[0])
  350. // },
  351. // getUser(deptCode) {
  352. // getUserPage({
  353. // pageNum: 1,
  354. // size: -1,
  355. // groupId: deptCode
  356. // }).then(data => {
  357. // this.userList = data.list.map(item => {
  358. // item.text = item.name
  359. // item.value = item.id
  360. // return item
  361. // })
  362. // })
  363. // },
  364. sectionChange(index) {
  365. this.currentValue = this.tabs[index].id;
  366. },
  367. }
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. /deep/.u-subsection__item__text {
  372. font-size: 28rpx !important;
  373. }
  374. /deep/.u-cell__body__content {
  375. flex: none;
  376. margin-right: 16rpx;
  377. }
  378. /deep/ .time_select .uni-data-tree-input {
  379. width: 200rpx;
  380. }
  381. /deep/ .executor_user {
  382. background: #fff;
  383. }
  384. .footerButton {
  385. width: 100%;
  386. height: 84rpx;
  387. display: flex;
  388. position: fixed;
  389. bottom: 0;
  390. z-index: 10;
  391. justify-content: space-between;
  392. /deep/.u-button {
  393. height: 100%;
  394. width: 50%;
  395. }
  396. >view {
  397. flex: 1;
  398. }
  399. }
  400. .footer_button {
  401. /deep/.u-button {
  402. height: 100%;
  403. width: 30%;
  404. }
  405. }
  406. .scrollable-tabs {
  407. white-space: nowrap;
  408. /* 防止选项卡换行 */
  409. overflow-x: auto;
  410. /* 启用横向滚动 */
  411. -webkit-overflow-scrolling: touch;
  412. /* 优化iOS滚动体验 */
  413. /deep/ .u-subsection {
  414. overflow-x: auto;
  415. }
  416. /deep/ .u-subsection__item__text {
  417. width: 144rpx;
  418. text-align: center;
  419. display: inline-block;
  420. }
  421. }
  422. </style>