add.vue 11 KB

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