lj-uselocation.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. <!-- L1新仓位组件v0.0.2 -->
  2. <template>
  3. <van-popup
  4. v-model="visiblePopup"
  5. position="bottom"
  6. :style="{ height: '80%' }"
  7. get-container="body"
  8. class="lj-uselocation-popup"
  9. @closed="handleCloseWidget"
  10. >
  11. <div class="popup_body" :class="searchState ? 'searching':''">
  12. <van-search
  13. class="search-widget"
  14. v-model.trim="searchKeyWord"
  15. :placeholder="searchPlaceholder"
  16. show-action
  17. shape="round"
  18. @search="handleSearchNow(false, searchKeyWord)"
  19. >
  20. <template #left-icon>
  21. <div class="search-icon">
  22. <van-loading v-if="searchingState" type="spinner" size="18" color="#1989fa" />
  23. <i v-else class="iconfont icon-search" style="font-size: 18px; margin: auto;" @click="handleSearchNow(false, searchKeyWord)"></i>
  24. </div>
  25. </template>
  26. <template #right-icon v-if="!searchState">
  27. <div class="search-icon">
  28. <i class="iconfont icon-iconfontscan" style="font-size: 18px; margin: auto 3px; color: #1989fa" @click="hanldeScanLocation"></i>
  29. </div>
  30. </template>
  31. <template #action>
  32. <div class="search-right-action">
  33. <div v-if="searchState" class="search-child-btn" @click="handleCancelSearch">取消</div>
  34. <div v-else class="confirm-btn search-child-btn" @click="handleConfirm">确定</div>
  35. </div>
  36. </template>
  37. </van-search>
  38. <van-notice-bar mode="closeable" v-if="suggestStr" color="#1989fa" background="#ecf9ff" left-icon="info-o">{{ suggestStr }}</van-notice-bar>
  39. <div class="popup-main">
  40. <div class="material-widget" v-if="JSON.stringify(target) != '{}'" v-show="!searchState">
  41. <slot name="material" :targetname="targetName" :targetcode="targetCode" :title="isTypeName" :total="sumSeled">
  42. <van-cell
  43. class="material-cell"
  44. :title="targetCode"
  45. :label="targetName"
  46. >
  47. <template #icon>
  48. <i class="iconfont icon-huowu"></i>
  49. </template>
  50. <template #default>
  51. <div class="cell-right-part">
  52. <div class="title">{{ isTypeName }}</div>
  53. <div class="num" v-if="planqty > 0">{{ planqty | thousandSeparatorFilter }}</div>
  54. </div>
  55. </template>
  56. </van-cell>
  57. </slot>
  58. </div>
  59. <lj-uselocation-list
  60. ref="uselocation"
  61. :waretype="waretype"
  62. :searchmodel="searchState"
  63. :select-list="selectList"
  64. :loca-list="isShowLocaList"
  65. :finished="isFinished"
  66. :datatype="datatype"
  67. :selected-text="isSearchSelectedTitle"
  68. :selected-right-text="isSelectRightText"
  69. :canchoose-text="isCanchooseText"
  70. :canchoose-right-text="isSearchSelectRightText"
  71. @actionLoca="handleActionLoca"
  72. @loadMore="_fnOnloadMore"
  73. @change="autoComputAll"
  74. @showdetail="handleClickLoca"
  75. >
  76. <template slot="choose-right" slot-scope="data">
  77. <div class="cell-right-part">
  78. <template v-if="Number(waretype)">
  79. <template v-if="data.item[data.dtype.numberA] != 0 || data.item[data.dtype.numberB] != 0">
  80. <div class="num">{{ data.item[data.dtype.numberA] | thousandSeparatorFilter }}</div>
  81. <div class="num_label">{{ data.item[data.dtype.numberB] | thousandSeparatorFilter }}</div>
  82. </template>
  83. </template>
  84. <template v-else>
  85. <div class="num">{{ data.item[data.dtype.numberA] | thousandSeparatorFilter }}</div>
  86. </template>
  87. </div>
  88. </template>
  89. </lj-uselocation-list>
  90. </div>
  91. <lj-uselocation-detail
  92. v-if="detailState"
  93. ref="uselocationDetailWidget"
  94. :error="detailError"
  95. :title="detailKeyWord"
  96. :datatype="detailDatatype"
  97. :dataList="detail_mtrllist"
  98. :total="detailTotal"
  99. :storage="detailStorage"
  100. @loadMore="handleOnloadDetail(1)"
  101. ></lj-uselocation-detail>
  102. </div>
  103. </van-popup>
  104. </template>
  105. <script>
  106. import {Popup, Search, Cell, Skeleton, Stepper, Loading, NoticeBar } from "vant";
  107. import LjUselocationList from "./lj-uselocation-list"
  108. import LjUselocationDetail from "./lj-uselocation-detail"
  109. export default {
  110. components: {
  111. "van-popup": Popup,
  112. "van-search": Search,
  113. "van-cell": Cell,
  114. "van-skeleton": Skeleton,
  115. "van-stepper": Stepper,
  116. "van-loading": Loading,
  117. "van-notice-bar": NoticeBar,
  118. LjUselocationList,
  119. LjUselocationDetail
  120. },
  121. data() {
  122. return {
  123. searchKeyWord: "",
  124. searchKW: "", // 接口提交之用
  125. detailKeyWord: "", // 接口提交之用
  126. visiblePopup: false,
  127. searchState: false,
  128. searchingState: false, // 正在搜索
  129. selLoading: true, // 组件等待状态
  130. locaLoading: true, // 组件等待状态
  131. selectList: [], // 已选仓库-列表
  132. locaList: [], // 可选仓库-列表
  133. search_localist: [], // 搜索可选结果-列表
  134. detail_mtrllist: [], // 详情物料结果-列表
  135. sumSeled: 0,
  136. pageSize: 20, // 每页展示量
  137. pageIndex: 1, // 页码
  138. searchPageIndex: 1, // 搜索页码
  139. detailPageIndex: 1, // 详情页码
  140. selectedNow: [],
  141. detailState: false,
  142. detailTotal: 0, // 仓位存储种类数
  143. detailStorage: 0, // 仓位总存放量
  144. searchError: false, // 搜索列表错误状态
  145. // loadmoreError: false, // 加载更多错误状态
  146. detailError: false, // 详情错误状态
  147. // planQty: 0, // 计划出仓数
  148. targetValue: [], // 搜索库存条件
  149. actionType: 0, // 1:加,0:减
  150. finishState: false,
  151. searchFinishState: false,
  152. }
  153. },
  154. props: {
  155. /**操作类型:1:进仓,0:出仓 */
  156. searchPlaceholder: {
  157. type: String,
  158. default: "搜索仓位编码/仓位名称"
  159. },
  160. /**操作类型:1:进仓,0:出仓 */
  161. waretype: {
  162. type: Number/String,
  163. default: 1
  164. },
  165. /**已选仓库 */
  166. selected: {
  167. type: String,
  168. default: ""
  169. },
  170. //建议说明
  171. suggestStr:{
  172. type: String,
  173. default: ""
  174. },
  175. /**属性名 */
  176. datatype: {
  177. type: Object,
  178. default: function () {
  179. return {
  180. code: "lcode",
  181. name: "locacode",
  182. numberA: "notoutqty",
  183. numberB: "loca_qty",
  184. };
  185. }
  186. },
  187. /**详情属性名 */
  188. detailDatatype: {
  189. type: Object,
  190. default: function () {
  191. return {
  192. propA: "mtrlcode",
  193. propB: "mtrlname",
  194. propC: "notoutqty",
  195. propD: "unit",
  196. propE: "mtrltype",
  197. };
  198. }
  199. },
  200. apiName: {
  201. type: String,
  202. default: "GetL1APPNewLocation"
  203. },
  204. detailApiName: {
  205. type: String,
  206. default: "GetL1APPNewLocationDetail"
  207. },
  208. target: {
  209. type: Object,
  210. default: function () {
  211. return {}
  212. }
  213. },
  214. targetName: {
  215. type: String,
  216. default: ""
  217. },
  218. targetCode: {
  219. type: String,
  220. default: ""
  221. },
  222. storageid: {
  223. type: Number,
  224. default: 0
  225. },
  226. locationStr: {
  227. type: String,
  228. default: ""
  229. },
  230. planqty: {
  231. type: Number/String,
  232. default: 0
  233. },
  234. },
  235. created() {
  236. this.setPostCondition();
  237. },
  238. computed:{
  239. isTypeName() {
  240. return Number(this.waretype) ? '进仓' : '出仓';
  241. },
  242. isSelectRightText() {
  243. if (JSON.stringify(this.target) == "{}") {
  244. return Number(this.waretype) ? `进仓(${this.sumSeled})` : `出仓(${this.sumSeled})`;
  245. }
  246. return Number(this.waretype) ? `存放量(${this.sumSeled})` : `出仓量(${this.sumSeled})`;
  247. },
  248. isSearchSelectRightText() {
  249. return Number(this.waretype) ? '已存储/全部产品' : '已存储';
  250. },
  251. isCanchooseText() {
  252. return this.searchState ? '搜索结果-可选仓位' : '可选仓位';
  253. },
  254. isSearchSelectedTitle() {
  255. if (!this.searchState) return '已选仓位(' + this.selectList.length + ')';
  256. let num = 0;
  257. for (let i = 0; i < this.selectList.length; i++) {
  258. if (this.selectList[i].isMatch == true) {
  259. num++;
  260. }
  261. }
  262. return '搜索结果-已选仓位(' + num + ')'
  263. },
  264. isShowLocaList() {
  265. return this.searchState ? this.search_localist : this.locaList;
  266. },
  267. isFinished() {
  268. return this.searchState ? this.searchFinishState : this.finishState
  269. }
  270. },
  271. methods: {
  272. /**设置搜索物料条件 */
  273. setPostCondition() {
  274. this.targetValue = [];
  275. if (JSON.stringify(this.target) == "{}") return false;
  276. for (const key in this.target) {
  277. let obj = {};
  278. obj.lable = key;
  279. obj.value = this.target[key];
  280. this.targetValue.push(obj);
  281. }
  282. console.log("物料条件:==》", JSON.stringify(this.targetValue));
  283. },
  284. /**外用-开启组件-数据处理 */
  285. autoComputAll() {
  286. let sum = 0;
  287. for (let i = 0; i < this.selectList.length; i++) {
  288. sum = $lj.floatAdd(sum, this.selectList[i].value)
  289. }
  290. this.sumSeled = sum;
  291. },
  292. fnGetNewLocation(apiName, requestBody, callback, errorback) {
  293. let self = this;
  294. $lj.postLJRequest(apiName, requestBody, function(ret) {
  295. if (ret) {
  296. callback(ret);
  297. }
  298. }, function(ret) {
  299. if (errorback && !errorback(ret)) return false;
  300. }, true)
  301. },
  302. /**打开组件,数据处理 */
  303. open() {
  304. let self = this;
  305. this.visiblePopup = true;
  306. this.selectList = [];
  307. this.locaList = [];
  308. this.selectedNow = [];
  309. // this.planQty = Number(this.planqty);
  310. if (this.locationStr != "") {
  311. let selList = this.locationStr.split(";");
  312. console.log("selList==>", JSON.stringify(selList));
  313. let length = selList.length;
  314. for (let i = 0; i < length; i++) {
  315. if (selList[i] == "") continue;
  316. let obj = {};
  317. let val = selList[i].split(":");
  318. obj[this.datatype.name] = val[0];
  319. // obj[this.datatype.numberA] = Number(val[1]);
  320. obj.value = Number(val[1])
  321. obj.isMatch = true;
  322. this.selectList.push(obj);
  323. this.selectedNow.push(obj[this.datatype.name]);
  324. }
  325. /**计算总数 */
  326. this.autoComputAll();
  327. }
  328. // let sel_str = this.selectedNow.length ? this.selectedNow : "";
  329. // 打开组件,首次渲染
  330. let requestBody = {
  331. token: $lj.getStorage("token"),
  332. locaList: this.selectedNow,
  333. targetList: this.targetValue,
  334. storageid: this.storageid,
  335. keyword: "",
  336. pageindex: this.pageIndex,
  337. pagesize: this.pageSize,
  338. waretype: this.waretype
  339. };
  340. this.fnGetNewLocation(this.apiName, requestBody, function(ret) {
  341. if (ret.hasOwnProperty("selectedList") && ret.selectedList.length) {
  342. // 更新已选仓位信息
  343. let selList = JSON.parse(JSON.stringify(ret.selectedList));
  344. for (let i = 0; i < self.selectList.length; i++) {
  345. for (let j = selList.length - 1; j >= 0; j--) {
  346. if (self.selectList[i][self.datatype.name] == selList[j][self.datatype.name]) {
  347. self.selectList[i][self.datatype.code] = selList[j][self.datatype.code];
  348. self.selectList[i][self.datatype.numberA] = selList[j][self.datatype.numberA];
  349. if (self.waretype) { // 进仓
  350. self.selectList[i][self.datatype.numberB] = selList[j][self.datatype.numberB];
  351. }
  352. selList.splice(j, 1);
  353. }
  354. }
  355. }
  356. }
  357. self.$refs.uselocation.selFirstDone();
  358. if (ret.hasOwnProperty("locaList")) {
  359. // 对已存量排序,预设仓位进行升序,其他仓位降序
  360. ret.locaList.sort(function sortNum(a,b) {
  361. return a.ifmy ? a.notoutqty - b.notoutqty : b.notoutqty - a.notoutqty;
  362. })
  363. for (let i = 0; i < ret.locaList.length; i++) {
  364. let obj = JSON.parse(JSON.stringify(ret.locaList[i]));
  365. let name = obj[self.datatype.name]
  366. obj.hasSel = false;
  367. // 是否已选
  368. if (self.selectedNow.indexOf(name) > -1) {
  369. obj.hasSel = true;
  370. }
  371. // 预设仓位前置
  372. obj.ifmy ? self.locaList.unshift(obj) : self.locaList.push(obj);
  373. }
  374. if (ret.locaList.length < self.pageSize) {
  375. self.$refs.uselocation && self.$refs.uselocation.loadDone(1);
  376. self.finishState = true;
  377. } else {
  378. self.pageIndex++;
  379. self.$refs.uselocation && self.$refs.uselocation.loadDone(0);
  380. self.finishState = false;
  381. }
  382. self.$refs.uselocation.locaFirstDone();
  383. }
  384. }, function(ret) {
  385. self.$refs.uselocation.selFirstDone();
  386. self.$refs.uselocation.locaFirstDone();
  387. self.$refs.uselocation.loadError();
  388. return true;
  389. });
  390. },
  391. /**取消搜索 */
  392. handleCancelSearch() {
  393. this.$refs.uselocation.selFirstLoading();
  394. this.$refs.uselocation.locaFirstLoading();
  395. setTimeout(() => {
  396. this.searchState = false;
  397. this.searchKeyWord = "";
  398. this.searchKW = "";
  399. this.searchPageIndex = 1;
  400. this.selectedNow = [];
  401. for (let i = 0; i < this.selectList.length; i++) {
  402. if (!this.selectList[i].isMatch) {
  403. this.selectList[i].isMatch = true;
  404. }
  405. this.selectedNow.push(this.selectList[i][this.datatype.name]);
  406. }
  407. console.log('handleCancelSearch this.selectedNow :>> ', JSON.stringify(this.selectedNow));
  408. this.$nextTick(() => {
  409. this.$refs.uselocation.selFirstDone();
  410. this.$refs.uselocation.locaFirstDone();
  411. this.$refs.uselocation.resetState();
  412. })
  413. }, 100);
  414. },
  415. /**搜索事件 */
  416. handleSearchNow(isScan, keyword) {
  417. if (keyword == "") {
  418. $lj.toast("请输入仓位编码或名称,进行搜索");
  419. return false;
  420. }
  421. let _keyWord = $lj.matchStorageQrCode(keyword);
  422. this.searchKW = _keyWord;
  423. this.searchingState = true;
  424. this.searchPageIndex = 1;
  425. this.search_localist = [];
  426. let name = this.datatype.name;
  427. let code = this.datatype.code;
  428. if (isScan) {
  429. // 扫描-先检查缓存
  430. let hasInSel = undefined;
  431. let hasIndex = -1;
  432. // 是否已添加在选择列表中
  433. let length = this.locaList.length;
  434. for (let i = 0; i < length; i++) {
  435. if (_keyWord == this.locaList[i][name] || _keyWord == this.locaList[i][code]) {
  436. hasIndex = i;
  437. hasInSel = this.locaList[i].hasSel;
  438. break;
  439. }
  440. }
  441. console.log("hasIndex", hasIndex);
  442. if (hasIndex > -1) {
  443. let obj = JSON.parse(JSON.stringify(this.locaList[hasIndex]));
  444. // 已在缓存中,判断添加过了没
  445. if (hasInSel){
  446. this._autoRefreshSelected(_keyWord);
  447. } else {
  448. // 已下载、但未添加,马上添加
  449. this.searchState = false;
  450. this.locaList[hasIndex].hasSel = true;
  451. this.handleActionLoca({type:1, item: obj});
  452. $lj.toast(`扫描成功,已添加${obj[name]}`, 1000, "bottom")
  453. }
  454. this.searchingState = false;
  455. return false;
  456. }
  457. if (this.selectedNow.length) {
  458. // 检测是否未缓存在locaList,但系已添加的列表
  459. hasIndex = this.selectedNow.indexOf(_keyWord);
  460. if (hasIndex > -1) {
  461. this._autoRefreshSelected(_keyWord);
  462. this.searchingState = false;
  463. return false;
  464. }
  465. }
  466. }
  467. let self = this;
  468. // 打开组件,首次渲染
  469. let requestBody = {
  470. token: $lj.getStorage("token"),
  471. locaList: "",
  472. targetList: this.targetValue,
  473. storageid: this.storageid,
  474. keyword: _keyWord,
  475. pageindex: this.searchPageIndex,
  476. pagesize: this.pageSize,
  477. waretype: this.waretype
  478. };
  479. this.fnGetNewLocation(this.apiName, requestBody, function(ret) {
  480. self.searchingState = false;
  481. if (isScan && ret.locaList.length == 1) {
  482. if (self.selectedNow.indexOf(ret.locaList[0][name]) > -1) {
  483. $lj.toast(`${ret.locaList[0][name]}已添加`, 1000, "bottom");
  484. return false;
  485. }
  486. self.handleActionLoca({type:1, item:ret.locaList[0]});
  487. $lj.toast(`扫描成功,已添加${ret.locaList[0][name]}`, 1000, "bottom")
  488. return false;
  489. }
  490. self.searchState = true;
  491. self.searchKeyWord = keyword;
  492. self.$refs.uselocation.selFirstLoading();
  493. self.$refs.uselocation.locaFirstLoading();
  494. setTimeout(() => {
  495. self.$nextTick(() => {
  496. for (let i = 0; i < self.selectList.length; i++) {
  497. if (self.selectList[i][name].indexOf(self.searchKW) > -1 || (self.selectList[i][code] && self.selectList[i][code].indexOf(self.searchKW) > -1)) {
  498. self.selectList[i].isMatch = true;
  499. } else {
  500. self.selectList[i].isMatch = false;
  501. }
  502. }
  503. for (let i = 0; i < ret.locaList.length; i++) {
  504. let obj = JSON.parse(JSON.stringify(ret.locaList[i]));
  505. let nameVal = obj[self.datatype.name]
  506. obj.hasSel = false;
  507. // 是否已选
  508. if (self.selectedNow.length > 0 && self.selectedNow.indexOf(nameVal) > -1) {
  509. obj.hasSel = true;
  510. }
  511. self.search_localist.push(obj);
  512. }
  513. if (ret.locaList.length < self.pageSize) {
  514. self.$refs.uselocation.loadDone(1);
  515. self.searchFinishState = true;
  516. } else {
  517. self.searchPageIndex++;
  518. self.$refs.uselocation.loadDone(0);
  519. self.searchFinishState = false;
  520. }
  521. if (!ret.locaList.length) {
  522. self.$refs.uselocation.setEmpty();
  523. return false;
  524. }
  525. self.$refs.uselocation.selFirstDone();
  526. self.$refs.uselocation.locaFirstDone();
  527. });
  528. }, 100);
  529. }, function(ret) {
  530. self.searchingState = false;
  531. self.$refs.uselocation.selFirstDone();
  532. self.$refs.uselocation.locaFirstDone();
  533. self.$refs.uselocation.loadError();
  534. return true;
  535. });
  536. },
  537. /**进入搜索状态,重置已选列表匹配状态 */
  538. _autoRefreshSelected(kw) {
  539. // 已下载,已添加
  540. this.searchState = true;
  541. this.searchKeyWord = kw;
  542. this.$nextTick(() => {
  543. for (let i = 0; i < this.selectList.length; i++) {
  544. if (this.selectList[i][this.datatype.name] == kw || this.selectList[i][this.datatype.code] == kw) {
  545. this.selectList[i].isMatch = true;
  546. } else {
  547. this.selectList[i].isMatch = false;
  548. }
  549. }
  550. });
  551. },
  552. /**扫描,调用摄像头 */
  553. hanldeScanLocation() {
  554. let self = this;
  555. $lj.openScanner((ret) => {
  556. setTimeout(() => {
  557. self.handleSearchNow(ret.content.trim());
  558. }, 200);
  559. })
  560. },
  561. /**关闭组件后调用 */
  562. handleCloseWidget() {
  563. this.$emit("closed");
  564. },
  565. /**确定事件-保存 */
  566. handleConfirm() {
  567. let location = [];
  568. let sum = 0;
  569. let location_str = "";
  570. for (let i = 0; i < this.selectList.length; i++) {
  571. if (this.selectList[i].value > 0) {
  572. let val = this.selectList[i].value.toString();
  573. if (val.indexOf(".") == -1) {
  574. val += ".";
  575. }
  576. location.push(`${this.selectList[i][this.datatype.name]}:${val}`);
  577. sum += Number(val);
  578. }
  579. }
  580. if (location.length) {
  581. location_str = location.join(";") + ";";
  582. } else {
  583. location_str = "";
  584. }
  585. this.$emit("confirm", {location_str, sum})
  586. this.visiblePopup = false;
  587. },
  588. /**点击添加或删除 */
  589. handleActionLoca({type, item}) {
  590. let obj;
  591. api.notification({
  592. vibrate:[50,50],
  593. });
  594. this.actionType = type;
  595. if (type) {
  596. // add
  597. if (this.searchState) {
  598. // 正在搜索
  599. /**如果已经在数据源中,则改变显示状态 */
  600. let name = item[this.datatype.name];
  601. let length = this.locaList.length;
  602. for (let i = 0; i < length; i++) {
  603. if (name == this.locaList[i][this.datatype.name]) {
  604. this.locaList[i].hasSel = true;
  605. // this.$set(this.locaList[i], 'hasSel', true);
  606. break;
  607. }
  608. }
  609. }
  610. item.hasSel = true;
  611. obj = JSON.parse(JSON.stringify(item));
  612. obj.value = 0;
  613. obj.isMatch = true;
  614. this.selectList.push(obj);
  615. this.selectedNow.push(obj[this.datatype.name]);
  616. } else {
  617. // del
  618. let name = item[this.datatype.name];
  619. // 改变正常状态-可选仓库状态
  620. for (let i = 0; i < this.locaList.length; i++) {
  621. if (name == this.locaList[i][this.datatype.name]) {
  622. this.locaList[i].hasSel = false;
  623. break;
  624. }
  625. }
  626. if (this.searchState) {
  627. if (!this.search_localist.length) {
  628. // 只有一个已选列表中结果时,自动按取消
  629. this.handleCancelSearch();
  630. } else {
  631. // 正在搜索
  632. // 改变搜索状态-可选仓库状态
  633. for (let j = 0; j < this.search_localist.length; j++) {
  634. if (name == this.search_localist[j][this.datatype.name]) {
  635. this.search_localist[j].hasSel = false;
  636. break;
  637. }
  638. }
  639. }
  640. }
  641. // 删除已选仓库列表
  642. if (this.selectedNow.length > 0 && this.selectedNow.indexOf(item[this.datatype.name]) > -1) {
  643. let delIndex = this.selectedNow.indexOf(item[this.datatype.name]);
  644. this.selectList.splice(delIndex, 1);
  645. this.selectedNow.splice(delIndex, 1);
  646. }
  647. }
  648. this.autoComputAll();
  649. },
  650. _fnOnloadMore() {
  651. if (this.searchState) {
  652. // 在搜索
  653. this.handleOnloadSearch();
  654. } else {
  655. this.handleOnload();
  656. }
  657. },
  658. /**加载更多 */
  659. handleOnload() {
  660. console.log("加载正常状态数据")
  661. let self = this;
  662. // 打开组件,首次渲染
  663. let requestBody = {
  664. token: $lj.getStorage("token"),
  665. locaList: "",
  666. targetList: this.targetValue,
  667. storageid: this.storageid,
  668. keyword: "",
  669. pageindex: this.pageIndex,
  670. pagesize: this.pageSize,
  671. waretype: this.waretype
  672. };
  673. this.fnGetNewLocation(this.apiName, requestBody, function(ret) {
  674. if (ret.hasOwnProperty("locaList")) {
  675. for (let i = 0; i < ret.locaList.length; i++) {
  676. let obj = JSON.parse(JSON.stringify(ret.locaList[i]));
  677. let name = obj[self.datatype.name]
  678. obj.hasSel = false;
  679. // 是否已选
  680. if (self.selectedNow.indexOf(name) > -1) {
  681. obj.hasSel = true;
  682. }
  683. self.locaList.push(obj);
  684. }
  685. if (ret.locaList.length < self.pageSize) {
  686. self.$refs.uselocation && self.$refs.uselocation.loadDone(1);
  687. self.finishState = true;
  688. } else {
  689. self.pageIndex++;
  690. self.$refs.uselocation && self.$refs.uselocation.loadDone(0);
  691. self.finishState = false;
  692. }
  693. }
  694. }, function(ret) {
  695. $lj.toast(ret.ErrMsg);
  696. self.$refs.uselocation.loadError();
  697. return true;
  698. });
  699. },
  700. /**搜索-加载更多 */
  701. handleOnloadSearch() {
  702. let self = this;
  703. // 打开组件,首次渲染
  704. let requestBody = {
  705. token: $lj.getStorage("token"),
  706. locaList: "",
  707. targetList: this.targetValue,
  708. storageid: this.storageid,
  709. keyword: this.searchKW,
  710. pageindex: this.searchPageIndex,
  711. pagesize: this.pageSize,
  712. waretype: this.waretype
  713. };
  714. this.fnGetNewLocation(this.apiName, requestBody, function(ret) {
  715. if (ret.hasOwnProperty("locaList")) {
  716. for (let i = 0; i < ret.locaList.length; i++) {
  717. let obj = JSON.parse(JSON.stringify(ret.locaList[i]));
  718. let name = obj[self.datatype.name]
  719. obj.hasSel = false;
  720. // 是否已选
  721. console.log('handleOnloadSearch self.selectedNow :>> ', JSON.stringify(self.selectedNow));
  722. if (self.selectedNow.indexOf(name) > -1) {
  723. obj.hasSel = true;
  724. }
  725. self.search_localist.push(obj);
  726. }
  727. if (ret.locaList.length < self.pageSize) {
  728. self.$refs.uselocation && self.$refs.uselocation.loadDone(1);
  729. self.searchFinishState = true;
  730. } else {
  731. self.searchPageIndex++;
  732. self.$refs.uselocation && self.$refs.uselocation.loadDone(0);
  733. self.searchFinishState = false;
  734. }
  735. }
  736. }, function(ret) {
  737. self.$refs.uselocation && self.$refs.uselocation.loadError();
  738. return false;
  739. });
  740. },
  741. /** 查看仓位详情 */
  742. handleClickLoca(data) {
  743. this.detailState = true;
  744. this.detailPageIndex = 1;
  745. this.detailKeyWord = data[this.datatype.name];
  746. this.detail_mtrllist = [];
  747. this.detailTotal = 0;
  748. this.detailStorage = 0;
  749. this.$nextTick(() => {
  750. this.$refs.uselocationDetailWidget.open();
  751. this.handleOnloadDetail(0);
  752. });
  753. },
  754. /**仓位存储详情列表 */
  755. handleOnloadDetail(type) {
  756. let self = this;
  757. // 打开组件,首次渲染
  758. let requestBody = {
  759. token: $lj.getStorage("token"),
  760. storageid: this.storageid,
  761. locacode: this.detailKeyWord,
  762. pageindex: this.detailPageIndex,
  763. pagesize: this.pageSize,
  764. };
  765. this.fnGetNewLocation(this.detailApiName, requestBody, function(ret) {
  766. self.detail_mtrllist = self.detail_mtrllist.concat(ret.mtrlList);
  767. if (ret.mtrlList.length < self.pageSize) {
  768. self.$refs.uselocationDetailWidget && self.$refs.uselocationDetailWidget.loadDone(1);
  769. } else {
  770. self.detailPageIndex++;
  771. self.$refs.uselocationDetailWidget && self.$refs.uselocationDetailWidget.loadDone(0);
  772. }
  773. if (!type) {
  774. self.detailTotal = ret.sum;
  775. self.detailStorage = ret.loca_qty;
  776. }
  777. }, function(ret) {
  778. self.$refs.uselocationDetailWidget.loadError();
  779. return false;
  780. });
  781. }
  782. },
  783. watch: {
  784. selectList: {
  785. handler(newVal, oldVal) {
  786. let obj;
  787. // add
  788. if (this.planqty > 0 && this.actionType) {
  789. let sum = this.planqty;
  790. this.actionType = false;
  791. for (let i = 0; i < newVal.length; i++) {
  792. if (newVal[i].value > 0) {
  793. sum = $lj.floatSub(sum, newVal[i].value);
  794. }
  795. if (i == newVal.length - 1) {
  796. let num = 0;
  797. if (!Number(this.waretype)) {
  798. // 出仓
  799. num = sum > Number(obj[this.datatype.numberA]) ? Number(obj[this.datatype.numberA]) : sum > 0 ? sum : 0;
  800. } else if (Number(this.waretype)) {
  801. // 进仓
  802. num = sum > Number(this.planqty) ? Number(this.planqty) : sum > 0 ? sum : 0;
  803. }
  804. this.$set(newVal[i], "value", num);
  805. sum = 0;
  806. }
  807. if (sum <= 0) break;
  808. }
  809. this.autoComputAll();
  810. }
  811. },
  812. deep: false
  813. }
  814. }
  815. }
  816. </script>
  817. <style lang="less">
  818. @import "~assets/css/lj-style-variable.less";
  819. .lj-uselocation-popup {
  820. border-top-left-radius: 12px;
  821. border-top-right-radius: 12px;
  822. .popup_body {
  823. background-color: #f2f2f2;
  824. display: flex;
  825. flex-direction: column;
  826. overflow: hidden;
  827. height: 100%;
  828. &.searching {
  829. background-color: #fff;
  830. }
  831. }
  832. .search-widget {
  833. flex-shrink: 0;
  834. position: relative;
  835. display: flex;
  836. padding: 5px 10px;
  837. &::after{
  838. content: "";
  839. position: absolute;
  840. bottom: 0;
  841. left: 10px;
  842. right: 10px;
  843. border-bottom: 1px solid #ddd;
  844. }
  845. .search-icon {
  846. display: flex;
  847. justify-content: center;
  848. align-items: center;
  849. }
  850. }
  851. .suggestion{
  852. margin: 5px 10px;
  853. color: @musePrimary;
  854. font-size: 14px;
  855. }
  856. .popup-main {
  857. position: relative;
  858. flex: 1;
  859. overflow: auto;
  860. }
  861. .van-search__action {
  862. padding: 0;
  863. }
  864. .search-right-action {
  865. flex-shrink: 0;
  866. display: flex;
  867. width: 50px;
  868. margin: 0 5px;
  869. .search-child-btn {
  870. width: 100%;
  871. height: inherit;
  872. text-align: center;
  873. border-radius: 8px;
  874. &.confirm-btn {
  875. background-color: @musePrimary;
  876. color: #ffffff;
  877. }
  878. }
  879. }
  880. .material-widget {
  881. padding: 5px 10px;
  882. .material-cell {
  883. padding: 5px;
  884. border-radius: 8px;
  885. // background-color: #E6F1FF;
  886. .iconfont {
  887. padding-right: 5px;
  888. display: flex;
  889. justify-content: center;
  890. align-items: center;
  891. }
  892. }
  893. }
  894. .cell-right-part {
  895. display: flex;
  896. flex-direction: column;
  897. .title {
  898. color: #999999;
  899. flex: 1;
  900. }
  901. .num {
  902. font-size: 14px;
  903. color: #333;
  904. font-weight: bold;
  905. }
  906. }
  907. }
  908. </style>