add.vue 8.7 KB

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