add.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-select');
  4. ?>
  5. <div id="app" v-cloak>
  6. <el-card shadow="never" style="border:0;min-width: 1200px;"
  7. body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  8. <div slot="header">
  9. <span>添加商品</span>
  10. </div>
  11. <el-form size="small" v-loading="loading" label-width="200px" ref="form">
  12. <el-card shadow="never" style="margin-top: 10px">
  13. <el-row>
  14. <el-col :span="20">
  15. <div>
  16. <el-form-item label="选择商品">
  17. <el-button type="primary" size="small" plain @click="onShowGoodsDialog(0)">添加商品
  18. </el-button>
  19. </el-form-item>
  20. </div>
  21. <div style="margin-top: 10px; clear: both;margin-left:200px">
  22. <el-row>
  23. <el-col :span="24">
  24. <el-checkbox v-model="selectAllChecked" @change="toggleSelectAll">全选</el-checkbox>
  25. <el-input style="width:200px;margin-left: 10px;" v-model="store_scale"
  26. placeholder="小店收益" size="small">
  27. </el-input>
  28. <el-input style="width:200px;margin-left: 10px;" v-model="min_num"
  29. placeholder="最低提货量" size="small">
  30. </el-input>
  31. <el-input style="width:200px;margin-left: 10px;" v-model="warn_day"
  32. placeholder="临期提醒" size="small">
  33. <template slot="append">天</template>
  34. </el-input>
  35. <el-button style="margin-left: 10px" size="small" type="default"
  36. @click="batchSetScale">统一设置
  37. </el-button>
  38. <el-button size="small" type="default" @click="batchDelete">批量删除
  39. </el-button>
  40. </el-col>
  41. </el-row>
  42. <div style="height: 20px"></div>
  43. <el-table ref="tableMain" :data="form.goods" border style="width: 100%"
  44. @selection-change="handleSelectionChange">
  45. <el-table-column type="selection" width="55">
  46. </el-table-column>
  47. <el-table-column type="index" label="序号" width="50">
  48. </el-table-column>
  49. <el-table-column prop="id" label="商品ID" width="80">
  50. <template slot-scope="scope">
  51. {{scope.row.goods_id}}
  52. </template>
  53. </el-table-column>
  54. <el-table-column prop="cover_pic" label="图片" width="101">
  55. <template slot-scope="scope">
  56. <el-image style="width: 80px; height: 80px;" :src="scope.row.cover_pic"
  57. fit="cover"></el-image>
  58. </template>
  59. </el-table-column>
  60. <el-table-column prop="goods_name" label="商品名称" width="200">
  61. <template slot-scope="scope">
  62. <div class="text-line-1">
  63. {{ scope.row.goods_name }}
  64. </div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="label_id" label="商品标签" width="130">
  68. <template slot-scope="scope">
  69. <div class="text-line-1">
  70. {{ goods_label_list[scope.row.label_id].name }}
  71. </div>
  72. </template>
  73. </el-table-column>
  74. <el-table-column prop="store_scale" label="小店收益">
  75. <template slot-scope="scope">
  76. <el-input-number :min="goods_label_list[scope.row.label_id].income_start"
  77. :max="goods_label_list[scope.row.label_id].income_end" v-model="scope.row.store_scale" size="small"></el-input-number>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="min_num" label="最低提货数量">
  81. <template slot-scope="scope">
  82. <el-input v-model="scope.row.min_num" size="small"></el-input>
  83. </template>
  84. </el-table-column>
  85. <el-table-column prop="warn_day" label="临期提醒">
  86. <template slot-scope="scope">
  87. <el-input v-model="scope.row.warn_day" size="small">
  88. <template slot="append">天</template>
  89. </el-input>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="操作" width="80">
  93. <template slot-scope="scope">
  94. <el-popconfirm @confirm="() => onRemoveGoods(scope.row, 0)"
  95. title="您真的要移除当前商品吗?">
  96. <el-button slot="reference" type="default" size="small" plain>删除
  97. </el-button>
  98. </el-popconfirm>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. </div>
  103. </el-col>
  104. </el-row>
  105. </el-card>
  106. <div style="padding: 10px 0">
  107. <el-button type="primary" :disabled="btnLoading" :loading="btnLoading" @click="store('form')">保存
  108. </el-button>
  109. </div>
  110. </el-form>
  111. <el-dialog title="添加商品" :visible.sync="goodsAddVisible" append-to-body>
  112. <el-form :inline="true">
  113. <div>
  114. <el-form-item>
  115. <el-input size="small" v-model="keyword" autocomplete="off"
  116. placeholder="请输入商品名称进行搜索"></el-input>
  117. </el-form-item>
  118. <el-form-item>
  119. <el-button type="primary" size="small" :disabled="btnLoading" :loading="btnLoading"
  120. @click="searchGoods(1)">
  121. 查找商品
  122. </el-button>
  123. </el-form-item>
  124. <el-form-item>
  125. <el-button type="danger" size="small" @click="onBatchAddGoods">批量添加</el-button>
  126. </el-form-item>
  127. </div>
  128. <div>
  129. <el-form-item>
  130. <el-checkbox-group v-model="freight_type">
  131. <el-checkbox key="1" :label="1">快递物流</el-checkbox>
  132. <el-checkbox key="3" :label="3">同城配送</el-checkbox>
  133. <el-checkbox key="2" :label="2">上门自提</el-checkbox>
  134. </el-checkbox-group>
  135. </el-form-item>
  136. </div>
  137. <div>
  138. <el-form-item label="商品标签">
  139. <el-select v-model="goods_label" size="small" placeholder="请选择">
  140. <el-option
  141. v-for="item in goods_label_list"
  142. :key="item.level"
  143. :label="item.name"
  144. :value="item.level">
  145. </el-option>
  146. </el-select>
  147. </el-form-item>
  148. </div>
  149. </el-form>
  150. <el-table :data="goods" border size="small" @selection-change="onChangeMultiGoods" style="width: 100%">
  151. <el-table-column type="selection" width="55"></el-table-column>
  152. <el-table-column prop="id" label="ID" width="80"></el-table-column>
  153. <el-table-column prop="cover_pic" label="商品图" width="180">
  154. <template slot-scope="scope">
  155. <com-image mode="aspectFill" :src="scope.row.cover_pic"></com-image>
  156. </template>
  157. </el-table-column>
  158. <el-table-column prop="name" label="商品名称">
  159. <template slot-scope="scope">
  160. <com-ellipsis :line="2">{{scope.row.goods_name}}</com-ellipsis>
  161. </template>
  162. </el-table-column>
  163. <el-table-column label="操作" width="200">
  164. <template slot-scope="scope">
  165. <el-button v-if="gSelected.indexOf(scope.row.id) == -1" plain size="mini" type="primary"
  166. @click="onPushGoods(scope.row)">添加
  167. </el-button>
  168. <el-button v-else plain size="mini" type="danger" title="点击移除商品"
  169. @click="onRemoveGoods(scope.row,currentGoods)">已添加
  170. </el-button>
  171. </template>
  172. </el-table-column>
  173. </el-table>
  174. <div slot="footer" class="dialog-footer">
  175. <el-pagination v-if="gPagination" background @current-change="searchGoods" layout="prev, pager, next"
  176. :page-count="gPageCount">
  177. </el-pagination>
  178. </div>
  179. </el-dialog>
  180. </el-card>
  181. </div>
  182. <script>
  183. const app = new Vue({
  184. el: '#app',
  185. data() {
  186. return {
  187. activeName: 'basic',
  188. loading: false,
  189. btnLoading: false,
  190. goods_label:'',
  191. goods_label_list:'',
  192. store_scale: '',
  193. min_num: '',
  194. warn_day:'',
  195. selectAllChecked: false,
  196. selectedRows: [],
  197. form: {
  198. goods: [],
  199. },
  200. freight_type: [1,2,3],
  201. goodsAddVisible: false,
  202. gPage: 1,
  203. keyword: '',
  204. goods: [],
  205. gPageCount: 0,
  206. gPagination: null,
  207. gSelected: [],
  208. currentGoods: 0,
  209. }
  210. },
  211. mounted: function () {
  212. this.getLabelList()
  213. },
  214. methods: {
  215. toggleSelectAll() {
  216. const table = this.$refs.tableMain;
  217. if (this.selectAllChecked) {
  218. table.toggleAllSelection(true);
  219. } else {
  220. table.clearSelection();
  221. }
  222. },
  223. handleSelectionChange(rows) {
  224. this.selectedRows = rows;
  225. this.selectAllChecked = rows.length === this.form.goods.length;
  226. },
  227. batchSetScale() {
  228. const selectedGoods = this.selectedRows;
  229. if (selectedGoods.length === 0) {
  230. this.$message.warning('请选择至少一个商品');
  231. return;
  232. }
  233. const store_scale = parseFloat(this.store_scale);
  234. if (isNaN(store_scale)) {
  235. this.$message.error('请输入有效的收益数值');
  236. return;
  237. }
  238. const min_num = parseFloat(this.min_num);
  239. if (isNaN(min_num)) {
  240. this.$message.error('请输入有效最低提货数量');
  241. return;
  242. }
  243. const warn_day = parseFloat(this.warn_day);
  244. if (isNaN(warn_day)) {
  245. this.$message.error('请输入有效的临期提醒');
  246. return;
  247. }
  248. selectedGoods.forEach(row => {
  249. row.store_scale = store_scale;
  250. row.min_num = min_num;
  251. row.warn_day = warn_day;
  252. });
  253. this.store_scale = ''; // 清空输入框
  254. this.min_num = ''; // 清空输入框
  255. this.warn_day = ''; // 清空输入框
  256. this.$forceUpdate()
  257. },
  258. batchDelete() {
  259. const selectedGoods = this.selectedRows;
  260. if (selectedGoods.length === 0) {
  261. this.$message.warning('请选择至少一个商品');
  262. return;
  263. }
  264. selectedGoods.forEach((row,index) => {
  265. this.onRemoveGoods(row, 0)
  266. });
  267. },
  268. onInput(e) {
  269. this.$forceUpdate();
  270. },
  271. onShowGoodsDialog(type) {
  272. this.currentGoods = type
  273. this.gSelected = []
  274. if (type === 0) {
  275. this.form.goods.forEach(item => {
  276. this.gSelected.push(parseInt(item.goods_id))
  277. })
  278. }
  279. this.searchGoods(1)
  280. this.goodsAddVisible = true
  281. },
  282. getLabelList()
  283. {
  284. Vue.$http.get('happiness/store-goods/goods-label', {
  285. }).then(res => {
  286. this.goods_label_list = res
  287. }).catch(err => {
  288. this.$message.error(err.val)
  289. })
  290. },
  291. searchGoods(page) {
  292. this.btnLoading = true;
  293. Vue.$http.get('happiness/store-goods/goods-search', {
  294. keyword: this.keyword,
  295. page: page,
  296. limit: 7
  297. }).then(res => {
  298. this.btnLoading = false;
  299. this.goods = res.list
  300. this.gPagination = res.pagination
  301. this.gPageCount = res.page_count
  302. }).catch(err => {
  303. this.btnLoading = false;
  304. this.$message.error(err.val)
  305. })
  306. },
  307. onBatchAddGoods() {
  308. if (this.gMulti.length > 0) {
  309. for (let i in this.gMulti) {
  310. if (this.gSelected.indexOf(this.gMulti[i].goods_id) == -1) {
  311. this.onPushGoods(this.gMulti[i])
  312. }
  313. }
  314. }
  315. },
  316. onChangeMultiGoods(rows) {
  317. this.gMulti = rows
  318. },
  319. onPushGoods(item) {
  320. if(this.goods_label=='')
  321. {
  322. this.$message.error('请选择商品标签');
  323. return
  324. }
  325. if(this.freight_type.length==0)
  326. {
  327. this.$message.error('请选择配送方式');
  328. return;
  329. }
  330. this.gSelected.push(item.id)
  331. if (this.currentGoods == 0) {
  332. this.form.goods.push({
  333. goods_id: item.id,
  334. cover_pic: item.cover_pic,
  335. goods_name: item.goods_name,
  336. label_id:this.goods_label,
  337. store_scale: 0,
  338. min_num: 0,
  339. warn_day: 0,
  340. freight_type:this.freight_type
  341. })
  342. }
  343. },
  344. onRemoveGoods(item, type) {
  345. this.gSelected = [];
  346. console.log("id")
  347. console.log(item)
  348. console.log(this.currentGoods)
  349. if (type === 0) {
  350. this.form.goods.forEach(be => {
  351. this.gSelected.push(parseInt(be.goods_id))
  352. })
  353. }
  354. let isHas = false;
  355. let gsid = parseInt(item.goods_id ? item.goods_id : item.id);
  356. let gindex = 0;
  357. this.gSelected.forEach((gs, index) => {
  358. if (gs === gsid) {
  359. isHas = true
  360. gindex = index
  361. }
  362. })
  363. if (isHas) {
  364. if (type === 0) {
  365. this.form.goods.splice(gindex, 1)
  366. }
  367. this.gSelected.splice(gindex, 1);
  368. }
  369. },
  370. // 操作处理
  371. handle(type, data = null) {
  372. var self = this
  373. this.$forceUpdate()
  374. },
  375. store(formName) {
  376. var self = this
  377. self.btnLoading = true;
  378. request({
  379. params: {
  380. r: 'happiness/store-goods/add',
  381. },
  382. method: 'post',
  383. data: self.form
  384. }).then(e => {
  385. self.btnLoading = false;
  386. if (e.data.code == 0) {
  387. self.$message.success(e.data.msg);
  388. navigateTo({r:'happiness/store-goods/index'})
  389. } else {
  390. self.$message.error(e.data.msg);
  391. }
  392. }).catch(e => {
  393. self.$message.error(e);
  394. self.btnLoading = false;
  395. })
  396. },
  397. }
  398. });
  399. </script>
  400. <style>
  401. .alone-goods {
  402. margin-top: 10px;
  403. clear: both;
  404. margin-left: 200px;
  405. }
  406. .alone-goods .alone-item {
  407. padding-right: 10px;
  408. float: left;;
  409. width: 50%;
  410. margin-bottom: 10px;
  411. }
  412. .alone-goods .alone-item:nth-child(2n) {
  413. padding-right: 0;
  414. }
  415. .alone-goods .alone-item .item-image {
  416. height: 80px;
  417. float: left;
  418. margin-right: 10px;
  419. }
  420. .alone-goods .item-card {
  421. padding: 10px;
  422. margin-bottom: 10px;
  423. overflow: hidden;
  424. }
  425. .form_box {
  426. background-color: #f3f3f3;
  427. padding: 0 0 20px;
  428. }
  429. .button-item {
  430. margin-top: 12px;
  431. padding: 9px 25px;
  432. }
  433. .el-input-group__append {
  434. background-color: #fff;
  435. color: #353535;
  436. }
  437. .el-form-item {
  438. margin-bottom: 25px !important;
  439. }
  440. .title {
  441. display: flex;
  442. align-items: center;
  443. padding: 18px 20px;
  444. /* border-top: 1px solid #F3F3F3; */
  445. border-bottom: 1px solid #F3F3F3;
  446. background-color: #fff;
  447. }
  448. .title-line {
  449. width: 4px;
  450. height: 20px;
  451. background-color: #1479F0;
  452. margin-right: 10px;
  453. }
  454. .paddingTop {
  455. margin-top: 10px;
  456. }
  457. .text-line-1 {
  458. white-space: nowrap;
  459. overflow: hidden;
  460. text-overflow: ellipsis;
  461. }
  462. </style>