add.vue 17 KB

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