add.vue 19 KB

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