retail_form.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <div class="detail-container">
  3. <el-page-header @back="goBack" :content="listItem ? '编辑':'新增'"></el-page-header>
  4. <div class="main-title">
  5. <div class="title">订单信息</div>
  6. </div>
  7. <el-form ref="mainForm" :model="mainForm" :rules="mainFormRules" label-width="100px" size="small" label-position="right">
  8. <el-row :gutter="20">
  9. <el-col :xs="24" :sm="12" :lg="8">
  10. <el-form-item label="订单号" prop="orderNum">
  11. <el-input v-model="mainForm.orderNum" placeholder="系统自动生成" disabled></el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :xs="24" :sm="12" :lg="8" style="height: 51px;">
  15. <el-form-item label="单据日期" prop="date">
  16. <el-date-picker
  17. v-model="mainForm.date"
  18. disabled
  19. type="date"
  20. value-format="yyyy-MM-dd"
  21. style="width: 100%;"
  22. placeholder="系统自动生成">
  23. </el-date-picker>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :xs="24" :sm="12" :lg="8">
  27. <el-form-item label="业务员" prop="salesMan">
  28. <el-select v-model="mainForm.salesMan" placeholder="选择业务员" size="small" clearable style="width: 100%">
  29. <el-option
  30. v-for="item in outSalesmanList"
  31. :key="item.adminUserId"
  32. :label="item.nickName"
  33. :value="item.adminUserId">
  34. </el-option>
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. </el-row>
  39. <el-row :gutter="20">
  40. <el-col :xs="24" :sm="12" :lg="8">
  41. <el-form-item label="经销商编码" prop="jxsNum">
  42. <el-input v-model="mainForm.jxsNum" placeholder="请输入经销商编码" disabled></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="24" :sm="12" :lg="16">
  46. <el-form-item label="经销商名称" prop="jxsName">
  47. <el-input v-model="mainForm.jxsName" placeholder="请输入经销商名称" disabled></el-input>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :xs="24" :sm="24" :lg="24">
  51. <el-form-item label="表头备注" prop="remark">
  52. <el-input v-model="mainForm.remark" placeholder="请输入表头备注"></el-input>
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </el-form>
  57. <div class="main-title">
  58. <div class="title">货品信息</div>
  59. <div>
  60. <el-select v-model="warehouseValue" placeholder="请选择发货仓库" size="small" style="margin-right: 10px">
  61. <el-option :label="item.name" :value="item.id" v-for="(item, index) in warehouseList" :key="index"></el-option>
  62. </el-select>
  63. <el-button type="primary" size="small" icon="el-icon-search" @click="checkStock">检查库存</el-button>
  64. <el-divider direction="vertical"></el-divider>
  65. <el-button type="primary" size="small" icon="el-icon-plus" @click="openDialog">添加货品</el-button>
  66. </div>
  67. </div>
  68. <div class="table" style="margin-top: 20px">
  69. <el-table :data="goodsList" element-loading-text="Loading" border fit highlight-current-row stripe max-height="400">
  70. <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
  71. <el-table-column align="center" label="销售类型" prop="saleTypeName" min-width="100" show-overflow-tooltip></el-table-column>
  72. <el-table-column align="center" label="产品编码" prop="materialCode" min-width="100" show-overflow-tooltip></el-table-column>
  73. <el-table-column align="center" label="产品名称" prop="materialName" min-width="160" show-overflow-tooltip></el-table-column>
  74. <el-table-column align="center" label="规格型号" prop="specification" min-width="160" show-overflow-tooltip>
  75. <template slot-scope="scope">
  76. <el-input v-model="scope.row.specification" size="small" v-if="listItem"></el-input>
  77. <div v-else>{{scope.row.specification}}</div>
  78. </template>
  79. </el-table-column>
  80. <el-table-column align="center" label="单位" prop="unit" min-width="100" show-overflow-tooltip></el-table-column>
  81. <el-table-column align="center" label="单价" prop="price" min-width="100" show-overflow-tooltip>
  82. <template slot-scope="scope">
  83. <el-input v-model="scope.row.price" size="small" type="number" v-if="listItem && !isDealer"></el-input>
  84. <div v-else>{{scope.row.price}}</div>
  85. </template>
  86. </el-table-column>
  87. <el-table-column align="center" label="数量" prop="qty" min-width="100" show-overflow-tooltip>
  88. <template slot-scope="scope">
  89. <el-input v-model="scope.row.qty" size="small" type="number"></el-input>
  90. </template>
  91. </el-table-column>
  92. <el-table-column align="center" label="订单金额" min-width="100" show-overflow-tooltip>
  93. <template slot-scope="scope">
  94. {{scope.row.price * scope.row.qty}}
  95. </template>
  96. </el-table-column>
  97. <el-table-column align="center" label="返利类型" prop="customerWalletId2" min-width="160" show-overflow-tooltip>
  98. <template slot-scope="scope">
  99. <el-select v-model="scope.row.customerWalletId2" placeholder="选择返利类型" size="small" clearable @change="changeWallet(scope.$index)">
  100. <el-option
  101. v-for="item in scope.row.rebateWallets"
  102. :key="item.customerWalletId"
  103. :label="item.customerWalletName"
  104. :value="item.customerWalletId">
  105. </el-option>
  106. </el-select>
  107. </template>
  108. </el-table-column>
  109. <el-table-column align="center" label="使用返利金额" min-width="120" show-overflow-tooltip>
  110. <template slot-scope="scope">
  111. {{(scope.row.price * scope.row.qty * (scope.row.rebateRate * 100)) / 100}}
  112. </template>
  113. </el-table-column>
  114. <el-table-column align="center" label="格力折扣" min-width="100" show-overflow-tooltip>
  115. <template slot-scope="scope">
  116. {{scope.row.qty * scope.row.discAmount}}
  117. </template>
  118. </el-table-column>
  119. <el-table-column align="center" label="现金钱包" prop="customerWalletId" min-width="160" show-overflow-tooltip>
  120. <template slot-scope="scope">
  121. <el-select v-model="scope.row.customerWalletId" placeholder="选择现金钱包" size="small" clearable>
  122. <el-option
  123. v-for="item in scope.row.wallets"
  124. :key="item.customerWalletId"
  125. :label="item.customerWalletName"
  126. :value="item.customerWalletId">
  127. </el-option>
  128. </el-select>
  129. </template>
  130. </el-table-column>
  131. <el-table-column align="center" label="实付金额" prop="qty" min-width="100" show-overflow-tooltip>
  132. <template slot-scope="scope">
  133. {{((scope.row.price * scope.row.qty) * 100 - ((scope.row.price * scope.row.qty * (scope.row.rebateRate * 100)) / 100) * 100 - ((scope.row.qty * (scope.row.discAmount * 100)) / 100) * 100) / 100}}
  134. </template>
  135. </el-table-column>
  136. <el-table-column align="center" label="是否直调" prop="isDirectTransfer" min-width="100">
  137. <template slot-scope="scope">
  138. <el-checkbox v-model="scope.row.isDirectTransfer"></el-checkbox>
  139. </template>
  140. </el-table-column>
  141. <el-table-column align="center" label="直调数量" prop="directTransferQty" min-width="100"></el-table-column>
  142. <el-table-column align="center" label="备注" prop="remark" min-width="160">
  143. <template slot-scope="scope">
  144. <el-input v-model="scope.row.remark" size="small"></el-input>
  145. </template>
  146. </el-table-column>
  147. <el-table-column align="center" label="税率" prop="tax" min-width="100" show-overflow-tooltip></el-table-column>
  148. <el-table-column align="center" label="总仓库" prop="status1" min-width="100" show-overflow-tooltip v-if="!listItem">
  149. <template slot-scope="scope">
  150. <div>{{ scope.row.status1 | status1Filter }}</div>
  151. </template>
  152. </el-table-column>
  153. <el-table-column align="center" label="仓库状态" prop="status2" min-width="100" show-overflow-tooltip v-if="!listItem">
  154. <template slot-scope="scope">
  155. <div>{{ status2Filter(scope.row) }}</div>
  156. </template>
  157. </el-table-column>
  158. <el-table-column align="center" label="业务员" prop="serviceId" min-width="160" show-overflow-tooltip>
  159. <template slot-scope="scope">
  160. <el-select v-model="scope.row.serviceId" placeholder="选择业务员" size="small" clearable disabled>
  161. <el-option
  162. v-for="item in salesmanList"
  163. :key="item.adminUserId"
  164. :label="item.nickName"
  165. :value="item.adminUserId">
  166. </el-option>
  167. </el-select>
  168. </template>
  169. </el-table-column>
  170. <el-table-column align="center" label="操作" width="100" fixed="right">
  171. <template slot-scope="scope">
  172. <el-button type="text" @click="deleteItem(scope.$index)">删除</el-button>
  173. </template>
  174. </el-table-column>
  175. </el-table>
  176. </div>
  177. <div class="page-footer">
  178. <div class="footer">
  179. <el-button type="primary" @click="clickSubmitForm">保 存</el-button>
  180. <el-popconfirm title="确定关闭吗?" @onConfirm="goBack" style="margin-left: 10px;">
  181. <el-button slot="reference">关 闭</el-button>
  182. </el-popconfirm>
  183. </div>
  184. </div>
  185. <el-dialog title="添加产品" :visible.sync="isShowDialog" width="80%">
  186. <el-form ref="screenForm" :model="screenForm" size="small" label-position="left">
  187. <el-row :gutter="20">
  188. <!-- <el-col :xs="12" :sm="6" :lg="6">
  189. <el-form-item prop="type">
  190. <el-select v-model="mainForm.type" placeholder="选择产品大类" style="width: 100%" clearable :disabled="goodsList.length > 0 || rightGoodsList.length > 0">
  191. <el-option v-for="item in typeList" :key="item.dictCode" :label="item.dictValue" :value="item.dictCode"></el-option>
  192. </el-select>
  193. </el-form-item>
  194. </el-col> -->
  195. <el-col :xs="12" :sm="6" :lg="6">
  196. <el-form-item prop="salesType">
  197. <el-select v-model="screenForm.salesType" placeholder="选择销售类型" style="width: 100%" clearable>
  198. <el-option v-for="item in salesTypeList" :key="item.id" :label="item.saleName" :value="item.id"></el-option>
  199. </el-select>
  200. </el-form-item>
  201. </el-col>
  202. <el-col :xs="12" :sm="6" :lg="6">
  203. <el-form-item prop="proNum">
  204. <el-input v-model="screenForm.proNum" placeholder="请输入产品编码"></el-input>
  205. </el-form-item>
  206. </el-col>
  207. <el-col :xs="12" :sm="6" :lg="6">
  208. <el-form-item prop="proName">
  209. <el-input v-model="screenForm.proName" placeholder="请输入产品名称"></el-input>
  210. </el-form-item>
  211. </el-col>
  212. <el-col :xs="12" :sm="6" :lg="6">
  213. <el-form-item prop="proModel">
  214. <el-input v-model="screenForm.proModel" placeholder="请输入产品型号"></el-input>
  215. </el-form-item>
  216. </el-col>
  217. <el-col :xs="12" :sm="6" :lg="6">
  218. <el-form-item prop="price1" style="display: flex">
  219. <el-input v-model="screenForm.price1" placeholder="请输入价格" style="width: 46%"></el-input>
  220. <span> - </span>
  221. <el-input v-model="screenForm.price2" placeholder="请输入价格" style="width: 46%"></el-input>
  222. </el-form-item>
  223. </el-col>
  224. <el-col :xs="12" :sm="12" :lg="18" class="tr">
  225. <el-form-item label="">
  226. <el-button size="small" @click="resetScreenForm">清空</el-button>
  227. <el-button size="small" type="primary" @click="submitScreenForm">搜索</el-button>
  228. </el-form-item>
  229. </el-col>
  230. </el-row>
  231. </el-form>
  232. <div class="tables">
  233. <div class="table">
  234. <el-table :data="leftGoodsList" element-loading-text="Loading" border fit highlight-current-row stripe height="400" @selection-change="leftSelectionChange">
  235. <el-table-column align="center" type="selection" width="55" :selectable='checkboxSelect'></el-table-column>
  236. <el-table-column align="center" label="产品编码" prop="number" min-width="100" show-overflow-tooltip></el-table-column>
  237. <el-table-column align="center" label="产品名称" prop="name" min-width="160" show-overflow-tooltip></el-table-column>
  238. <el-table-column align="center" label="产品型号" prop="specification" min-width="160" show-overflow-tooltip></el-table-column>
  239. <el-table-column align="center" label="产品价格" prop="batchPrice" min-width="80" show-overflow-tooltip></el-table-column>
  240. </el-table>
  241. <div class="pagination clearfix" style="margin-top: 10px">
  242. <div class="fr">
  243. <el-pagination
  244. @current-change="handleTableCurrentChange"
  245. :current-page="currentPage"
  246. :page-size="10"
  247. background
  248. layout="prev, pager, next"
  249. :total="listTotal">
  250. </el-pagination>
  251. </div>
  252. </div>
  253. </div>
  254. <div class="buttons">
  255. <el-button size="small" type="primary" @click="addAllGoods">全部添加</el-button>
  256. <el-button size="small" type="primary" @click="addGoods">添&emsp;加</el-button>
  257. <el-button size="small" type="danger" @click="deleteGoods">删&emsp;除</el-button>
  258. <el-button size="small" type="danger" @click="deleteAllGoods">全部删除</el-button>
  259. </div>
  260. <div class="table">
  261. <el-table :data="rightGoodsList" element-loading-text="Loading" border fit highlight-current-row stripe height="400" @selection-change="rightSelectionChange">
  262. <el-table-column align="center" type="selection" width="55"></el-table-column>
  263. <el-table-column align="center" label="产品编码" prop="number" min-width="100" show-overflow-tooltip></el-table-column>
  264. <el-table-column align="center" label="产品名称" prop="name" min-width="160" show-overflow-tooltip></el-table-column>
  265. <el-table-column align="center" label="产品型号" prop="specification" min-width="160" show-overflow-tooltip></el-table-column>
  266. <el-table-column align="center" label="产品价格" prop="batchPrice" min-width="80" show-overflow-tooltip></el-table-column>
  267. </el-table>
  268. </div>
  269. </div>
  270. <span slot="footer" class="dialog-footer">
  271. <el-button @click="closeDialog">取 消</el-button>
  272. <el-button type="primary" @click="submitAddGoods">确 定</el-button>
  273. </span>
  274. </el-dialog>
  275. </div>
  276. </template>
  277. <script>
  278. import { getDetail, addData, editData, getSalesTypeList, getGoodsList, getWarehouseList, checkStock } from "@/api/supply/retail";
  279. import { getDictList, getSalesmanList } from '@/api/common'
  280. import { findElem } from '@/utils/util'
  281. let that
  282. export default {
  283. name: 'RetailForm',
  284. componentName: 'RetailForm',
  285. props: ['listItem'],
  286. filters: {
  287. status1Filter(val) {
  288. let STOCK_ORDER_START = that.stockList.find(o => o.dictCode == 'STOCK_ORDER_START').dictValue;
  289. let STOCK_ORDER_END = that.stockList.find(o => o.dictCode == 'STOCK_ORDER_END').dictValue;
  290. let STOCK_ORDER_HAVE_START = that.stockList.find(o => o.dictCode == 'STOCK_ORDER_HAVE_START').dictValue;
  291. let STOCK_ORDER_HAVE_END = that.stockList.find(o => o.dictCode == 'STOCK_ORDER_HAVE_END').dictValue;
  292. let STOCK_ORDER_ALL_NUM = that.stockList.find(o => o.dictCode == 'STOCK_ORDER_ALL_NUM').dictValue;
  293. if (val === '' || val === null || val === undefined) return '未检查';
  294. else if (val === 0) return '无货';
  295. else if (val > STOCK_ORDER_START && val <= STOCK_ORDER_END) return val;
  296. else if (val >= STOCK_ORDER_HAVE_START && val <= STOCK_ORDER_HAVE_END) return '有货';
  297. else if (val > STOCK_ORDER_ALL_NUM) return '充足';
  298. },
  299. },
  300. data() {
  301. return {
  302. mainForm: {
  303. orderNum: '',
  304. date: '',
  305. // type: '',
  306. jxsNum: '',
  307. jxsName: '',
  308. remark: '',
  309. salesMan: '',
  310. },
  311. mainFormRules: {
  312. // date: [
  313. // { required: true, message: '请选择单据日期', trigger: 'change' }
  314. // ],
  315. // type: [
  316. // { required: true, message: '请选择品类', trigger: 'change' }
  317. // ],
  318. },
  319. goodsList: [],
  320. warehouseList: [],
  321. warehouseValue: '',
  322. isShowDialog: false,
  323. screenForm: {
  324. type: '',
  325. salesType: '',
  326. proNum: '',
  327. proName: '',
  328. proModel: '',
  329. price1: '',
  330. price2: '',
  331. },
  332. currentPage: 1,
  333. listTotal: 0,
  334. salesTypeList: [],
  335. typeList: [],
  336. stockList: [],
  337. leftGoodsList: [],
  338. rightGoodsList: [],
  339. leftSelection: [],
  340. rightSelection: [],
  341. isFirst: false,
  342. salesmanList: [],
  343. }
  344. },
  345. computed: {
  346. isDealer() {
  347. return JSON.parse(localStorage.getItem("supply_user")).isCustomer;
  348. },
  349. outSalesmanList() {
  350. let list = [];
  351. if(this.goodsList && this.goodsList.length) {
  352. this.goodsList.forEach(item => {
  353. if(item.serviceId) {
  354. let hasItem = findElem(list, 'adminUserId', item.serviceId);
  355. if(hasItem < 0) {
  356. let obj = this.salesmanList.find(o => o.adminUserId == item.serviceId);
  357. list.push(obj);
  358. }
  359. }
  360. })
  361. if(this.isFirst) {
  362. this.isFirst = false;
  363. }else {
  364. this.mainForm.salesMan = this.goodsList[0].serviceId;
  365. }
  366. }
  367. return list
  368. }
  369. },
  370. beforeCreate() {
  371. that = this;
  372. },
  373. async created() {
  374. await this.getSalesmanList();
  375. this.getDictList();
  376. this.getWarehouseList();
  377. if(this.listItem) {
  378. this.isFirst = true;
  379. this.getDetail();
  380. }else {
  381. this.mainForm.jxsNum = JSON.parse(localStorage.getItem("supply_user")).customerNumber;
  382. this.mainForm.jxsName = JSON.parse(localStorage.getItem("supply_user")).customerName;
  383. }
  384. },
  385. methods: {
  386. // 返回列表
  387. goBack() {
  388. this.$emit('backListFormDetail');
  389. },
  390. // 获取详情
  391. getDetail() {
  392. getDetail({id: this.listItem.id}).then(res => {
  393. let data = res.data;
  394. this.mainForm.orderNum = data.id;
  395. this.mainForm.date = data.theTime.slice(0, 10);
  396. this.mainForm.salesMan = data.k3ServiceId;
  397. this.mainForm.jxsNum = data.customerNumber;
  398. this.mainForm.jxsName = data.customerName;
  399. this.mainForm.remark = data.remark;
  400. data.retailOrderItemList.forEach(item => {
  401. item.status1 = '';
  402. item.status2 = '';
  403. })
  404. this.goodsList = data.retailOrderItemList;
  405. })
  406. },
  407. // 获取仓库列表
  408. getWarehouseList() {
  409. getWarehouseList({
  410. pageNum: 1,
  411. pageSize: -1
  412. }).then((res) => {
  413. this.warehouseList = res.data.records;
  414. })
  415. },
  416. // 获取销售类型列表
  417. getSalesTypeList() {
  418. getSalesTypeList({
  419. pageNum: 1,
  420. pageSize: -1
  421. }).then((res) => {
  422. this.salesTypeList = res.data.records;
  423. })
  424. },
  425. getDictList() {
  426. // getDictList({sysDictEnum: 'PRODUCT_TYPE'}).then(res => {
  427. // this.typeList = res.data;
  428. // })
  429. getDictList({sysDictEnum: 'STOCK_ORDER'}).then(res => {
  430. this.stockList = res.data;
  431. })
  432. },
  433. async getSalesmanList() {
  434. const res = await getSalesmanList({
  435. pageNum: 1,
  436. pageSize: -1,
  437. isCustomer: 0,
  438. status: true,
  439. });
  440. this.salesmanList = res.data.records;
  441. },
  442. // 获取商品列表
  443. getGoodsList() {
  444. getGoodsList({
  445. pageNum: this.currentPage,
  446. pageSize: 10,
  447. // mainId: this.mainForm.type,
  448. saleId: this.screenForm.salesType,
  449. materialCode: this.screenForm.proNum,
  450. materialName: this.screenForm.proName,
  451. specification: this.screenForm.proModel,
  452. price1: this.screenForm.price1,
  453. price2: this.screenForm.price2,
  454. }).then(res => {
  455. let oldGoodsList = this.goodsList;
  456. let newGoodsList = res.data.records;
  457. for(let i = 0; i < oldGoodsList.length; i++) {
  458. let oldItem = oldGoodsList[i]
  459. for(let j = 0; j < newGoodsList.length; j++) {
  460. let newItem = newGoodsList[j]
  461. if(newItem.id === oldItem.id){
  462. newGoodsList[j].selected = true;
  463. break;
  464. }
  465. }
  466. }
  467. res.data.records.forEach(item => {
  468. item.materialName = item.name;
  469. item.materialCode = item.number;
  470. item.saleTypeName = item.saleName;
  471. item.unit = item.baseUnit;
  472. item.price = item.batchPrice;
  473. item.tax = item.taxRate;
  474. item.isDirectTransfer = false;
  475. item.directTransferQty = '';
  476. item.status1 = '';
  477. item.status2 = '';
  478. item.rebateAmount = '';
  479. item.rebateRate = '';
  480. item.productPriceId = item.id;
  481. item.customerWalletId = (item.wallets && item.wallets.length) ? item.wallets[0].customerWalletId : '';
  482. });
  483. this.leftGoodsList = res.data.records;
  484. this.listTotal = res.data.total;
  485. })
  486. },
  487. // 查询重复值并禁选
  488. checkboxSelect(row, rowIndex) {
  489. if (row.selected) {
  490. return false // 禁用
  491. }else{
  492. return true // 不禁用
  493. }
  494. },
  495. // 点击 选择商品
  496. openDialog() {
  497. this.getSalesTypeList();
  498. this.isShowDialog = true;
  499. // if(this.mainForm.type) {
  500. this.getGoodsList();
  501. // }
  502. },
  503. // 提交筛选表单
  504. submitScreenForm() {
  505. // if(!this.mainForm.type) {
  506. // return this.$errorMsg('请选择产品大类');
  507. // }
  508. this.currentPage = 1;
  509. this.getGoodsList();
  510. },
  511. // 重置筛选表单
  512. resetScreenForm() {
  513. this.$refs.screenForm.resetFields();
  514. this.currentPage = 1;
  515. this.getGoodsList();
  516. },
  517. // 更改列表当前页
  518. handleTableCurrentChange(val) {
  519. this.currentPage = val;
  520. this.getGoodsList();
  521. },
  522. // 关闭 弹窗
  523. closeDialog() {
  524. this.isShowDialog = false;
  525. },
  526. // 左侧列表选择
  527. leftSelectionChange(val) {
  528. this.leftSelection = val;
  529. },
  530. // 右侧列表选择
  531. rightSelectionChange(val) {
  532. this.rightSelection = val;
  533. },
  534. // 数组去重
  535. delRepeat(arr1, arr2) {
  536. let allArr = arr1.concat(arr2); // 两个数组对象合并
  537. let newArr = []; // 存放去重后数据的新数组
  538. for(let i=0; i<allArr.length; i++){ // 循环allArr数组对象的内容
  539. let flag = true; // 建立标记,判断数据是否重复,true为不重复
  540. for(let j=0; j<newArr.length; j++){ // 循环新数组的内容
  541. if(allArr[i].id == newArr[j].id){ // 让allArr数组对象的内容与新数组的内容作比较,相同的话,改变标记为false
  542. flag = false;
  543. }
  544. }
  545. if(flag){ // 判断是否重复
  546. newArr.push(allArr[i]); // 不重复的放入新数组。 新数组的内容会继续进行上边的循环。
  547. }
  548. }
  549. return newArr;
  550. },
  551. // 全部添加
  552. addAllGoods() {
  553. this.rightGoodsList = this.delRepeat(this.leftGoodsList, this.rightGoodsList);
  554. },
  555. // 添加
  556. addGoods() {
  557. this.rightGoodsList = this.delRepeat(this.leftSelection, this.rightGoodsList);
  558. },
  559. // 删除
  560. deleteGoods() {
  561. let rightGoodsList = this.rightGoodsList;
  562. let rightSelection = this.rightSelection;
  563. for(let i = 0; i < rightGoodsList.length; i++) {
  564. for(let j = 0; j < rightSelection.length; j++) {
  565. if(rightSelection[j].materialId == rightGoodsList[i].materialId){
  566. this.rightGoodsList.splice(i, 1);
  567. }
  568. }
  569. }
  570. },
  571. // 全部删除
  572. deleteAllGoods() {
  573. this.rightGoodsList = [];
  574. },
  575. // 确定 添加产品
  576. submitAddGoods() {
  577. this.goodsList = this.delRepeat(this.rightGoodsList, this.goodsList);
  578. this.isShowDialog = false;
  579. this.leftGoodsList = [];
  580. this.rightGoodsList = [];
  581. },
  582. // 删除产品
  583. deleteItem(index) {
  584. this.goodsList.splice(index, 1);
  585. },
  586. // 修改返利钱包
  587. changeWallet(index) {
  588. if(this.goodsList[index].customerWalletId2) {
  589. let obj = this.goodsList[index].rebateWallets.find(o => o.customerWalletId == this.goodsList[index].customerWalletId2);
  590. this.goodsList[index].rebateRate = obj.rebateRate;
  591. }else {
  592. this.goodsList[index].rebateRate = '';
  593. }
  594. },
  595. // 检查库存
  596. checkStock() {
  597. if(!this.warehouseValue) {
  598. return this.$errorMsg('请选择仓库');
  599. }
  600. if(!this.goodsList) {
  601. return this.$errorMsg('请添加货品');
  602. }
  603. let ids = [];
  604. this.goodsList.forEach(item => {
  605. ids.push(item.materialId);
  606. })
  607. checkStock({
  608. correspondId: this.warehouseValue,
  609. materialId: ids.join(',')
  610. }).then(res => {
  611. if(res.data) {
  612. this.goodsList.forEach((item, index) => {
  613. item.status1 = res.data[index].allStockNum;
  614. item.status2 = res.data[index].stockNum;
  615. })
  616. }
  617. })
  618. },
  619. status2Filter(item) {
  620. if (item.status2 === '' || item.status2 === null || item.status2 === undefined) return '未检查';
  621. else if (item.status2 >= item.qty) return '可用';
  622. else return '短缺';
  623. },
  624. // 保存
  625. clickSubmitForm() {
  626. this.$refs.mainForm.validate((valid) => {
  627. if (valid) {
  628. for(let i=0; i<this.goodsList.length; i++) {
  629. if(!this.goodsList[i].customerWalletId) {
  630. this.$errorMsg('请选择现金钱包');
  631. return;
  632. }
  633. }
  634. let goodsList = JSON.parse(JSON.stringify(this.goodsList));
  635. goodsList.forEach(item => {
  636. delete item.rebateWallets;
  637. delete item.wallets;
  638. })
  639. let saleManItem = this.mainForm.salesMan ? this.mainForm.salesManthis.outSalesmanList.find(o => o.adminUserId == this.mainForm.salesMan) : '';
  640. let params = {
  641. // theTime: this.mainForm.date + ' 00:00:00',
  642. // mainId: this.mainForm.type,
  643. // mainName,
  644. k3ServiceId: this.mainForm.salesMan,
  645. k3ServiceName: saleManItem.nickName,
  646. remark: this.mainForm.remark,
  647. type: 1, // 1:普通零售单,2:政策零售单
  648. retailOrderItemList: goodsList
  649. }
  650. if(this.listItem) {
  651. params.id = this.listItem.id;
  652. editData(params).then(res => {
  653. this.$successMsg('编辑成功');
  654. this.goBack();
  655. this.$parent.getList();
  656. })
  657. }else {
  658. addData(params).then(res => {
  659. this.$successMsg('添加成功');
  660. this.goBack();
  661. this.$parent.getList();
  662. })
  663. }
  664. }
  665. })
  666. },
  667. }
  668. }
  669. </script>
  670. <style scoped lang="scss">
  671. .detail-container {
  672. width: 100%;
  673. height: 100%;
  674. }
  675. .main-title {
  676. display: flex;
  677. justify-content: space-between;
  678. align-items: center;
  679. margin-top: 20px;
  680. height: 60px;
  681. border-bottom: 1px solid #DCDFE6;
  682. margin-bottom: 20px;
  683. .title {
  684. font-size: 16px;
  685. font-weight: 600;
  686. padding-left: 10px;
  687. }
  688. }
  689. .tables {
  690. display: flex;
  691. margin-top: 10px;
  692. .table {
  693. width: 45%;
  694. }
  695. .buttons {
  696. display: flex;
  697. flex-direction: column;
  698. justify-content: center;
  699. align-items: center;
  700. padding: 0 10px;
  701. button {
  702. margin: 0;
  703. margin-top: 10px;
  704. }
  705. }
  706. }
  707. </style>