add.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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. <u-subsection :list="list" :current="current" @change="sectionChange"></u-subsection>
  7. <u-cell-group v-show="current == 0">
  8. <!-- 售后对象 -->
  9. <u-cell title="需求编码" arrow-direction="down">
  10. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  11. <u--input disabled style="flex:1" border="surround" v-model="form.code">
  12. </u--input>
  13. </view>
  14. </u-cell>
  15. <u-cell title="关联类型" arrow-direction="down" class="required-mark-new">
  16. <uni-data-picker :readonly="!isDisable" v-model="form.associationType" slot="value" placeholder="请选择"
  17. :localdata="associationTypeList" @change="associationTypeOnchange">
  18. </uni-data-picker>
  19. </u-cell>
  20. <u-cell title="需求名称" arrow-direction="down" class="required-mark-new">
  21. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  22. <u--input style="flex:1" :disabled="!isDisable" placeholder="请输入" border="surround"
  23. v-model="form.name">
  24. </u--input>
  25. </view>
  26. </u-cell>
  27. <u-cell title="客户名称" arrow-direction="down" class="required-mark-new">
  28. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  29. <u--input :disabled="!isDisable" style="flex:1" placeholder="请选择" border="surround"
  30. @click.native="selectContactShow" v-model="form.contactName">
  31. </u--input>
  32. </view>
  33. </u-cell>
  34. <u-cell v-if="form.associationType" :title="orderCodeName" arrow-direction="down" class="required-mark-new">
  35. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  36. <u--input :disabled="!isDisable" style="flex:1" placeholder="请选择" border="surround"
  37. @click.native="invoiceDialogOpen" v-model="form.orderCode">
  38. </u--input>
  39. </view>
  40. </u-cell>
  41. <u-cell title="报修地址" arrow-direction="down" class="required-mark-new">
  42. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  43. <u--input :disabled="!isDisable" style="flex:1" placeholder="请输入" border="surround"
  44. v-model="form.contactAddress">
  45. </u--input>
  46. </view>
  47. </u-cell>
  48. <u-cell title="故障等级" arrow-direction="down" class="required-mark-new">
  49. <uni-data-picker :readonly="!isDisable" v-model="form.faultLevel" slot="value" placeholder="请选择"
  50. :localdata="fault_level" @change="sourceCodeOnchange">
  51. </uni-data-picker>
  52. </u-cell>
  53. <u-cell title="期望解决时间" arrow-direction="down">
  54. <uni-datetime-picker :disabled="!isDisable" type="date" slot="value" v-model="form.expectedTime">
  55. </uni-datetime-picker>
  56. </u-cell>
  57. <u-cell title="售后类型" arrow-direction="down" class="required-mark-new">
  58. <uni-data-picker :readonly="!isDisable" v-model="form.afterSalesType" slot="value" placeholder="请选择"
  59. :localdata="after_sales_type">
  60. </uni-data-picker>
  61. </u-cell>
  62. <u-cell title="是否收费" arrow-direction="down" class="required-mark-new">
  63. <uni-data-picker v-if="isDisable" v-model="form.isFee" slot="value" placeholder="请选择"
  64. :localdata="chargeList">
  65. </uni-data-picker>
  66. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  67. :value="form.isFee==1?'是':'否'">
  68. </u--input>
  69. </u-cell>
  70. <u-cell title="是否带配件" arrow-direction="down" class="required-mark-new">
  71. <uni-data-picker v-if="isDisable" v-model="form.isWithAccessories" slot="value" placeholder="请选择"
  72. :localdata="chargeList">
  73. </uni-data-picker>
  74. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  75. :value="form.isWithAccessories==1?'是':'否'">
  76. </u--input>
  77. </u-cell>
  78. <u-cell title="是否派车" arrow-direction="down" class="required-mark-new">
  79. <uni-data-picker v-if="isDisable" v-model="form.isPieCar" slot="value" placeholder="请选择"
  80. :localdata="chargeList">
  81. </uni-data-picker>
  82. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  83. :value="form.isPieCar==1?'是':'否'">
  84. </u--input>
  85. </u-cell>
  86. <u-cell title="派车类型" arrow-direction="down" class="required-mark-new" v-if="form.isPieCar==1">
  87. <uni-data-picker v-if="isDisable" v-model="form.pieCarType" slot="value" placeholder="请选择"
  88. :localdata="pie_car_type">
  89. </uni-data-picker>
  90. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  91. :value="getTetx(form.pieCarType)">
  92. </u--input>
  93. </u-cell>
  94. <u-cell title="是否外包" arrow-direction="down" class="required-mark-new">
  95. <uni-data-picker v-if="isDisable" v-model="form.isOutsource" slot="value" placeholder="请选择"
  96. :localdata="chargeList">
  97. </uni-data-picker>
  98. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  99. :value="form.isOutsource==1?'是':'否'">
  100. </u--input>
  101. </u-cell>
  102. <u-cell title="是否生成采购订单" arrow-direction="down" class="required-mark-new">
  103. <uni-data-picker v-if="isDisable" v-model="form.isCreatePurchaseOrder" slot="value" placeholder="请选择"
  104. :localdata="chargeList">
  105. </uni-data-picker>
  106. <u--input v-else slot="value" style="flex:1" placeholder="请输入" disabled border="surround"
  107. :value="form.isCreatePurchaseOrder==1?'是':'否'">
  108. </u--input>
  109. </u-cell>
  110. <u-cell title="涉及事业部门" arrow-direction="down" class="required-mark-new" @click.native="salesDeptShow">
  111. <u--input slot="value" :disabled="!isDisable" style="pointer-events: none;" placeholder="请选择"
  112. border="surround" v-model="form.involveDeptName"></u--input>
  113. </u-cell>
  114. <u-cell title="备注说明" arrow-direction="down">
  115. <u--textarea border="surround" :disabled="!isDisable" placeholder=" " slot="value" v-model="form.remark"
  116. autoHeight></u--textarea>
  117. </u-cell>
  118. </u-cell-group>
  119. <AfterSales ref="salesRef" :type="type" v-show="current == 1" :afterSalesType="form.afterSalesType"
  120. :itemList="form.productDetail" />
  121. <!-- 方案列表 -->
  122. <SchemeList ref="schemeRef" v-show="current == 2" :type='type' :itemList="costListVOS" />
  123. <!-- 联系人 -->
  124. <ContactList ref="contactRef" :type="type" v-show="current == 3" :itemList="form.contactInfoVOS" />
  125. <view class="footerButton" v-if="isDisable">
  126. <u-button type="default" text="返回" @click="back"></u-button>
  127. <u-button type="primary" @click="save" text="保存"></u-button>
  128. </view>
  129. <view style="height:84rpx;width:100%">
  130. </view>
  131. <u-toast ref="uToast"></u-toast>
  132. <ba-tree-picker ref="treePicker" :multiple="false" @select-change="confirm" :localdata="listData" valueKey="id"
  133. textKey="name" childrenKey="children" />
  134. </view>
  135. </template>
  136. <script>
  137. import {
  138. getByCode
  139. } from '@/api/pda/common.js'
  140. import {
  141. contactDetail
  142. } from '@/api/saleManage/contact/index.js'
  143. import {
  144. saveSalesDemand,
  145. updateSalesDemand,
  146. getSalesDemandById
  147. } from '@/api/salesServiceManagement/demandList/index.js'
  148. import AfterSales from './components/AfterSales.vue'
  149. import ContactList from './components/contactList.vue'
  150. import SchemeList from '@/pages/salesServiceManagement/workOrder/components/schemeList.vue';
  151. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  152. import {
  153. listOrganizations,
  154. } from '@/api/myTicket/index.js'
  155. export default {
  156. components: {
  157. AfterSales,
  158. ContactList,
  159. SchemeList
  160. },
  161. computed: {
  162. isDisable() {
  163. let flag = this.type != 'view'
  164. return flag;
  165. },
  166. orderCodeName() {
  167. let name = this.associationTypeList.find(item => item.value === this.form.associationType)?.text || ''
  168. if (name === '客户') {
  169. return '产品'
  170. }
  171. return name
  172. }
  173. },
  174. data() {
  175. return {
  176. form: {
  177. tableList: [],
  178. contactInfoVOS: [],
  179. faultDetailList: [],
  180. associationType: '1',
  181. aftertype: '',
  182. salespersonName: '',
  183. salespersonId: '',
  184. isWithAccessories: 0,
  185. isFee: 0,
  186. isPieCar: 0,
  187. pieCarType: '',
  188. isOutsource: 0,
  189. isCreatePurchaseOrder: 0,
  190. supplierName: '',
  191. supplierId: '',
  192. supplierCode: '',
  193. involveDeptId: '',
  194. involveDeptName: '',
  195. remark: '',
  196. processInstanceId: '' // 新增流程实例ID字段
  197. },
  198. costListVOS: [],
  199. associationTypeList: [{
  200. value: '1',
  201. text: '发货单'
  202. },
  203. {
  204. value: '2',
  205. text: '销售订单'
  206. },
  207. {
  208. value: '3',
  209. text: '客户'
  210. }
  211. ],
  212. createUserName: '',
  213. list: ['基本信息', '售后对象', '方案', '联系人'],
  214. current: 0,
  215. fault_level: [],
  216. after_sales_type: [],
  217. chargeList: [{
  218. text: '是',
  219. value: 1
  220. },
  221. {
  222. text: '否',
  223. value: 0
  224. }
  225. ],
  226. partList: [{
  227. text: '是',
  228. value: 1
  229. },
  230. {
  231. text: '否',
  232. value: 0
  233. }
  234. ],
  235. carList: [{
  236. text: '是',
  237. value: 1
  238. },
  239. {
  240. text: '否',
  241. value: 0
  242. }
  243. ],
  244. title: '新增需求',
  245. type: 'add',
  246. listData: [],
  247. pie_car_type: []
  248. }
  249. },
  250. created() {
  251. },
  252. onLoad(params) {
  253. this.type = params.type;
  254. console.log(params.type, 'params.type')
  255. if (params.id) {
  256. this.title = params.type == 'view' ? '需求详情' : '修改需求'
  257. this.getDetails(params.id);
  258. } else {
  259. const userInfo = uni.getStorageSync('userInfo');
  260. this.createUserName = userInfo.name;
  261. this.getByCode();
  262. }
  263. // 客户数据
  264. uni.$off('setSelectList')
  265. uni.$on('setSelectList', (data) => {
  266. if (data && data.length > 0) {
  267. let res = data[0]
  268. this.$set(this.form, 'contactId', res.id);
  269. this.$set(this.form, 'contactName', res.name);
  270. this.contactDetail(res.id)
  271. // this.$forceUpdate();
  272. }
  273. })
  274. // 售后对象数据
  275. uni.$on('goosData', (data) => {
  276. this.$set(this.form, 'orderCode', data.orderCode);
  277. this.$set(this.form, 'orderId', data.orderId);
  278. console.log(data, 'data');
  279. let list = JSON.parse(JSON.stringify(data.tableList));
  280. console.log(list);
  281. // 如果计量数量没有的话默认是 1
  282. list.map(
  283. (el) =>
  284. (el.measureQuantity = el.measureQuantity ? el.measureQuantity : 1)
  285. );
  286. this.$set(this.form, 'productDetail', list);
  287. })
  288. listOrganizations(1).then(data => {
  289. this.listData = data
  290. })
  291. uni.$off('setProduceList')
  292. uni.$on('setProduceList', (data) => {
  293. console.log('data', data)
  294. let list = data.map((el) => {
  295. el.categoryCode = el.code;
  296. el.categoryName = el.name;
  297. el.categoryModel = el.modelType;
  298. el.productCategoryName = el.categoryLevelPath
  299. return el;
  300. });
  301. let params = {
  302. orderCode: list[0].categoryCode,
  303. orderId: list[0].id,
  304. tableList: list,
  305. };
  306. // this.tableList.push(...data)
  307. this.$set(this.form, 'orderCode', params.orderCode);
  308. this.$set(this.form, 'orderId', params.orderId);
  309. console.log(params, 'params');
  310. let listnew = JSON.parse(JSON.stringify(params.tableList));
  311. console.log(listnew);
  312. // 如果计量数量没有的话默认是 1
  313. listnew.map(
  314. (el) =>
  315. (el.measureQuantity = el.measureQuantity ? el.measureQuantity : 1)
  316. );
  317. this.$set(this.form, 'productDetail', listnew);
  318. })
  319. },
  320. onUnload() {
  321. uni.$off('setSelectList');
  322. uni.$off('goosData');
  323. uni.$off('setProduceList');
  324. },
  325. mounted() {
  326. },
  327. methods: {
  328. getTetx(val) {
  329. return this.pie_car_type.find(data => data.value == val)?.text
  330. },
  331. //选择部门
  332. salesDeptShow() {
  333. if (!this.isDisable) {
  334. return
  335. }
  336. this.$refs.treePicker._show()
  337. },
  338. // 查询详情
  339. async getDetails(id) {
  340. this.getByCode();
  341. const res = await getSalesDemandById(id);
  342. console.log('res', res.orderCode)
  343. let data = JSON.parse(JSON.stringify(res));
  344. console.log('data111', data.orderCode)
  345. data.pieCarType = data.pieCarType?.toString() || '';
  346. this.form = data;
  347. ['afterSalesType'].forEach(key => {
  348. this.$set(
  349. this.form,
  350. key,
  351. res[key].toString()
  352. );
  353. })
  354. this.costListVOS = this.form.costListVOS
  355. this.createUserName = data.createUserName;
  356. console.log(this.form, 'this.form')
  357. let obj = this.fault_level.find(el => el.value == res.faultLevel)
  358. let associationTypeObj = this.associationTypeList.find(el => el.value == res.associationType)
  359. this.form.associationType = associationTypeObj.value;
  360. if (res.faultLevel) {
  361. this.sourceCodeOnchange({
  362. "detail": {
  363. "value": [obj]
  364. }
  365. });
  366. }
  367. },
  368. sectionChange(index) {
  369. this.current = index;
  370. },
  371. selectContactShow() {
  372. if (!this.isDisable) {
  373. return
  374. }
  375. uni.navigateTo({
  376. url: `/pages/saleManage/components/selectContact?isAll=2&type=需求`
  377. })
  378. },
  379. //客户回调
  380. async contactDetail(id) {
  381. let {
  382. base,
  383. other,
  384. linkList
  385. } = await contactDetail(id);
  386. base.contactName = base.name;
  387. let addressName = '';
  388. if (other.addressName) {
  389. addressName += other.addressName;
  390. }
  391. if (other.address) {
  392. addressName += other.address;
  393. }
  394. this.form.contactCode = base.code;
  395. if (this.type != 'view') {
  396. this.$set(this.form, 'contactAddress', addressName);
  397. this.$set(
  398. this.form,
  399. 'contactInfoVOS',
  400. linkList.map((item) => {
  401. item['contactName'] = item.linkName;
  402. item['contactPhone'] = item.mobilePhone;
  403. item['telephone'] = item.phone;
  404. return item;
  405. })
  406. );
  407. // 清空发货单的数据 *** 初次进来不清空
  408. this.$set(this.form, 'orderCode', '');
  409. this.$set(this.form, 'orderId', '');
  410. this.$set(this.form, 'productDetail', []);
  411. }
  412. },
  413. sourceCodeOnchange(e) {
  414. const value = e.detail.value;
  415. this.form.faultLevel = value[0].value;
  416. },
  417. associationTypeOnchange(e) {
  418. const value = e.detail.value;
  419. this.form.associationType = value[0].value;
  420. this.form.orderCode = ''
  421. },
  422. invoiceDialogOpen() {
  423. if (!this.isDisable) {
  424. return
  425. }
  426. if (!this.form.contactId && this.form.associationType !== '3') {
  427. this.$refs.uToast.show({
  428. type: "warning",
  429. message: "请先选择客户",
  430. })
  431. return;
  432. }
  433. console.log(this.form.associationType)
  434. if (this.form.associationType === '3') {
  435. // uni.navigateTo({
  436. // url: '/pages/salesServiceManagement/demandList/components/product?contactId=' + this.form
  437. // .contactId + '&associationType=' + this.form.associationType
  438. // })
  439. uni.navigateTo({
  440. url: '/pages/saleManage/components/selectProduce?isAll=' + 0
  441. })
  442. } else {
  443. uni.navigateTo({
  444. url: '/pages/salesServiceManagement/demandList/components/Invoice?contactId=' + this.form
  445. .contactId + '&associationType=' + this.form.associationType
  446. })
  447. }
  448. },
  449. //部门回调
  450. confirm(data, name) {
  451. this.form.involveDeptName = name || ''
  452. this.form.involveDeptId = data[0] || ''
  453. console.log(this.form, 'this.form')
  454. },
  455. getByCode() {
  456. const codeS = ['fault_level', 'after_sales_type', 'pie_car_type']
  457. codeS.forEach(async (code) => {
  458. const codeValue = await getByCode(code);
  459. this[code] = codeValue.map(item => {
  460. const key = Object.keys(item)[0]
  461. return {
  462. value: key,
  463. text: item[key]
  464. }
  465. })
  466. })
  467. },
  468. save() {
  469. let data = JSON.parse(JSON.stringify(this.form));
  470. delete data.productDetail;
  471. try {
  472. if (!data.name) {
  473. this.$refs.uToast.show({
  474. type: "warning",
  475. message: "请输入需求名称",
  476. })
  477. return
  478. }
  479. if (!data.contactName) {
  480. this.$refs.uToast.show({
  481. type: "warning",
  482. message: "请选择客户名称",
  483. })
  484. return
  485. }
  486. if (!data.associationType) {
  487. this.$refs.uToast.show({
  488. type: "warning",
  489. message: "请选择关联类型",
  490. })
  491. return
  492. }
  493. if (data.isPieCar==1 && !data.pieCarType) {
  494. this.$refs.uToast.show({
  495. type: "warning",
  496. message: "请选择派车类型",
  497. })
  498. return
  499. }
  500. if (!data.orderCode && this.form.associationType !== '3') {
  501. const message = this.form.associationType === "1" ? "请选择发货单" : "请选择销售订单"
  502. this.$refs.uToast.show({
  503. type: "warning",
  504. message: message,
  505. })
  506. return
  507. }
  508. if (!data.contactAddress) {
  509. this.$refs.uToast.show({
  510. type: "warning",
  511. message: "请输入报修地址",
  512. })
  513. return
  514. }
  515. if (!data.faultLevel) {
  516. this.$refs.uToast.show({
  517. type: "warning",
  518. message: "请选择故障等级",
  519. })
  520. return
  521. }
  522. if (!data.afterSalesType) {
  523. this.$refs.uToast.show({
  524. type: "warning",
  525. message: "请选择售后类型",
  526. })
  527. return
  528. }
  529. if (!data.involveDeptName) {
  530. this.$refs.uToast.show({
  531. type: "warning",
  532. message: "请选择涉及事业部门",
  533. })
  534. return
  535. }
  536. let isMessage = [];
  537. [{
  538. name: '请选择是否收费',
  539. key: 'isFee'
  540. }, {
  541. name: '请选择是否带配件',
  542. key: 'isWithAccessories'
  543. }, {
  544. name: '请选择是否派车',
  545. key: 'isPieCar'
  546. }, {
  547. name: '请选择是否外包',
  548. key: 'isOutsource'
  549. }, {
  550. name: '请选择是否生成采购订单',
  551. key: 'isCreatePurchaseOrder'
  552. }].forEach(item => {
  553. if (data[item.key] != 1 && data[item.key] !== 0 && !isMessage.length) {
  554. console.log(item, 'item')
  555. isMessage.push(item)
  556. }
  557. })
  558. if (isMessage.length) {
  559. this.$refs.uToast.show({
  560. type: "warning",
  561. message: isMessage[0].name,
  562. })
  563. return
  564. }
  565. // 联系人数据
  566. let contactInfoVOS = this.$refs.contactRef.getTabData();
  567. if (contactInfoVOS.length == 0) {
  568. this.$refs.uToast.show({
  569. type: "warning",
  570. message: "至少需要存在一条联系人数据",
  571. })
  572. this.current = 2
  573. return
  574. }
  575. data.contactInfoVOS = this.$refs.contactRef.getTabData();
  576. // 售后对象数据
  577. let productDetail = this.$refs.salesRef.getTabData();
  578. data.productDetail = productDetail.map((item) => {
  579. item['produceTime'] = item['produceTime'] || null;
  580. return item;
  581. })
  582. data.costListVOS = this.$refs.schemeRef.getTabData()
  583. uni.showLoading({
  584. title: '加载中'
  585. })
  586. let requestname =
  587. this.type === 'add' ? saveSalesDemand : updateSalesDemand;
  588. requestname(data).then((res) => {
  589. uni.hideLoading()
  590. this.back()
  591. this.$refs.uToast.show({
  592. type: "success",
  593. message: "操作成功",
  594. })
  595. }).catch((e) => {
  596. uni.hideLoading()
  597. })
  598. } catch (error) {
  599. uni.hideLoading();
  600. }
  601. }
  602. },
  603. }
  604. </script>
  605. <style lang="scss" scoped>
  606. /deep/.u-subsection__item__text {
  607. font-size: 28rpx !important;
  608. }
  609. /deep/.u-cell__body__content {
  610. flex: none;
  611. margin-right: 16rpx;
  612. }
  613. /deep/.uni-textarea-textarea {
  614. color: red;
  615. }
  616. .footerButton {
  617. width: 100%;
  618. height: 84rpx;
  619. display: flex;
  620. position: fixed;
  621. bottom: 0;
  622. z-index: 10;
  623. background: #fff;
  624. /deep/.u-button {
  625. height: 100%;
  626. }
  627. >view {
  628. flex: 1;
  629. }
  630. }
  631. </style>