add.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back" :title="this.form.id?'修改商机':'新建商机'"
  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. <u-cell title="客户" arrow-direction="down">
  9. <u--input slot="value" placeholder="请选择" border="surround" v-model="form.contactName"
  10. @click.native="selectContactShow"></u--input>
  11. </u-cell>
  12. <u-cell title="商机名称" arrow-direction="down">
  13. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.name"></u--input>
  14. </u-cell>
  15. <u-cell title="负责人" arrow-direction="down">
  16. <u--input slot="value" :disabled="true" placeholder="请输入" border="surround"
  17. v-model="form.responsibleName"></u--input>
  18. </u-cell>
  19. <u-cell title="商机来源" arrow-direction="down">
  20. <uni-data-picker v-model="form.sourceCode" slot="value" placeholder="请选择"
  21. :localdata="business_opport_code" @change="sourceCodeOnchange">
  22. </uni-data-picker>
  23. </u-cell>
  24. <u-cell title="赢单率" arrow-direction="down">
  25. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  26. <u--input style="flex:1" type="number" max="100" min="0" placeholder="请输入" border="surround"
  27. v-model="form.winRate">
  28. </u--input>
  29. %
  30. </view>
  31. </u-cell>
  32. <u-cell title="预算" arrow-direction="down">
  33. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  34. <u--input style="flex:1" type="number" placeholder="请输入" border="surround" v-model="form.budget">
  35. </u--input>
  36. 万元
  37. </view>
  38. </u-cell>
  39. <u-cell title="预计结单日期" arrow-direction="down">
  40. <uni-datetime-picker type="date" slot="value" v-model="form.expectedClosingDate">
  41. </uni-datetime-picker>
  42. </u-cell>
  43. <u-cell title="计价方式" arrow-direction="down">
  44. <radio-group @change="radioChange" v-model="form.pricingWay" slot="value">
  45. <radio value="1" :checked="form.pricingWay==1">按数量计价</radio>
  46. <radio value="2" :checked="form.pricingWay==2">按重量计价</radio>
  47. </radio-group>
  48. </u-cell>
  49. <u-cell title="备注" arrow-direction="down">
  50. <u--textarea slot="value" placeholder="请输入" border="surround" v-model="form.remark"></u--textarea>
  51. </u-cell>
  52. </u-cell-group>
  53. <view class="footerButton">
  54. <u-button type="default" text="返回" @click="back"></u-button>
  55. <u-button type="primary" @click="save" text="保存"></u-button>
  56. </view>
  57. <produceList ref="produceListRef" v-show="current==1" :pricingWay="form.pricingWay"></produceList>
  58. <businessList ref="businessListRef" v-show="current==2"></businessList>
  59. <personnelList ref="personnelListRef" :linkList="linkList" v-show="current==3"></personnelList>
  60. <u-toast ref="uToast"></u-toast>
  61. </view>
  62. </template>
  63. <script>
  64. // file:///D:/中赢/aiot-app/pages/warehouse/enterHouse/selectEnterType.vue
  65. import {
  66. getByCode
  67. } from '@/api/pda/common.js'
  68. import {
  69. contactDetail,
  70. } from '@/api/saleManage/contact/index.js'
  71. import {
  72. businessopportunitySave,
  73. getDetail
  74. } from '@/api/saleManage/businessOpportunity/index.js'
  75. import produceList from '../components/produceList.vue'
  76. import businessList from './components/businessList.vue'
  77. import personnelList from './components/personnelList.vue'
  78. export default {
  79. components: {
  80. produceList,
  81. businessList,
  82. personnelList
  83. },
  84. data() {
  85. return {
  86. list: ['基本信息', '产品清单', '竞品', '关键人信息'],
  87. current: 0,
  88. form: {
  89. id: '',
  90. contactName: '',
  91. contactId: '',
  92. budget: null,
  93. expectedClosingDate: '',
  94. sourceCode: '',
  95. sourceName: '',
  96. stageCode: '',
  97. stageName: '',
  98. winRate: null,
  99. name: '',
  100. remark: '',
  101. responsibleName: '',
  102. responsibleId: '',
  103. source: '',
  104. status: 1,
  105. pricingWay: '1',
  106. files: []
  107. },
  108. business_opport_code: [],
  109. linkList: [],
  110. }
  111. },
  112. created() {
  113. this.getByCode()
  114. },
  115. onLoad(data) {
  116. uni.$off('setSelectList')
  117. uni.$on('setSelectList', async (data) => {
  118. if (data && data.length > 0) {
  119. const {
  120. linkList
  121. } = await contactDetail(data[0].id)
  122. this.linkList = linkList
  123. this.$set(this.form, 'contactId', data[0].id);
  124. this.$set(this.form, 'contactName', data[0].name);
  125. }
  126. })
  127. if (data && data.id) {
  128. getDetail(data.id).then(async res => {
  129. this.form = res
  130. const {
  131. linkList
  132. } = await contactDetail(res.contactId)
  133. this.linkList = linkList
  134. this.$nextTick(() => {
  135. this.$refs.produceListRef.init(res.productList)
  136. this.$refs.businessListRef.init(res.competAnalysisList)
  137. this.$refs.personnelListRef.init(res.partyList)
  138. })
  139. })
  140. } else {
  141. const userInfo = uni.getStorageSync('userInfo')
  142. this.$set(this.form, 'responsibleId', userInfo.userId);
  143. this.$set(this.form, 'responsibleName', userInfo.name);
  144. }
  145. },
  146. onUnload() {
  147. uni.$off('setSelectList')
  148. // uni.$off('updatelinkList')
  149. },
  150. methods: {
  151. getByCode() {
  152. const codeS = ['business_opport_code']
  153. codeS.forEach(async (code) => {
  154. const codeValue = await getByCode(code);
  155. this[code] = codeValue.map(item => {
  156. const key = Object.keys(item)[0]
  157. return {
  158. value: key,
  159. text: item[key]
  160. }
  161. })
  162. })
  163. },
  164. selectContactShow() {
  165. uni.navigateTo({
  166. url: '/pages/saleManage/components/selectContact?isAll=' + 2
  167. })
  168. },
  169. sourceCodeOnchange(e) {
  170. const value = e.detail.value
  171. this.form.sourceCode = value.map(item => item.value).toString()
  172. this.form.sourceName = value.map(item => item.text).toString()
  173. },
  174. radioChange(e) {
  175. this.form.pricingWay = e.detail.value
  176. this.$nextTick(()=>{
  177. this.$refs.produceListRef.getTotalPrice()
  178. })
  179. },
  180. sectionChange(index) {
  181. this.current = index;
  182. },
  183. async save() {
  184. console.log(this.$refs.produceListRef.getValue(), 'this.$refs.produceListRef.getValue()')
  185. try {
  186. if (!this.form.contactName) {
  187. this.$refs.uToast.show({
  188. type: "error",
  189. message: "请选择客户",
  190. })
  191. return
  192. }
  193. if (!this.form.name) {
  194. this.$refs.uToast.show({
  195. type: "error",
  196. message: "请输入商机名称",
  197. })
  198. return
  199. }
  200. if (!this.form.sourceCode) {
  201. this.$refs.uToast.show({
  202. type: "error",
  203. message: "请选择商机来源",
  204. })
  205. return
  206. }
  207. if (this.$refs.produceListRef.getValue().length == 0) {
  208. this.$message.warning('产品清单不能为空');
  209. return;
  210. }
  211. uni.showLoading({
  212. title: '加载中'
  213. })
  214. const data = {
  215. opportunity: this.form,
  216. competAnalysisList: this.$refs.businessListRef.getValue(),
  217. partyList: this.$refs.personnelListRef.getValue(),
  218. productList: this.$refs.produceListRef.getValue()
  219. };
  220. businessopportunitySave(data)
  221. .then((id) => {
  222. uni.hideLoading()
  223. this.back()
  224. })
  225. .catch((e) => {
  226. uni.hideLoading()
  227. });
  228. } catch (error) {
  229. uni.hideLoading()
  230. console.log(error, 'error')
  231. }
  232. },
  233. }
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. /deep/.u-cell__body__content {
  238. flex: none;
  239. margin-right: 16rpx;
  240. }
  241. .mainBox {
  242. padding-bottom: 84rpx;
  243. }
  244. .footerButton {
  245. width: 100%;
  246. height: 84rpx;
  247. display: flex;
  248. position: fixed;
  249. bottom: 0;
  250. z-index: 10;
  251. /deep/.u-button {
  252. height: 100%;
  253. }
  254. >view {
  255. flex: 1;
  256. }
  257. }
  258. /deep/.u-button {
  259. // height: 100%;
  260. }
  261. /deep/.u-subsection__item__text {
  262. font-size: 24rpx !important;
  263. }
  264. </style>