add.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. console.log(list);
  146. // 如果计量数量没有的话默认是 1
  147. list.map(
  148. (el) =>
  149. (el.measureQuantity = el.measureQuantity ? el.measureQuantity : 1)
  150. );
  151. this.$set(this.form, 'productDetail', list);
  152. })
  153. },
  154. onUnload() {
  155. uni.$off('setSelectList');
  156. uni.$off('goosData');
  157. },
  158. mounted() {
  159. },
  160. methods: {
  161. // 查询详情
  162. async getDetails(id) {
  163. this.getByCode();
  164. const res = await getSalesDemandById(id);
  165. let data = JSON.parse(JSON.stringify(res));
  166. this.form = data;
  167. this.createUserName = data.createUserName;
  168. let obj = this.fault_level.find(el => el.value == res.faultLevel)
  169. this.sourceCodeOnchange({
  170. "detail": {
  171. "value": [obj]
  172. }
  173. });
  174. },
  175. sectionChange(index) {
  176. this.current = index;
  177. },
  178. selectContactShow() {
  179. uni.navigateTo({
  180. url: `/pages/saleManage/components/selectContact?isAll=2&type=需求`
  181. })
  182. },
  183. //客户回调
  184. async contactDetail(id) {
  185. let {
  186. base,
  187. other,
  188. linkList
  189. } = await contactDetail(id);
  190. base.contactName = base.name;
  191. let addressName = '';
  192. if (other.addressName) {
  193. addressName += other.addressName;
  194. }
  195. if (other.address) {
  196. addressName += other.address;
  197. }
  198. this.form.contactCode = base.code;
  199. if (this.type != 'view') {
  200. this.$set(this.form, 'contactAddress', addressName);
  201. this.$set(
  202. this.form,
  203. 'contactInfoVOS',
  204. linkList.map((item) => {
  205. item['contactName'] = item.linkName;
  206. item['contactPhone'] = item.mobilePhone;
  207. item['telephone'] = item.phone;
  208. return item;
  209. })
  210. );
  211. // 清空发货单的数据 *** 初次进来不清空
  212. this.$set(this.form, 'orderCode', '');
  213. this.$set(this.form, 'orderId', '');
  214. this.$set(this.form, 'productDetail', []);
  215. }
  216. },
  217. sourceCodeOnchange(e) {
  218. const value = e.detail.value;
  219. this.form.faultLevel = value[0].value;
  220. },
  221. invoiceDialogOpen() {
  222. if (!this.form.contactId) {
  223. this.$refs.uToast.show({
  224. type: "warning",
  225. message: "请先选择客户",
  226. })
  227. return;
  228. }
  229. uni.navigateTo({
  230. url: '/pages/salesServiceManagement/demandList/components/Invoice?contactId=' + this.form
  231. .contactId
  232. })
  233. },
  234. async getByCode() {
  235. const codeValue = await getByCode('fault_level');
  236. let list = codeValue.map(item => {
  237. const key = Object.keys(item)[0]
  238. return {
  239. value: key,
  240. text: item[key]
  241. }
  242. })
  243. this.fault_level = list;
  244. },
  245. save() {
  246. let data = JSON.parse(JSON.stringify(this.form));
  247. delete data.productDetail;
  248. try {
  249. if (!data.name) {
  250. this.$refs.uToast.show({
  251. type: "warning",
  252. message: "请输入需求名称",
  253. })
  254. return
  255. }
  256. if (!data.contactName) {
  257. this.$refs.uToast.show({
  258. type: "warning",
  259. message: "请选择客户名称",
  260. })
  261. return
  262. }
  263. if (!data.orderCode) {
  264. this.$refs.uToast.show({
  265. type: "warning",
  266. message: "请选择发货单",
  267. })
  268. return
  269. }
  270. if (!data.contactAddress) {
  271. this.$refs.uToast.show({
  272. type: "warning",
  273. message: "请输入报修地址",
  274. })
  275. return
  276. }
  277. if (!data.faultLevel) {
  278. this.$refs.uToast.show({
  279. type: "warning",
  280. message: "请选择故障等级",
  281. })
  282. return
  283. }
  284. // 联系人数据
  285. let contactInfoVOS = this.$refs.contactRef.getTabData();
  286. if (contactInfoVOS.length == 0) {
  287. this.$refs.uToast.show({
  288. type: "warning",
  289. message: "至少需要存在一条联系人数据",
  290. })
  291. this.current = 2
  292. return
  293. }
  294. data.contactInfoVOS = contactInfoVOS;
  295. // 售后对象数据
  296. let productDetail = this.$refs.salesRef.getTabData();
  297. data.productDetail = productDetail.map((item) => {
  298. item['produceTime'] = item['produceTime'] || null;
  299. return item;
  300. }),
  301. uni.showLoading({
  302. title: '加载中'
  303. })
  304. let requestname =
  305. this.type === 'add' ? saveSalesDemand : updateSalesDemand;
  306. requestname(data).then((res) => {
  307. uni.hideLoading()
  308. this.back()
  309. this.$refs.uToast.show({
  310. type: "success",
  311. message: "操作成功",
  312. })
  313. }).catch((e) => {
  314. uni.hideLoading()
  315. })
  316. } catch (error) {
  317. uni.hideLoading();
  318. }
  319. }
  320. },
  321. }
  322. </script>
  323. <style lang="scss" scoped>
  324. /deep/.u-subsection__item__text {
  325. font-size: 28rpx !important;
  326. }
  327. /deep/.u-cell__body__content {
  328. flex: none;
  329. margin-right: 16rpx;
  330. }
  331. .footerButton {
  332. width: 100%;
  333. height: 84rpx;
  334. display: flex;
  335. position: fixed;
  336. bottom: 0;
  337. z-index: 10;
  338. /deep/.u-button {
  339. height: 100%;
  340. }
  341. >view {
  342. flex: 1;
  343. }
  344. }
  345. </style>