add.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. let {
  200. base,
  201. other,
  202. linkList
  203. } = await contactDetail(id);
  204. base.contactName = base.name;
  205. let addressName = '';
  206. if (other.addressName) {
  207. addressName += other.addressName;
  208. }
  209. if (other.address) {
  210. addressName += other.address;
  211. }
  212. this.form.contactCode = base.code;
  213. if (this.type != 'view') {
  214. this.$set(this.form, 'contactAddress', addressName);
  215. this.$set(
  216. this.form,
  217. 'contactInfoVOS',
  218. linkList.map((item) => {
  219. item['contactName'] = item.linkName;
  220. item['contactPhone'] = item.mobilePhone;
  221. item['telephone'] = item.phone;
  222. return item;
  223. })
  224. );
  225. // 清空发货单的数据 *** 初次进来不清空
  226. this.$set(this.form, 'orderCode', '');
  227. this.$set(this.form, 'orderId', '');
  228. this.$set(this.form, 'productDetail', []);
  229. }
  230. },
  231. sourceCodeOnchange(e) {
  232. const value = e.detail.value;
  233. this.form.faultLevel = value[0].value;
  234. },
  235. invoiceDialogOpen() {
  236. if (!this.form.contactId) {
  237. this.$refs.uToast.show({
  238. type: "warning",
  239. message: "请先选择客户",
  240. })
  241. return;
  242. }
  243. uni.navigateTo({
  244. url: '/pages/salesServiceManagement/demandList/components/Invoice?contactId=' + this.form
  245. .contactId
  246. })
  247. },
  248. async getByCode() {
  249. const codeValue = await getByCode('fault_level');
  250. let list = codeValue.map(item => {
  251. const key = Object.keys(item)[0]
  252. return {
  253. value: key,
  254. text: item[key]
  255. }
  256. })
  257. this.fault_level = list;
  258. },
  259. save() {
  260. let data = JSON.parse(JSON.stringify(this.form));
  261. delete data.productDetail;
  262. try {
  263. if (!data.name) {
  264. this.$refs.uToast.show({
  265. type: "warning",
  266. message: "请输入需求名称",
  267. })
  268. return
  269. }
  270. if (!data.contactName) {
  271. this.$refs.uToast.show({
  272. type: "warning",
  273. message: "请选择客户名称",
  274. })
  275. return
  276. }
  277. if (!data.orderCode) {
  278. this.$refs.uToast.show({
  279. type: "warning",
  280. message: "请选择发货单",
  281. })
  282. return
  283. }
  284. if (!data.contactAddress) {
  285. this.$refs.uToast.show({
  286. type: "warning",
  287. message: "请输入报修地址",
  288. })
  289. return
  290. }
  291. if (!data.faultLevel) {
  292. this.$refs.uToast.show({
  293. type: "warning",
  294. message: "请选择故障等级",
  295. })
  296. return
  297. }
  298. // 联系人数据
  299. let contactInfoVOS = this.$refs.contactRef.getTabData();
  300. if (contactInfoVOS.length == 0) {
  301. this.$refs.uToast.show({
  302. type: "warning",
  303. message: "至少需要存在一条联系人数据",
  304. })
  305. this.current = 2
  306. return
  307. }
  308. data.contactInfoVOS = contactInfoVOS;
  309. // 售后对象数据
  310. let productDetail = this.$refs.salesRef.getTabData();
  311. data.productDetail = productDetail.map((item) => {
  312. item['produceTime'] = item['produceTime'] || null;
  313. return item;
  314. }),
  315. uni.showLoading({
  316. title: '加载中'
  317. })
  318. let requestname =
  319. this.type === 'add' ? saveSalesDemand : updateSalesDemand;
  320. requestname(data).then((res) => {
  321. uni.hideLoading()
  322. this.back()
  323. this.$refs.uToast.show({
  324. type: "success",
  325. message: "操作成功",
  326. })
  327. }).catch((e) => {
  328. console.log(e, '报错了')
  329. uni.hideLoading()
  330. })
  331. } catch (error) {
  332. uni.hideLoading();
  333. console.log(error, 'error');
  334. }
  335. }
  336. },
  337. }
  338. </script>
  339. <style lang="scss" scoped>
  340. /deep/.u-subsection__item__text {
  341. font-size: 28rpx !important;
  342. }
  343. /deep/.u-cell__body__content {
  344. flex: none;
  345. margin-right: 16rpx;
  346. }
  347. .footerButton {
  348. width: 100%;
  349. height: 84rpx;
  350. display: flex;
  351. position: fixed;
  352. bottom: 0;
  353. z-index: 10;
  354. /deep/.u-button {
  355. height: 100%;
  356. }
  357. >view {
  358. flex: 1;
  359. }
  360. }
  361. </style>