add.vue 14 KB

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