add.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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" 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. this.form = data;
  346. ['afterSalesType'].forEach(key => {
  347. this.$set(
  348. this.form,
  349. key,
  350. res[key].toString()
  351. );
  352. })
  353. this.costListVOS = this.form.costListVOS
  354. this.createUserName = data.createUserName;
  355. console.log(this.form, 'this.form')
  356. let obj = this.fault_level.find(el => el.value == res.faultLevel)
  357. let associationTypeObj = this.associationTypeList.find(el => el.value == res.associationType)
  358. this.form.associationType = associationTypeObj.value;
  359. if (res.faultLevel) {
  360. this.sourceCodeOnchange({
  361. "detail": {
  362. "value": [obj]
  363. }
  364. });
  365. }
  366. },
  367. sectionChange(index) {
  368. this.current = index;
  369. },
  370. selectContactShow() {
  371. if (!this.isDisable) {
  372. return
  373. }
  374. uni.navigateTo({
  375. url: `/pages/saleManage/components/selectContact?isAll=2&type=需求`
  376. })
  377. },
  378. //客户回调
  379. async contactDetail(id) {
  380. let {
  381. base,
  382. other,
  383. linkList
  384. } = await contactDetail(id);
  385. base.contactName = base.name;
  386. let addressName = '';
  387. if (other.addressName) {
  388. addressName += other.addressName;
  389. }
  390. if (other.address) {
  391. addressName += other.address;
  392. }
  393. this.form.contactCode = base.code;
  394. if (this.type != 'view') {
  395. this.$set(this.form, 'contactAddress', addressName);
  396. this.$set(
  397. this.form,
  398. 'contactInfoVOS',
  399. linkList.map((item) => {
  400. item['contactName'] = item.linkName;
  401. item['contactPhone'] = item.mobilePhone;
  402. item['telephone'] = item.phone;
  403. return item;
  404. })
  405. );
  406. // 清空发货单的数据 *** 初次进来不清空
  407. this.$set(this.form, 'orderCode', '');
  408. this.$set(this.form, 'orderId', '');
  409. this.$set(this.form, 'productDetail', []);
  410. }
  411. },
  412. sourceCodeOnchange(e) {
  413. const value = e.detail.value;
  414. this.form.faultLevel = value[0].value;
  415. },
  416. associationTypeOnchange(e) {
  417. const value = e.detail.value;
  418. this.form.associationType = value[0].value;
  419. this.form.orderCode = ''
  420. },
  421. invoiceDialogOpen() {
  422. if (!this.isDisable) {
  423. return
  424. }
  425. if (!this.form.contactId && this.form.associationType !== '3') {
  426. this.$refs.uToast.show({
  427. type: "warning",
  428. message: "请先选择客户",
  429. })
  430. return;
  431. }
  432. console.log(this.form.associationType)
  433. if (this.form.associationType === '3') {
  434. // uni.navigateTo({
  435. // url: '/pages/salesServiceManagement/demandList/components/product?contactId=' + this.form
  436. // .contactId + '&associationType=' + this.form.associationType
  437. // })
  438. uni.navigateTo({
  439. url: '/pages/saleManage/components/selectProduce?isAll=' + 0
  440. })
  441. } else {
  442. uni.navigateTo({
  443. url: '/pages/salesServiceManagement/demandList/components/Invoice?contactId=' + this.form
  444. .contactId + '&associationType=' + this.form.associationType
  445. })
  446. }
  447. },
  448. //部门回调
  449. confirm(data, name) {
  450. this.form.involveDeptName = name || ''
  451. this.form.involveDeptId = data[0] || ''
  452. console.log(this.form, 'this.form')
  453. },
  454. getByCode() {
  455. const codeS = ['fault_level', 'after_sales_type', 'pie_car_type']
  456. codeS.forEach(async (code) => {
  457. const codeValue = await getByCode(code);
  458. this[code] = codeValue.map(item => {
  459. const key = Object.keys(item)[0]
  460. return {
  461. value: key,
  462. text: item[key]
  463. }
  464. })
  465. })
  466. },
  467. save() {
  468. let data = JSON.parse(JSON.stringify(this.form));
  469. delete data.productDetail;
  470. try {
  471. if (!data.name) {
  472. this.$refs.uToast.show({
  473. type: "warning",
  474. message: "请输入需求名称",
  475. })
  476. return
  477. }
  478. if (!data.contactName) {
  479. this.$refs.uToast.show({
  480. type: "warning",
  481. message: "请选择客户名称",
  482. })
  483. return
  484. }
  485. if (!data.associationType) {
  486. this.$refs.uToast.show({
  487. type: "warning",
  488. message: "请选择关联类型",
  489. })
  490. return
  491. }
  492. if (!data.orderCode && this.form.associationType !== '3') {
  493. const message = this.form.associationType === "1" ? "请选择发货单" : "请选择销售订单"
  494. this.$refs.uToast.show({
  495. type: "warning",
  496. message: message,
  497. })
  498. return
  499. }
  500. if (!data.contactAddress) {
  501. this.$refs.uToast.show({
  502. type: "warning",
  503. message: "请输入报修地址",
  504. })
  505. return
  506. }
  507. if (!data.faultLevel) {
  508. this.$refs.uToast.show({
  509. type: "warning",
  510. message: "请选择故障等级",
  511. })
  512. return
  513. }
  514. if (!data.afterSalesType) {
  515. this.$refs.uToast.show({
  516. type: "warning",
  517. message: "请选择售后类型",
  518. })
  519. return
  520. }
  521. if (!data.involveDeptName) {
  522. this.$refs.uToast.show({
  523. type: "warning",
  524. message: "请选择涉及事业部门",
  525. })
  526. return
  527. }
  528. let isMessage = [];
  529. [{
  530. name: '请选择是否收费',
  531. key: 'isFee'
  532. }, {
  533. name: '请选择是否带配件',
  534. key: 'isWithAccessories'
  535. }, {
  536. name: '请选择是否派车',
  537. key: 'isPieCar'
  538. }, {
  539. name: '请选择是否外包',
  540. key: 'isOutsource'
  541. }, {
  542. name: '请选择是否生成采购订单',
  543. key: 'isCreatePurchaseOrder'
  544. }].forEach(item => {
  545. if (data[item.key] != 1 && data[item.key] !== 0 && !isMessage.length) {
  546. console.log(item, 'item')
  547. isMessage.push(item)
  548. }
  549. })
  550. if (isMessage.length) {
  551. this.$refs.uToast.show({
  552. type: "warning",
  553. message: isMessage[0].name,
  554. })
  555. return
  556. }
  557. // 联系人数据
  558. let contactInfoVOS = this.$refs.contactRef.getTabData();
  559. if (contactInfoVOS.length == 0) {
  560. this.$refs.uToast.show({
  561. type: "warning",
  562. message: "至少需要存在一条联系人数据",
  563. })
  564. this.current = 2
  565. return
  566. }
  567. data.contactInfoVOS = this.$refs.contactRef.getTabData();
  568. // 售后对象数据
  569. let productDetail = this.$refs.salesRef.getTabData();
  570. data.productDetail = productDetail.map((item) => {
  571. item['produceTime'] = item['produceTime'] || null;
  572. return item;
  573. })
  574. data.costListVOS = this.$refs.schemeRef.getTabData()
  575. uni.showLoading({
  576. title: '加载中'
  577. })
  578. let requestname =
  579. this.type === 'add' ? saveSalesDemand : updateSalesDemand;
  580. requestname(data).then((res) => {
  581. uni.hideLoading()
  582. this.back()
  583. this.$refs.uToast.show({
  584. type: "success",
  585. message: "操作成功",
  586. })
  587. }).catch((e) => {
  588. uni.hideLoading()
  589. })
  590. } catch (error) {
  591. uni.hideLoading();
  592. }
  593. }
  594. },
  595. }
  596. </script>
  597. <style lang="scss" scoped>
  598. /deep/.u-subsection__item__text {
  599. font-size: 28rpx !important;
  600. }
  601. /deep/.u-cell__body__content {
  602. flex: none;
  603. margin-right: 16rpx;
  604. }
  605. /deep/.uni-textarea-textarea {
  606. color: red;
  607. }
  608. .footerButton {
  609. width: 100%;
  610. height: 84rpx;
  611. display: flex;
  612. position: fixed;
  613. bottom: 0;
  614. z-index: 10;
  615. background: #fff;
  616. /deep/.u-button {
  617. height: 100%;
  618. }
  619. >view {
  620. flex: 1;
  621. }
  622. }
  623. </style>