add.vue 9.5 KB

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