add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  59. <u--input style="flex:1" placeholder="请输入" disabled border="surround" v-model="createUserName">
  60. </u--input>
  61. </view>
  62. </u-cell>
  63. </u-cell-group>
  64. <AfterSales ref="salesRef" :type="type" v-show="current == 1" :itemList="form.productDetail" />
  65. <!-- 联系人 -->
  66. <ContactList ref="contactRef" :type="type" v-show="current == 2" :itemList="form.contactInfoVOS" />
  67. <view class="footerButton" v-if="isDisable">
  68. <u-button type="default" text="返回" @click="back"></u-button>
  69. <u-button type="primary" @click="save" text="保存"></u-button>
  70. </view>
  71. <u-toast ref="uToast"></u-toast>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. getByCode
  77. } from '@/api/pda/common.js'
  78. import {
  79. contactDetail
  80. } from '@/api/saleManage/contact/index.js'
  81. import {
  82. saveSalesDemand,
  83. updateSalesDemand,
  84. getSalesDemandById
  85. } from '@/api/salesServiceManagement/demandList/index.js'
  86. import AfterSales from './components/AfterSales.vue'
  87. import ContactList from './components/contactList.vue'
  88. export default {
  89. components: {
  90. AfterSales,
  91. ContactList
  92. },
  93. computed: {
  94. isDisable() {
  95. let flag = this.type != 'view'
  96. return flag;
  97. },
  98. orderCodeName() {
  99. let name = this.associationTypeList.find(item => item.value === this.form.associationType)?.text || ''
  100. if(name === '客户') {
  101. return '产品'
  102. }
  103. return name
  104. }
  105. },
  106. data() {
  107. return {
  108. form: {
  109. code: '',
  110. name: '',
  111. contactName: '',
  112. expectedTime: '',
  113. faultLevel: '',
  114. contactAddress: '',
  115. orderCode: '',
  116. productDetail: [],
  117. contactInfoVOS: [],
  118. contactCode: '',
  119. },
  120. associationTypeList: [
  121. {
  122. value: '1',
  123. text: '发货单'
  124. },
  125. {
  126. value: '2',
  127. text: '销售订单'
  128. },
  129. {
  130. value: '3',
  131. text: '客户'
  132. }
  133. ],
  134. createUserName: '',
  135. list: ['基本信息', '售后对象', '联系人'],
  136. current: 0,
  137. fault_level: [],
  138. title: '新增需求',
  139. type: 'add'
  140. }
  141. },
  142. created() {
  143. },
  144. onLoad(params) {
  145. this.type = params.type;
  146. if (params.id) {
  147. this.title = params.type == 'view' ? '需求详情' : '修改需求'
  148. this.getDetails(params.id);
  149. } else {
  150. const userInfo = uni.getStorageSync('userInfo');
  151. this.createUserName = userInfo.name;
  152. this.getByCode();
  153. }
  154. // 客户数据
  155. uni.$off('setSelectList')
  156. uni.$on('setSelectList', (data) => {
  157. if (data && data.length > 0) {
  158. let res = data[0]
  159. this.$set(this.form, 'contactId', res.id);
  160. this.$set(this.form, 'contactName', res.name);
  161. this.contactDetail(res.id)
  162. // this.$forceUpdate();
  163. }
  164. })
  165. // 售后对象数据
  166. uni.$on('goosData', (data) => {
  167. this.$set(this.form, 'orderCode', data.orderCode);
  168. this.$set(this.form, 'orderId', data.orderId);
  169. console.log(data, 'data');
  170. let list = JSON.parse(JSON.stringify(data.tableList));
  171. console.log(list);
  172. // 如果计量数量没有的话默认是 1
  173. list.map(
  174. (el) =>
  175. (el.measureQuantity = el.measureQuantity ? el.measureQuantity : 1)
  176. );
  177. this.$set(this.form, 'productDetail', list);
  178. })
  179. uni.$off('setProduceList')
  180. uni.$on('setProduceList', (data) => {
  181. console.log('data', data)
  182. let list = data.map((el) => {
  183. el.categoryCode = el.code;
  184. el.categoryName = el.name;
  185. el.categoryModel = el.modelType;
  186. return el;
  187. });
  188. let params = {
  189. orderCode: list[0].categoryCode,
  190. orderId: list[0].id,
  191. tableList: list,
  192. };
  193. // this.tableList.push(...data)
  194. this.$set(this.form, 'orderCode', params.orderCode);
  195. this.$set(this.form, 'orderId', params.orderId);
  196. console.log(params, 'params');
  197. let listnew = JSON.parse(JSON.stringify(params.tableList));
  198. console.log(listnew);
  199. // 如果计量数量没有的话默认是 1
  200. listnew.map(
  201. (el) =>
  202. (el.measureQuantity = el.measureQuantity ? el.measureQuantity : 1)
  203. );
  204. this.$set(this.form, 'productDetail', listnew);
  205. })
  206. },
  207. onUnload() {
  208. uni.$off('setSelectList');
  209. uni.$off('goosData');
  210. uni.$off('setProduceList');
  211. },
  212. mounted() {
  213. },
  214. methods: {
  215. // 查询详情
  216. async getDetails(id) {
  217. this.getByCode();
  218. const res = await getSalesDemandById(id);
  219. console.log('res', res.orderCode)
  220. let data = JSON.parse(JSON.stringify(res));
  221. console.log('data111', data.orderCode)
  222. this.form = data;
  223. // this.$set(this.form, 'orderCode', data.orderCode);
  224. this.createUserName = data.createUserName;
  225. let obj = this.fault_level.find(el => el.value == res.faultLevel)
  226. let associationTypeObj = this.associationTypeList.find(el => el.value == res.associationType)
  227. this.form.associationType = associationTypeObj.value;
  228. if(res.faultLevel) {
  229. this.sourceCodeOnchange({
  230. "detail": {
  231. "value": [obj]
  232. }
  233. });
  234. }
  235. },
  236. sectionChange(index) {
  237. this.current = index;
  238. },
  239. selectContactShow() {
  240. uni.navigateTo({
  241. url: `/pages/saleManage/components/selectContact?isAll=2&type=需求`
  242. })
  243. },
  244. //客户回调
  245. async contactDetail(id) {
  246. let {
  247. base,
  248. other,
  249. linkList
  250. } = await contactDetail(id);
  251. base.contactName = base.name;
  252. let addressName = '';
  253. if (other.addressName) {
  254. addressName += other.addressName;
  255. }
  256. if (other.address) {
  257. addressName += other.address;
  258. }
  259. this.form.contactCode = base.code;
  260. if (this.type != 'view') {
  261. this.$set(this.form, 'contactAddress', addressName);
  262. this.$set(
  263. this.form,
  264. 'contactInfoVOS',
  265. linkList.map((item) => {
  266. item['contactName'] = item.linkName;
  267. item['contactPhone'] = item.mobilePhone;
  268. item['telephone'] = item.phone;
  269. return item;
  270. })
  271. );
  272. // 清空发货单的数据 *** 初次进来不清空
  273. this.$set(this.form, 'orderCode', '');
  274. this.$set(this.form, 'orderId', '');
  275. this.$set(this.form, 'productDetail', []);
  276. }
  277. },
  278. sourceCodeOnchange(e) {
  279. const value = e.detail.value;
  280. this.form.faultLevel = value[0].value;
  281. },
  282. associationTypeOnchange(e) {
  283. const value = e.detail.value;
  284. this.form.associationType = value[0].value;
  285. this.form.orderCode = ''
  286. },
  287. invoiceDialogOpen() {
  288. if (!this.form.contactId && this.form.associationType !== '3') {
  289. this.$refs.uToast.show({
  290. type: "warning",
  291. message: "请先选择客户",
  292. })
  293. return;
  294. }
  295. console.log(this.form.associationType)
  296. if(this.form.associationType === '3') {
  297. // uni.navigateTo({
  298. // url: '/pages/salesServiceManagement/demandList/components/product?contactId=' + this.form
  299. // .contactId + '&associationType=' + this.form.associationType
  300. // })
  301. uni.navigateTo({
  302. url: '/pages/saleManage/components/selectProduce?isAll=' + 0
  303. })
  304. } else {
  305. uni.navigateTo({
  306. url: '/pages/salesServiceManagement/demandList/components/Invoice?contactId=' + this.form
  307. .contactId + '&associationType=' + this.form.associationType
  308. })
  309. }
  310. },
  311. async getByCode() {
  312. const codeValue = await getByCode('fault_level');
  313. let list = codeValue.map(item => {
  314. const key = Object.keys(item)[0]
  315. return {
  316. value: key,
  317. text: item[key]
  318. }
  319. })
  320. this.fault_level = list;
  321. },
  322. save() {
  323. let data = JSON.parse(JSON.stringify(this.form));
  324. delete data.productDetail;
  325. try {
  326. if (!data.name) {
  327. this.$refs.uToast.show({
  328. type: "warning",
  329. message: "请输入需求名称",
  330. })
  331. return
  332. }
  333. if (!data.contactName) {
  334. this.$refs.uToast.show({
  335. type: "warning",
  336. message: "请选择客户名称",
  337. })
  338. return
  339. }
  340. if (!data.orderCode && this.form.associationType !== '3') {
  341. const message = this.form.associationType === "1" ? "请选择发货单" : "请选择销售订单"
  342. this.$refs.uToast.show({
  343. type: "warning",
  344. message: message,
  345. })
  346. return
  347. }
  348. if (!data.contactAddress) {
  349. this.$refs.uToast.show({
  350. type: "warning",
  351. message: "请输入报修地址",
  352. })
  353. return
  354. }
  355. if (!data.faultLevel) {
  356. this.$refs.uToast.show({
  357. type: "warning",
  358. message: "请选择故障等级",
  359. })
  360. return
  361. }
  362. // 联系人数据
  363. let contactInfoVOS = this.$refs.contactRef.getTabData();
  364. if (contactInfoVOS.length == 0) {
  365. this.$refs.uToast.show({
  366. type: "warning",
  367. message: "至少需要存在一条联系人数据",
  368. })
  369. this.current = 2
  370. return
  371. }
  372. data.contactInfoVOS = contactInfoVOS;
  373. // 售后对象数据
  374. let productDetail = this.$refs.salesRef.getTabData();
  375. data.productDetail = productDetail.map((item) => {
  376. item['produceTime'] = item['produceTime'] || null;
  377. return item;
  378. }),
  379. uni.showLoading({
  380. title: '加载中'
  381. })
  382. let requestname =
  383. this.type === 'add' ? saveSalesDemand : updateSalesDemand;
  384. requestname(data).then((res) => {
  385. uni.hideLoading()
  386. this.back()
  387. this.$refs.uToast.show({
  388. type: "success",
  389. message: "操作成功",
  390. })
  391. }).catch((e) => {
  392. uni.hideLoading()
  393. })
  394. } catch (error) {
  395. uni.hideLoading();
  396. }
  397. }
  398. },
  399. }
  400. </script>
  401. <style lang="scss" scoped>
  402. /deep/.u-subsection__item__text {
  403. font-size: 28rpx !important;
  404. }
  405. /deep/.u-cell__body__content {
  406. flex: none;
  407. margin-right: 16rpx;
  408. }
  409. .footerButton {
  410. width: 100%;
  411. height: 84rpx;
  412. display: flex;
  413. position: fixed;
  414. bottom: 0;
  415. z-index: 10;
  416. /deep/.u-button {
  417. height: 100%;
  418. }
  419. >view {
  420. flex: 1;
  421. }
  422. }
  423. </style>