add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar background-color="#157A2C" color="#fff" fixed="true" statusBar="true" left-icon="back"
  4. :title="this.form.id?'修改采购需求':'新建采购需求'" @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. <view slot="title" style="display: flex; align-items: center;">
  10. <text class="required-mark">*</text>
  11. 需求类型
  12. </view>
  13. <!-- <u--input slot="value" placeholder="请选择" border="surround" v-model="form.sourceType"
  14. @click.native="selectContactShow"></u--input> -->
  15. <!-- <u-picker :show="show" :columns="requirementSourceType" keyName="label"></u-picker> -->
  16. <uni-data-picker v-model="form.sourceType" slot="value" placeholder="请选择"
  17. :localdata="requirementSourceType" @change="sourceCodeOnchange">
  18. </uni-data-picker>
  19. </u-cell>
  20. <u-cell :title="'需求单名称'" arrow-direction="down">
  21. <view slot="title" style="display: flex; align-items: center;">
  22. <text class="required-mark">*</text>
  23. 需求单名称
  24. </view>
  25. <u--input slot="value" placeholder="请输入" border="surround" v-model="form.requirementName"></u--input>
  26. </u-cell>
  27. <u-cell :title="'需求部门'" arrow-direction="down">
  28. <view slot="title" style="display: flex; align-items: center;">
  29. <text class="required-mark">*</text>
  30. 需求部门
  31. </view>
  32. <!-- <u--input slot="value" placeholder="请输入" border="surround" v-model="form.requireDeptId"></u--input> -->
  33. <u--input slot="value" @click.native="classification" style="flex:1" border="surround"
  34. placeholder="请选择需求部门" v-model="form.requireDeptId">
  35. </u--input>
  36. </u-cell>
  37. <u-cell :title="'需求人'" arrow-direction="down">
  38. <view slot="title" style="display: flex; align-items: center;">
  39. <text class="required-mark">*</text>
  40. 需求人
  41. </view>
  42. <!-- <u--input slot="value" placeholder="请输入" border="requireUserId" v-model="form.name"></u--input> -->
  43. <u--input slot="value" style="flex:1" border="surround" v-model="form.requireUserId"
  44. placeholder="请选择需求人" @click.native="openSelector">
  45. </u--input>
  46. </u-cell>
  47. <u-cell title="销售合同" arrow-direction="down">
  48. <!-- <u--input slot="value" placeholder="请输入" border="requireUserId" v-model="form.name"></u--input> -->
  49. <u--input slot="value" style="flex:1" border="surround" v-model="form.requireUserId"
  50. placeholder="请选择需求人" @click.native="openSelector">
  51. </u--input>
  52. </u-cell>
  53. <u-cell title="销售订单" arrow-direction="down">
  54. <!-- <u--input slot="value" placeholder="请输入" border="requireUserId" v-model="form.name"></u--input> -->
  55. <u--input slot="value" style="flex:1" border="surround" v-model="form.requireUserId"
  56. placeholder="请选择需求人" @click.native="openSelector">
  57. </u--input>
  58. </u-cell>
  59. <u-cell title="是否接受拆单" arrow-direction="down">
  60. <uni-data-picker v-model="form.acceptUnpack" slot="value" placeholder="请选择"
  61. :localdata="[{text: '接受', value: '1'}, { text: '不接受', value: '0'}]" @change="sourceCodeOnchange">
  62. </uni-data-picker>
  63. <!-- <u--input slot="value" :disabled="true" placeholder="请输入" border="surround"
  64. v-model="form.responsibleName"></u--input> -->
  65. <!-- <u-radio-group
  66. v-model="form.acceptUnpack"
  67. placement="column"
  68. @change="groupChange"
  69. >
  70. <u-radio
  71. :customStyle="{marginBottom: '8px'}"
  72. v-for="(item, index) in radiolist1"
  73. :key="index"
  74. :label="item.name"
  75. :name="item.name"
  76. @change="radioChange"
  77. >
  78. </u-radio>
  79. </u-radio-group> -->
  80. </u-cell>
  81. <u-cell title="'用途" arrow-direction="down">
  82. <view slot="title" style="display: flex; align-items: center;">
  83. <text class="required-mark">*</text>
  84. 用途
  85. </view>
  86. <!-- <uni-data-picker v-model="form.useTo" slot="value" placeholder="请选择"
  87. :localdata="business_opport_code" @change="sourceCodeOnchange">
  88. </uni-data-picker> -->
  89. <u--textarea slot="value" placeholder="请输入" border="surround" v-model="form.useTo"></u--textarea>
  90. </u-cell>
  91. <u-cell title="附件" arrow-direction="down">
  92. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  93. <fileMain v-model="form.fileId"></fileMain>
  94. </view>
  95. </u-cell>
  96. <u-cell title="备注" arrow-direction="down">
  97. <u--textarea slot="value" placeholder="请输入" border="surround" v-model="form.remark"></u--textarea>
  98. </u-cell>
  99. </u-cell-group>
  100. <view class="footerButton">
  101. <u-button type="default" text="返回" @click="back"></u-button>
  102. <u-button type="primary" @click="save" text="保存"></u-button>
  103. </view>
  104. <produceList ref="produceListRef" v-show="current==1" :isTemporary="true"></produceList>
  105. <!-- <businessList ref="businessListRef" v-show="current==2"></businessList> -->
  106. <!-- <personnelList ref="personnelListRef" :linkList="linkList" v-show="current==3"></personnelList> -->
  107. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择部门"
  108. :selectedData="selectedData" :localdata="classificationList" valueKey="id" textKey="name"
  109. childrenKey="children" />
  110. <search-select ref="selector" v-model="form.requireUserId" :data-list="executorList" title="选择使用人" @change="onClose">
  111. </search-select>
  112. <u-toast ref="uToast"></u-toast>
  113. </view>
  114. </template>
  115. <script>
  116. // file:///D:/中赢/aiot-app/pages/warehouse/enterHouse/selectEnterType.vue
  117. import {
  118. getByCode
  119. } from '@/api/pda/common.js'
  120. import {
  121. contactDetail,
  122. } from '@/api/saleManage/contact/index.js'
  123. import {
  124. businessopportunitySave,
  125. getDetail
  126. } from '@/api/saleManage/businessOpportunity/index.js'
  127. import searchSelect from '@/pages/salesServiceManagement/accessory/components/searchSelect.vue';
  128. import produceList from '../components/produceList.vue'
  129. // import businessList from './components/businessList.vue'
  130. // import personnelList from './components/personnelList.vue'
  131. import fileMain from "@/pages/doc/index.vue"
  132. import { requirementSourceType } from '@/enum/dict'
  133. import {
  134. listOrganizations
  135. } from '@/api/salesServiceManagement/workOrder/index.js';
  136. import {
  137. toTreeData
  138. } from '@/utils/utils.js';
  139. import {
  140. getUserPage
  141. } from '@/api/common.js';
  142. export default {
  143. components: {
  144. produceList,
  145. // businessList,
  146. // personnelList,
  147. fileMain,
  148. searchSelect
  149. },
  150. data() {
  151. return {
  152. list: ['基本信息', '需求清单'],
  153. current: 0,
  154. show: false,
  155. requirementSourceType,
  156. classificationList: [],
  157. form: {
  158. id: '',
  159. receiveDate: null,
  160. remark: null,
  161. requireDeptId: '',
  162. requireDeptName: '',
  163. requireUserId: '',
  164. requireUserName: '',
  165. sourceCode: '',
  166. sourceId: '',
  167. sourceType: '',
  168. requirementName: '',
  169. saleContractName: '',
  170. saleContractNo: '',
  171. saleContractId: '',
  172. saleOrderId: '',
  173. saleOrderNo: '',
  174. files: [],
  175. acceptUnpack: 1,
  176. fileId: [] //附件集合
  177. },
  178. business_opport_code: [],
  179. linkList: [],
  180. selectedData: [], // 使用部门绑定值
  181. executorList: []
  182. }
  183. },
  184. created() {
  185. this.getByCode()
  186. },
  187. onLoad(data) {
  188. this.getTreeList()
  189. uni.$off('setSelectList')
  190. uni.$on('setSelectList', async (data) => {
  191. if (data && data.length > 0) {
  192. const {
  193. linkList
  194. } = await contactDetail(data[0].id)
  195. this.linkList = linkList
  196. this.$set(this.form, 'contactId', data[0].id);
  197. this.$set(this.form, 'contactName', data[0].name);
  198. }
  199. })
  200. if (data && data.id) {
  201. getDetail(data.id).then(async res => {
  202. this.form = res
  203. const {
  204. linkList
  205. } = await contactDetail(res.contactId)
  206. this.linkList = linkList
  207. this.$nextTick(() => {
  208. this.$refs.produceListRef.init(res.productList)
  209. this.$refs.businessListRef.init(res.competAnalysisList)
  210. this.$refs.personnelListRef.init(res.partyList)
  211. })
  212. })
  213. } else {
  214. const userInfo = uni.getStorageSync('userInfo')
  215. this.$set(this.form, 'responsibleId', userInfo.userId);
  216. this.$set(this.form, 'responsibleName', userInfo.name);
  217. }
  218. },
  219. onUnload() {
  220. uni.$off('setSelectList')
  221. // uni.$off('updatelinkList')
  222. },
  223. methods: {
  224. async getTreeList() {
  225. const data = await listOrganizations({});
  226. let treeList = toTreeData({
  227. data: data || [],
  228. idField: 'id',
  229. parentIdField: 'parentId'
  230. });
  231. this.classificationList = treeList;
  232. },
  233. // 打开部门弹窗
  234. classification() {
  235. this.$refs.treePicker._show();
  236. },
  237. // 使用部门选择
  238. confirm(id, name) {
  239. this.form.useDeptName = name;
  240. this.form.useDeptId = id[0];
  241. this.form.userId = '';
  242. this.form.userName = '';
  243. this.executorList = [];
  244. this.getUserList(id[0]);
  245. this.$refs.selector.clearSearchText();
  246. },
  247. // 打开使用人弹窗
  248. openSelector() {
  249. this.$refs.selector.open();
  250. },
  251. // 获取使用人数据
  252. async getUserList(id) {
  253. let params = {
  254. pageNum: 1,
  255. size: -1,
  256. groupId: id
  257. }
  258. try {
  259. const res = await getUserPage(params);
  260. let list = res.list && res.list.map((el) => {
  261. return {
  262. text: el.name,
  263. value: el.id
  264. }
  265. })
  266. this.executorList = list;
  267. } catch (error) {
  268. this.executorList = [];
  269. }
  270. },
  271. // 使用人选择
  272. onClose(item) {
  273. this.form.userName = item.text;
  274. },
  275. getByCode() {
  276. const codeS = ['business_opport_code']
  277. codeS.forEach(async (code) => {
  278. const codeValue = await getByCode(code);
  279. this[code] = codeValue.map(item => {
  280. const key = Object.keys(item)[0]
  281. return {
  282. value: key,
  283. text: item[key]
  284. }
  285. })
  286. })
  287. },
  288. selectContactShow() {
  289. uni.navigateTo({
  290. url: '/pages/saleManage/components/selectContact?isAll=' + 2
  291. })
  292. },
  293. sourceCodeOnchange(e) {
  294. const value = e.detail.value
  295. this.form.sourceCode = value.map(item => item.value).toString()
  296. this.form.sourceName = value.map(item => item.text).toString()
  297. },
  298. radioChange(e) {
  299. this.form.pricingWay = e.detail.value
  300. this.$nextTick(() => {
  301. this.$refs.produceListRef.getTotalPrice()
  302. })
  303. },
  304. sectionChange(index) {
  305. this.current = index;
  306. },
  307. async save() {
  308. try {
  309. if (!this.form.contactName) {
  310. this.$refs.uToast.show({
  311. type: "error",
  312. message: "请选择客户",
  313. })
  314. return
  315. }
  316. if (!this.form.name) {
  317. this.$refs.uToast.show({
  318. type: "error",
  319. message: "请输入商机名称",
  320. })
  321. return
  322. }
  323. if (!this.form.sourceCode) {
  324. this.$refs.uToast.show({
  325. type: "error",
  326. message: "请选择商机来源",
  327. })
  328. return
  329. }
  330. if (this.$refs.produceListRef.getValue().length == 0) {
  331. this.$refs.uToast.show({
  332. type: "error",
  333. message: "产品清单不能为空",
  334. })
  335. return;
  336. }
  337. uni.showLoading({
  338. title: '加载中'
  339. })
  340. const data = {
  341. opportunity: this.form,
  342. competAnalysisList: this.$refs.businessListRef.getValue(),
  343. partyList: this.$refs.personnelListRef.getValue(),
  344. productList: this.$refs.produceListRef.getValue()
  345. };
  346. businessopportunitySave(data)
  347. .then((id) => {
  348. uni.hideLoading()
  349. this.back()
  350. })
  351. .catch((e) => {
  352. uni.hideLoading()
  353. });
  354. } catch (error) {
  355. uni.hideLoading()
  356. console.log(error, 'error')
  357. }
  358. },
  359. }
  360. }
  361. </script>
  362. <style lang="scss" scoped>
  363. .required-mark {
  364. color: #FF3333;
  365. margin-right: 4rpx;
  366. }
  367. /deep/.u-cell__body__content {
  368. flex: none;
  369. margin-right: 16rpx;
  370. }
  371. .mainBox {
  372. padding-bottom: 84rpx;
  373. }
  374. .footerButton {
  375. width: 100%;
  376. height: 84rpx;
  377. display: flex;
  378. position: fixed;
  379. bottom: 0;
  380. z-index: 10;
  381. background-color: #fff;
  382. /deep/.u-button {
  383. height: 100%;
  384. }
  385. >view {
  386. flex: 1;
  387. }
  388. }
  389. /deep/.u-button {
  390. // height: 100%;
  391. }
  392. /deep/.u-subsection__item__text {
  393. font-size: 28rpx !important;
  394. }
  395. /deep/.uni-input-placeholder {
  396. font-size: 28rpx !important;
  397. }
  398. /deep/.selected-item {
  399. font-size: 28rpx !important;
  400. }
  401. /deep/.uni-input-input {
  402. font-size: 28rpx !important;
  403. }
  404. </style>