retail_form.vue 29 KB

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