add.vue 14 KB

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