add.vue 18 KB

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