edit.php 18 KB

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